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

feat(module): generate tailwindcss theme colors #2967

Draft
wants to merge 3 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions docs/content/1.getting-started/3.theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,63 +286,6 @@ export default defineConfig({
:::
::

::warning
These color aliases are not automatically defined as Tailwind CSS colors, so classes like `text-primary-500 dark:text-primary-400` won't be available by default as in Nuxt UI v2. This approach provides more flexibility and prevents overwriting of user-defined Tailwind CSS colors.<br><br>

However, you can generate these classes using Tailwind's `@theme` directive, allowing you to use custom color utility classes while maintaining dynamic color aliases:

::module-only
#ui
:::div{class="*:!mb-0 *:!mt-2.5"}

```css [main.css]
@import "tailwindcss";
@import "@nuxt/ui";

@theme {
--color-primary-50: var(--ui-color-primary-50);
--color-primary-100: var(--ui-color-primary-100);
--color-primary-200: var(--ui-color-primary-200);
--color-primary-300: var(--ui-color-primary-300);
--color-primary-400: var(--ui-color-primary-400);
--color-primary-500: var(--ui-color-primary-500);
--color-primary-600: var(--ui-color-primary-600);
--color-primary-700: var(--ui-color-primary-700);
--color-primary-800: var(--ui-color-primary-800);
--color-primary-900: var(--ui-color-primary-900);
--color-primary-950: var(--ui-color-primary-950);
}
```

:::

#ui-pro
:::div{class="*:!mb-0 *:!mt-2.5"}

```css [main.css]
@import "tailwindcss";
@import "@nuxt/ui-pro";

@theme {
--color-primary-50: var(--ui-color-primary-50);
--color-primary-100: var(--ui-color-primary-100);
--color-primary-200: var(--ui-color-primary-200);
--color-primary-300: var(--ui-color-primary-300);
--color-primary-400: var(--ui-color-primary-400);
--color-primary-500: var(--ui-color-primary-500);
--color-primary-600: var(--ui-color-primary-600);
--color-primary-700: var(--ui-color-primary-700);
--color-primary-800: var(--ui-color-primary-800);
--color-primary-900: var(--ui-color-primary-900);
--color-primary-950: var(--ui-color-primary-950);
}
```

:::
::

::

### Tokens

Nuxt UI leverages a robust system of CSS variables as design tokens to ensure consistent and flexible component styling. These tokens form the foundation of the theming system, offering smooth support for both light and dark modes.
Expand Down
1 change: 1 addition & 0 deletions src/runtime/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import '#build/ui.css';
sandros94 marked this conversation as resolved.
Show resolved Hide resolved
@import './keyframes.css';

@variant dark (&:where(.dark, .dark *));
Expand Down
9 changes: 9 additions & 0 deletions src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export function getTemplates(options: ModuleOptions, uiConfig: Record<string, an
})
}

templates.push({
filename: 'ui.css',
write: true,
getContents: () => `@theme default {
${[...(options.theme?.colors || []), 'neutral'].map(color => [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950].map(shade => `--color-${color}-${shade}: var(--ui-color-${color}-${shade});`).join('\n\t')).join('\n\t')}
}
`
})

templates.push({
filename: 'ui/index.ts',
write: true,
Expand Down
Loading