Repository navigation
Add OKLCH color support to Storybook #34161
nikwilliamson
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
We recently migrated our design system's color tokens from hex to OKLCH for better perceptual uniformity across our palette. After the migration, two things broke in Storybook:
ColorItem/ColorPaletteblocks in our MDX documentation pages throw the error: "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation." These blocks are a core part of how we document our color system, and they don't accept OKLCH values at all.Storybook's theming system crashes with
PolishedErrorbecause@storybook/theming'screate()function runs color values throughpolished'sparseToRgb/opacifyinternally, which has no OKLCH support. Any theme that passes a design token value as a color — which is the intended usage — breaks immediately.OKLCH is a CSS Color Level 4 spec that's been supported in all major browsers since 2023. Design systems are adopting it because it provides perceptually uniform lightness and predictable chroma scaling — things that hex/HSL can't offer. Storybook's color handling hasn't kept up with this.
Describe the solution you'd like
ColorItemandColorPaletteshould accept any valid CSS color value, includingoklch(),oklab(),lch(),lab(), andcolor().@storybook/theming'screate()function should handle modern CSS color formats without crashing. Ifpolishedcan't parse them, Storybook should either replacepolishedwith a modern color library or add a fallback path that sets colors via CSS properties directly.Describe alternatives you've considered
ColorItemblocks from our documentation and replaced them with a customTokenVisualizercomponent that renders swatches via CSSbackgroundColor(which browsers handle natively). This works, but we lose the built-in Storybook doc patterns.Are you able to assist to bring the feature to reality?
no
Additional context
The root of the issue is
polished— it's used internally by@storybook/themingand doesn't support any CSS Color Level 4 formats. TheparseToRgbfunction only handles hex, rgb(a), and hsl(a). Sincepolishedhasn't been actively maintained, it might be worth considering a switch to a library likeculorior even native CSS parsing via<canvas>context for color conversion.OKLCH adoption is accelerating across design systems (see Evil Martians' guide, Adam Argyle's work on Open Props, and the Tailwind CSS v4 migration to OKLCH). This is quickly becoming the standard for design token authoring, and Storybook's color tooling should support it.
Relevant Storybook internals affected:
@storybook/addon-docs—ColorItem,ColorPaletteblocks@storybook/theming—create(), color processing viapolished@storybook/addon-controls— color picker/control typeAll reactions