Skip to content

Commit fce8ed4

Browse files
docs: add dynamic colors section
1 parent 921dd78 commit fce8ed4

2 files changed

Lines changed: 139 additions & 2 deletions

File tree

layers/documentation/content/documentation/10.setup/3.installation.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: "Option 1: New nuxt project with github layers"
1111
The **recommended way** to start a new project with Tairo.
1212

1313
:::doc-message{color="muted-contrast" icon="ph:info"}
14-
This step requires you to have unlocked your [github access](https://cssninja.io/faq/github-access) and have a [github personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
14+
This step requires you to have unlocked your [github access](https://cssninja.io/faq/github-access) and have a [github personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with the `repo` scope for classic token, or read access to the Tairo repository for fine-grained access token.
1515
:::
1616

1717

@@ -61,7 +61,7 @@ This step requires you to have unlocked your [github access](https://cssninja.io
6161
::
6262

6363
#description
64-
Link your project to the Tairo layers by adding them to the `nuxt.config.ts` file. Note the version number `v1.5.0` which you can change to the latest version.
64+
Link your project to the Tairo layers by adding them to the `nuxt.config.ts` file. The version `__TAIRO_LAYERS_VERSION__` is the latest stable version of Tairo, you can also use the `edge` version which contains the current development version (useful for testing new features).
6565
:::
6666

6767

@@ -125,6 +125,7 @@ This step requires you to have unlocked your [github access](https://cssninja.io
125125
::tairo-toc-anchor
126126
---
127127
label: "Run the development server"
128+
id: "run-the-development-server-from-github"
128129
prefix: " "
129130
level: 3
130131
---
@@ -141,6 +142,7 @@ This step requires you to have unlocked your [github access](https://cssninja.io
141142
::tairo-toc-anchor
142143
---
143144
label: "Done!"
145+
id: "done-with-github"
144146
prefix: " "
145147
level: 3
146148
---
@@ -297,6 +299,7 @@ It's also the way to go if you want to **run the demo app**.
297299
::tairo-toc-anchor
298300
---
299301
label: "Run the development server"
302+
id: "run-the-development-server-from-source"
300303
prefix: " "
301304
level: 3
302305
---
@@ -314,6 +317,7 @@ It's also the way to go if you want to **run the demo app**.
314317
::tairo-toc-anchor
315318
---
316319
label: "Done!"
320+
id: "done-with-source"
317321
prefix: " "
318322
level: 3
319323
---

layers/documentation/content/documentation/30.tailwindcss/4.colors.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,139 @@ export default withShurikenUI({
220220
::
221221

222222

223+
224+
::doc-component-demo
225+
---
226+
title: Dynamic color with CSS variables
227+
---
228+
229+
Sometimes you need to use CSS variables to dynamically change a color at runtime. For example, to change the primary color on dark mode, or based on the user's preference (like with the customizer).
230+
231+
232+
233+
::code-timeline{.mt-12}
234+
:::code-timeline-item{vertical}
235+
::code-group
236+
```ts [<app>/tailwind.config.ts]
237+
import { withShurikenUI } from '@shuriken-ui/tailwind'
238+
239+
export default withShurikenUI({
240+
theme: {
241+
extend: {
242+
primary: {
243+
50: 'rgb(var(--color-primary-50) / <alpha-value>)',
244+
100: 'rgb(var(--color-primary-100) / <alpha-value>)',
245+
200: 'rgb(var(--color-primary-200) / <alpha-value>)',
246+
300: 'rgb(var(--color-primary-300) / <alpha-value>)',
247+
400: 'rgb(var(--color-primary-400) / <alpha-value>)',
248+
500: 'rgb(var(--color-primary-500) / <alpha-value>)',
249+
600: 'rgb(var(--color-primary-600) / <alpha-value>)',
250+
700: 'rgb(var(--color-primary-700) / <alpha-value>)',
251+
800: 'rgb(var(--color-primary-800) / <alpha-value>)',
252+
900: 'rgb(var(--color-primary-900) / <alpha-value>)',
253+
950: 'rgb(var(--color-primary-950) / <alpha-value>)',
254+
},
255+
},
256+
},
257+
})
258+
```
259+
::
260+
261+
#title
262+
::tairo-toc-anchor
263+
---
264+
label: "Update tailwind.config.ts"
265+
prefix: " "
266+
level: 3
267+
---
268+
::
269+
270+
#description
271+
This maps all the primary color shades to CSS variables. You can use any CSS variable name you want. The `<alpha-value>` is the opacity placeholder that will be replaced by Tailwind CSS at build time.
272+
:::
273+
274+
275+
:::code-timeline-item{vertical}
276+
::code-group
277+
```css [<app>/assets/colors.css]
278+
:root {
279+
--color-primary-50: 245 243 255; /* #f5f3ff */
280+
--color-primary-100: 237 233 254; /* #ede9fe */
281+
--color-primary-200: 221 214 254; /* #ddd6fe */
282+
--color-primary-300: 196 181 253; /* #c4b5fd */
283+
--color-primary-400: 167 139 250; /* #a78bfa */
284+
--color-primary-500: 139 92 246; /* #a855f7 */
285+
--color-primary-600: 124 58 237; /* #9333ea */
286+
--color-primary-700: 109 40 217; /* #7e22ce */
287+
--color-primary-800: 91 33 182; /* #6b21a8 */
288+
--color-primary-900: 76 29 149; /* #581c87 */
289+
--color-primary-950: 46 16 101; /* #3b0764 */
290+
}
291+
292+
.dark {
293+
--color-primary-50: 255 244 212; /* #FFF4D4 */
294+
--color-primary-100: 255 233 172; /* #FFE9AC */
295+
--color-primary-200: 254 222 131; /* #FEDE83 */
296+
--color-primary-300: 254 211 91; /* #FED35B */
297+
--color-primary-400: 254 200 50; /* #FEC832 */
298+
--color-primary-500: 247 182 1; /* #F7B601 */
299+
--color-primary-600: 191 141 1; /* #BF8D01 */
300+
--color-primary-700: 135 99 1; /* #876301 */
301+
--color-primary-800: 79 58 0; /* #4F3A00 */
302+
--color-primary-900: 48 36 0; /* #302400 */
303+
--color-primary-950: 36 27 1; /* #241b01 */
304+
}
305+
```
306+
::
307+
308+
#title
309+
::tairo-toc-anchor
310+
---
311+
label: "Register the CSS variables"
312+
prefix: " "
313+
level: 3
314+
---
315+
::
316+
317+
#description
318+
Here you need to define the CSS variables that will be used to change the primary color. The values used are the RGB values of the color you want to use. You can also define a different color for dark mode.
319+
:::
320+
321+
:::code-timeline-item{vertical}
322+
::code-group
323+
```ts [<app>/nuxt.config.ts]
324+
export default defineNuxtConfig({
325+
css: [
326+
'~/assets/css/colors.css',
327+
],
328+
})
329+
```
330+
::
331+
332+
#title
333+
::tairo-toc-anchor
334+
---
335+
label: "Load the CSS file"
336+
prefix: " "
337+
level: 3
338+
---
339+
::
340+
341+
#description
342+
Register your CSS file in the `nuxt.config.ts` file to make sure it is loaded in your application to make it work.
343+
:::
344+
::
345+
346+
347+
---
348+
349+
Useful resources:
350+
351+
- [Using CSS Variables on tailwindcss.com](https://tailwindcss.com/docs/customizing-colors#using-css-variables)
352+
353+
::
354+
355+
223356
::doc-nav
224357
---
225358
prev: /documentation/tailwindcss/shuriken-ui

0 commit comments

Comments
 (0)