Skip to content
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

Add CSS color-scheme utilities #11271

Closed
wants to merge 1 commit into from

Conversation

lukewarlow
Copy link
Contributor

This PR adds utilities for the color-scheme CSS property.

(Ignore the browser support for the only word it doesn't break functionality in any browser and definitely works in Chrome)

@jonnitto
Copy link

Funny, I've the same code in my projects

@elizabethmitchell00
Copy link

Thanks for the information.

@RobinMalfait RobinMalfait changed the base branch from master to archive/master-2024-02-23 March 4, 2024 21:43
@RobinMalfait RobinMalfait changed the base branch from archive/master-2024-02-23 to next April 17, 2024 20:49
@RobinMalfait RobinMalfait changed the title Add CSS color-scheme utilities Add CSS color-scheme utilities Apr 17, 2024
@RobinMalfait
Copy link
Member

Hey!

You might have noticed that I forced pushed to this branch. The reason is because the PR now uses next as the base branch which is our working branch for Tailwind CSS v4. In other words, the feature you implemented here is now written in the new codebase.

The code is ported as-is, so no API changes of your feature happened while moving it to the new codebase.

I also made sure to add you as a co-author because you still deserve all the credit 💪

@brandonmcconnell
Copy link
Contributor

brandonmcconnell commented Apr 20, 2024

@lukewarlow @RobinMalfait How would you feel about using shorter utility names?

  • color-scheme-dark or scheme-dark or dark
    (dark in a util context would be different from its dark: variant context)
  • color-scheme-dark-only or scheme-dark-only or dark-only

I could see an argument for the verbose names as these would not be so commonly used and would be simpler to understand when encountered if they are 1:1 with CSS, but I could also see it being helpful to have shorter names if a codebase has a common practice of making certain sections dark vs. light in different contexts.

@lukewarlow
Copy link
Contributor Author

My thinking on this is that more verbosity is better, makes them easily discoverable. dark-only might make someone think this hides this element in dark mode.

For an existing example there's the file: pseudo instead of file-selector-button which admittedly is a bit verbose but people didn't realise tailwind had this variant I think in part because it wasn't a match to the pseudo name. (file might also end up being a future compat issue if other file element pseudos are ever added but that's a separate discussion).

All that being said I trust in the framework authors to weigh up tradeoffs and come to a decision that's right for them :)

@brandonmcconnell
Copy link
Contributor

@lukewarlow Absolutely! I'm with it 🙂

@adamwathan
Copy link
Member

Opened a fresh PR for this one because the merge conflicts were a nightmare for me to try and resolve 😬

#14567

Added you as a co-author though @lukewarlow so will still be credited. Thanks!

@adamwathan adamwathan closed this Oct 2, 2024
adamwathan added a commit that referenced this pull request Oct 2, 2024
Replaces #11271 — the merge conflicts are killing me and it's way easier
to just do it again (added you as a co-author though @lukewarlow so
you're still credited!)

This PR adds the following new utilities for the `color-scheme`
property:

| Class               | CSS                        |
| ------------------- | -------------------------- |
| `scheme-normal`     | `color-scheme: normal`     |
| `scheme-dark`       | `color-scheme: dark`       |
| `scheme-light`      | `color-scheme: light`      |
| `scheme-light-dark` | `color-scheme: light dark` |
| `scheme-only-dark`  | `color-scheme: dark only`  |
| `scheme-only-light` | `color-scheme: light only` |

Went with `scheme-*` for the utilities because there are currently no
other CSS properties with the word `scheme` in them and
`scheme-light-dark` is going to be a common value which is three words
already even with the shortened property name.

I considered setting `color-scheme: light dark` by default as part of
Preflight for this PR but decided against it, at least for this PR. I
think that could still be a useful default but we should think about it
a bit more because if you're building a light-mode-only site it'll force
you to do some extra work.

---------

Co-authored-by: Adam Wathan <[email protected]>
Co-authored-by: Luke Warlow <[email protected]>
@lukewarlow lukewarlow deleted the color-scheme branch October 2, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants