Skip to content

Commit e000e1a

Browse files
feat: introduce dynamic() and helper functions for dynamic colors (#3)
1 parent 303224e commit e000e1a

File tree

6 files changed

+460
-227
lines changed

6 files changed

+460
-227
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,44 @@ realtimeColors({
115115
| `tailwind` | Uses a `Tint` and `Shade` based approach like TailwindCSS. | Generates better results. This is the default. |
116116
| `realtimeColors` | Uses the same algorithm like Realtime Colors. | Shades are not that great. You can use this if you want feature parity with Realtime Colors. |
117117

118+
## 🔥 Dynamic Colors
119+
120+
> This doesn't work with URL based colors.
121+
122+
Sometimes you may want to use dynamic colors based on user preferences. To skip generating a color at build time, you can pass `dynamic()` as the color value.
123+
124+
```js
125+
realtimeColors({
126+
colors: {
127+
text: "#ededee",
128+
background: "#0c0d13",
129+
primary: "dynamic()",
130+
secondary: "#243579",
131+
accent: "#3053dc",
132+
},
133+
theme: true,
134+
});
135+
```
136+
137+
This will skip generating the primary color in the CSS. You will need to manually set the primary color using CSS variables. To help in generating the CSS, you can use the new helper functions exported along with the plugin.
138+
139+
```js
140+
import { generateDynamicPalette, invertColor } from "tailwind-plugin-realtime-colors";
141+
142+
const primaryColor = getPrimaryColorSomehow();
143+
144+
// You can also pass a config object as the second argument
145+
const palette = generateDynamicPalette({primary: primaryColor});
146+
const darkPalette = generateDynamicPalette(invertColor({primary: primaryColor}));
147+
148+
// Now you can use the styles in your CSS
149+
for (const [key, value] of Object.entries(palette)) {
150+
document.documentElement.style.setProperty(key, value);
151+
}
152+
// Use dark palette for dark mode later
153+
154+
```
155+
118156
## 🏗️ How to contribute
119157

120158
### 🐛 Reporting Bugs

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"devDependencies": {
2525
"@biomejs/biome": "1.4.1",
2626
"@types/color-convert": "^2.0.3",
27-
"@types/node": "^20.10.4",
28-
"tsup": "^8.0.1",
27+
"@types/node": "^20.11.17",
28+
"tsup": "^8.0.2",
2929
"typescript": "^5.3.3"
3030
},
3131
"peerDependencies": {
@@ -39,7 +39,12 @@
3939
"url": "https://github.com/BlankParticle/tailwind-plugin-realtime-colors/issues"
4040
},
4141
"homepage": "https://github.com/BlankParticle/tailwind-plugin-realtime-colors",
42-
"keywords": ["tailwindcss", "tailwind", "tailwind-plugin", "realtime-colors"],
42+
"keywords": [
43+
"tailwindcss",
44+
"tailwind",
45+
"tailwind-plugin",
46+
"realtime-colors"
47+
],
4348
"funding": [
4449
{
4550
"type": "github",

0 commit comments

Comments
 (0)