Skip to content

Commit 1cc7e2a

Browse files
authoredAug 2, 2024··
fix(module): handle nested colors from ui config (#2008)

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

‎docs/content/1.getting-started/3.theming.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default defineAppConfig({
2323
Try to change the `primary` and `gray` colors by clicking on the :u-icon{name="i-heroicons-swatch-20-solid" class="w-4 h-4 align-middle text-primary-500 dark:text-primary-400"} button in the header.
2424
::
2525

26-
As this module uses Tailwind CSS under the hood, you can use any of the [Tailwind CSS colors](https://tailwindcss.com/docs/customizing-colors#color-palette-reference) or your own custom colors. By default, the `primary` color is `green` and the `gray` color is `cool`.
26+
As this module uses Tailwind CSS under the hood, you can use any of the [Tailwind CSS colors](https://tailwindcss.com/docs/customizing-colors#color-palette-reference) or your own custom colors or groups, such as `brand.primary`. By default, the `primary` color is `green` and the `gray` color is `cool`.
2727

2828
When [using custom colors](https://tailwindcss.com/docs/customizing-colors#using-custom-colors) or [adding additional colors](https://tailwindcss.com/docs/customizing-colors#adding-additional-colors) through the `extend` key in your `tailwind.config.ts`, you'll need to make sure to define all the shades from `50` to `950` as most of them are used in the components config defined in [`ui.config/`](https://github.com/nuxt/ui/tree/dev/src/runtime/ui.config) directory. You can [generate your colors](https://tailwindcss.com/docs/customizing-colors#generating-colors) using tools such as https://uicolors.app/ for example.
2929

‎src/runtime/plugins/colors.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed } from 'vue'
2-
import { hexToRgb } from '../utils'
2+
import { get, hexToRgb } from '../utils'
33
import { defineNuxtPlugin, useAppConfig, useNuxtApp, useHead } from '#imports'
44
import colors from '#tailwind-config/theme/colors'
55

@@ -8,8 +8,8 @@ export default defineNuxtPlugin(() => {
88
const nuxtApp = useNuxtApp()
99

1010
const root = computed(() => {
11-
const primary: Record<string, string> | undefined = colors[appConfig.ui.primary]
12-
const gray: Record<string, string> | undefined = colors[appConfig.ui.gray]
11+
const primary: Record<string, string> | undefined = get(colors, appConfig.ui.primary)
12+
const gray: Record<string, string> | undefined = get(colors, appConfig.ui.gray)
1313

1414
if (!primary) {
1515
console.warn(`[@nuxt/ui] Primary color '${appConfig.ui.primary}' not found in Tailwind config`)

0 commit comments

Comments
 (0)
Please sign in to comment.