Skip to content

Try CSS variable again #545

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

Conversation

agjohnson
Copy link
Contributor

Potentially replaces #492

humitos and others added 21 commits December 16, 2024 11:44
Use our heuristic to detect the documentation tool/theme and add specific
`--readthedocs-*` CSS variables based on that for known tools/themes.

Reference: readthedocs/readthedocs.org#11849 (comment)
This moves the inner CSS rules from inside the shadow DOM to the parent
DOM. This allows users to still set a `--readthedocs-font-size` and
similar variables.
This moves the inner CSS rules from inside the shadow DOM to the parent
DOM. This allows users to still set a `--readthedocs-font-size` and
similar variables.
Merge branch 'humitos/footer-style' into agj/footer-style
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is for illustration only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also for illustration only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And also not needed

Copy link
Member

Choose a reason for hiding this comment

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

We can probably create another HTML file to keep in the repository and show this as example 👍🏼

@agjohnson
Copy link
Contributor Author

Marking this for review so it doesn't get lost again. @humitos can you look at this and see if it makes sense to you?

There are some extra changes here that can be removed before merging, it's just for example.

Right now, with all of the changes and the defaults applied with the extra files, here is what the flyout and notification look like:

image

@agjohnson agjohnson marked this pull request as ready for review February 19, 2025 03:42
@agjohnson agjohnson requested review from humitos and a team as code owners February 19, 2025 03:42
@agjohnson agjohnson self-assigned this Feb 20, 2025
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

I think this is a good pattern and it's going in a good direction.

Here you have my observations:

  • I'd like to write the CSS code in a CSS file
  • We should have a new HTML file showing an example that overrides the defaults
  • There are some properties that were calculated based in others and now they are fixed values
  • Some defaults are not defined (eg. font family)

/*
* Specific styles based on documentation tools and themes
*
* Usage of `@layer` at-rule pushes this rules down a step in
* precedence/priority. This allows a user `:root` rule to override these
* values.
**/
defaultStyleSheet.replaceSync(`
Copy link
Member

Choose a reason for hiding this comment

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

I don't like too much that we are writing all these CSS in a JS file. Can't we just have a defaults.css file and import it here instead?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I don't really understand why you migrated from doctools.css to default.js. You had to change the code in application.js as well -- why not just keep the doctools.css (or defaults.css if you want) but keeping the CSS extension and importing the CSS from application.js as we were doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can't be an imported CSS file (Lit stylesheet) as these lack all of the functionality of the native CSSStyleSheet instances, namely insertRule() used below.

So I would not make this a CSS import, what is here is easiest. There are only a few lines of CSS here, so this doesn't feel like a barrier. If we eventually find we would gain some value from splitting this out to another CSS file, we can create a merge strategy that includes a separate file first.

Copy link
Member

Choose a reason for hiding this comment

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

We can probably create another HTML file to keep in the repository and show this as example 👍🏼

src/flyout.css Outdated
Comment on lines 7 to 8
--readthedocs-flyout-font-family: var(--readthedocs-font-family);
--readthedocs-flyout-font-size: var(--readthedocs-font-size);
Copy link
Member

Choose a reason for hiding this comment

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

It seems we need to define these in defaults.js, right? I mean, --readthedocs-font-*. I didn't find where they are defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup correct. This was probably lost in merging.

color: var(--readthedocs-flyout-current-version-color, #27ae60);
color: var(--readthedocs-flyout-current-version-color);
font-size: var(--readthedocs-flyout-header-font-size);
margin-left: 10px;
Copy link
Member

Choose a reason for hiding this comment

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

This property is new. Is this correct?

@hgoel0
Copy link

hgoel0 commented Apr 14, 2025

Thank you for the work on this. Would it be possible to also test this against the pydata theme?

I am happy to deploy to our rtd to test and provide feedback.

@flying-sheep
Copy link

flying-sheep commented Apr 22, 2025

See here for some currently hardcoded colors: #570 (comment)

Here’s an adapter for the pydata theme I’m currently using:

:root {
    --readthedocs-search-backdrop-color: var(--pst-color-shadow);
    --readthedocs-search-color: var(--pst-color-text-base);
    --readthedocs-search-content-background-color: var(--pst-color-background);
    --readthedocs-search-content-border-color: var(--pst-color-border);
    --readthedocs-search-filters-border-color: var(--pst-color-border);
    --readthedocs-search-font-family: var(--pst-font-family-base);
    --readthedocs-search-font-size: var(--pst-font-size-base);
    --readthedocs-search-footer-background-color: var(--pst-color-on-background);
    --readthedocs-search-footer-code-background-color: var(--pst-color-surface);
    --readthedocs-search-footer-code-border-color: var(--pst-color-border);
    --readthedocs-search-input-background-color: var(--pst-color-surface);
    --readthedocs-search-result-section-border-color: var(--pst-color-border);
    --readthedocs-search-result-section-color: var(--pst-color-link);
    --readthedocs-search-result-section-highlight-color: var(--pst-color-accent);
    --readthedocs-search-result-section-subheading-color: var(--pst-color-text-muted);
}

@agjohnson agjohnson requested a review from humitos April 23, 2025 16:40
@agjohnson
Copy link
Contributor Author

agjohnson commented Apr 23, 2025

See here for some currently hardcoded colors: #570 (comment)

I had skipped the search addon for this first pass, but it probably makes sense to also use these changes here. I'll replicate these variables and the new ones from your #571 in this PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

4 participants