feat(module)!: use tailwind-merge for app.config & move config to components & type props (#692)

Co-authored-by: Pooya Parsa <pooya@pi0.io>
This commit is contained in:
Benjamin Canac
2023-09-20 18:07:51 +02:00
committed by GitHub
parent 2c98628f98
commit 34d2f57801
59 changed files with 835 additions and 882 deletions

View File

@@ -52,12 +52,12 @@ jobs:
- name: Lint - name: Lint
run: pnpm run lint run: pnpm run lint
- name: Build
run: pnpm run build
- name: Typecheck - name: Typecheck
run: pnpm run typecheck run: pnpm run typecheck
- name: Build
run: pnpm run build
- name: Release Edge - name: Release Edge
if: github.event_name == 'push' if: github.event_name == 'push'
run: ./scripts/release-edge.sh run: ./scripts/release-edge.sh

View File

@@ -52,12 +52,12 @@ jobs:
- name: Lint - name: Lint
run: pnpm run lint run: pnpm run lint
- name: Build
run: pnpm run build
- name: Typecheck - name: Typecheck
run: pnpm run typecheck run: pnpm run typecheck
- name: Build
run: pnpm run build
- name: Version Check - name: Version Check
id: check id: check
uses: EndBug/version-check@v2 uses: EndBug/version-check@v2

3
.nuxtrc Normal file
View File

@@ -0,0 +1,3 @@
imports.autoImport=false
typescript.includeWorkspace=true
typescript.strict=false

1
docs/.nuxtrc Normal file
View File

@@ -0,0 +1 @@
imports.autoImport=true

View File

@@ -24,10 +24,14 @@
</template> </template>
<template #right> <template #right>
<UButton aria-label="Nuxt Website" icon="i-simple-icons-nuxtdotjs" to="https://nuxt.com" target="_blank" v-bind="$elements.button.secondary" /> <UButton aria-label="Nuxt Website" icon="i-simple-icons-nuxtdotjs" to="https://nuxt.com" target="_blank" v-bind="($elements.button.secondary as any)" />
<UButton aria-label="Nuxt on X" icon="i-simple-icons-x" to="https://x.com/nuxt_js" target="_blank" v-bind="$elements.button.secondary" /> <UButton aria-label="Nuxt on X" icon="i-simple-icons-x" to="https://x.com/nuxt_js" target="_blank" v-bind="($elements.button.secondary as any)" />
<UButton aria-label="Nuxt UI on Discord" icon="i-simple-icons-discord" to="https://discord.com/channels/473401852243869706/1153996761426300948" target="_blank" v-bind="$elements.button.secondary" /> <UButton aria-label="Nuxt UI on Discord" icon="i-simple-icons-discord" to="https://discord.com/channels/473401852243869706/1153996761426300948" target="_blank" v-bind="($elements.button.secondary as any)" />
<UButton aria-label="Nuxt UI on GitHub" icon="i-simple-icons-github" to="https://github.com/nuxt/ui" target="_blank" v-bind="$elements.button.secondary" /> <UButton aria-label="Nuxt UI on GitHub" icon="i-simple-icons-github" to="https://github.com/nuxt/ui" target="_blank" v-bind="($elements.button.secondary as any)" />
</template> </template>
</UFooter> </UFooter>
</template> </template>
<script setup lang="ts">
// force typescript
</script>

View File

@@ -27,7 +27,7 @@
icon="i-simple-icons-github" icon="i-simple-icons-github"
aria-label="GitHub" aria-label="GitHub"
class="hidden lg:inline-flex" class="hidden lg:inline-flex"
v-bind="$elements.button.secondary" v-bind="($elements.button.secondary as any)"
/> />
</template> </template>

View File

@@ -27,8 +27,6 @@ const links = [{
to: 'https://github.com/smarroufin', to: 'https://github.com/smarroufin',
target: '_blank' target: '_blank'
}] }]
const { ui } = useAppConfig()
</script> </script>
<template> <template>
@@ -36,8 +34,8 @@ const { ui } = useAppConfig()
<template #avatar="{ link }"> <template #avatar="{ link }">
<UAvatar <UAvatar
v-if="link.avatar" v-if="link.avatar"
v-bind="{ size: ui.verticalNavigation.avatar.size, ...link.avatar }" v-bind="link.avatar"
:class="[ui.verticalNavigation.avatar.base]" size="3xs"
loading="lazy" loading="lazy"
/> />
<UIcon v-else name="i-heroicons-user-circle-20-solid" class="text-lg" /> <UIcon v-else name="i-heroicons-user-circle-20-solid" class="text-lg" />

View File

@@ -1,5 +1,7 @@
--- ---
description: 'Learn how to customize the look and feel of the components.' description: 'Learn how to customize the look and feel of the components.'
navigation:
badge: New
--- ---
## Overview ## Overview
@@ -79,7 +81,7 @@ This can also happen when you bind a dynamic color to a component: `<UBadge :col
### `app.config.ts` ### `app.config.ts`
Components are styled with Tailwind CSS but classes are all defined in the default [app.config.ts](https://github.com/nuxt/ui/blob/dev/src/runtime/app.config.ts) file. You can override those in your own `app.config.ts`. Components are styled with Tailwind CSS but classes are all defined in the default [ui.config.ts](https://github.com/nuxt/ui/blob/dev/src/runtime/ui.config.ts) file. You can override those in your own `app.config.ts`.
```ts [app.config.ts] ```ts [app.config.ts]
export default defineAppConfig({ export default defineAppConfig({
@@ -91,6 +93,25 @@ export default defineAppConfig({
}) })
``` ```
Thanks to [tailwind-merge](https://github.com/dcastil/tailwind-merge), the `app.config.ts` is smartly merged with the default config. This means you don't have to rewrite everything.
You can change this behaviour by setting `strategy` to `override` in your `app.config.ts`: :u-badge{label="New" class="!rounded-full" variant="subtle"}
```ts [app.config.ts]
export default defineAppConfig({
ui: {
strategy: 'override',
button: {
color: {
white: {
solid: 'bg-white dark:bg-gray-900'
}
}
}
}
})
```
### `ui` prop ### `ui` prop
Each component has a `ui` prop that allows you to customize everything specifically. Each component has a `ui` prop that allows you to customize everything specifically.
@@ -113,25 +134,36 @@ For example, the default preset of the `FormGroup` component looks like this:
```json ```json
{ {
...
"label": { "label": {
"base": "block font-medium text-gray-700 dark:text-gray-200", "base": "block font-medium text-gray-700 dark:text-gray-200"
...
} }
...
} }
``` ```
To change the font of the `label`, you only need to write: To change the font of the `label`, you only need to write:
```vue ```vue
<UFormGroup name="email" label="Email" :ui="{ label: { base: 'font-semibold' } }"> <UFormGroup name="email" label="Email" :ui="{ label: { base: 'font-semibold' } }" />
...
</UFormGroup>
``` ```
This will smartly replace the `font-medium` by `font-semibold` and prevent any class duplication and any class priority issue. This will smartly replace the `font-medium` by `font-semibold` and prevent any class duplication and any class priority issue.
You can change this behaviour by setting `strategy` to `override` inside the `ui` prop: :u-badge{label="New" class="!rounded-full" variant="subtle"}
```vue
<UButton
to="https://github.com/nuxt/ui"
:ui="{
strategy: 'override',
color: {
white: {
solid: 'bg-white dark:bg-gray-900'
}
}
}"
/>
```
### `class` attribute ### `class` attribute
You can also use the `class` attribute to add classes to the component. You can also use the `class` attribute to add classes to the component.

View File

@@ -125,8 +125,6 @@ const links = [{
to: 'https://github.com/benjamincanac', to: 'https://github.com/benjamincanac',
target: '_blank' target: '_blank'
}, ...] }, ...]
const { ui } = useAppConfig()
</script> </script>
<template> <template>
@@ -134,8 +132,8 @@ const { ui } = useAppConfig()
<template #avatar="{ link }"> <template #avatar="{ link }">
<UAvatar <UAvatar
v-if="link.avatar" v-if="link.avatar"
v-bind="{ size: ui.verticalNavigation.avatar.size, ...link.avatar }" v-bind="link.avatar"
:class="[ui.verticalNavigation.avatar.base]" size="3xs"
/> />
<UIcon v-else name="i-heroicons-user-circle-20-solid" class="text-lg" /> <UIcon v-else name="i-heroicons-user-circle-20-solid" class="text-lg" />
</template> </template>

View File

@@ -76,10 +76,6 @@ export default defineNuxtConfig({
exposed: false exposed: false
} }
}, },
typescript: {
strict: false,
includeWorkspace: true
},
hooks: { hooks: {
// Related to https://github.com/nuxt/nuxt/pull/22558 // Related to https://github.com/nuxt/nuxt/pull/22558
'components:extend': (components) => { 'components:extend': (components) => {

View File

@@ -10,7 +10,7 @@
"@nuxt/content": "npm:@nuxt/content-edge@2.8.2-28246255.cae34d7", "@nuxt/content": "npm:@nuxt/content-edge@2.8.2-28246255.cae34d7",
"@nuxt/devtools": "^0.8.3", "@nuxt/devtools": "^0.8.3",
"@nuxt/eslint-config": "^0.2.0", "@nuxt/eslint-config": "^0.2.0",
"@nuxthq/elements": "npm:@nuxthq/elements-edge@0.0.1-28246521.0e46d44", "@nuxthq/elements": "npm:@nuxthq/elements-edge@0.0.1-28253627.e4bd6ad",
"@nuxthq/studio": "^0.14.1", "@nuxthq/studio": "^0.14.1",
"@nuxtjs/fontaine": "^0.4.1", "@nuxtjs/fontaine": "^0.4.1",
"@nuxtjs/google-fonts": "^3.0.2", "@nuxtjs/google-fonts": "^3.0.2",

View File

@@ -25,8 +25,8 @@
"build:docs": "nuxi generate docs", "build:docs": "nuxi generate docs",
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"typecheck": "nuxi typecheck", "typecheck": "vue-tsc --noEmit && nuxi typecheck docs",
"prepare": "nuxi prepare docs", "prepare": "nuxt-module-build --stub && nuxt-module-build prepare && nuxi prepare docs",
"release": "release-it" "release": "release-it"
}, },
"dependencies": { "dependencies": {
@@ -45,9 +45,10 @@
"@vueuse/integrations": "^10.4.1", "@vueuse/integrations": "^10.4.1",
"@vueuse/math": "^10.4.1", "@vueuse/math": "^10.4.1",
"defu": "^6.1.2", "defu": "^6.1.2",
"ohash": "^1.1.3",
"scule": "^1.0.0",
"fuse.js": "^6.6.2", "fuse.js": "^6.6.2",
"ohash": "^1.1.3",
"pathe": "^1.1.1",
"scule": "^1.0.0",
"tailwind-merge": "^1.14.0", "tailwind-merge": "^1.14.0",
"tailwindcss": "^3.3.3" "tailwindcss": "^3.3.3"
}, },
@@ -61,9 +62,9 @@
"release-it": "^16.1.5", "release-it": "^16.1.5",
"typescript": "^5.2.2", "typescript": "^5.2.2",
"unbuild": "^2.0.0", "unbuild": "^2.0.0",
"valibot": "^0.15.0",
"vue-tsc": "^1.8.11", "vue-tsc": "^1.8.11",
"yup": "^1.2.0", "yup": "^1.2.0",
"zod": "^3.22.2", "zod": "^3.22.2"
"valibot": "^0.15.0"
} }
} }

20
pnpm-lock.yaml generated
View File

@@ -59,6 +59,9 @@ importers:
ohash: ohash:
specifier: ^1.1.3 specifier: ^1.1.3
version: 1.1.3 version: 1.1.3
pathe:
specifier: ^1.1.1
version: 1.1.1
scule: scule:
specifier: ^1.0.0 specifier: ^1.0.0
version: 1.0.0 version: 1.0.0
@@ -120,7 +123,7 @@ importers:
version: 1.1.12 version: 1.1.12
'@iconify-json/simple-icons': '@iconify-json/simple-icons':
specifier: latest specifier: latest
version: 1.1.70 version: 1.1.71
'@nuxt/content': '@nuxt/content':
specifier: npm:@nuxt/content-edge@2.8.2-28246255.cae34d7 specifier: npm:@nuxt/content-edge@2.8.2-28246255.cae34d7
version: /@nuxt/content-edge@2.8.2-28246255.cae34d7(rollup@3.28.1)(vue@3.3.4) version: /@nuxt/content-edge@2.8.2-28246255.cae34d7(rollup@3.28.1)(vue@3.3.4)
@@ -131,8 +134,8 @@ importers:
specifier: ^0.2.0 specifier: ^0.2.0
version: 0.2.0(eslint@8.49.0) version: 0.2.0(eslint@8.49.0)
'@nuxthq/elements': '@nuxthq/elements':
specifier: npm:@nuxthq/elements-edge@0.0.1-28246521.0e46d44 specifier: npm:@nuxthq/elements-edge@0.0.1-28253627.e4bd6ad
version: /@nuxthq/elements-edge@0.0.1-28246521.0e46d44(rollup@3.28.1)(vue@3.3.4)(webpack@5.88.2) version: /@nuxthq/elements-edge@0.0.1-28253627.e4bd6ad(rollup@3.28.1)(vue@3.3.4)(webpack@5.88.2)
'@nuxthq/studio': '@nuxthq/studio':
specifier: ^0.14.1 specifier: ^0.14.1
version: 0.14.1(rollup@3.28.1) version: 0.14.1(rollup@3.28.1)
@@ -1061,8 +1064,8 @@ packages:
dependencies: dependencies:
'@iconify/types': 2.0.0 '@iconify/types': 2.0.0
/@iconify-json/simple-icons@1.1.70: /@iconify-json/simple-icons@1.1.71:
resolution: {integrity: sha512-YZoHn180s0PELhjlMMTMVG8FxQOfP3AIn7P6KNV8xONzt/GwqMkYQ92DNYZbvSyQ4NhRajm27YkaOeSwNusr7A==} resolution: {integrity: sha512-3WVgJTaWBUOvq4G99v3Qs46zqnOJGNVMMlKCw+p8/gfbVz9mEAiwiqfGr+mpraotuwvUuQoJMi4SyseO8qjYDQ==}
dependencies: dependencies:
'@iconify/types': 2.0.0 '@iconify/types': 2.0.0
dev: true dev: true
@@ -1748,8 +1751,8 @@ packages:
- vue-tsc - vue-tsc
dev: true dev: true
/@nuxthq/elements-edge@0.0.1-28246521.0e46d44(rollup@3.28.1)(vue@3.3.4)(webpack@5.88.2): /@nuxthq/elements-edge@0.0.1-28253627.e4bd6ad(rollup@3.28.1)(vue@3.3.4)(webpack@5.88.2):
resolution: {integrity: sha512-8MU2WXawTcZFpaAOuz0WYDBR8fjblH6UTS9wlXz3qNRya15wOAH62a7VNfdy2xsE8Rlmv1DeuIVFZnIO24Rmbw==} resolution: {integrity: sha512-y7ujX/dr4CcmY1JilTjpU++IEN5+9NrdeQseC8+OvLE3rHE0/5d9KWusa+0y+o5z3NjM3mzupSYraBWoH8/qvQ==}
dependencies: dependencies:
'@nuxt/ui': 2.8.1(rollup@3.28.1)(vue@3.3.4)(webpack@5.88.2) '@nuxt/ui': 2.8.1(rollup@3.28.1)(vue@3.3.4)(webpack@5.88.2)
'@vueuse/core': 10.4.1(vue@3.3.4) '@vueuse/core': 10.4.1(vue@3.3.4)
@@ -7050,6 +7053,7 @@ packages:
/jiti@1.19.3: /jiti@1.19.3:
resolution: {integrity: sha512-5eEbBDQT/jF1xg6l36P+mWGGoH9Spuy0PCdSr2dtWRDGC6ph/w9ZCL4lmESW8f8F7MwT3XKescfP0wnZWAKL9w==} resolution: {integrity: sha512-5eEbBDQT/jF1xg6l36P+mWGGoH9Spuy0PCdSr2dtWRDGC6ph/w9ZCL4lmESW8f8F7MwT3XKescfP0wnZWAKL9w==}
hasBin: true hasBin: true
dev: true
/jiti@1.20.0: /jiti@1.20.0:
resolution: {integrity: sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==} resolution: {integrity: sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==}
@@ -11191,7 +11195,7 @@ packages:
fast-glob: 3.3.1 fast-glob: 3.3.1
glob-parent: 6.0.2 glob-parent: 6.0.2
is-glob: 4.0.3 is-glob: 4.0.3
jiti: 1.19.3 jiti: 1.20.0
lilconfig: 2.1.0 lilconfig: 2.1.0
micromatch: 4.0.5 micromatch: 4.0.5
normalize-path: 3.0.0 normalize-path: 3.0.0

View File

@@ -1,12 +1,12 @@
import { defineNuxtModule, installModule, addComponentsDir, addImportsDir, createResolver, addPlugin, resolvePath } from '@nuxt/kit' import { defineNuxtModule, installModule, addComponentsDir, addImportsDir, createResolver, addPlugin } from '@nuxt/kit'
import defaultColors from 'tailwindcss/colors.js' import defaultColors from 'tailwindcss/colors.js'
import { defaultExtractor as createDefaultExtractor } from 'tailwindcss/lib/lib/defaultExtractor.js' import { defaultExtractor as createDefaultExtractor } from 'tailwindcss/lib/lib/defaultExtractor.js'
import { iconsPlugin, getIconCollections } from '@egoist/tailwindcss-icons' import { iconsPlugin, getIconCollections } from '@egoist/tailwindcss-icons'
import { name, version } from '../package.json' import { name, version } from '../package.json'
import { generateSafelist, excludeColors, customSafelistExtractor } from './colors' import { generateSafelist, excludeColors, customSafelistExtractor } from './colors'
import appConfig from './runtime/app.config' import createTemplates from './templates'
import * as config from './runtime/ui.config'
type DeepPartial<T> = Partial<{ [P in keyof T]: DeepPartial<T[P]> | { [key: string]: string } }> import type { DeepPartial, Strategy } from './runtime/types/utils'
const defaultExtractor = createDefaultExtractor({ tailwindConfig: { separator: ':' } }) const defaultExtractor = createDefaultExtractor({ tailwindConfig: { separator: ':' } })
@@ -16,13 +16,21 @@ delete defaultColors.trueGray
delete defaultColors.coolGray delete defaultColors.coolGray
delete defaultColors.blueGray delete defaultColors.blueGray
type UI = {
primary?: string
gray?: string
colors?: string[]
strategy?: Strategy
} & DeepPartial<typeof config>
declare module 'nuxt/schema' {
interface AppConfigInput {
ui?: UI
}
}
declare module '@nuxt/schema' { declare module '@nuxt/schema' {
interface AppConfigInput { interface AppConfigInput {
ui?: { ui?: UI
primary?: string
gray?: string
colors?: string[]
} & DeepPartial<typeof appConfig.ui>
} }
} }
@@ -64,12 +72,9 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.build.transpile.push(runtimeDir) nuxt.options.build.transpile.push(runtimeDir)
nuxt.options.build.transpile.push('@popperjs/core', '@headlessui/vue') nuxt.options.build.transpile.push('@popperjs/core', '@headlessui/vue')
nuxt.options.css.push(resolve(runtimeDir, 'ui.css')) nuxt.options.alias['#ui'] = runtimeDir
const appConfigFile = await resolvePath(resolve(runtimeDir, 'app.config')) nuxt.options.css.push(resolve(runtimeDir, 'ui.css'))
nuxt.hook('app:resolve', (app) => {
app.configs.push(appConfigFile)
})
nuxt.hook('tailwindcss:config', function (tailwindConfig) { nuxt.hook('tailwindcss:config', function (tailwindConfig) {
const globalColors: any = { const globalColors: any = {
@@ -117,10 +122,10 @@ export default defineNuxtModule<ModuleOptions>({
const colors = excludeColors(globalColors) const colors = excludeColors(globalColors)
nuxt.options.appConfig.ui = { nuxt.options.appConfig.ui = {
...nuxt.options.appConfig.ui,
primary: 'green', primary: 'green',
gray: 'cool', gray: 'cool',
colors colors,
strategy: 'merge'
} }
tailwindConfig.safelist = tailwindConfig.safelist || [] tailwindConfig.safelist = tailwindConfig.safelist || []
@@ -130,6 +135,8 @@ export default defineNuxtModule<ModuleOptions>({
tailwindConfig.plugins.push(iconsPlugin({ collections: getIconCollections(options.icons as any[]) })) tailwindConfig.plugins.push(iconsPlugin({ collections: getIconCollections(options.icons as any[]) }))
}) })
createTemplates(nuxt)
// Modules // Modules
await installModule('@nuxtjs/color-mode', { classSuffix: '' }) await installModule('@nuxtjs/color-mode', { classSuffix: '' })

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :class="wrapperClass" v-bind="attrs"> <div :class="ui.wrapper" v-bind="attrs">
<table :class="[ui.base, ui.divide]"> <table :class="[ui.base, ui.divide]">
<thead :class="ui.thead"> <thead :class="ui.thead">
<tr :class="ui.tr.base"> <tr :class="ui.tr.base">
@@ -71,19 +71,17 @@ import { ref, computed, defineComponent, toRaw } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { upperFirst } from 'scule' import { upperFirst } from 'scule'
import { defu } from 'defu' import { defu } from 'defu'
import { twMerge } from 'tailwind-merge'
import { omit, get } from '../../utils/lodash'
import { defuTwMerge } from '../../utils'
import UButton from '../elements/Button.vue' import UButton from '../elements/Button.vue'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UCheckbox from '../forms/Checkbox.vue' import UCheckbox from '../forms/Checkbox.vue'
import type { Button } from '../../types/button' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig, omit, get } from '../../utils'
// TODO: Remove import type { Strategy, Button } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { table } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof table>(appConfig.ui.strategy, appConfig.ui.table, table)
function defaultComparator<T> (a: T, z: T): boolean { function defaultComparator<T> (a: T, z: T): boolean {
return a === z return a === z
@@ -123,15 +121,15 @@ export default defineComponent({
}, },
sortButton: { sortButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.table.default.sortButton default: () => config.default.sortButton as Button
}, },
sortAscIcon: { sortAscIcon: {
type: String, type: String,
default: () => appConfig.ui.table.default.sortAscIcon default: () => config.default.sortAscIcon
}, },
sortDescIcon: { sortDescIcon: {
type: String, type: String,
default: () => appConfig.ui.table.default.sortDescIcon default: () => config.default.sortDescIcon
}, },
loading: { loading: {
type: Boolean, type: Boolean,
@@ -139,25 +137,20 @@ export default defineComponent({
}, },
loadingState: { loadingState: {
type: Object as PropType<{ icon: string, label: string }>, type: Object as PropType<{ icon: string, label: string }>,
default: () => appConfig.ui.table.default.loadingState default: () => config.default.loadingState
}, },
emptyState: { emptyState: {
type: Object as PropType<{ icon: string, label: string }>, type: Object as PropType<{ icon: string, label: string }>,
default: () => appConfig.ui.table.default.emptyState default: () => config.default.emptyState
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.table>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue'], emits: ['update:modelValue'],
setup (props, { emit, attrs }) { setup (props, { emit, attrs: $attrs }) {
// TODO: Remove const { ui, attrs } = useUI('table', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.table>>(() => defuTwMerge({}, props.ui, appConfig.ui.table))
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const columns = computed(() => props.columns ?? Object.keys(omit(props.rows[0] ?? {}, ['click'])).map((key) => ({ key, label: upperFirst(key), sortable: false }))) const columns = computed(() => props.columns ?? Object.keys(omit(props.rows[0] ?? {}, ['click'])).map((key) => ({ key, label: upperFirst(key), sortable: false })))
@@ -238,12 +231,12 @@ export default defineComponent({
} }
function onSelect (row) { function onSelect (row) {
if (!attrs.onSelect) { if (!$attrs.onSelect) {
return return
} }
// @ts-ignore // @ts-ignore
attrs.onSelect(row) $attrs.onSelect(row)
} }
function selectAllRows () { function selectAllRows () {
@@ -254,7 +247,7 @@ export default defineComponent({
} }
// @ts-ignore // @ts-ignore
attrs.onSelect ? attrs.onSelect(row) : selected.value.push(row) $attrs.onSelect ? $attrs.onSelect(row) : selected.value.push(row)
}) })
} }
@@ -271,10 +264,9 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
wrapperClass, attrs,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
sort, sort,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :class="wrapperClass"> <div :class="ui.wrapper">
<HDisclosure v-for="(item, index) in items" v-slot="{ open, close }" :key="index" :default-open="defaultOpen || item.defaultOpen"> <HDisclosure v-for="(item, index) in items" v-slot="{ open, close }" :key="index" :default-open="defaultOpen || item.defaultOpen">
<HDisclosureButton :ref="() => buttonRefs[index] = close" as="template" :disabled="item.disabled"> <HDisclosureButton :ref="() => buttonRefs[index] = close" as="template" :disabled="item.disabled">
<slot :item="item" :index="index" :open="open" :close="close"> <slot :item="item" :index="index" :open="open" :close="close">
@@ -43,17 +43,19 @@
import { ref, computed, defineComponent } from 'vue' import { ref, computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { Disclosure as HDisclosure, DisclosureButton as HDisclosureButton, DisclosurePanel as HDisclosurePanel } from '@headlessui/vue' import { Disclosure as HDisclosure, DisclosureButton as HDisclosureButton, DisclosurePanel as HDisclosurePanel } from '@headlessui/vue'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UButton from '../elements/Button.vue' import UButton from '../elements/Button.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { mergeConfig, omit } from '../../utils'
import StateEmitter from '../../utils/StateEmitter' import StateEmitter from '../../utils/StateEmitter'
import type { AccordionItem } from '../../types/accordion' import type { AccordionItem, Strategy } from '../../types'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { accordion, button } from '#ui/ui.config'
const config = mergeConfig<typeof accordion>(appConfig.ui.strategy, appConfig.ui.accordion, accordion)
const configButton = mergeConfig<typeof button>(appConfig.ui.strategy, appConfig.ui.button, button)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -76,30 +78,25 @@ export default defineComponent({
}, },
openIcon: { openIcon: {
type: String, type: String,
default: () => appConfig.ui.accordion.default.openIcon default: () => config.default.openIcon
}, },
closeIcon: { closeIcon: {
type: String, type: String,
default: () => appConfig.ui.accordion.default.closeIcon default: () => config.default.closeIcon
}, },
multiple: { multiple: {
type: Boolean, type: Boolean,
default: false default: false
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.accordion>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs } = useUI('accordion', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.accordion>>(() => defuTwMerge({}, props.ui, appConfig.ui.accordion)) const uiButton = computed<Partial<typeof configButton>>(() => configButton)
const uiButton = computed<Partial<typeof appConfig.ui.button>>(() => appConfig.ui.button)
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const buttonRefs = ref<Function[]>([]) const buttonRefs = ref<Function[]>([])
@@ -139,11 +136,10 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
uiButton, uiButton,
wrapperClass, attrs,
buttonRefs, buttonRefs,
closeOthers, closeOthers,
omit, omit,

View File

@@ -38,16 +38,15 @@ import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue' import UAvatar from '../elements/Avatar.vue'
import UButton from '../elements/Button.vue' import UButton from '../elements/Button.vue'
import type { Avatar } from '../../types/avatar' import { useUI } from '../../composables/useUI'
import type { Button } from '../../types/button' import type { Avatar, Button, NestedKeyOf, Strategy } from '../../types'
import { defuTwMerge } from '../../utils' import { mergeConfig } from '../../utils'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { omit } from '../../utils/lodash' import { alert } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof alert>(appConfig.ui.strategy, appConfig.ui.alert, alert)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -67,7 +66,7 @@ export default defineComponent({
}, },
icon: { icon: {
type: String, type: String,
default: () => appConfig.ui.alert.default.icon default: () => config.default.icon
}, },
avatar: { avatar: {
type: Object as PropType<Avatar>, type: Object as PropType<Avatar>,
@@ -75,40 +74,37 @@ export default defineComponent({
}, },
closeButton: { closeButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.alert.default.closeButton default: () => config.default.closeButton as Button
}, },
actions: { actions: {
type: Array as PropType<(Button & { click?: Function })[]>, type: Array as PropType<(Button & { click?: Function })[]>,
default: () => [] default: () => []
}, },
color: { color: {
type: String, type: String as PropType<keyof typeof config.color | typeof colors[number]>,
default: () => appConfig.ui.alert.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.alert.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
default: () => appConfig.ui.alert.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.alert.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.alert.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.alert>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['close'], emits: ['close'],
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('alert', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.alert>>(() => defuTwMerge({}, props.ui, appConfig.ui.alert))
const alertClass = computed(() => { const alertClass = computed(() => {
const variant = ui.value.color?.[props.color as string]?.[props.variant as string] || ui.value.variant[props.variant] const variant = ui.value.color?.[props.color as string]?.[props.variant as string] || ui.value.variant[props.variant]
@@ -119,13 +115,13 @@ export default defineComponent({
ui.value.shadow, ui.value.shadow,
ui.value.padding, ui.value.padding,
variant?.replaceAll('{color}', props.color) variant?.replaceAll('{color}', props.color)
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
alertClass alertClass
} }
} }

View File

@@ -24,13 +24,14 @@ import { defineComponent, ref, computed, watch } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { AvatarSize, AvatarChipColor, AvatarChipPosition, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { omit } from '../../utils/lodash' import { avatar } from '#ui/ui.config'
// const appConfig = useAppConfig()
const config = mergeConfig<typeof avatar>(appConfig.ui.strategy, appConfig.ui.avatar, avatar)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -52,27 +53,27 @@ export default defineComponent({
}, },
icon: { icon: {
type: String, type: String,
default: () => appConfig.ui.avatar.default.icon default: () => config.default.icon
}, },
size: { size: {
type: String, type: String as PropType<AvatarSize>,
default: () => appConfig.ui.avatar.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.avatar.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
chipColor: { chipColor: {
type: String, type: String as PropType<AvatarChipColor>,
default: () => appConfig.ui.avatar.default.chipColor, default: () => config.default.chipColor,
validator (value: string) { validator (value: string) {
return ['gray', ...appConfig.ui.colors].includes(value) return ['gray', ...appConfig.ui.colors].includes(value)
} }
}, },
chipPosition: { chipPosition: {
type: String, type: String as PropType<AvatarChipPosition>,
default: () => appConfig.ui.avatar.default.chipPosition, default: () => config.default.chipPosition,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.avatar.chip.position).includes(value) return Object.keys(config.chip.position).includes(value)
} }
}, },
chipText: { chipText: {
@@ -84,15 +85,12 @@ export default defineComponent({
default: '' default: ''
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.avatar>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('avatar', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.avatar>>(() => defuTwMerge({}, props.ui, appConfig.ui.avatar))
const url = computed(() => { const url = computed(() => {
if (typeof props.src === 'boolean') { if (typeof props.src === 'boolean') {
@@ -111,7 +109,7 @@ export default defineComponent({
(error.value || !url.value) && ui.value.background, (error.value || !url.value) && ui.value.background,
ui.value.rounded, ui.value.rounded,
ui.value.size[props.size] ui.value.size[props.size]
), attrs.class as string) ), attrsClass)
}) })
const imgClass = computed(() => { const imgClass = computed(() => {
@@ -150,7 +148,9 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])), // eslint-disable-next-line vue/no-dupe-keys
ui,
attrs,
wrapperClass, wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
imgClass, imgClass,

View File

@@ -1,24 +1,26 @@
import { h, cloneVNode, computed, defineComponent } from 'vue' import { h, cloneVNode, computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge, getSlotsChildren } from '../../utils' import UAvatar from './Avatar.vue'
import Avatar from './Avatar.vue' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig, getSlotsChildren } from '../../utils'
// TODO: Remove import type { AvatarSize, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { avatar, avatarGroup } from '#ui/ui.config'
// const appConfig = useAppConfig() const avatarConfig = mergeConfig<typeof avatar>(appConfig.ui.strategy, appConfig.ui.avatar, avatar)
const avatarGroupConfig = mergeConfig<typeof avatarGroup>(appConfig.ui.strategy, appConfig.ui.avatarGroup, avatarGroup)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: { props: {
size: { size: {
type: String, type: String as PropType<keyof typeof avatarConfig.size>,
default: null, default: null,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.avatar.size).includes(value) return Object.keys(avatarConfig.size).includes(value)
} }
}, },
max: { max: {
@@ -26,15 +28,12 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.avatarGroup>>, type: Object as PropType<Partial<typeof avatarGroupConfig & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs, slots }) { setup (props, { slots }) {
// TODO: Remove const { ui, attrs } = useUI('avatarGroup', props.ui, avatarGroupConfig, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.avatarGroup>>(() => defuTwMerge({}, props.ui, appConfig.ui.avatarGroup))
const children = computed(() => getSlotsChildren(slots)) const children = computed(() => getSlotsChildren(slots))
@@ -55,8 +54,8 @@ export default defineComponent({
} }
if (max.value !== undefined && index === max.value) { if (max.value !== undefined && index === max.value) {
return h(Avatar, { return h(UAvatar, {
size: props.size || appConfig.ui.avatar.default.size, size: props.size || (avatarConfig.default.size as AvatarSize),
text: `+${children.value.length - max.value}`, text: `+${children.value.length - max.value}`,
class: twJoin(ui.value.ring, ui.value.margin) class: twJoin(ui.value.ring, ui.value.margin)
}) })
@@ -65,6 +64,6 @@ export default defineComponent({
return null return null
}).filter(Boolean).reverse()) }).filter(Boolean).reverse())
return () => h('div', { class: twMerge(ui.value.wrapper, attrs.class as string), ...omit(attrs, ['class']) }, clones.value) return () => h('div', { class: ui.value.wrapper, ...attrs.value }, clones.value)
} }
}) })

View File

@@ -7,40 +7,41 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { NestedKeyOf, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { badge } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof badge>(appConfig.ui.strategy, appConfig.ui.badge, badge)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: { props: {
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.badge.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.badge.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<keyof typeof config.color | typeof colors[number]>,
default: () => appConfig.ui.badge.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.badge.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
default: () => appConfig.ui.badge.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.badge.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.badge.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
@@ -49,15 +50,12 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.badge>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('badge', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.badge>>(() => defuTwMerge({}, props.ui, appConfig.ui.badge))
const badgeClass = computed(() => { const badgeClass = computed(() => {
const variant = ui.value.color?.[props.color as string]?.[props.variant as string] || ui.value.variant[props.variant] const variant = ui.value.color?.[props.color as string]?.[props.variant as string] || ui.value.variant[props.variant]
@@ -68,11 +66,11 @@ export default defineComponent({
ui.value.rounded, ui.value.rounded,
ui.value.size[props.size], ui.value.size[props.size],
variant?.replaceAll('{color}', props.color) variant?.replaceAll('{color}', props.color)
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])), attrs,
badgeClass badgeClass
} }
} }

View File

@@ -19,17 +19,17 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import ULink from '../elements/Link.vue' import ULink from '../elements/Link.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { ButtonColor, ButtonSize, ButtonVariant, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { button } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof button>(appConfig.ui.strategy, appConfig.ui.button, button)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -63,26 +63,26 @@ export default defineComponent({
default: true default: true
}, },
size: { size: {
type: String, type: String as PropType<ButtonSize>,
default: () => appConfig.ui.button.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.button.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<ButtonColor>,
default: () => appConfig.ui.button.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.button.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<ButtonVariant>,
default: () => appConfig.ui.button.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.button.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.button.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
@@ -92,7 +92,7 @@ export default defineComponent({
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: () => appConfig.ui.button.default.loadingIcon default: () => config.default.loadingIcon
}, },
leadingIcon: { leadingIcon: {
type: String, type: String,
@@ -119,15 +119,12 @@ export default defineComponent({
default: false default: false
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.button>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs, slots }) { setup (props, { slots }) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('button', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.button>>(() => defuTwMerge({}, props.ui, appConfig.ui.button))
const isLeading = computed(() => { const isLeading = computed(() => {
return (props.icon && props.leading) || (props.icon && !props.trailing) || (props.loading && !props.trailing) || props.leadingIcon return (props.icon && props.leading) || (props.icon && !props.trailing) || (props.loading && !props.trailing) || props.leadingIcon
@@ -151,7 +148,7 @@ export default defineComponent({
props.padded && ui.value[isSquare.value ? 'square' : 'padding'][props.size], props.padded && ui.value[isSquare.value ? 'square' : 'padding'][props.size],
variant?.replaceAll('{color}', props.color), variant?.replaceAll('{color}', props.color),
props.block ? 'w-full flex justify-center items-center' : 'inline-flex items-center' props.block ? 'w-full flex justify-center items-center' : 'inline-flex items-center'
), attrs.class as string) ), attrsClass)
}) })
const leadingIconName = computed(() => { const leadingIconName = computed(() => {
@@ -187,7 +184,7 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])), attrs,
isLeading, isLeading,
isTrailing, isTrailing,
isSquare, isSquare,

View File

@@ -1,23 +1,24 @@
import { h, cloneVNode, computed, defineComponent } from 'vue' import { h, cloneVNode, computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge, getSlotsChildren } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig, getSlotsChildren } from '../../utils'
// TODO: Remove import type { ButtonSize, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { button, buttonGroup } from '#ui/ui.config'
// const appConfig = useAppConfig() const buttonConfig = mergeConfig<typeof button>(appConfig.ui.strategy, appConfig.ui.button, button)
const buttonGroupConfig = mergeConfig<typeof buttonGroup>(appConfig.ui.strategy, appConfig.ui.buttonGroup, buttonGroup)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: { props: {
size: { size: {
type: String, type: String as PropType<ButtonSize>,
default: null, default: null,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.button.size).includes(value) return Object.keys(buttonConfig.size).includes(value)
} }
}, },
orientation: { orientation: {
@@ -28,15 +29,12 @@ export default defineComponent({
} }
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.buttonGroup>>, type: Object as PropType<Partial<typeof buttonGroupConfig & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs, slots }) { setup (props, { slots }) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('buttonGroup', props.ui, buttonGroupConfig)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.buttonGroup>>(() => defuTwMerge({}, props.ui, appConfig.ui.buttonGroup))
const children = computed(() => getSlotsChildren(slots)) const children = computed(() => getSlotsChildren(slots))
@@ -58,12 +56,6 @@ export default defineComponent({
const clones = computed(() => children.value.map((node, index) => { const clones = computed(() => children.value.map((node, index) => {
const vProps: any = {} const vProps: any = {}
if (props.orientation === 'vertical') {
ui.value.wrapper = 'flex flex-col -space-y-px'
} else {
ui.value.wrapper = 'inline-flex -space-x-px'
}
if (props.size) { if (props.size) {
vProps.size = props.size vProps.size = props.size
} }
@@ -83,6 +75,14 @@ export default defineComponent({
return cloneVNode(node, vProps) return cloneVNode(node, vProps)
})) }))
return () => h('div', { class: twMerge(twJoin(ui.value.wrapper, ui.value.rounded, ui.value.shadow), attrs.class as string), ...omit(attrs, ['class']) }, clones.value) const wrapperClass = computed(() => {
return twMerge(twJoin(
ui.value.wrapper[props.orientation],
ui.value.rounded,
ui.value.shadow
), attrsClass)
})
return () => h('div', { class: wrapperClass.value, ...attrs.value }, clones.value)
} }
}) })

View File

@@ -1,5 +1,5 @@
<template> <template>
<HMenu v-slot="{ open }" as="div" :class="wrapperClass" v-bind="attrs" @mouseleave="onMouseLeave"> <HMenu v-slot="{ open }" as="div" :class="ui.wrapper" v-bind="attrs" @mouseleave="onMouseLeave">
<HMenuButton <HMenuButton
ref="trigger" ref="trigger"
as="div" as="div"
@@ -49,22 +49,19 @@ import { defineComponent, ref, computed, onMounted } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { Menu as HMenu, MenuButton as HMenuButton, MenuItems as HMenuItems, MenuItem as HMenuItem } from '@headlessui/vue' import { Menu as HMenu, MenuButton as HMenuButton, MenuItems as HMenuItems, MenuItem as HMenuItem } from '@headlessui/vue'
import { defu } from 'defu' import { defu } from 'defu'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue' import UAvatar from '../elements/Avatar.vue'
import UKbd from '../elements/Kbd.vue' import UKbd from '../elements/Kbd.vue'
import ULink from '../elements/Link.vue' import ULink from '../elements/Link.vue'
import { useUI } from '../../composables/useUI'
import { usePopper } from '../../composables/usePopper' import { usePopper } from '../../composables/usePopper'
import { defuTwMerge } from '../../utils' import { mergeConfig, omit } from '../../utils'
import type { DropdownItem } from '../../types/dropdown' import type { DropdownItem, PopperOptions, Strategy } from '../../types'
import type { PopperOptions } from '../../types/popper'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { dropdown } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof dropdown>(appConfig.ui.strategy, appConfig.ui.dropdown, dropdown)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -105,15 +102,12 @@ export default defineComponent({
default: 0 default: 0
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.dropdown>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs } = useUI('dropdown', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.dropdown>>(() => defuTwMerge({}, props.ui, appConfig.ui.dropdown))
const popper = computed<PopperOptions>(() => defu(props.mode === 'hover' ? { offsetDistance: 0 } : {}, props.popper, ui.value.popper as PopperOptions)) const popper = computed<PopperOptions>(() => defu(props.mode === 'hover' ? { offsetDistance: 0 } : {}, props.popper, ui.value.popper as PopperOptions))
@@ -143,8 +137,6 @@ export default defineComponent({
return props.mode === 'hover' ? { paddingTop: `${offsetDistance}px`, paddingBottom: `${offsetDistance}px` } : {} return props.mode === 'hover' ? { paddingTop: `${offsetDistance}px`, paddingBottom: `${offsetDistance}px` } : {}
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
function onMouseOver () { function onMouseOver () {
if (props.mode !== 'hover' || !menuApi.value) { if (props.mode !== 'hover' || !menuApi.value) {
return return
@@ -186,13 +178,12 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
trigger, trigger,
container, container,
containerStyle, containerStyle,
wrapperClass,
onMouseOver, onMouseOver,
onMouseLeave, onMouseLeave,
omit omit

View File

@@ -7,15 +7,15 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, computed } from 'vue' import { defineComponent, computed } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { kbd } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof kbd>(appConfig.ui.strategy, appConfig.ui.kbd, kbd)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -25,22 +25,19 @@ export default defineComponent({
default: null default: null
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.kbd.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.kbd.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.kbd>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('kbd', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.kbd>>(() => defuTwMerge({}, props.ui, appConfig.ui.kbd))
const kbdClass = computed(() => { const kbdClass = computed(() => {
return twMerge(twJoin( return twMerge(twJoin(
@@ -51,13 +48,13 @@ export default defineComponent({
ui.value.font, ui.value.font,
ui.value.background, ui.value.background,
ui.value.ring ui.value.ring
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
kbdClass kbdClass
} }
} }

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :class="wrapperClass"> <div :class="ui.wrapper">
<div class="flex items-center h-5"> <div class="flex items-center h-5">
<input <input
:id="name" :id="name"
@@ -32,16 +32,17 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { checkbox } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof checkbox>(appConfig.ui.strategy, appConfig.ui.checkbox, checkbox)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -83,8 +84,8 @@ export default defineComponent({
default: false default: false
}, },
color: { color: {
type: String, type: String as PropType<typeof colors[number]>,
default: () => appConfig.ui.checkbox.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return appConfig.ui.colors.includes(value) return appConfig.ui.colors.includes(value)
} }
@@ -94,16 +95,13 @@ export default defineComponent({
default: '' default: ''
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.checkbox>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'change'], emits: ['update:modelValue', 'change'],
setup (props, { emit, attrs }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs } = useUI('checkbox', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.checkbox>>(() => defuTwMerge({}, props.ui, appConfig.ui.checkbox))
const { emitFormChange, formGroup } = useFormGroup() const { emitFormChange, formGroup } = useFormGroup()
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
@@ -122,8 +120,6 @@ export default defineComponent({
emitFormChange() emitFormChange()
} }
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const inputClass = computed(() => { const inputClass = computed(() => {
return twMerge(twJoin( return twMerge(twJoin(
ui.value.base, ui.value.base,
@@ -136,11 +132,10 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
toggle, toggle,
wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
inputClass, inputClass,
onChange onChange

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :class="wrapperClass" v-bind="attrs"> <div :class="ui.wrapper" v-bind="attrs">
<div v-if="label" :class="[ui.label.wrapper, size]"> <div v-if="label" :class="[ui.label.wrapper, size]">
<label :for="labelFor" :class="[ui.label.base, required ? ui.label.required : '']">{{ label }}</label> <label :for="labelFor" :class="[ui.label.base, required ? ui.label.required : '']">{{ label }}</label>
<span v-if="hint" :class="[ui.hint]">{{ hint }}</span> <span v-if="hint" :class="[ui.hint]">{{ hint }}</span>
@@ -20,18 +20,16 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, provide, inject } from 'vue' import { computed, defineComponent, provide, inject, ref } from 'vue'
import type { PropType } from 'vue' import type { Ref, PropType } from 'vue'
import { omit } from '../../utils/lodash' import { useUI } from '../../composables/useUI'
import { twMerge } from 'tailwind-merge' import { mergeConfig } from '../../utils'
import type { FormError, InjectedFormGroupValue } from '../../types/form' import type { FormError, InjectedFormGroupValue, Strategy } from '../../types'
import { defuTwMerge } from '../../utils'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { formGroup } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof formGroup>(appConfig.ui.strategy, appConfig.ui.formGroup, formGroup)
let increment = 0 let increment = 0
@@ -43,10 +41,10 @@ export default defineComponent({
default: null default: null
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: null, default: null,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.formGroup.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
label: { label: {
@@ -74,17 +72,12 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.formGroup>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs } = useUI('formGroup', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.formGroup>>(() => defuTwMerge({}, props.ui, appConfig.ui.formGroup))
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const formErrors = inject<Ref<FormError[]> | null>('form-errors', null) const formErrors = inject<Ref<FormError[]> | null>('form-errors', null)
@@ -94,7 +87,7 @@ export default defineComponent({
: formErrors?.value?.find((error) => error.path === props.name)?.message : formErrors?.value?.find((error) => error.path === props.name)?.message
}) })
const size = computed(() => ui.value.size[props.size ?? appConfig.ui.input.default.size]) const size = computed(() => ui.value.size[props.size ?? config.default.size])
const labelFor = ref(`${props.name || 'lf'}-${increment = increment < 1000000 ? increment + 1 : 0}`) const labelFor = ref(`${props.name || 'lf'}-${increment = increment < 1000000 ? increment + 1 : 0}`)
provide<InjectedFormGroupValue>('form-group', { provide<InjectedFormGroupValue>('form-group', {
@@ -105,11 +98,10 @@ export default defineComponent({
}) })
return { return {
labelFor,
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
wrapperClass, attrs,
labelFor,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
size, size,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys

View File

@@ -1,7 +1,7 @@
<template> <template>
<div :class="wrapperClass"> <div :class="ui.wrapper">
<input <input
:id="labelFor" :id="id"
ref="input" ref="input"
:name="name" :name="name"
:value="modelValue" :value="modelValue"
@@ -34,17 +34,18 @@
<script lang="ts"> <script lang="ts">
import { ref, computed, onMounted, defineComponent } from 'vue' import { ref, computed, onMounted, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { NestedKeyOf, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { input } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof input>(appConfig.ui.strategy, appConfig.ui.input, input)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -90,7 +91,7 @@ export default defineComponent({
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: () => appConfig.ui.input.default.loadingIcon default: () => config.default.loadingIcon
}, },
leadingIcon: { leadingIcon: {
type: String, type: String,
@@ -117,26 +118,26 @@ export default defineComponent({
default: true default: true
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.input.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.input.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<keyof typeof config.color | typeof colors[number]>,
default: () => appConfig.ui.input.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.input.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
default: () => appConfig.ui.input.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.input.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.input.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
@@ -145,21 +146,18 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.input>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'blur'], emits: ['update:modelValue', 'blur'],
setup (props, { emit, attrs, slots }) { setup (props, { emit, slots }) {
// TODO: Remove const { ui, attrs } = useUI('input', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.input>>(() => defuTwMerge({}, props.ui, appConfig.ui.input))
const { emitFormBlur, emitFormInput, formGroup } = useFormGroup(props) const { emitFormBlur, emitFormInput, formGroup } = useFormGroup(props)
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
const size = computed(() => formGroup?.size?.value ?? props.size) const size = computed(() => formGroup?.size?.value ?? props.size)
const labelFor = formGroup?.labelFor const id = formGroup?.labelFor
const input = ref<HTMLInputElement | null>(null) const input = ref<HTMLInputElement | null>(null)
@@ -185,8 +183,6 @@ export default defineComponent({
}, 100) }, 100)
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const inputClass = computed(() => { const inputClass = computed(() => {
const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant] const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant]
@@ -261,14 +257,14 @@ export default defineComponent({
}) })
return { return {
labelFor,
attrs: computed(() => omit(attrs, ['class', labelFor ? 'id' : null ])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
// eslint-disable-next-line vue/no-dupe-keys
id,
input, input,
isLeading, isLeading,
isTrailing, isTrailing,
wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
inputClass, inputClass,
leadingIconName, leadingIconName,

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :class="wrapperClass"> <div :class="ui.wrapper">
<div class="flex items-center h-5"> <div class="flex items-center h-5">
<input <input
:id="`${name}-${value}`" :id="`${name}-${value}`"
@@ -29,16 +29,17 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { radio } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof radio>(appConfig.ui.strategy, appConfig.ui.radio, radio)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -72,8 +73,8 @@ export default defineComponent({
default: false default: false
}, },
color: { color: {
type: String, type: String as PropType<typeof colors[number]>,
default: () => appConfig.ui.radio.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return appConfig.ui.colors.includes(value) return appConfig.ui.colors.includes(value)
} }
@@ -83,16 +84,13 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.radio>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue'], emits: ['update:modelValue'],
setup (props, { emit, attrs }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs } = useUI('radio', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.radio>>(() => defuTwMerge({}, props.ui, appConfig.ui.radio))
const { emitFormChange, formGroup } = useFormGroup() const { emitFormChange, formGroup } = useFormGroup()
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
@@ -109,8 +107,6 @@ export default defineComponent({
} }
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const inputClass = computed(() => { const inputClass = computed(() => {
return twMerge(twJoin( return twMerge(twJoin(
ui.value.base, ui.value.base,
@@ -122,11 +118,10 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
pick, pick,
wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
inputClass inputClass
} }

View File

@@ -1,7 +1,7 @@
<template> <template>
<div :class="wrapperClass"> <div :class="wrapperClass">
<input <input
:id="labelFor" :id="id"
ref="input" ref="input"
v-model.number="value" v-model.number="value"
:name="name" :name="name"
@@ -22,14 +22,17 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { range } from '#ui/ui.config'
import colors from '#ui-colors'
const config = mergeConfig<typeof range>(appConfig.ui.strategy, appConfig.ui.range, range)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -63,15 +66,15 @@ export default defineComponent({
default: 1 default: 1
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.range.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.range.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<typeof colors[number]>,
default: () => appConfig.ui.range.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return appConfig.ui.colors.includes(value) return appConfig.ui.colors.includes(value)
} }
@@ -81,21 +84,18 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.range>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'change'], emits: ['update:modelValue', 'change'],
setup (props, { emit, attrs }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('range', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.range>>(() => defuTwMerge({}, props.ui, appConfig.ui.range))
const { emitFormChange, formGroup } = useFormGroup(props) const { emitFormChange, formGroup } = useFormGroup(props)
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
const size = computed(() => formGroup?.size?.value ?? props.size) const size = computed(() => formGroup?.size?.value ?? props.size)
const labelFor = formGroup?.labelFor const id = formGroup?.labelFor
const value = computed({ const value = computed({
get () { get () {
@@ -115,7 +115,7 @@ export default defineComponent({
return twMerge(twJoin( return twMerge(twJoin(
ui.value.wrapper, ui.value.wrapper,
ui.value.size[size.value] ui.value.size[size.value]
), attrs.class as string) ), attrsClass)
}) })
const inputClass = computed(() => { const inputClass = computed(() => {
@@ -167,10 +167,11 @@ export default defineComponent({
}) })
return { return {
labelFor,
attrs: computed(() => omit(attrs, ['class', labelFor ? 'id' : null ])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
// eslint-disable-next-line vue/no-dupe-keys
id,
value, value,
wrapperClass, wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys

View File

@@ -1,7 +1,7 @@
<template> <template>
<div :class="wrapperClass"> <div :class="ui.wrapper">
<select <select
:id="labelFor" :id="id"
:name="name" :name="name"
:value="modelValue" :value="modelValue"
:required="required" :required="required"
@@ -56,17 +56,18 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType, ComputedRef } from 'vue' import type { PropType, ComputedRef } from 'vue'
import { get, omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig, get } from '../../utils'
// TODO: Remove import type { NestedKeyOf, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { select } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof select>(appConfig.ui.strategy, appConfig.ui.select, select)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -104,7 +105,7 @@ export default defineComponent({
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: () => appConfig.ui.input.default.loadingIcon default: () => config.default.loadingIcon
}, },
leadingIcon: { leadingIcon: {
type: String, type: String,
@@ -112,7 +113,7 @@ export default defineComponent({
}, },
trailingIcon: { trailingIcon: {
type: String, type: String,
default: () => appConfig.ui.select.default.trailingIcon default: () => config.default.trailingIcon
}, },
trailing: { trailing: {
type: Boolean, type: Boolean,
@@ -135,26 +136,26 @@ export default defineComponent({
default: () => [] default: () => []
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.select.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.select.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<keyof typeof config.color | typeof colors[number]>,
default: () => appConfig.ui.select.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.select.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
default: () => appConfig.ui.select.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.select.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.select.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
@@ -171,22 +172,18 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.select>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'change'], emits: ['update:modelValue', 'change'],
setup (props, { emit, attrs, slots }) { setup (props, { emit, slots }) {
// TODO: Remove const { ui, attrs } = useUI('select', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.select>>(() => defuTwMerge({}, props.ui, appConfig.ui.select))
const { emitFormChange, formGroup } = useFormGroup(props) const { emitFormChange, formGroup } = useFormGroup(props)
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
const size = computed(() => formGroup?.size?.value ?? props.size) const size = computed(() => formGroup?.size?.value ?? props.size)
const labelFor = formGroup?.labelFor const id = formGroup?.labelFor
const onInput = (event: InputEvent) => { const onInput = (event: InputEvent) => {
emit('update:modelValue', (event.target as HTMLInputElement).value) emit('update:modelValue', (event.target as HTMLInputElement).value)
@@ -249,8 +246,6 @@ export default defineComponent({
return foundOption[props.valueAttribute] return foundOption[props.valueAttribute]
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const selectClass = computed(() => { const selectClass = computed(() => {
const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant] const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant]
@@ -324,15 +319,15 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class', labelFor ? 'id' : null ])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
labelFor, attrs,
// eslint-disable-next-line vue/no-dupe-keys
id,
normalizedOptionsWithPlaceholder, normalizedOptionsWithPlaceholder,
normalizedValue, normalizedValue,
isLeading, isLeading,
isTrailing, isTrailing,
wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
selectClass, selectClass,
leadingIconName, leadingIconName,

View File

@@ -8,7 +8,7 @@
:multiple="multiple" :multiple="multiple"
:disabled="disabled || loading" :disabled="disabled || loading"
as="div" as="div"
:class="wrapperClass" :class="ui.wrapper"
@update:model-value="onUpdate" @update:model-value="onUpdate"
> >
<input <input
@@ -28,7 +28,7 @@
class="inline-flex w-full" class="inline-flex w-full"
> >
<slot :open="open" :disabled="disabled" :loading="loading"> <slot :open="open" :disabled="disabled" :loading="loading">
<button :id="labelFor" :class="selectClass" :disabled="disabled || loading" type="button" v-bind="attrs"> <button :id="id" :class="selectClass" :disabled="disabled || loading" type="button" v-bind="attrs">
<span v-if="(isLeading && leadingIconName) || $slots.leading" :class="leadingWrapperIconClass"> <span v-if="(isLeading && leadingIconName) || $slots.leading" :class="leadingWrapperIconClass">
<slot name="leading" :disabled="disabled" :loading="loading"> <slot name="leading" :disabled="disabled" :loading="loading">
<UIcon :name="leadingIconName" :class="leadingIconClass" /> <UIcon :name="leadingIconName" :class="leadingIconClass" />
@@ -131,20 +131,22 @@ import {
} from '@headlessui/vue' } from '@headlessui/vue'
import { computedAsync, useDebounceFn } from '@vueuse/core' import { computedAsync, useDebounceFn } from '@vueuse/core'
import { defu } from 'defu' import { defu } from 'defu'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue' import UAvatar from '../elements/Avatar.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { usePopper } from '../../composables/usePopper' import { usePopper } from '../../composables/usePopper'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import type { PopperOptions } from '../../types/popper' import { mergeConfig } from '../../utils'
import { useAppConfig } from '#imports' import type { PopperOptions, NestedKeyOf, Strategy } from '../../types'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { select, selectMenu } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof select>(appConfig.ui.strategy, appConfig.ui.select, select)
const configMenu = mergeConfig<typeof selectMenu>(appConfig.ui.strategy, appConfig.ui.selectMenu, selectMenu)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -192,7 +194,7 @@ export default defineComponent({
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: () => appConfig.ui.input.default.loadingIcon default: () => config.default.loadingIcon
}, },
leadingIcon: { leadingIcon: {
type: String, type: String,
@@ -200,7 +202,7 @@ export default defineComponent({
}, },
trailingIcon: { trailingIcon: {
type: String, type: String,
default: () => appConfig.ui.select.default.trailingIcon default: () => config.default.trailingIcon
}, },
trailing: { trailing: {
type: Boolean, type: Boolean,
@@ -216,7 +218,7 @@ export default defineComponent({
}, },
selectedIcon: { selectedIcon: {
type: String, type: String,
default: () => appConfig.ui.selectMenu.default.selectedIcon default: () => configMenu.default.selectedIcon
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
@@ -251,26 +253,26 @@ export default defineComponent({
default: true default: true
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.select.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.select.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<keyof typeof config.color | typeof colors[number]>,
default: () => appConfig.ui.select.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.select.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
default: () => appConfig.ui.select.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.select.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.select.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
@@ -295,21 +297,19 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.select>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
}, },
uiMenu: { uiMenu: {
type: Object as PropType<Partial<typeof appConfig.ui.selectMenu>>, type: Object as PropType<Partial<typeof configMenu & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'open', 'close', 'change'], emits: ['update:modelValue', 'open', 'close', 'change'],
setup (props, { emit, attrs, slots }) { setup (props, { emit, slots }) {
// TODO: Remove const { ui, attrs } = useUI('select', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.select>>(() => defuTwMerge({}, props.ui, appConfig.ui.select)) const { ui: uiMenu } = useUI('selectMenu', props.uiMenu, configMenu)
const uiMenu = computed<Partial<typeof appConfig.ui.selectMenu>>(() => defuTwMerge({}, props.uiMenu, appConfig.ui.selectMenu))
const popper = computed<PopperOptions>(() => defu({}, props.popper, uiMenu.value.popper as PopperOptions)) const popper = computed<PopperOptions>(() => defu({}, props.popper, uiMenu.value.popper as PopperOptions))
@@ -317,13 +317,11 @@ export default defineComponent({
const { emitFormBlur, emitFormChange, formGroup } = useFormGroup(props) const { emitFormBlur, emitFormChange, formGroup } = useFormGroup(props)
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
const size = computed(() => formGroup?.size?.value ?? props.size) const size = computed(() => formGroup?.size?.value ?? props.size)
const labelFor = formGroup?.labelFor const id = formGroup?.labelFor
const query = ref('') const query = ref('')
const searchInput = ref<ComponentPublicInstance<HTMLElement>>() const searchInput = ref<ComponentPublicInstance<HTMLElement>>()
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const selectClass = computed(() => { const selectClass = computed(() => {
const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant] const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant]
@@ -442,15 +440,17 @@ export default defineComponent({
} }
return { return {
labelFor, // eslint-disable-next-line vue/no-dupe-keys
attrs: computed(() => omit(attrs, ['class', labelFor ? 'id' : null ])), ui,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
uiMenu, uiMenu,
attrs,
// eslint-disable-next-line vue/no-dupe-keys
id,
trigger, trigger,
container, container,
isLeading, isLeading,
isTrailing, isTrailing,
wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
selectClass, selectClass,
leadingIconName, leadingIconName,

View File

@@ -1,7 +1,7 @@
<template> <template>
<div :class="wrapperClass"> <div :class="ui.wrapper">
<textarea <textarea
:id="labelFor" :id="id"
ref="textarea" ref="textarea"
:value="modelValue" :value="modelValue"
:name="name" :name="name"
@@ -21,16 +21,17 @@
<script lang="ts"> <script lang="ts">
import { ref, computed, watch, onMounted, nextTick, defineComponent } from 'vue' import { ref, computed, watch, onMounted, nextTick, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { NestedKeyOf, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { textarea } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof textarea>(appConfig.ui.strategy, appConfig.ui.textarea, textarea)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -80,26 +81,26 @@ export default defineComponent({
default: true default: true
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof config.size>,
default: () => appConfig.ui.textarea.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.textarea.size).includes(value) return Object.keys(config.size).includes(value)
} }
}, },
color: { color: {
type: String, type: String as PropType<keyof typeof config.color | typeof colors[number]>,
default: () => appConfig.ui.textarea.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.textarea.color)].includes(value) return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
} }
}, },
variant: { variant: {
type: String, type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
default: () => appConfig.ui.textarea.default.variant, default: () => config.default.variant,
validator (value: string) { validator (value: string) {
return [ return [
...Object.keys(appConfig.ui.textarea.variant), ...Object.keys(config.variant),
...Object.values(appConfig.ui.textarea.color).flatMap(value => Object.keys(value)) ...Object.values(config.color).flatMap(value => Object.keys(value))
].includes(value) ].includes(value)
} }
}, },
@@ -108,23 +109,20 @@ export default defineComponent({
default: null default: null
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.textarea>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'blur'], emits: ['update:modelValue', 'blur'],
setup (props, { emit, attrs }) { setup (props, { emit }) {
const textarea = ref<HTMLTextAreaElement | null>(null) const { ui, attrs } = useUI('textarea', props.ui, config, { mergeWrapper: true })
// TODO: Remove
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.textarea>>(() => defuTwMerge({}, props.ui, appConfig.ui.textarea))
const { emitFormBlur, emitFormInput, formGroup } = useFormGroup(props) const { emitFormBlur, emitFormInput, formGroup } = useFormGroup(props)
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
const size = computed(() => formGroup?.size?.value ?? props.size) const size = computed(() => formGroup?.size?.value ?? props.size)
const labelFor = formGroup?.labelFor const id = formGroup?.labelFor
const textarea = ref<HTMLTextAreaElement | null>(null)
const autoFocus = () => { const autoFocus = () => {
if (props.autofocus) { if (props.autofocus) {
@@ -183,8 +181,6 @@ export default defineComponent({
}, 100) }, 100)
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const textareaClass = computed(() => { const textareaClass = computed(() => {
const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant] const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant]
@@ -200,10 +196,12 @@ export default defineComponent({
}) })
return { return {
labelFor, // eslint-disable-next-line vue/no-dupe-keys
attrs: computed(() => omit(attrs, ['class', labelFor ? 'id' : null ])), ui,
attrs,
// eslint-disable-next-line vue/no-dupe-keys
id,
textarea, textarea,
wrapperClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
textareaClass, textareaClass,
onInput, onInput,

View File

@@ -1,6 +1,6 @@
<template> <template>
<HSwitch <HSwitch
:id="labelFor" :id="id"
v-model="active" v-model="active"
:name="name" :name="name"
:disabled="disabled" :disabled="disabled"
@@ -22,17 +22,18 @@
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { Switch as HSwitch } from '@headlessui/vue' import { Switch as HSwitch } from '@headlessui/vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useFormGroup } from '../../composables/useFormGroup' import { useFormGroup } from '../../composables/useFormGroup'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { toggle } from '#ui/ui.config'
import colors from '#ui-colors'
// const appConfig = useAppConfig() const config = mergeConfig<typeof toggle>(appConfig.ui.strategy, appConfig.ui.toggle, toggle)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -59,34 +60,31 @@ export default defineComponent({
}, },
onIcon: { onIcon: {
type: String, type: String,
default: () => appConfig.ui.toggle.default.onIcon default: () => config.default.onIcon
}, },
offIcon: { offIcon: {
type: String, type: String,
default: () => appConfig.ui.toggle.default.offIcon default: () => config.default.offIcon
}, },
color: { color: {
type: String, type: String as PropType<typeof colors[number]>,
default: () => appConfig.ui.toggle.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return appConfig.ui.colors.includes(value) return appConfig.ui.colors.includes(value)
} }
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.toggle>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue'], emits: ['update:modelValue'],
setup (props, { emit, attrs }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('toggle', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.toggle>>(() => defuTwMerge({}, props.ui, appConfig.ui.toggle))
const { emitFormChange, formGroup } = useFormGroup(props) const { emitFormChange, formGroup } = useFormGroup(props)
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) const color = computed(() => formGroup?.error?.value ? 'red' : props.color)
const labelFor = formGroup?.labelFor const id = formGroup?.labelFor
const active = computed({ const active = computed({
get () { get () {
@@ -104,7 +102,7 @@ export default defineComponent({
ui.value.rounded, ui.value.rounded,
ui.value.ring.replaceAll('{color}', color.value), ui.value.ring.replaceAll('{color}', color.value),
(active.value ? ui.value.active : ui.value.inactive).replaceAll('{color}', color.value) (active.value ? ui.value.active : ui.value.inactive).replaceAll('{color}', color.value)
), attrs.class as string) ), attrsClass)
}) })
const onIconClass = computed(() => { const onIconClass = computed(() => {
@@ -120,10 +118,11 @@ export default defineComponent({
}) })
return { return {
labelFor,
attrs: computed(() => omit(attrs, ['class', labelFor ? 'id' : null ])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
// eslint-disable-next-line vue/no-dupe-keys
id,
active, active,
switchClass, switchClass,
onIconClass, onIconClass,

View File

@@ -19,15 +19,15 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { card } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof card>(appConfig.ui.strategy, appConfig.ui.card, card)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -37,15 +37,12 @@ export default defineComponent({
default: 'div' default: 'div'
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.card>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('card', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.card>>(() => defuTwMerge({}, props.ui, appConfig.ui.card))
const cardClass = computed(() => { const cardClass = computed(() => {
return twMerge(twJoin( return twMerge(twJoin(
@@ -55,13 +52,13 @@ export default defineComponent({
ui.value.ring, ui.value.ring,
ui.value.shadow, ui.value.shadow,
ui.value.background ui.value.background
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
cardClass cardClass
} }
} }

View File

@@ -7,15 +7,15 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { container } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof container>(appConfig.ui.strategy, appConfig.ui.container, container)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -25,28 +25,25 @@ export default defineComponent({
default: 'div' default: 'div'
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.container>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('container', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.container>>(() => defuTwMerge({}, props.ui, appConfig.ui.container))
const containerClass = computed(() => { const containerClass = computed(() => {
return twMerge(twJoin( return twMerge(twJoin(
ui.value.base, ui.value.base,
ui.value.padding, ui.value.padding,
ui.value.constrained ui.value.constrained
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
containerClass containerClass
} }
} }

View File

@@ -5,42 +5,39 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { skeleton } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof skeleton>(appConfig.ui.strategy, appConfig.ui.skeleton, skeleton)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: { props: {
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.skeleton>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('skeleton', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.skeleton>>(() => defuTwMerge({}, props.ui, appConfig.ui.skeleton))
const skeletonClass = computed(() => { const skeletonClass = computed(() => {
return twMerge(twJoin( return twMerge(twJoin(
ui.value.base, ui.value.base,
ui.value.background, ui.value.background,
ui.value.rounded ui.value.rounded
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
skeletonClass skeletonClass
} }
} }

View File

@@ -4,7 +4,7 @@
:model-value="modelValue" :model-value="modelValue"
:multiple="multiple" :multiple="multiple"
:nullable="nullable" :nullable="nullable"
:class="wrapperClass" :class="ui.wrapper"
v-bind="attrs" v-bind="attrs"
as="div" as="div"
@update:model-value="onSelect" @update:model-value="onSelect"
@@ -67,22 +67,20 @@ import { Combobox as HCombobox, ComboboxInput as HComboboxInput, ComboboxOptions
import type { ComputedRef, PropType, ComponentPublicInstance } from 'vue' import type { ComputedRef, PropType, ComponentPublicInstance } from 'vue'
import { useDebounceFn } from '@vueuse/core' import { useDebounceFn } from '@vueuse/core'
import { useFuse } from '@vueuse/integrations/useFuse' import { useFuse } from '@vueuse/integrations/useFuse'
import { twMerge, twJoin } from 'tailwind-merge'
import { omit } from '../../utils/lodash'
import { defu } from 'defu'
import type { UseFuseOptions } from '@vueuse/integrations/useFuse' import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
import type { Group, Command } from '../../types/command-palette' import { twJoin } from 'tailwind-merge'
import { defu } from 'defu'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UButton from '../elements/Button.vue' import UButton from '../elements/Button.vue'
import type { Button } from '../../types/button'
import CommandPaletteGroup from './CommandPaletteGroup.vue' import CommandPaletteGroup from './CommandPaletteGroup.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Group, Command, Button, Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { commandPalette } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof commandPalette>(appConfig.ui.strategy, appConfig.ui.commandPalette, commandPalette)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -125,23 +123,23 @@ export default defineComponent({
}, },
icon: { icon: {
type: String, type: String,
default: () => appConfig.ui.commandPalette.default.icon default: () => config.default.icon
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: () => appConfig.ui.commandPalette.default.loadingIcon default: () => config.default.loadingIcon
}, },
selectedIcon: { selectedIcon: {
type: String, type: String,
default: () => appConfig.ui.commandPalette.default.selectedIcon default: () => config.default.selectedIcon
}, },
closeButton: { closeButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.commandPalette.default.closeButton default: () => config.default.closeButton as Button
}, },
emptyState: { emptyState: {
type: Object as PropType<{ icon: string, label: string, queryLabel: string }>, type: Object as PropType<{ icon: string, label: string, queryLabel: string }>,
default: () => appConfig.ui.commandPalette.default.emptyState default: () => config.default.emptyState
}, },
placeholder: { placeholder: {
type: String, type: String,
@@ -172,16 +170,13 @@ export default defineComponent({
default: () => ({}) default: () => ({})
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.commandPalette>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'close'], emits: ['update:modelValue', 'close'],
setup (props, { emit, attrs, expose }) { setup (props, { emit, expose }) {
// TODO: Remove const { ui, attrs } = useUI('commandPalette', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.commandPalette>>(() => defuTwMerge({}, props.ui, appConfig.ui.commandPalette))
const query = ref('') const query = ref('')
const comboboxInput = ref<ComponentPublicInstance<HTMLInputElement>>() const comboboxInput = ref<ComponentPublicInstance<HTMLInputElement>>()
@@ -284,8 +279,6 @@ export default defineComponent({
}, 0) }, 0)
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const iconName = computed(() => { const iconName = computed(() => {
if ((props.loading || isLoading.value) && props.loadingIcon) { if ((props.loading || isLoading.value) && props.loadingIcon) {
return props.loadingIcon return props.loadingIcon
@@ -343,14 +336,13 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
groups, groups,
comboboxInput, comboboxInput,
query, query,
wrapperClass,
iconName, iconName,
iconClass, iconClass,
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys

View File

@@ -76,12 +76,8 @@ import { ComboboxOption as HComboboxOption } from '@headlessui/vue'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue' import UAvatar from '../elements/Avatar.vue'
import UKbd from '../elements/Kbd.vue' import UKbd from '../elements/Kbd.vue'
import type { Group } from '../../types/command-palette' import type { Group } from '../../types'
// TODO: Remove import { commandPalette } from '#ui/ui.config'
// @ts-expect-error
import appConfig from '#build/app.config'
// const appConfig = useAppConfig()
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -112,8 +108,8 @@ export default defineComponent({
required: true required: true
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.commandPalette>>, type: Object as PropType<typeof commandPalette>,
default: () => ({}) required: true
} }
}, },
setup (props) { setup (props) {

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :class="wrapperClass" v-bind="attrs"> <div :class="ui.wrapper" v-bind="attrs">
<slot name="prev" :on-click="onClickPrev"> <slot name="prev" :on-click="onClickPrev">
<UButton <UButton
v-if="prevButton" v-if="prevButton"
@@ -42,17 +42,17 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UButton from '../elements/Button.vue' import UButton from '../elements/Button.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import type { Button } from '../../types/button' import { mergeConfig } from '../../utils'
import { useAppConfig } from '#imports' import type { Button, Strategy } from '../../types'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { pagination, button } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof pagination>(appConfig.ui.strategy, appConfig.ui.pagination, pagination)
const buttonConfig = mergeConfig<typeof button>(appConfig.ui.strategy, appConfig.ui.button, button)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -80,43 +80,40 @@ export default defineComponent({
} }
}, },
size: { size: {
type: String, type: String as PropType<keyof typeof buttonConfig.size>,
default: () => appConfig.ui.pagination.default.size, default: () => config.default.size,
validator (value: string) { validator (value: string) {
return Object.keys(appConfig.ui.button.size).includes(value) return Object.keys(buttonConfig.size).includes(value)
} }
}, },
activeButton: { activeButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.pagination.default.activeButton default: () => config.default.activeButton as Button
}, },
inactiveButton: { inactiveButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.pagination.default.inactiveButton default: () => config.default.inactiveButton as Button
}, },
prevButton: { prevButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.pagination.default.prevButton default: () => config.default.prevButton as Button
}, },
nextButton: { nextButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.pagination.default.nextButton default: () => config.default.nextButton as Button
}, },
divider: { divider: {
type: String, type: String,
default: '…' default: '…'
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.pagination>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue'], emits: ['update:modelValue'],
setup (props, { attrs, emit }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs } = useUI('pagination', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.pagination>>(() => defuTwMerge({}, props.ui, appConfig.ui.pagination))
const currentPage = computed({ const currentPage = computed({
get () { get () {
@@ -182,8 +179,6 @@ export default defineComponent({
const canGoPrev = computed(() => currentPage.value > 1) const canGoPrev = computed(() => currentPage.value > 1)
const canGoNext = computed(() => currentPage.value < pages.value.length) const canGoNext = computed(() => currentPage.value < pages.value.length)
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
function onClickPage (page: number | string) { function onClickPage (page: number | string) {
if (typeof page === 'string') { if (typeof page === 'string') {
return return
@@ -209,15 +204,14 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
currentPage, currentPage,
pages, pages,
displayedPages, displayedPages,
canGoPrev, canGoPrev,
canGoNext, canGoNext,
wrapperClass,
onClickPrev, onClickPrev,
onClickNext, onClickNext,
onClickPage onClickPage

View File

@@ -3,7 +3,7 @@
:vertical="orientation === 'vertical'" :vertical="orientation === 'vertical'"
:selected-index="selectedIndex" :selected-index="selectedIndex"
as="div" as="div"
:class="wrapperClass" :class="ui.wrapper"
v-bind="attrs" v-bind="attrs"
@change="onChange" @change="onChange"
> >
@@ -48,20 +48,18 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { ref, computed, watch, onMounted, defineComponent } from 'vue' import { ref, watch, onMounted, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { TabGroup as HTabGroup, TabList as HTabList, Tab as HTab, TabPanels as HTabPanels, TabPanel as HTabPanel } from '@headlessui/vue' import { TabGroup as HTabGroup, TabList as HTabList, Tab as HTab, TabPanels as HTabPanels, TabPanel as HTabPanel } from '@headlessui/vue'
import { useResizeObserver } from '@vueuse/core' import { useResizeObserver } from '@vueuse/core'
import { omit } from '../../utils/lodash' import { useUI } from '../../composables/useUI'
import { twMerge } from 'tailwind-merge' import { mergeConfig } from '../../utils'
import { defuTwMerge } from '../../utils' import type { TabItem, Strategy } from '../../types'
import type { TabItem } from '../../types/tabs'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { tabs } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof tabs>(appConfig.ui.strategy, appConfig.ui.tabs, tabs)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -91,16 +89,13 @@ export default defineComponent({
default: () => [] default: () => []
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.tabs>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'change'], emits: ['update:modelValue', 'change'],
setup (props, { attrs, emit }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs } = useUI('tabs', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.tabs>>(() => defuTwMerge({}, props.ui, appConfig.ui.tabs))
const listRef = ref<HTMLElement>() const listRef = ref<HTMLElement>()
const itemRefs = ref<HTMLElement[]>([]) const itemRefs = ref<HTMLElement[]>([])
@@ -108,8 +103,6 @@ export default defineComponent({
const selectedIndex = ref(props.modelValue || props.defaultIndex) const selectedIndex = ref(props.modelValue || props.defaultIndex)
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
// Methods // Methods
function calcMarkerSize (index: number) { function calcMarkerSize (index: number) {
@@ -149,14 +142,13 @@ export default defineComponent({
onMounted(() => calcMarkerSize(selectedIndex.value)) onMounted(() => calcMarkerSize(selectedIndex.value))
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
listRef, listRef,
itemRefs, itemRefs,
markerRef, markerRef,
selectedIndex, selectedIndex,
wrapperClass,
onChange onChange
} }
} }

View File

@@ -1,5 +1,5 @@
<template> <template>
<nav :class="wrapperClass" v-bind="attrs"> <nav :class="ui.wrapper" v-bind="attrs">
<ULink <ULink
v-for="(link, index) of links" v-for="(link, index) of links"
v-slot="{ isActive }" v-slot="{ isActive }"
@@ -38,21 +38,19 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue' import UAvatar from '../elements/Avatar.vue'
import ULink from '../elements/Link.vue' import ULink from '../elements/Link.vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import type { VerticalNavigationLink } from '../../types/vertical-navigation' import { mergeConfig, omit } from '../../utils'
import { useAppConfig } from '#imports' import type { VerticalNavigationLink, Strategy } from '../../types'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { verticalNavigation } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof verticalNavigation>(appConfig.ui.strategy, appConfig.ui.verticalNavigation, verticalNavigation)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -67,23 +65,17 @@ export default defineComponent({
default: () => [] default: () => []
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.verticalNavigation>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs } = useUI('verticalNavigation', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.verticalNavigation>>(() => defuTwMerge({}, props.ui, appConfig.ui.verticalNavigation))
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
wrapperClass, attrs,
omit omit
} }
} }

View File

@@ -14,17 +14,16 @@ import type { PropType, Ref } from 'vue'
import { defu } from 'defu' import { defu } from 'defu'
import { onClickOutside } from '@vueuse/core' import { onClickOutside } from '@vueuse/core'
import type { VirtualElement } from '@popperjs/core' import type { VirtualElement } from '@popperjs/core'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import { useUI } from '../../composables/useUI'
import { usePopper } from '../../composables/usePopper' import { usePopper } from '../../composables/usePopper'
import { defuTwMerge } from '../../utils' import { mergeConfig } from '../../utils'
import type { PopperOptions } from '../../types/popper' import type { PopperOptions, Strategy } from '../../types'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { contextMenu } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof contextMenu>(appConfig.ui.strategy, appConfig.ui.contextMenu, contextMenu)
export default defineComponent({ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
@@ -42,16 +41,13 @@ export default defineComponent({
default: () => ({}) default: () => ({})
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.contextMenu>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'close'], emits: ['update:modelValue', 'close'],
setup (props, { attrs, emit }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('contextMenu', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.contextMenu>>(() => defuTwMerge({}, props.ui, appConfig.ui.contextMenu))
const popper = computed<PopperOptions>(() => defu({}, props.popper, ui.value.popper as PopperOptions)) const popper = computed<PopperOptions>(() => defu({}, props.popper, ui.value.popper as PopperOptions))
@@ -72,7 +68,7 @@ export default defineComponent({
return twMerge(twJoin( return twMerge(twJoin(
ui.value.container, ui.value.container,
ui.value.width ui.value.width
), attrs.class as string) ), attrsClass)
}) })
onClickOutside(container, () => { onClickOutside(container, () => {
@@ -80,9 +76,9 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
isOpen, isOpen,
wrapperClass, wrapperClass,
container container

View File

@@ -1,6 +1,6 @@
<template> <template>
<TransitionRoot :appear="appear" :show="isOpen" as="template"> <TransitionRoot :appear="appear" :show="isOpen" as="template">
<HDialog :class="wrapperClass" v-bind="attrs" @close="(e) => !preventClose && close(e)"> <HDialog :class="ui.wrapper" v-bind="attrs" @close="(e) => !preventClose && close(e)">
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition"> <TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
<div :class="[ui.overlay.base, ui.overlay.background]" /> <div :class="[ui.overlay.base, ui.overlay.background]" />
</TransitionChild> </TransitionChild>
@@ -32,16 +32,15 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import { Dialog as HDialog, DialogPanel as HDialogPanel, TransitionRoot, TransitionChild } from '@headlessui/vue' import { Dialog as HDialog, DialogPanel as HDialogPanel, TransitionRoot, TransitionChild } from '@headlessui/vue'
import { defuTwMerge } from '../../utils' import { useUI } from '../../composables/useUI'
import { useAppConfig } from '#imports' import { mergeConfig } from '../../utils'
// TODO: Remove import type { Strategy } from '../../types'
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { modal } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof modal>(appConfig.ui.strategy, appConfig.ui.modal, modal)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -77,16 +76,13 @@ export default defineComponent({
default: false default: false
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.modal>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'close'], emits: ['update:modelValue', 'close'],
setup (props, { attrs, emit }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs } = useUI('modal', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.modal>>(() => defuTwMerge({}, props.ui, appConfig.ui.modal))
const isOpen = computed({ const isOpen = computed({
get () { get () {
@@ -97,8 +93,6 @@ export default defineComponent({
} }
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const transitionClass = computed(() => { const transitionClass = computed(() => {
if (!props.transition) { if (!props.transition) {
return {} return {}
@@ -116,11 +110,10 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
isOpen, isOpen,
wrapperClass,
transitionClass, transitionClass,
close close
} }

View File

@@ -41,22 +41,19 @@
<script lang="ts"> <script lang="ts">
import { ref, computed, onMounted, onUnmounted, watchEffect, defineComponent } from 'vue' import { ref, computed, onMounted, onUnmounted, watchEffect, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue' import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue' import UAvatar from '../elements/Avatar.vue'
import UButton from '../elements/Button.vue' import UButton from '../elements/Button.vue'
import { useUI } from '../../composables/useUI'
import { useTimer } from '../../composables/useTimer' import { useTimer } from '../../composables/useTimer'
import type { NotificationAction } from '../../types/notification' import { mergeConfig } from '../../utils'
import type { Avatar } from '../../types/avatar' import type { Avatar, Button, NotificationColor, NotificationAction, Strategy } from '../../types'
import type { Button } from '../../types/button'
import { defuTwMerge } from '../../utils'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { notification } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof notification>(appConfig.ui.strategy, appConfig.ui.notification, notification)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -80,7 +77,7 @@ export default defineComponent({
}, },
icon: { icon: {
type: String, type: String,
default: () => appConfig.ui.notification.default.icon default: () => config.default.icon
}, },
avatar: { avatar: {
type: Object as PropType<Avatar>, type: Object as PropType<Avatar>,
@@ -88,7 +85,7 @@ export default defineComponent({
}, },
closeButton: { closeButton: {
type: Object as PropType<Button>, type: Object as PropType<Button>,
default: () => appConfig.ui.notification.default.closeButton default: () => config.default.closeButton as Button
}, },
timeout: { timeout: {
type: Number, type: Number,
@@ -103,23 +100,20 @@ export default defineComponent({
default: null default: null
}, },
color: { color: {
type: String, type: String as PropType<NotificationColor>,
default: () => appConfig.ui.notification.default.color, default: () => config.default.color,
validator (value: string) { validator (value: string) {
return ['gray', ...appConfig.ui.colors].includes(value) return ['gray', ...appConfig.ui.colors].includes(value)
} }
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.notification>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['close'], emits: ['close'],
setup (props, { attrs, emit }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('notification', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.notification>>(() => defuTwMerge({}, props.ui, appConfig.ui.notification))
let timer: any = null let timer: any = null
const remaining = ref(props.timeout) const remaining = ref(props.timeout)
@@ -130,7 +124,7 @@ export default defineComponent({
ui.value.background, ui.value.background,
ui.value.rounded, ui.value.rounded,
ui.value.shadow ui.value.shadow
), attrs.class as string) ), attrsClass)
}) })
const progressClass = computed(() => { const progressClass = computed(() => {
@@ -210,9 +204,9 @@ export default defineComponent({
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
wrapperClass, wrapperClass,
progressClass, progressClass,
progressStyle, progressStyle,

View File

@@ -20,18 +20,18 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { omit } from '../../utils/lodash'
import { twMerge, twJoin } from 'tailwind-merge' import { twMerge, twJoin } from 'tailwind-merge'
import UNotification from './Notification.vue' import UNotification from './Notification.vue'
import { useUI } from '../../composables/useUI'
import { useToast } from '../../composables/useToast' import { useToast } from '../../composables/useToast'
import { defuTwMerge } from '../../utils' import { mergeConfig } from '../../utils'
import type { Notification } from '../../types/notification' import type { Notification, Strategy } from '../../types'
import { useState, useAppConfig } from '#imports' import { useState } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { notifications } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof notifications>(appConfig.ui.strategy, appConfig.ui.notifications, notifications)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -40,15 +40,12 @@ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: { props: {
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.notifications>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs, attrsClass } = useUI('notifications', props.ui, config)
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.notifications>>(() => defuTwMerge({}, props.ui, appConfig.ui.notifications))
const toast = useToast() const toast = useToast()
const notifications = useState<Notification[]>('notifications', () => []) const notifications = useState<Notification[]>('notifications', () => [])
@@ -58,13 +55,13 @@ export default defineComponent({
ui.value.wrapper, ui.value.wrapper,
ui.value.position, ui.value.position,
ui.value.width ui.value.width
), attrs.class as string) ), attrsClass)
}) })
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
toast, toast,
notifications, notifications,
wrapperClass wrapperClass

View File

@@ -1,5 +1,5 @@
<template> <template>
<HPopover ref="popover" v-slot="{ open, close }" :class="wrapperClass" v-bind="attrs" @mouseleave="onMouseLeave"> <HPopover ref="popover" v-slot="{ open, close }" :class="ui.wrapper" v-bind="attrs" @mouseleave="onMouseLeave">
<HPopoverButton <HPopoverButton
ref="trigger" ref="trigger"
as="div" as="div"
@@ -29,18 +29,16 @@
import { computed, ref, onMounted, defineComponent } from 'vue' import { computed, ref, onMounted, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { defu } from 'defu' import { defu } from 'defu'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import { Popover as HPopover, PopoverButton as HPopoverButton, PopoverPanel as HPopoverPanel } from '@headlessui/vue' import { Popover as HPopover, PopoverButton as HPopoverButton, PopoverPanel as HPopoverPanel } from '@headlessui/vue'
import { useUI } from '../../composables/useUI'
import { usePopper } from '../../composables/usePopper' import { usePopper } from '../../composables/usePopper'
import { defuTwMerge } from '../../utils' import { mergeConfig } from '../../utils'
import type { PopperOptions } from '../../types/popper' import type { PopperOptions, Strategy } from '../../types'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { popover } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof popover>(appConfig.ui.strategy, appConfig.ui.popover, popover)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -72,15 +70,12 @@ export default defineComponent({
default: () => ({}) default: () => ({})
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.popover>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs } = useUI('popover', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.popover>>(() => defuTwMerge({}, props.ui, appConfig.ui.popover))
const popper = computed<PopperOptions>(() => defu(props.mode === 'hover' ? { offsetDistance: 0 } : {}, props.popper, ui.value.popper as PopperOptions)) const popper = computed<PopperOptions>(() => defu(props.mode === 'hover' ? { offsetDistance: 0 } : {}, props.popper, ui.value.popper as PopperOptions))
@@ -108,8 +103,6 @@ export default defineComponent({
return props.mode === 'hover' ? { paddingTop: `${offsetDistance}px`, paddingBottom: `${offsetDistance}px` } : {} return props.mode === 'hover' ? { paddingTop: `${offsetDistance}px`, paddingBottom: `${offsetDistance}px` } : {}
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
function onMouseOver () { function onMouseOver () {
if (props.mode !== 'hover' || !popoverApi.value) { if (props.mode !== 'hover' || !popoverApi.value) {
return return
@@ -151,14 +144,13 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
popover, popover,
trigger, trigger,
container, container,
containerStyle, containerStyle,
wrapperClass,
onMouseOver, onMouseOver,
onMouseLeave onMouseLeave
} }

View File

@@ -1,6 +1,6 @@
<template> <template>
<TransitionRoot as="template" :appear="appear" :show="isOpen"> <TransitionRoot as="template" :appear="appear" :show="isOpen">
<HDialog :class="[wrapperClass, { 'justify-end': side === 'right' }]" v-bind="attrs" @close="(e) => !preventClose && close(e)"> <HDialog :class="[ui.wrapper, { 'justify-end': side === 'right' }]" v-bind="attrs" @close="(e) => !preventClose && close(e)">
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition"> <TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
<div :class="[ui.overlay.base, ui.overlay.background]" /> <div :class="[ui.overlay.base, ui.overlay.background]" />
</TransitionChild> </TransitionChild>
@@ -18,15 +18,14 @@
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { WritableComputedRef, PropType } from 'vue' import type { WritableComputedRef, PropType } from 'vue'
import { Dialog as HDialog, DialogPanel as HDialogPanel, TransitionRoot, TransitionChild } from '@headlessui/vue' import { Dialog as HDialog, DialogPanel as HDialogPanel, TransitionRoot, TransitionChild } from '@headlessui/vue'
import { omit } from '../../utils/lodash' import { useUI } from '../../composables/useUI'
import { twMerge } from 'tailwind-merge' import { mergeConfig } from '../../utils'
import { defuTwMerge } from '../../utils' import type { Strategy } from '../../types'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { slideover } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof slideover>(appConfig.ui.strategy, appConfig.ui.slideover, slideover)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -63,16 +62,13 @@ export default defineComponent({
default: false default: false
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.slideover>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
emits: ['update:modelValue', 'close'], emits: ['update:modelValue', 'close'],
setup (props, { attrs, emit }) { setup (props, { emit }) {
// TODO: Remove const { ui, attrs } = useUI('slideover', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.slideover>>(() => defuTwMerge({}, props.ui, appConfig.ui.slideover))
const isOpen: WritableComputedRef<boolean> = computed({ const isOpen: WritableComputedRef<boolean> = computed({
get () { get () {
@@ -83,8 +79,6 @@ export default defineComponent({
} }
}) })
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
const transitionClass = computed(() => { const transitionClass = computed(() => {
if (!props.transition) { if (!props.transition) {
return {} return {}
@@ -105,11 +99,10 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
isOpen, isOpen,
wrapperClass,
transitionClass, transitionClass,
close close
} }

View File

@@ -1,5 +1,5 @@
<template> <template>
<div ref="trigger" :class="wrapperClass" v-bind="attrs" @mouseover="onMouseOver" @mouseleave="onMouseLeave"> <div ref="trigger" :class="ui.wrapper" v-bind="attrs" @mouseover="onMouseOver" @mouseleave="onMouseLeave">
<slot :open="open"> <slot :open="open">
Hover Hover
</slot> </slot>
@@ -27,18 +27,16 @@
import { computed, ref, defineComponent } from 'vue' import { computed, ref, defineComponent } from 'vue'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { defu } from 'defu' import { defu } from 'defu'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UKbd from '../elements/Kbd.vue' import UKbd from '../elements/Kbd.vue'
import { useUI } from '../../composables/useUI'
import { usePopper } from '../../composables/usePopper' import { usePopper } from '../../composables/usePopper'
import { defuTwMerge } from '../../utils' import { mergeConfig } from '../../utils'
import type { PopperOptions } from '../../types/popper' import type { PopperOptions, Strategy } from '../../types'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error // @ts-expect-error
import appConfig from '#build/app.config' import appConfig from '#build/app.config'
import { tooltip } from '#ui/ui.config'
// const appConfig = useAppConfig() const config = mergeConfig<typeof tooltip>(appConfig.ui.strategy, appConfig.ui.tooltip, tooltip)
export default defineComponent({ export default defineComponent({
components: { components: {
@@ -71,15 +69,12 @@ export default defineComponent({
default: () => ({}) default: () => ({})
}, },
ui: { ui: {
type: Object as PropType<Partial<typeof appConfig.ui.tooltip>>, type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: () => ({}) default: undefined
} }
}, },
setup (props, { attrs }) { setup (props) {
// TODO: Remove const { ui, attrs } = useUI('tooltip', props.ui, config, { mergeWrapper: true })
const appConfig = useAppConfig()
const ui = computed<Partial<typeof appConfig.ui.tooltip>>(() => defuTwMerge({}, props.ui, appConfig.ui.tooltip))
const popper = computed<PopperOptions>(() => defu({}, props.popper, ui.value.popper as PopperOptions)) const popper = computed<PopperOptions>(() => defu({}, props.popper, ui.value.popper as PopperOptions))
@@ -90,8 +85,6 @@ export default defineComponent({
let openTimeout: NodeJS.Timeout | null = null let openTimeout: NodeJS.Timeout | null = null
let closeTimeout: NodeJS.Timeout | null = null let closeTimeout: NodeJS.Timeout | null = null
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
// Methods // Methods
function onMouseOver () { function onMouseOver () {
@@ -127,13 +120,12 @@ export default defineComponent({
} }
return { return {
attrs: computed(() => omit(attrs, ['class'])),
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
ui, ui,
attrs,
trigger, trigger,
container, container,
open, open,
wrapperClass,
onMouseOver, onMouseOver,
onMouseLeave onMouseLeave
} }

View File

@@ -0,0 +1,24 @@
import { computed, toValue, useAttrs } from 'vue'
import { useAppConfig } from '#imports'
import { mergeConfig, omit } from '../utils'
import { Strategy } from '../types'
export const useUI = <T>(key, $ui: Partial<T & { strategy: Strategy }>, $config?: T, { mergeWrapper = false }: { mergeWrapper?: boolean } = {}) => {
const $attrs = useAttrs()
const appConfig = useAppConfig()
const ui = computed(() => mergeConfig<T>(
$ui?.strategy || (appConfig.ui?.strategy as Strategy),
mergeWrapper ? { wrapper: $attrs?.class } : {},
$ui || {},
process.dev ? (appConfig.ui[key] || {}) : {},
toValue($config || {})
))
const attrs = computed(() => omit($attrs, ['class']))
return {
ui,
attrs,
attrsClass: mergeWrapper ? undefined : $attrs?.class as string
}
}

View File

@@ -1,9 +1,15 @@
import { avatar } from '../ui.config'
import colors from '#ui-colors'
export type AvatarSize = keyof typeof avatar.size
export type AvatarChipColor = 'gray' | typeof colors[number]
export type AvatarChipPosition = keyof typeof avatar.chip.position
export interface Avatar { export interface Avatar {
src?: string | boolean src?: string | boolean
alt?: string alt?: string
text?: string text?: string
size?: string size?: AvatarSize
chipColor?: string chipColor?: AvatarChipColor
chipVariant?: string chipPosition?: AvatarChipPosition
chipPosition?: string
} }

View File

@@ -1,4 +1,11 @@
import type { Link } from './link' import type { Link } from './link'
import { button } from '../ui.config'
import type { NestedKeyOf } from '.'
import colors from '#ui-colors'
export type ButtonSize = keyof typeof button.size
export type ButtonColor = keyof typeof button.color | typeof colors[number]
export type ButtonVariant = keyof typeof button.variant | NestedKeyOf<typeof button.color>
export interface Button extends Link { export interface Button extends Link {
type?: string type?: string
@@ -7,9 +14,9 @@ export interface Button extends Link {
loading?: boolean loading?: boolean
disabled?: boolean disabled?: boolean
padded?: boolean padded?: boolean
size?: string size?: ButtonSize
color?: string color?: ButtonColor
variant?: string variant?: ButtonVariant
icon?: string icon?: string
loadingIcon?: string loadingIcon?: string
leadingIcon?: string leadingIcon?: string

View File

@@ -4,7 +4,7 @@ export interface FormError {
} }
export interface Form<T> { export interface Form<T> {
validate(path?: string, opts: { silent?: boolean } = { silent: false }): Promise<T> validate(path?: string, opts: { silent?: boolean }): Promise<T>
clear(path?: string): void clear(path?: string): void
errors: Ref<FormError[]> errors: Ref<FormError[]>
setErrors(errs: FormError[], path?: string): void setErrors(errs: FormError[], path?: string): void

View File

@@ -10,3 +10,4 @@ export * from './notification'
export * from './popper' export * from './popper'
export * from './tabs' export * from './tabs'
export * from './vertical-navigation' export * from './vertical-navigation'
export * from './utils'

View File

@@ -1,6 +1,8 @@
import type { Avatar } from './avatar' import type { Avatar } from './avatar'
import type { Button } from './button' import type { Button } from './button'
import appConfig from '#build/app.config' import colors from '#ui-colors'
export type NotificationColor = 'gray' | typeof colors[number]
export interface NotificationAction extends Button { export interface NotificationAction extends Button {
click?: Function click?: Function
@@ -17,6 +19,6 @@ export interface Notification {
actions?: NotificationAction[] actions?: NotificationAction[]
click?: Function click?: Function
callback?: Function callback?: Function
color?: string color?: NotificationColor
ui?: Partial<typeof appConfig.ui.notification> ui?: any
} }

11
src/runtime/types/utils.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
export type Strategy = 'merge' | 'override';
export type NestedKeyOf<ObjectType extends object> = {
[Key in keyof ObjectType]: ObjectType[Key] extends object
? NestedKeyOf<ObjectType[Key]>
: Key;
}[keyof ObjectType];
export type DeepPartial<T> = Partial<{
[P in keyof T]: DeepPartial<T[P]> | { [key: string]: string };
}>;

View File

@@ -1,6 +1,6 @@
// Data // Data
const table = { export const table = {
wrapper: 'relative overflow-x-auto', wrapper: 'relative overflow-x-auto',
base: 'min-w-full table-fixed', base: 'min-w-full table-fixed',
divide: 'divide-y divide-gray-300 dark:divide-gray-700', divide: 'divide-y divide-gray-300 dark:divide-gray-700',
@@ -62,7 +62,7 @@ const table = {
// Elements // Elements
const avatar = { export const avatar = {
wrapper: 'relative inline-flex items-center justify-center flex-shrink-0', wrapper: 'relative inline-flex items-center justify-center flex-shrink-0',
background: 'bg-gray-100 dark:bg-gray-800', background: 'bg-gray-100 dark:bg-gray-800',
rounded: 'rounded-full', rounded: 'rounded-full',
@@ -122,13 +122,13 @@ const avatar = {
} }
} }
const avatarGroup = { export const avatarGroup = {
wrapper: 'flex flex-row-reverse justify-end', wrapper: 'inline-flex flex-row-reverse justify-end',
ring: 'ring-2 ring-white dark:ring-gray-900', ring: 'ring-2 ring-white dark:ring-gray-900',
margin: '-me-1.5 first:me-0' margin: '-me-1.5 first:me-0'
} }
const badge = { export const badge = {
base: 'inline-flex items-center', base: 'inline-flex items-center',
rounded: 'rounded-md', rounded: 'rounded-md',
font: 'font-medium', font: 'font-medium',
@@ -162,7 +162,7 @@ const badge = {
} }
} }
const button = { export const button = {
base: 'focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0', base: 'focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0',
font: 'font-medium', font: 'font-medium',
rounded: 'rounded-md', rounded: 'rounded-md',
@@ -239,13 +239,16 @@ const button = {
} }
} }
const buttonGroup = { export const buttonGroup = {
wrapper: 'inline-flex -space-x-px', wrapper: {
horizontal: 'inline-flex -space-x-px',
vertical: 'inline-flex flex-col -space-y-px'
},
rounded: 'rounded-md', rounded: 'rounded-md',
shadow: 'shadow-sm' shadow: 'shadow-sm'
} }
const dropdown = { export const dropdown = {
wrapper: 'relative inline-flex text-left rtl:text-right', wrapper: 'relative inline-flex text-left rtl:text-right',
container: 'z-20', container: 'z-20',
width: 'w-48', width: 'w-48',
@@ -291,7 +294,7 @@ const dropdown = {
} }
} }
const accordion = { export const accordion = {
wrapper: 'w-full flex flex-col', wrapper: 'w-full flex flex-col',
item: { item: {
base: '', base: '',
@@ -312,7 +315,7 @@ const accordion = {
} }
} }
const alert = { export const alert = {
wrapper: 'w-full relative overflow-hidden', wrapper: 'w-full relative overflow-hidden',
title: 'text-sm font-medium', title: 'text-sm font-medium',
description: 'mt-1 text-sm leading-4 opacity-90', description: 'mt-1 text-sm leading-4 opacity-90',
@@ -350,7 +353,7 @@ const alert = {
} }
} }
const kbd = { export const kbd = {
base: 'inline-flex items-center justify-center text-gray-900 dark:text-white', base: 'inline-flex items-center justify-center text-gray-900 dark:text-white',
padding: 'px-1', padding: 'px-1',
size: { size: {
@@ -369,7 +372,7 @@ const kbd = {
// Forms // Forms
const input = { export const input = {
wrapper: 'relative', wrapper: 'relative',
base: 'relative block w-full disabled:cursor-not-allowed disabled:opacity-75 focus:outline-none border-0', base: 'relative block w-full disabled:cursor-not-allowed disabled:opacity-75 focus:outline-none border-0',
rounded: 'rounded-md', rounded: 'rounded-md',
@@ -474,7 +477,7 @@ const input = {
} }
} }
const formGroup = { export const formGroup = {
wrapper: '', wrapper: '',
label: { label: {
wrapper: 'flex content-center items-center justify-between', wrapper: 'flex content-center items-center justify-between',
@@ -494,10 +497,13 @@ const formGroup = {
description: 'text-gray-500 dark:text-gray-400', description: 'text-gray-500 dark:text-gray-400',
hint: 'text-gray-500 dark:text-gray-400', hint: 'text-gray-500 dark:text-gray-400',
help: 'mt-2 text-gray-500 dark:text-gray-400', help: 'mt-2 text-gray-500 dark:text-gray-400',
error: 'mt-2 text-red-500 dark:text-red-400' error: 'mt-2 text-red-500 dark:text-red-400',
default: {
size: 'sm'
}
} }
const textarea = { export const textarea = {
...input, ...input,
default: { default: {
size: 'sm', size: 'sm',
@@ -506,7 +512,7 @@ const textarea = {
} }
} }
const select = { export const select = {
...input, ...input,
placeholder: 'text-gray-900 dark:text-white', placeholder: 'text-gray-900 dark:text-white',
default: { default: {
@@ -518,7 +524,7 @@ const select = {
} }
} }
const selectMenu = { export const selectMenu = {
container: 'z-20', container: 'z-20',
width: 'w-full', width: 'w-full',
height: 'max-h-60', height: 'max-h-60',
@@ -573,7 +579,7 @@ const selectMenu = {
} }
} }
const radio = { export const radio = {
wrapper: 'relative flex items-start', wrapper: 'relative flex items-start',
base: 'h-4 w-4 dark:checked:bg-current dark:checked:border-transparent disabled:opacity-50 disabled:cursor-not-allowed focus:ring-0 focus:ring-transparent focus:ring-offset-transparent', base: 'h-4 w-4 dark:checked:bg-current dark:checked:border-transparent disabled:opacity-50 disabled:cursor-not-allowed focus:ring-0 focus:ring-transparent focus:ring-offset-transparent',
color: 'text-{color}-500 dark:text-{color}-400', color: 'text-{color}-500 dark:text-{color}-400',
@@ -588,7 +594,7 @@ const radio = {
} }
} }
const checkbox = { export const checkbox = {
wrapper: 'relative flex items-start', wrapper: 'relative flex items-start',
base: 'h-4 w-4 dark:checked:bg-current dark:checked:border-transparent dark:indeterminate:bg-current dark:indeterminate:border-transparent disabled:opacity-50 disabled:cursor-not-allowed focus:ring-0 focus:ring-transparent focus:ring-offset-transparent', base: 'h-4 w-4 dark:checked:bg-current dark:checked:border-transparent dark:indeterminate:bg-current dark:indeterminate:border-transparent disabled:opacity-50 disabled:cursor-not-allowed focus:ring-0 focus:ring-transparent focus:ring-offset-transparent',
rounded: 'rounded', rounded: 'rounded',
@@ -604,7 +610,7 @@ const checkbox = {
} }
} }
const toggle = { export const toggle = {
base: 'relative inline-flex h-5 w-9 flex-shrink-0 border-2 border-transparent disabled:cursor-not-allowed disabled:opacity-50 focus:outline-none', base: 'relative inline-flex h-5 w-9 flex-shrink-0 border-2 border-transparent disabled:cursor-not-allowed disabled:opacity-50 focus:outline-none',
rounded: 'rounded-full', rounded: 'rounded-full',
ring: 'focus-visible:ring-2 focus-visible:ring-{color}-500 dark:focus-visible:ring-{color}-400 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900', ring: 'focus-visible:ring-2 focus-visible:ring-{color}-500 dark:focus-visible:ring-{color}-400 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900',
@@ -629,7 +635,7 @@ const toggle = {
} }
} }
const range = { export const range = {
wrapper: 'relative w-full flex items-center', wrapper: 'relative w-full flex items-center',
base: 'w-full absolute appearance-none cursor-pointer disabled:cursor-not-allowed disabled:bg-opacity-50 focus:outline-none peer group', base: 'w-full absolute appearance-none cursor-pointer disabled:cursor-not-allowed disabled:bg-opacity-50 focus:outline-none peer group',
rounded: 'rounded-lg', rounded: 'rounded-lg',
@@ -679,7 +685,7 @@ const range = {
// Layout // Layout
const card = { export const card = {
base: 'overflow-hidden', base: 'overflow-hidden',
background: 'bg-white dark:bg-gray-900', background: 'bg-white dark:bg-gray-900',
divide: 'divide-y divide-gray-200 dark:divide-gray-800', divide: 'divide-y divide-gray-200 dark:divide-gray-800',
@@ -703,13 +709,13 @@ const card = {
} }
} }
const container = { export const container = {
base: 'mx-auto', base: 'mx-auto',
padding: 'px-4 sm:px-6 lg:px-8', padding: 'px-4 sm:px-6 lg:px-8',
constrained: 'max-w-7xl' constrained: 'max-w-7xl'
} }
const skeleton = { export const skeleton = {
base: 'animate-pulse', base: 'animate-pulse',
background: 'bg-gray-100 dark:bg-gray-800', background: 'bg-gray-100 dark:bg-gray-800',
rounded: 'rounded-md' rounded: 'rounded-md'
@@ -717,7 +723,7 @@ const skeleton = {
// Navigation // Navigation
const verticalNavigation = { export const verticalNavigation = {
wrapper: 'relative', wrapper: 'relative',
base: 'group relative flex items-center gap-2 focus:outline-none focus-visible:outline-none dark:focus-visible:outline-none focus-visible:before:ring-inset focus-visible:before:ring-1 focus-visible:before:ring-primary-500 dark:focus-visible:before:ring-primary-400 before:absolute before:inset-px before:rounded-md disabled:cursor-not-allowed disabled:opacity-75', base: 'group relative flex items-center gap-2 focus:outline-none focus-visible:outline-none dark:focus-visible:outline-none focus-visible:before:ring-inset focus-visible:before:ring-1 focus-visible:before:ring-primary-500 dark:focus-visible:before:ring-primary-400 before:absolute before:inset-px before:rounded-md disabled:cursor-not-allowed disabled:opacity-75',
ring: 'focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-primary-500 dark:focus-visible:ring-primary-400', ring: 'focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-primary-500 dark:focus-visible:ring-primary-400',
@@ -745,7 +751,7 @@ const verticalNavigation = {
} }
} }
const commandPalette = { export const commandPalette = {
wrapper: 'flex flex-col flex-1 min-h-0 divide-y divide-gray-100 dark:divide-gray-800', wrapper: 'flex flex-col flex-1 min-h-0 divide-y divide-gray-100 dark:divide-gray-800',
container: 'relative flex-1 overflow-y-auto divide-y divide-gray-100 dark:divide-gray-800 scroll-py-2', container: 'relative flex-1 overflow-y-auto divide-y divide-gray-100 dark:divide-gray-800 scroll-py-2',
input: { input: {
@@ -789,7 +795,7 @@ const commandPalette = {
}, },
avatar: { avatar: {
base: 'flex-shrink-0', base: 'flex-shrink-0',
size: '3xs' size: '3xs' as const
}, },
chip: { chip: {
base: 'flex-shrink-0 w-2 h-2 mx-1 rounded-full' base: 'flex-shrink-0 w-2 h-2 mx-1 rounded-full'
@@ -813,7 +819,7 @@ const commandPalette = {
} }
} }
const pagination = { export const pagination = {
wrapper: 'flex items-center -space-x-px', wrapper: 'flex items-center -space-x-px',
base: '', base: '',
rounded: 'first:rounded-s-md last:rounded-e-md', rounded: 'first:rounded-s-md last:rounded-e-md',
@@ -838,7 +844,7 @@ const pagination = {
} }
} }
const tabs = { export const tabs = {
wrapper: 'relative space-y-2', wrapper: 'relative space-y-2',
container: 'relative w-full', container: 'relative w-full',
base: 'focus:outline-none', base: 'focus:outline-none',
@@ -874,7 +880,7 @@ const tabs = {
// Overlays // Overlays
const modal = { export const modal = {
wrapper: 'relative z-50', wrapper: 'relative z-50',
inner: 'fixed inset-0 overflow-y-auto', inner: 'fixed inset-0 overflow-y-auto',
container: 'flex min-h-full items-end sm:items-center justify-center text-center', container: 'flex min-h-full items-end sm:items-center justify-center text-center',
@@ -911,7 +917,7 @@ const modal = {
} }
} }
const slideover = { export const slideover = {
wrapper: 'fixed inset-0 flex z-50', wrapper: 'fixed inset-0 flex z-50',
overlay: { overlay: {
base: 'fixed inset-0 transition-opacity', base: 'fixed inset-0 transition-opacity',
@@ -940,7 +946,7 @@ const slideover = {
} }
} }
const tooltip = { export const tooltip = {
wrapper: 'relative inline-flex', wrapper: 'relative inline-flex',
container: 'z-20', container: 'z-20',
width: 'max-w-xs', width: 'max-w-xs',
@@ -965,7 +971,7 @@ const tooltip = {
} }
} }
const popover = { export const popover = {
wrapper: 'relative', wrapper: 'relative',
container: 'z-20', container: 'z-20',
width: '', width: '',
@@ -988,7 +994,7 @@ const popover = {
} }
} }
const contextMenu = { export const contextMenu = {
wrapper: 'relative', wrapper: 'relative',
container: 'z-20', container: 'z-20',
width: '', width: '',
@@ -1012,7 +1018,7 @@ const contextMenu = {
} }
} }
const notification = { export const notification = {
wrapper: 'w-full pointer-events-auto', wrapper: 'w-full pointer-events-auto',
container: 'relative overflow-hidden', container: 'relative overflow-hidden',
title: 'text-sm font-medium text-gray-900 dark:text-white', title: 'text-sm font-medium text-gray-900 dark:text-white',
@@ -1028,7 +1034,7 @@ const notification = {
}, },
avatar: { avatar: {
base: 'flex-shrink-0 self-center', base: 'flex-shrink-0 self-center',
size: 'md' size: 'md' as const
}, },
progress: { progress: {
base: 'absolute bottom-0 end-0 start-0 h-1', base: 'absolute bottom-0 end-0 start-0 h-1',
@@ -1059,47 +1065,9 @@ const notification = {
} }
} }
const notifications = { export const notifications = {
wrapper: 'fixed flex flex-col justify-end z-[55]', wrapper: 'fixed flex flex-col justify-end z-[55]',
position: 'bottom-0 end-0', position: 'bottom-0 end-0',
width: 'w-full sm:w-96', width: 'w-full sm:w-96',
container: 'px-4 sm:px-6 py-6 space-y-3 overflow-y-auto' container: 'px-4 sm:px-6 py-6 space-y-3 overflow-y-auto'
} }
export default {
ui: {
table,
avatar,
avatarGroup,
badge,
button,
buttonGroup,
dropdown,
kbd,
accordion,
alert,
input,
formGroup,
textarea,
select,
selectMenu,
checkbox,
radio,
toggle,
range,
card,
container,
skeleton,
verticalNavigation,
commandPalette,
pagination,
tabs,
modal,
slideover,
popover,
tooltip,
contextMenu,
notification,
notifications
}
}

View File

@@ -1,15 +1,30 @@
import { createDefu } from 'defu' import { defu, createDefu } from 'defu'
import { twMerge } from 'tailwind-merge' import { extendTailwindMerge } from 'tailwind-merge'
import type { Strategy } from '../types'
export const defuTwMerge = createDefu((obj, key, value) => { const customTwMerge = extendTailwindMerge({
if (typeof obj[key] === 'string' && typeof value === 'string' && obj[key] && value) { classGroups: {
icons: [(classPart: string) => /^i-/.test(classPart)]
}
})
const defuTwMerge = createDefu((obj, key, value, namespace) => {
if (namespace !== 'default' && typeof obj[key] === 'string' && typeof value === 'string' && obj[key] && value) {
// @ts-ignore // @ts-ignore
obj[key] = twMerge(obj[key], value) obj[key] = customTwMerge(obj[key], value)
return true return true
} }
}) })
export const hexToRgb = (hex: string) => { export function mergeConfig<T> (strategy: Strategy, ...configs): T {
if (strategy === 'override') {
return defu({}, ...configs) as T
}
return defuTwMerge({}, ...configs) as T
}
export function hexToRgb (hex: string) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i
hex = hex.replace(shorthandRegex, function (_, r, g, b) { hex = hex.replace(shorthandRegex, function (_, r, g, b) {
@@ -22,7 +37,7 @@ export const hexToRgb = (hex: string) => {
: null : null
} }
export const getSlotsChildren = (slots: any) => { export function getSlotsChildren (slots: any) {
let children = slots.default?.() let children = slots.default?.()
if (children.length) { if (children.length) {
children = children.flatMap(c => { children = children.flatMap(c => {
@@ -40,3 +55,5 @@ export const getSlotsChildren = (slots: any) => {
} }
return children return children
} }
export * from './lodash'

21
src/templates.ts Normal file
View File

@@ -0,0 +1,21 @@
import { dirname } from 'pathe'
import { useNuxt, addTemplate } from '@nuxt/kit'
export default function createTemplates (nuxt = useNuxt()) {
const template = addTemplate({
filename: 'ui.colors.mjs',
getContents: () => `export default ${JSON.stringify(nuxt.options.appConfig.ui.colors)};`,
write: true
})
const typesTemplate = addTemplate({
filename: 'ui.colors.d.ts',
getContents: () => `declare module '#ui-colors' { const defaultExport: ${JSON.stringify(nuxt.options.appConfig.ui.colors)}; export default defaultExport; }`,
write: true
})
nuxt.options.alias['#ui-colors'] = dirname(template.dst)
nuxt.hook('prepare:types', (opts) => {
opts.references.push({ path: typesTemplate.dst })
})
}

View File

@@ -1,3 +1,4 @@
{ {
"extends": "./docs/.nuxt/tsconfig.json" "extends": "./.nuxt/tsconfig.json",
"exclude": ["docs"]
} }