Skip to content
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

Document new color functions #1214

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/pages/docs/customizing-colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ Again, we recommend sticking to the default naming convention for most projects,

If you're using abstract color names because you want to support multiple themes in your project, there's a good chance you also want to use CSS variables to define your colors.

The best way to do this is to define your CSS variables as just the color _channels_, without including the actual color function:
The best way to do this is to define your CSS variables as just the color _channels_ separated by spaces, without including the actual color function *or* alpha value:

```css main.css
@tailwind base;
Expand All @@ -322,40 +322,31 @@ The best way to do this is to define your CSS variables as just the color _chann

.theme-startup {
--color-primary: 255 115 179;
--color-secondary: 111 114 185;
--color-secondary: 238deg 35% 58%;
/* ... */
}

.theme-boring {
--color-primary: 2 82 204;
--color-secondary: 255 196 2;
--color-secondary: 46deg 100% 50%;
/* ... */
}

.theme-elegant {
--color-primary: 192 178 131;
--color-secondary: 220 208 192;
--color-secondary: 34deg 29% 81%;
/* ... */
}
```

Then define your colors in your configuration file as _functions_, and apply the `opacityValue` if it's defined:
Then define your colors using either the `rgb` or `hsl` helpers which wraps the variable with the color function and applies an alpha channel if needed:

```js tailwind.config.js
function withOpacityValue(variable) {
return ({ opacityValue }) => {
if (opacityValue === undefined) {
return `rgb(var(${variable}))`
}
return `rgb(var(${variable}) / ${opacityValue})`
}
}

module.exports = {
theme: {
colors: {
primary: withOpacityValue('--color-primary'),
secondary: withOpacityValue('--color-secondary'),
colors: ({ rgb, hsl }) => {
primary: rgb('--color-primary'),
secondary: hsl('--color-secondary'),
// ...
}
}
Expand Down