mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
fix(module): handle tailwindcss import without theme(static) (#3630)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
import { computed } from 'vue'
|
||||
import colors from 'tailwindcss/colors'
|
||||
import type { UseHeadInput } from '@unhead/vue/types'
|
||||
import { defineNuxtPlugin, useAppConfig, useNuxtApp, useHead } from '#imports'
|
||||
// FIXME: https://github.com/nuxt/module-builder/issues/141#issuecomment-2078248248
|
||||
import type {} from '#app'
|
||||
import type { UseHeadInput } from '@unhead/vue/types'
|
||||
|
||||
const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const
|
||||
|
||||
function getColor(color: keyof typeof colors, shade: typeof shades[number]): string {
|
||||
if (color in colors && typeof colors[color] === 'object' && shade in colors[color]) {
|
||||
return colors[color][shade] as string
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function generateShades(key: string, value: string) {
|
||||
return `${shades.map(shade => `--ui-color-${key}-${shade}: var(--color-${value === 'neutral' ? 'old-neutral' : value}-${shade}, ${getColor(value as keyof typeof colors, shade)});`).join('\n ')}`
|
||||
}
|
||||
function generateColor(key: string, shade: number) {
|
||||
return `--ui-${key}: var(--ui-color-${key}-${shade});`
|
||||
}
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const appConfig = useAppConfig()
|
||||
const nuxtApp = useNuxtApp()
|
||||
|
||||
const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
|
||||
|
||||
function generateShades(key: string, value: string) {
|
||||
return `${shades.map(shade => `--ui-color-${key}-${shade}: var(--color-${value === 'neutral' ? 'old-neutral' : value}-${shade});`).join('\n ')}`
|
||||
}
|
||||
function generateColor(key: string, shade: number) {
|
||||
return `--ui-${key}: var(--ui-color-${key}-${shade});`
|
||||
}
|
||||
|
||||
const root = computed(() => {
|
||||
const { neutral, ...colors } = appConfig.ui.colors
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ export function getTemplates(options: ModuleOptions, uiConfig: Record<string, an
|
||||
write: true,
|
||||
getContents: () => `@source "./ui";
|
||||
|
||||
@theme default static {
|
||||
@theme default {
|
||||
--color-old-neutral-50: ${colors.neutral[50]};
|
||||
--color-old-neutral-100: ${colors.neutral[100]};
|
||||
--color-old-neutral-200: ${colors.neutral[200]};
|
||||
|
||||
Reference in New Issue
Block a user