mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-21 23:40:39 +01:00
refactor(module)!: implement design system with CSS variables (#2298)
This commit is contained in:
@@ -2,6 +2,7 @@ import { defu } from 'defu'
|
||||
import { createResolver, defineNuxtModule, addComponentsDir, addImportsDir, addVitePlugin, addPlugin, installModule, hasNuxtModule } from '@nuxt/kit'
|
||||
import { addTemplates } from './templates'
|
||||
import icons from './theme/icons'
|
||||
import { pick } from './runtime/utils'
|
||||
|
||||
export type * from './runtime/types'
|
||||
|
||||
@@ -18,10 +19,16 @@ export interface ModuleOptions {
|
||||
*/
|
||||
fonts?: boolean
|
||||
|
||||
/**
|
||||
* Enable or disable `@nuxtjs/color-mode` module
|
||||
* @defaultValue true
|
||||
*/
|
||||
colorMode?: boolean
|
||||
|
||||
theme?: {
|
||||
/**
|
||||
* Colors to generate classes for (defaults to TailwindCSS colors)
|
||||
* @defaultValue ['red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose']
|
||||
* @defaultValue ['primary', 'secondary', 'success', 'info', 'warning', 'error']
|
||||
*/
|
||||
colors?: string[]
|
||||
|
||||
@@ -44,6 +51,7 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
defaults: {
|
||||
prefix: 'U',
|
||||
fonts: true,
|
||||
colorMode: true,
|
||||
theme: {
|
||||
colors: undefined,
|
||||
transitions: true
|
||||
@@ -53,18 +61,22 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
const { resolve } = createResolver(import.meta.url)
|
||||
|
||||
options.theme = options.theme || {}
|
||||
options.theme.colors = options.theme.colors?.length ? [...new Set(['primary', 'error', ...options.theme.colors])] : ['primary', 'error', 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose']
|
||||
options.theme.colors = options.theme.colors?.length ? [...new Set(['primary', ...options.theme.colors])] : ['primary', 'secondary', 'success', 'info', 'warning', 'error']
|
||||
|
||||
nuxt.options.ui = options
|
||||
|
||||
nuxt.options.alias['#ui'] = resolve('./runtime')
|
||||
|
||||
nuxt.options.appConfig.ui = defu(nuxt.options.appConfig.ui || {}, {
|
||||
colors: {
|
||||
colors: pick({
|
||||
primary: 'green',
|
||||
secondary: 'blue',
|
||||
success: 'green',
|
||||
info: 'blue',
|
||||
warning: 'yellow',
|
||||
error: 'red',
|
||||
gray: 'slate'
|
||||
},
|
||||
neutral: 'slate'
|
||||
}, [...(options.theme?.colors || []), 'neutral' as any]),
|
||||
icons
|
||||
})
|
||||
|
||||
@@ -88,8 +100,12 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
}
|
||||
|
||||
await registerModule('@nuxt/icon', { cssLayer: 'components' })
|
||||
await registerModule('@nuxt/fonts', { experimental: { processCSSVariables: true } })
|
||||
await registerModule('@nuxtjs/color-mode', { classSuffix: '', disableTransition: true })
|
||||
if (options.fonts) {
|
||||
await registerModule('@nuxt/fonts', { experimental: { processCSSVariables: true } })
|
||||
}
|
||||
if (options.colorMode) {
|
||||
await registerModule('@nuxtjs/color-mode', { classSuffix: '', disableTransition: true })
|
||||
}
|
||||
|
||||
addPlugin({ src: resolve('./runtime/plugins/colors') })
|
||||
addPlugin({ src: resolve('./runtime/plugins/modal') })
|
||||
|
||||
Reference in New Issue
Block a user