Skip to content

Commit 7fca5d7

Browse files
feat(module): add theme.prefix option (#5341)
1 parent ef6d580 commit 7fca5d7

File tree

17 files changed

+553
-321
lines changed

17 files changed

+553
-321
lines changed

docs/app/components/home/HomeContributors.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const { width } = useElementSize(el)
100100
}
101101
102102
.dark .circle:after {
103-
--highlight-color: var(--color-white);
103+
--highlight-color: white;
104104
}
105105
106106
.animation-paused.circle:after,

docs/content/docs/1.getting-started/2.installation/1.nuxt.md

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Use the `prefix` option to change the prefix of the components.
256256

257257
- Default: `U`{lang="ts-type"}
258258

259-
```ts [nuxt.config.ts]
259+
```ts [nuxt.config.ts] {4-6}
260260
export default defineNuxtConfig({
261261
modules: ['@nuxt/ui'],
262262
css: ['~/assets/css/main.css'],
@@ -272,7 +272,7 @@ Use the `fonts` option to enable or disable the [`@nuxt/fonts`](https://github.c
272272

273273
- Default: `true`{lang="ts-type"}
274274

275-
```ts [nuxt.config.ts]
275+
```ts [nuxt.config.ts] {4-6}
276276
export default defineNuxtConfig({
277277
modules: ['@nuxt/ui'],
278278
css: ['~/assets/css/main.css'],
@@ -288,7 +288,7 @@ Use the `colorMode` option to enable or disable the [`@nuxt/color-mode`](https:/
288288

289289
- Default: `true`{lang="ts-type"}
290290

291-
```ts [nuxt.config.ts]
291+
```ts [nuxt.config.ts] {4-6}
292292
export default defineNuxtConfig({
293293
modules: ['@nuxt/ui'],
294294
css: ['~/assets/css/main.css'],
@@ -304,7 +304,7 @@ Use the `theme.colors` option to define the dynamic color aliases used to genera
304304

305305
- Default: `['primary', 'secondary', 'success', 'info', 'warning', 'error']`{lang="ts-type" class="inline"}
306306

307-
```ts [nuxt.config.ts]
307+
```ts [nuxt.config.ts] {4-8}
308308
export default defineNuxtConfig({
309309
modules: ['@nuxt/ui'],
310310
css: ['~/assets/css/main.css'],
@@ -326,7 +326,7 @@ Use the `theme.transitions` option to enable or disable transitions on component
326326

327327
- Default: `true`{lang="ts-type"}
328328

329-
```ts [nuxt.config.ts]
329+
```ts [nuxt.config.ts] {4-8}
330330
export default defineNuxtConfig({
331331
modules: ['@nuxt/ui'],
332332
css: ['~/assets/css/main.css'],
@@ -348,7 +348,7 @@ Use the `theme.defaultVariants` option to override the default `color` and `size
348348

349349
- Default: `{ color: 'primary', size: 'md' }`{lang="ts-type"}
350350

351-
```ts [nuxt.config.ts]
351+
```ts [nuxt.config.ts] {4-11}
352352
export default defineNuxtConfig({
353353
modules: ['@nuxt/ui'],
354354
css: ['~/assets/css/main.css'],
@@ -363,13 +363,71 @@ export default defineNuxtConfig({
363363
})
364364
```
365365

366+
### `theme.prefix` :badge{label="Soon"}
367+
368+
Use the `theme.prefix` option to configure the same prefix you set on your Tailwind CSS import. This ensures Nuxt UI components use the correct prefixed utility classes and CSS variables.
369+
370+
::code-group
371+
372+
```ts [nuxt.config.ts] {4-8}
373+
export default defineNuxtConfig({
374+
modules: ['@nuxt/ui'],
375+
css: ['~/assets/css/main.css'],
376+
ui: {
377+
theme: {
378+
prefix: 'tw'
379+
}
380+
}
381+
})
382+
```
383+
384+
```css [app/assets/css/main.css] {1}
385+
@import "tailwindcss" prefix(tw);
386+
@import "@nuxt/ui";
387+
```
388+
389+
::
390+
391+
::warning{to="https://fonts.nuxt.com/get-started/configuration#processcssvariables"}
392+
You might need to enable `fonts.processCSSVariables` to use the prefix option with the `@nuxt/fonts` module:
393+
394+
```ts [nuxt.config.ts] {9-11}
395+
export default defineNuxtConfig({
396+
modules: ['@nuxt/ui'],
397+
css: ['~/assets/css/main.css'],
398+
ui: {
399+
theme: {
400+
prefix: 'tw'
401+
}
402+
},
403+
fonts: {
404+
processCSSVariables: true
405+
}
406+
})
407+
```
408+
::
409+
410+
This will automatically prefix all Tailwind utility classes and CSS variables in Nuxt UI component themes:
411+
412+
```html
413+
<!-- Without prefix -->
414+
<button class="px-2 py-1 text-xs hover:bg-primary/75">Button</button>
415+
416+
<!-- With prefix: tw -->
417+
<button class="tw:px-2 tw:py-1 tw:text-xs tw:hover:bg-primary/75">Button</button>
418+
```
419+
420+
::note{to="https://tailwindcss.com/docs/styling-with-utility-classes#using-the-prefix-option" target="_blank"}
421+
Learn more about using a prefix in the Tailwind CSS documentation.
422+
::
423+
366424
### `mdc`
367425

368426
Use the `mdc` option to force the import of Nuxt UI `<Prose>` components even if `@nuxtjs/mdc` or `@nuxt/content` is not installed.
369427

370428
- Default: `false`{lang="ts-type"}
371429

372-
```ts [nuxt.config.ts]
430+
```ts [nuxt.config.ts] {4-6}
373431
export default defineNuxtConfig({
374432
modules: ['@nuxt/ui'],
375433
css: ['~/assets/css/main.css'],
@@ -385,7 +443,7 @@ Use the `content` option to force the import of Nuxt UI `<Prose>` and `<UContent
385443

386444
- Default: `false`{lang="ts-type"}
387445

388-
```ts [nuxt.config.ts]
446+
```ts [nuxt.config.ts] {4-6}
389447
export default defineNuxtConfig({
390448
modules: ['@nuxt/ui'],
391449
css: ['~/assets/css/main.css'],
@@ -404,7 +462,7 @@ Use the `experimental.componentDetection` option to enable automatic component d
404462

405463
**Enable automatic detection:**
406464

407-
```ts [nuxt.config.ts]
465+
```ts [nuxt.config.ts] {4-8}
408466
export default defineNuxtConfig({
409467
modules: ['@nuxt/ui'],
410468
css: ['~/assets/css/main.css'],
@@ -418,7 +476,7 @@ export default defineNuxtConfig({
418476

419477
**Include additional components for dynamic usage:**
420478

421-
```ts [nuxt.config.ts]
479+
```ts [nuxt.config.ts] {4-8}
422480
export default defineNuxtConfig({
423481
modules: ['@nuxt/ui'],
424482
css: ['~/assets/css/main.css'],

docs/content/docs/1.getting-started/2.installation/2.vue.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ Use the `prefix` option to change the prefix of the components.
518518

519519
- Default: `U`{lang="ts-type"}
520520

521-
```ts [vite.config.ts]
521+
```ts [vite.config.ts] {9}
522522
import { defineConfig } from 'vite'
523523
import vue from '@vitejs/plugin-vue'
524524
import ui from '@nuxt/ui/vite'
@@ -537,7 +537,7 @@ export default defineConfig({
537537

538538
Use the `ui` option to provide configuration for Nuxt UI.
539539

540-
```ts [vite.config.ts]
540+
```ts [vite.config.ts] {9-14}
541541
import { defineConfig } from 'vite'
542542
import vue from '@vitejs/plugin-vue'
543543
import ui from '@nuxt/ui/vite'
@@ -563,7 +563,7 @@ Use the `colorMode` option to enable or disable the color mode integration from
563563

564564
- Default: `true`{lang="ts-type"}
565565

566-
```ts [vite.config.ts]
566+
```ts [vite.config.ts] {9}
567567
import { defineConfig } from 'vite'
568568
import vue from '@vitejs/plugin-vue'
569569
import ui from '@nuxt/ui/vite'
@@ -584,7 +584,7 @@ Use the `theme.colors` option to define the dynamic color aliases used to genera
584584

585585
- Default: `['primary', 'secondary', 'success', 'info', 'warning', 'error']`{lang="ts-type" class="inline"}
586586

587-
```ts [vite.config.ts]
587+
```ts [vite.config.ts] {9-11}
588588
import { defineConfig } from 'vite'
589589
import vue from '@vitejs/plugin-vue'
590590
import ui from '@nuxt/ui/vite'
@@ -611,7 +611,7 @@ Use the `theme.transitions` option to enable or disable transitions on component
611611

612612
- Default: `true`{lang="ts-type"}
613613

614-
```ts [vite.config.ts]
614+
```ts [vite.config.ts] {9-11}
615615
import { defineConfig } from 'vite'
616616
import vue from '@vitejs/plugin-vue'
617617
import ui from '@nuxt/ui/vite'
@@ -638,7 +638,7 @@ Use the `theme.defaultVariants` option to override the default `color` and `size
638638

639639
- Default: `{ color: 'primary', size: 'md' }`{lang="ts-type"}
640640

641-
```ts [vite.config.ts]
641+
```ts [vite.config.ts] {9-14}
642642
import { defineConfig } from 'vite'
643643
import vue from '@vitejs/plugin-vue'
644644
import ui from '@nuxt/ui/vite'
@@ -658,11 +658,55 @@ export default defineConfig({
658658
})
659659
```
660660

661+
### `theme.prefix` :badge{label="Soon"}
662+
663+
Use the `theme.prefix` option to configure the same prefix you set on your Tailwind CSS import. This ensures Nuxt UI components use the correct prefixed utility classes and CSS variables.
664+
665+
::code-group
666+
667+
```ts [vite.config.ts] {9-11}
668+
import { defineConfig } from 'vite'
669+
import vue from '@vitejs/plugin-vue'
670+
import ui from '@nuxt/ui/vite'
671+
672+
export default defineConfig({
673+
plugins: [
674+
vue(),
675+
ui({
676+
theme: {
677+
prefix: 'tw'
678+
}
679+
})
680+
]
681+
})
682+
```
683+
684+
```css [assets/main.css] {1}
685+
@import "tailwindcss" prefix(tw);
686+
@import "@nuxt/ui";
687+
```
688+
689+
::
690+
691+
This will automatically prefix all Tailwind utility classes and CSS variables in Nuxt UI component themes:
692+
693+
```html
694+
<!-- Without prefix -->
695+
<button class="px-2 py-1 text-xs hover:bg-primary/75">Button</button>
696+
697+
<!-- With prefix: tw -->
698+
<button class="tw:px-2 tw:py-1 tw:text-xs tw:hover:bg-primary/75">Button</button>
699+
```
700+
701+
::note{to="https://tailwindcss.com/docs/styling-with-utility-classes#using-the-prefix-option" target="_blank"}
702+
Learn more about using a prefix in the Tailwind CSS documentation.
703+
::
704+
661705
### `inertia`
662706

663707
Use the `inertia` option to enable compatibility with [Inertia.js](https://inertiajs.com/).
664708

665-
```ts [vite.config.ts]
709+
```ts [vite.config.ts] {9}
666710
import { defineConfig } from 'vite'
667711
import vue from '@vitejs/plugin-vue'
668712
import ui from '@nuxt/ui/vite'

docs/content/docs/1.getting-started/5.theme/2.css-variables.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Each utility class uses a CSS variable to set its color for light and dark modes
126126
--ui-text-toned: var(--ui-color-neutral-600);
127127
--ui-text: var(--ui-color-neutral-700);
128128
--ui-text-highlighted: var(--ui-color-neutral-900);
129-
--ui-text-inverted: var(--color-white);
129+
--ui-text-inverted: white;
130130
}
131131
```
132132

@@ -136,7 +136,7 @@ Each utility class uses a CSS variable to set its color for light and dark modes
136136
--ui-text-muted: var(--ui-color-neutral-400);
137137
--ui-text-toned: var(--ui-color-neutral-300);
138138
--ui-text: var(--ui-color-neutral-200);
139-
--ui-text-highlighted: var(--color-white);
139+
--ui-text-highlighted: white;
140140
--ui-text-inverted: var(--ui-color-neutral-900);
141141
}
142142
```
@@ -155,7 +155,7 @@ You can customize these CSS variables in your `main.css` file:
155155
}
156156

157157
.dark {
158-
--ui-text: var(--color-white);
158+
--ui-text: white;
159159
}
160160
```
161161
::
@@ -189,7 +189,7 @@ Each utility class uses a CSS variable to set its color for light and dark modes
189189

190190
```css [Light]
191191
:root {
192-
--ui-bg: var(--color-white);
192+
--ui-bg: white;
193193
--ui-bg-muted: var(--ui-color-neutral-50);
194194
--ui-bg-elevated: var(--ui-color-neutral-100);
195195
--ui-bg-accented: var(--ui-color-neutral-200);
@@ -203,7 +203,7 @@ Each utility class uses a CSS variable to set its color for light and dark modes
203203
--ui-bg-muted: var(--ui-color-neutral-800);
204204
--ui-bg-elevated: var(--ui-color-neutral-800);
205205
--ui-bg-accented: var(--ui-color-neutral-700);
206-
--ui-bg-inverted: var(--color-white);
206+
--ui-bg-inverted: white;
207207
}
208208
```
209209

@@ -265,7 +265,7 @@ Each utility class uses a CSS variable to set its color for light and dark modes
265265
--ui-border: var(--ui-color-neutral-800);
266266
--ui-border-muted: var(--ui-color-neutral-700);
267267
--ui-border-accented: var(--ui-color-neutral-700);
268-
--ui-border-inverted: var(--color-white);
268+
--ui-border-inverted: white;
269269
}
270270
```
271271

@@ -346,7 +346,7 @@ Nuxt UI provides a `--ui-container` CSS variable that controls the maximum width
346346

347347
```css
348348
:root {
349-
--ui-container: var(--container-7xl);
349+
--ui-container: 80rem; /* var(--container-7xl) */
350350
}
351351
```
352352

playgrounds/nuxt/app/components/ThemeDropdown.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ const items = computed<DropdownMenuItem[]>(() => [{
4848
/>
4949

5050
<template #item-leading="{ item }">
51-
<span
52-
:style="{
53-
'--chip-light': `var(--color-${(item as any).chip}-500)`,
54-
'--chip-dark': `var(--color-${(item as any).chip}-400)`
55-
}"
56-
class="ms-0.5 size-2 rounded-full bg-(--chip-light) dark:bg-(--chip-dark)"
57-
/>
51+
<div class="inline-flex items-center justify-center shrink-0 size-5">
52+
<span
53+
class="rounded-full ring ring-bg bg-(--chip-light) dark:bg-(--chip-dark) size-2"
54+
:style="{
55+
'--chip-light': `var(--color-${(item as any).chip}-500)`,
56+
'--chip-dark': `var(--color-${(item as any).chip}-400)`
57+
}"
58+
/>
59+
</div>
5860
</template>
5961
</UDropdownMenu>
6062
</template>

src/defaults.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)