Skip to content

Conversation

@kaelansmith
Copy link

Currently the plugin only pulls colors from the global "colors" theme property; it would be nice to be able to specify scrollbar-specific colors via its own theme color property, labelled scrollbarColor. This is the norm for all other color-related utilities; eg. you can specify utility-specific color palettes under theme.textColor, theme.borderColor, etc... so this PR adds support for this. If you don't specify a scrollbar-specific color palette, it falls back to the global "colors" -- so this PR doesn't introduce any breaking changes.

@kaelansmith
Copy link
Author

Hi @adoxography, just following up about this PR -- any concerns/questions?

@kaelansmith
Copy link
Author

Hi again @adoxography, sorry to bug you -- I assume you're busy. I would really love to use this feature in prod soon, and would prefer not to have to fork the package just for this simple change; any chance you can review and, assuming all looks good, merge/release a new package version?

@kaelansmith
Copy link
Author

@adoxography poking you once more (sorry)!

@kaelansmith
Copy link
Author

Hi @adoxography, checking in once more -- just looking for a response of any type before I move ahead with forking

Copy link
Owner

@adoxography adoxography left a comment

Choose a reason for hiding this comment

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

Overall, I'm fine with the concept, but I'd want a little more out of this before I'd consider merging it:

  1. Defining custom scrollbar theme properties shouldn't prevent you from using global colours
  2. CSS config support
  3. Tests to prove that this works.

*/
const addColorUtilities = ({ matchUtilities, theme }) => {
const themeColors = flattenColorPalette(theme('colors'));
const themeColors = theme('scrollbarColor') ?? theme('colors');
Copy link
Owner

Choose a reason for hiding this comment

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

This shadows your global colors definitions. If you've defined scrollbarColor in your config, this change would prevent you from using any colours for scrollbars that aren't a scrollbarColor.

*/
const addColorUtilities = ({ matchUtilities, theme }) => {
const themeColors = flattenColorPalette(theme('colors'));
const themeColors = theme('scrollbarColor') ?? theme('colors');
Copy link
Owner

@adoxography adoxography Mar 2, 2025

Choose a reason for hiding this comment

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

The key scrollbarColor works with legacy JavaScript configs, but it won't play nicely with the CSS-based config introduced in Tailwind v4. As pointed out in #109, it's common to configure prettier to lowercase all of your CSS custom properties.

The new (undocumented) pattern Tailwind 4 is following for this is kebab-case (e.g. --border-color-neutral); so in this case, colours defined as --scrollbar-color-____ should also be recognized.

See tailwindlabs/tailwindcss#16512, tailwindlabs/tailwindcss#15757

Happily, it looks like theme('scrollbar-color') does what you hope it will - so there isn't any technical limitation here.

const themeColors = theme('scrollbarColor') ?? theme('colors');
const colors = Object.fromEntries(
Object.entries(themeColors).map(([k, v]) => [k, toColorValue(v)])
Object.entries(flattenColorPalette(themeColors)).map(([k, v]) => [k, toColorValue(v)])
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: this line becomes (even more) cognitively heavy by moving flattenColorPalette into it. I'd generally prefer to assign to a different variable and leave this line alone.

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.

2 participants