From c79e6f188da1a508f0f736e70c28814ac01fe9f2 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Thu, 7 Mar 2024 15:33:53 +0100 Subject: [PATCH] chore(module): update theming --- src/module.ts | 55 ++++--- src/runtime/components/Button.vue | 18 +-- src/runtime/components/Container.vue | 2 +- src/runtime/components/Tooltip.vue | 2 +- src/runtime/plugins/index.ts | 1 - src/runtime/theme/button.ts | 142 ----------------- src/templates.ts | 25 ++- src/theme/button.ts | 149 ++++++++++++++++++ src/{runtime => }/theme/container.ts | 4 +- src/{runtime => }/theme/index.ts | 0 src/{runtime => }/theme/tooltip.ts | 4 +- .../__snapshots__/Button.spec.ts.snap | 40 ++--- 12 files changed, 231 insertions(+), 211 deletions(-) delete mode 100644 src/runtime/theme/button.ts create mode 100644 src/theme/button.ts rename src/{runtime => }/theme/container.ts (65%) rename src/{runtime => }/theme/index.ts (100%) rename src/{runtime => }/theme/tooltip.ts (90%) diff --git a/src/module.ts b/src/module.ts index be539dc9..5be8c361 100644 --- a/src/module.ts +++ b/src/module.ts @@ -2,27 +2,31 @@ import { defu } from 'defu' import { createResolver, defineNuxtModule, addComponentsDir, addImportsDir, addVitePlugin, addPlugin, installModule } from '@nuxt/kit' import tailwindcss from '@tailwindcss/vite' import createTemplates from './templates' -import type { DeepPartial } from './runtime/types' -import * as theme from './runtime/theme' +// import type { DeepPartial } from './runtime/types' +// import * as theme from './runtime/theme' -type UI = { - primary?: string - gray?: string - [key: string]: any -} & DeepPartial +// type UI = { +// primary?: string +// gray?: string +// [key: string]: any +// } & DeepPartial -declare module 'nuxt/schema' { - interface AppConfigInput { - ui?: UI - } -} -declare module '@nuxt/schema' { - interface AppConfigInput { - ui?: UI - } +// declare module 'nuxt/schema' { +// interface AppConfigInput { +// ui?: UI +// } +// } +// declare module '@nuxt/schema' { +// interface AppConfigInput { +// ui?: UI +// } +// } + +export interface ModuleOptions { + colors: string[] } -export default defineNuxtModule({ +export default defineNuxtModule({ meta: { name: 'ui', configKey: 'ui', @@ -30,10 +34,13 @@ export default defineNuxtModule({ nuxt: '^3.10.0' } }, - async setup (_, nuxt) { - const resolver = createResolver(import.meta.url) + defaults: { + colors: ['primary', 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchia', 'pink', 'rose'] + }, + async setup (options, nuxt) { + const { resolve } = createResolver(import.meta.url) - nuxt.options.alias['#ui'] = resolver.resolve('./runtime') + nuxt.options.alias['#ui'] = resolve('./runtime') nuxt.options.appConfig.ui = defu(nuxt.options.appConfig.ui || {}, { primary: 'green', @@ -49,21 +56,21 @@ export default defineNuxtModule({ addVitePlugin(tailwindcss) - createTemplates(nuxt) + createTemplates(options, nuxt) await installModule('nuxt-icon') // await installModule('@nuxtjs/color-mode', { classSuffix: '' }) addPlugin({ - src: resolver.resolve('./runtime/plugins/index') + src: resolve('./runtime/plugins/index') }) addComponentsDir({ - path: resolver.resolve('./runtime/components'), + path: resolve('./runtime/components'), prefix: 'U', pathPrefix: false }) - addImportsDir(resolver.resolve('./runtime/composables')) + addImportsDir(resolve('./runtime/composables')) } }) diff --git a/src/runtime/components/Button.vue b/src/runtime/components/Button.vue index 769ae128..5356078a 100644 --- a/src/runtime/components/Button.vue +++ b/src/runtime/components/Button.vue @@ -2,10 +2,11 @@ import { tv, type VariantProps } from 'tailwind-variants' // import appConfig from '#build/app.config' import type { LinkProps } from '#ui/components/Link.vue' -import theme from '#ui/theme/button' +import theme from '#build/ui/button' +// @ts-ignore const button = tv(theme) -// const appButton = tv({ extend: button, ...(appConfig.ui?.button || {}) }) +// const button = tv({ extend: tv(theme), ...(appConfig.ui?.button || {}) }) type ButtonVariants = VariantProps @@ -90,19 +91,6 @@ const trailingIconName = computed(() => { :disabled="disabled || loading" :class="ui.base({ class: props.class })" v-bind="{ ...forward, ...$attrs }" - :style="color && { - '--color-current-50': `var(--color-${color}-50)`, - '--color-current-100': `var(--color-${color}-100)`, - '--color-current-200': `var(--color-${color}-200)`, - '--color-current-300': `var(--color-${color}-300)`, - '--color-current-400': `var(--color-${color}-400)`, - '--color-current-500': `var(--color-${color}-500)`, - '--color-current-600': `var(--color-${color}-600)`, - '--color-current-700': `var(--color-${color}-700)`, - '--color-current-800': `var(--color-${color}-800)`, - '--color-current-900': `var(--color-${color}-900)`, - '--color-current-950': `var(--color-${color}-950)` - }" >