-
-
Notifications
You must be signed in to change notification settings - Fork 483
refactor(tailwindcss): enhance color handling with CSS variables #1635
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
Merged
SutuSebastian
merged 6 commits into
main
from
1582-some-tailwind-4-color-variables-are-undefined-when-used-with-reactflowbite
Dec 8, 2025
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
93d7bf0
refactor(tailwindcss): enhance color handling with CSS variables
SutuSebastian 7f53cab
separate tailwindcss v3 and v4 plugins
SutuSebastian 916d0ab
generate `plugins/tailwindcss/index.css` file
SutuSebastian 6edce33
fix(generate-tailwind-plugin-css-file): background image prefix
SutuSebastian 6a38334
add changeset
SutuSebastian 4aae918
Update .changeset/free-turkeys-lick.md
SutuSebastian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| "flowbite-react": patch | ||
| --- | ||
|
|
||
| Use CSS variables for `tailwindcss@v4` instead of inline colors. | ||
|
|
||
| ### Changes | ||
|
|
||
| - [x] automatically generate `tailwindcss@v4` config file | ||
| - [x] use css variables for the `v4` config | ||
|
|
||
| ### Breaking changes | ||
|
|
||
| Only applicable to `tailwindcss@v4`: | ||
|
|
||
| before | ||
| `@plugin "flowbite-react/plugins/tailwindcss"` - this points to the legacy JS plugin (that uses inline colors) | ||
|
|
||
| after | ||
| `@import "flowbite-react/plugins/tailwindcss"` - this points to the CSS based plugin (that uses CSS variables) | ||
|
|
||
| The breaking change is self-managed once upgrading `flowbite-react` and starting/building the app, which runs the `flowbite-react dev` or respectively `flowbite-react build` command that triggers the patch/fix/migration automatically. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| coverage | ||
| dist | ||
| src/metadata | ||
| src/plugin/tailwindcss/index.css |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import prettier from "prettier"; | ||
| import { colors } from "../src/plugin/tailwindcss/colors"; | ||
| import { backgroundImage, boxShadow } from "../src/plugin/tailwindcss/theme"; | ||
|
|
||
| let VARS = ""; | ||
| let COLORS = ""; | ||
|
|
||
| for (const colorName in colors) { | ||
| const colorShades = colors[colorName as keyof typeof colors]; | ||
|
|
||
| for (const shade in colorShades) { | ||
| VARS += `--${colorName}-${shade}: ${colorShades[shade as unknown as keyof typeof colorShades]};\n`; | ||
| } | ||
| VARS += `\n`; | ||
|
|
||
| for (const shade in colorShades) { | ||
| COLORS += `--color-${colorName}-${shade}: var(--${colorName}-${shade});\n`; | ||
| } | ||
| COLORS += `\n`; | ||
| } | ||
|
|
||
| const BACKGROUND_IMAGES = Object.entries(backgroundImage) | ||
| .map(([name, value]) => `--background-image-${name}: ${value};`) | ||
| .join("\n"); | ||
|
|
||
| const SHADOWS = Object.entries(boxShadow) | ||
| .map(([name, value]) => `--shadow-${name}: ${value};`) | ||
| .join("\n"); | ||
|
|
||
| const content = ` | ||
| :root { | ||
| ${VARS} | ||
| } | ||
|
|
||
| @theme inline { | ||
| ${COLORS} | ||
| } | ||
|
|
||
| @theme { | ||
| ${BACKGROUND_IMAGES} | ||
| } | ||
|
|
||
| @theme { | ||
| ${SHADOWS} | ||
| } | ||
| `; | ||
|
|
||
| const outputFile = "src/plugin/tailwindcss/index.css"; | ||
|
|
||
| try { | ||
| await Bun.write( | ||
| outputFile, | ||
| await prettier.format(content, { | ||
| parser: "css", | ||
| }), | ||
| ); | ||
| console.log(`Tailwind plugin CSS file generated successfully: ${outputFile}`); | ||
| } catch (error) { | ||
| console.error(`Failed generating Tailwind plugin CSS file: ${outputFile}`, error); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.