Skip to content

Flyout: use theme default for position #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2025
Merged

Conversation

humitos
Copy link
Member

@humitos humitos commented Jan 8, 2025

Initial POC to prove if this idea is possible and how we feel about it.

I put together an example of what I understand we want to build here 😅 . In this example, the theme author will make explicitly how they want to use readthedocs-flyout HTML tag:

<readthedocs-flyout position="top-right"></readthedocs-flyout>

That will add the class top-right and show the flyout as follows:

Screenshot_2025-01-08_12-44-20

However, the project author can change the position value from the dashboard if they prefer to override the theme's default value:

Peek 2025-01-08 12-46

Initial POC to prove if this idea is possible and how we feel about it.

* Related #51
* Closes #434
@humitos humitos requested a review from a team as a code owner January 8, 2025 11:47
src/flyout.js Outdated
Comment on lines 53 to 55
this.position =
objectPath.get(this.config, "addons.flyout.position", null) ||
this.position;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems clearer to set this in an if, instead of resetting the value to itself?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.position =
objectPath.get(this.config, "addons.flyout.position", null) ||
this.position;
position = objectPath.get(this.config, "addons.flyout.position", null);
if position:
this.position = position;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reading is "get the value from the API or keep the actual one".

I don't have a strong preference, but happy to change it if wanted.

Copy link
Member

@ericholscher ericholscher Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel super strongly, but think it's more explicit. Setting a value to itself is odd to me?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

position is a reactive property, so it's best to avoid triggering unneeded updates to the property. Wrapping this with a conditional is probably best. Otherwise this pattern for setting variable defaults is pretty common though.

@humitos
Copy link
Member Author

humitos commented Jan 13, 2025

@agjohnson I would appreciate your review on this PR so we can decide whether or not move forward with this implementation.

src/flyout.js Outdated
Comment on lines 53 to 55
this.position =
objectPath.get(this.config, "addons.flyout.position", null) ||
this.position;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

position is a reactive property, so it's best to avoid triggering unneeded updates to the property. Wrapping this with a conditional is probably best. Otherwise this pattern for setting variable defaults is pretty common though.

@humitos humitos merged commit cae1273 into main Jan 14, 2025
4 checks passed
@humitos humitos deleted the humitos/theme-defaults branch January 14, 2025 10:14
humitos added a commit that referenced this pull request Jan 22, 2025
Initial POC to prove if this idea is possible and how we feel about it.

I put together an example of what I understand we want to build here 😅 .
In this example, the theme author will make explicitly how they want to
use `readthedocs-flyout` HTML tag:

```html
<readthedocs-flyout position="top-right"></readthedocs-flyout>
```

That will add the class `top-right` and show the flyout as follows:


![Screenshot_2025-01-08_12-44-20](https://github.com/user-attachments/assets/14ed7946-a1ab-4c44-84dc-d2a9ee456b8c)

However, the project author can change the `position` value from the
dashboard if they prefer to override the theme's default value:


![Peek 2025-01-08
12-46](https://github.com/user-attachments/assets/d8ab340b-2fc1-4704-ac0e-4a12bfe0ae07)

* Related #51
* Requires readthedocs/ext-theme#554
* Requires readthedocs/readthedocs.org#11891
* Example using
https://test-builds.readthedocs.io/en/addons-theme-defaults/
* Closes #434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement POC for theme default options
3 participants