Skip to content

Conversation

te6-in
Copy link
Contributor

@te6-in te6-in commented Feb 28, 2025

Make --tw-prose-kbd-shadows to have 10% alpha color even if the colors are in oklch (Tailwind v4)

Fixes #386

Copy link

vercel bot commented Feb 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
tailwindcss-typography Ready Ready Preview Comment Sep 18, 2025 10:40am

Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

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

Hey! Thanks for the PR! I decided to use a different approach that is a tiny bit more robust. In Tailwind v3, the tailwindcss/colors export is always in hex and our code here also only handled hex, so I left this as-is. However, if hex can not be parsed I'm now using color-mix(…) syntax and we assume we're in v4 where we can use that! That avoids us introspecting the color values and won't break things.

I was trying to add a unit test but because this is operating off a static export, mocking is a total PITA and I was able to verify it works only with test.only.

Will try to add this in a v4 sample app briefly just to be sure but I think we're good now!

@philipp-spiess
Copy link
Member

Ok, works 😅

CleanShot 2025-09-18 at 12 38 33@2x

@philipp-spiess philipp-spiess merged commit f822222 into tailwindlabs:main Sep 18, 2025
3 checks passed
philipp-spiess added a commit that referenced this pull request Sep 19, 2025
* fix: correctly apply alpha to kbd shadows when not hex

* Use `color-mix(…)` for non hex values

* Add changelog

---------

Co-authored-by: Philipp Spiess <[email protected]>
// only handled these values. We keep the old behavior for backward
// compatibility with v3 codebases but use color-mix for any other color
// values.
hex = color.replace('#', '')
Copy link

@suasgn suasgn Sep 19, 2025

Choose a reason for hiding this comment

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

The hex variable is not defined because in the previous version it originated from the functions' arguments:

// v0.5.16
const hexToRgb = (hex) => {
  hex = hex.replace('#', '')
  // ...
}

We need to declare the variable to avoid the issue.

// v0.5.17
const opacity = (color, opacity) => {
  let hex = color.replace('#', '')
  // ...
}

CleanShot_2025-09-19_22 06 42_xBqtzCOx@2x

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.

--tw-prose-kbd-shadows is NaN NaN NaN since the colors are assumed to be hex
3 participants