-
Notifications
You must be signed in to change notification settings - Fork 2
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
Customization via CSS variables #282
base: main
Are you sure you want to change the base?
Conversation
In order to make the notifications box customizable when it comes to font-size, we need to ensure other aspects (like paddings, line-heights, etc) are changed accordingly as well.
…an :root For some reason, defining the initial CSS variable on :root doesn't work. The easy workaround (which also makes it a bit more flexible) is to define it on :host instead.
Should we have a specific variable for this? I don't know, maybe |
That's a good idea. But no, it's more a matter of going through every single design element in the search modal, determining how it should relate to the font-size (or some kind of a global variable) and making sure it works well with it. It's just a time-consuming process more than anything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this seems good. It is indeed a shame there isn't a way to reference the root shadow dom element using an absolute unit like rem
.
I will try to test this locally soon and merge after that. |
@zanderle @agjohnson how are you testing this? I added the following CSS and I'm not seeing any change: :host {
--readthedocs-flyout-font-size: 0.2rem;
--readthedocs-notification-font-size: 0.2rem;
--readthedocs-search-font-size: 0.2rem;
} |
Did you try setting those variables on |
Using html {
--readthedocs-flyout-font-size: 0.63rem; /* Material for MkDocs */
} @agjohnson Is this the correct way we want users to customize the sizes? One thing I noticed here is the branch icon doesn't scale accordingly with this setting: I found this because the size of this icon is bigger on Material for MkDocs than on Sphinx by default (same as the font), but changing the |
You can also set it on
Yes, I'll add that. Good catch. |
@zanderle can you tell me what are the steps you are following to test this? I'm having issues with. I'm not sure why sometimes it works and sometimes it doesn't. I may not be following the correct steps here. |
When I'm testing, I do it in developer tools, and create the variable on the element itself: |
OK, yeah. Testing it that way it works for me as well (and the SVG icon scales properly 👍🏼 ). However, it's still not clear to me how users should define these variables. We talked about defining them under @agjohnson how do we want users to define these variables? Can you provide an example about this? |
I opened #292 to track and work on this in a following PR 👍🏼 |
Yeah, I'm noticing it now too. Not sure about the "sometimes it works, sometimes it doesn't", but it looks like the css variable defined in the web-component using /* Using the element */
readthedocs-flyout {
--readthedocs-flyout-font-size: 1.2rem;
} or if we defined the webcomponent to have a specific class, we could do:
If that's not acceptable, I'll have to do some more research to see if I'm missing something |
So, all of these options should operate the same, they are all valid methods. However, our variables are scoped per-addon (
There isn't really a standard to point at here. MDN docs show
There are two ways I see us getting around this: First, we can use an internal variable name that doesn't conflict with the outer variable name. Inside the flyout CSS for example: :host {
--readthedocs-inner-flyout-font-size: var(--readthedocs-flyout-font-size, 0.8rem);
} This seems easy and low friction, I didn't test this though and maybe I'm wrong here. Maybe a larger wrench in our plans than we wanted is a different version of the above though. At the parent level, users could do any of these: :root {
--readthedocs-font-size: 19px;
}
readthedocs-flyout {
--readthedocs-font-size: 20px;
}
readthedocs-flyout.bigger {
--readthedocs-flyout-font-size: 21px;
} And our addons set the variables as: :host {
--readthedocs-flyout-font-size: var(--readthedocs-font-size, 0.8rem);
}
p {
font-size: var(--readthedocs-flyout-font-size);
} Giving us shared CSS variables at |
Yeah, this one should be pretty easy to do - it would just be a matter of renaming the "inner" variables.
Yeah, I think the combination would be a good approach too. I'll try putting this together to see if there are any hidden problems and then we can decide on the final "format". |
Allow for a general --readthedocs-font-size, but make it easy to override the specific addon with --readthedocs-<addon>-font-size
I wasn't sure about the naming, but take a look at the last commit in this PR. How do you feel about this approach? @humitos @agjohnson |
Looks good to me 👍🏼 |
It looks like @humitos you are generally a proponent of keeping the Otherwise this approach looks great to me. |
I'm not too worried about the internal name. We can always change it later if we find a better one. However, I want to keep |
This PR makes the notifications a bit more reliant on the CSS variables. I tried doing the same for search as well, but focused mostly on colors. Making the full design rely on
font-size
is a bit more tricky for the search modal, because there's more involved than the "simple box" that are the notifications. We can always improve as we move further.I also had to change the setting of the default CSS variable on flyout from
:root
to:host
as the former didn't seem to work.Closes #197