mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { defu } from 'defu'
|
|
import { createResolver, defineNuxtModule, addComponentsDir, addImportsDir, addVitePlugin, addPlugin, installModule } from '@nuxt/kit'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
import { addTemplates } from './templates'
|
|
import icons from './theme/icons'
|
|
|
|
export type * from './runtime/types'
|
|
|
|
export interface ModuleOptions {
|
|
/**
|
|
* Prefix for components
|
|
* @defaultValue U
|
|
*/
|
|
prefix?: string
|
|
/**
|
|
* Colors to generate classes for (based on TailwindCSS colors)
|
|
* @defaultValue ['primary', 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchia', 'pink', 'rose']
|
|
*/
|
|
colors?: string[]
|
|
/**
|
|
* Disable color transitions
|
|
* @defaultValue true
|
|
*/
|
|
transitions?: boolean
|
|
}
|
|
|
|
export default defineNuxtModule<ModuleOptions>({
|
|
meta: {
|
|
name: 'ui',
|
|
configKey: 'ui',
|
|
compatibility: {
|
|
nuxt: '>=3.10.0'
|
|
}
|
|
},
|
|
defaults: {
|
|
prefix: 'U',
|
|
colors: undefined,
|
|
transitions: true
|
|
},
|
|
async setup(options, nuxt) {
|
|
const { resolve } = createResolver(import.meta.url)
|
|
|
|
options.colors = options.colors?.length ? [...new Set(['primary', ...options.colors])] : ['primary', 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchia', 'pink', 'rose']
|
|
|
|
// @ts-expect-error - Add ui options to nuxt
|
|
nuxt.options.ui = options
|
|
|
|
nuxt.options.alias['#ui'] = resolve('./runtime')
|
|
|
|
nuxt.options.appConfig.ui = defu(nuxt.options.appConfig.ui || {}, {
|
|
primary: 'green',
|
|
gray: 'cool',
|
|
icons
|
|
})
|
|
|
|
// Isolate root node from portaled components
|
|
nuxt.options.app.rootAttrs = nuxt.options.app.rootAttrs || {}
|
|
nuxt.options.app.rootAttrs.class = [nuxt.options.app.rootAttrs.class, 'isolate'].filter(Boolean).join(' ')
|
|
|
|
// Add keyframes for animations
|
|
nuxt.options.css.push(resolve('./runtime/assets/css/animations.css'))
|
|
|
|
addVitePlugin(tailwindcss)
|
|
|
|
await installModule('@nuxt/icon', {
|
|
componentName: 'UIcon',
|
|
cssLayer: 'components'
|
|
})
|
|
// await installModule('@nuxtjs/color-mode', { classSuffix: '' })
|
|
|
|
addPlugin({
|
|
src: resolve('./runtime/plugins/colors')
|
|
})
|
|
addPlugin({
|
|
src: resolve('./runtime/plugins/modal')
|
|
})
|
|
addPlugin({
|
|
src: resolve('./runtime/plugins/slideover')
|
|
})
|
|
|
|
addComponentsDir({
|
|
path: resolve('./runtime/components'),
|
|
prefix: options.prefix,
|
|
pathPrefix: false
|
|
})
|
|
|
|
addImportsDir(resolve('./runtime/composables'))
|
|
|
|
addTemplates(options, nuxt)
|
|
}
|
|
})
|