mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-20 23:11:43 +01:00
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:
@@ -4,7 +4,7 @@
|
||||
:model-value="modelValue"
|
||||
:multiple="multiple"
|
||||
:nullable="nullable"
|
||||
:class="wrapperClass"
|
||||
:class="ui.wrapper"
|
||||
v-bind="attrs"
|
||||
as="div"
|
||||
@update:model-value="onSelect"
|
||||
@@ -67,22 +67,20 @@ import { Combobox as HCombobox, ComboboxInput as HComboboxInput, ComboboxOptions
|
||||
import type { ComputedRef, PropType, ComponentPublicInstance } from 'vue'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
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 { Group, Command } from '../../types/command-palette'
|
||||
import { twJoin } from 'tailwind-merge'
|
||||
import { defu } from 'defu'
|
||||
import UIcon from '../elements/Icon.vue'
|
||||
import UButton from '../elements/Button.vue'
|
||||
import type { Button } from '../../types/button'
|
||||
import CommandPaletteGroup from './CommandPaletteGroup.vue'
|
||||
import { defuTwMerge } from '../../utils'
|
||||
import { useAppConfig } from '#imports'
|
||||
// TODO: Remove
|
||||
import { useUI } from '../../composables/useUI'
|
||||
import { mergeConfig } from '../../utils'
|
||||
import type { Group, Command, Button, Strategy } from '../../types'
|
||||
// @ts-expect-error
|
||||
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({
|
||||
components: {
|
||||
@@ -125,23 +123,23 @@ export default defineComponent({
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
default: () => appConfig.ui.commandPalette.default.icon
|
||||
default: () => config.default.icon
|
||||
},
|
||||
loadingIcon: {
|
||||
type: String,
|
||||
default: () => appConfig.ui.commandPalette.default.loadingIcon
|
||||
default: () => config.default.loadingIcon
|
||||
},
|
||||
selectedIcon: {
|
||||
type: String,
|
||||
default: () => appConfig.ui.commandPalette.default.selectedIcon
|
||||
default: () => config.default.selectedIcon
|
||||
},
|
||||
closeButton: {
|
||||
type: Object as PropType<Button>,
|
||||
default: () => appConfig.ui.commandPalette.default.closeButton
|
||||
default: () => config.default.closeButton as Button
|
||||
},
|
||||
emptyState: {
|
||||
type: Object as PropType<{ icon: string, label: string, queryLabel: string }>,
|
||||
default: () => appConfig.ui.commandPalette.default.emptyState
|
||||
default: () => config.default.emptyState
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
@@ -172,16 +170,13 @@ export default defineComponent({
|
||||
default: () => ({})
|
||||
},
|
||||
ui: {
|
||||
type: Object as PropType<Partial<typeof appConfig.ui.commandPalette>>,
|
||||
default: () => ({})
|
||||
type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
emits: ['update:modelValue', 'close'],
|
||||
setup (props, { emit, attrs, expose }) {
|
||||
// TODO: Remove
|
||||
const appConfig = useAppConfig()
|
||||
|
||||
const ui = computed<Partial<typeof appConfig.ui.commandPalette>>(() => defuTwMerge({}, props.ui, appConfig.ui.commandPalette))
|
||||
setup (props, { emit, expose }) {
|
||||
const { ui, attrs } = useUI('commandPalette', props.ui, config, { mergeWrapper: true })
|
||||
|
||||
const query = ref('')
|
||||
const comboboxInput = ref<ComponentPublicInstance<HTMLInputElement>>()
|
||||
@@ -284,8 +279,6 @@ export default defineComponent({
|
||||
}, 0)
|
||||
})
|
||||
|
||||
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
|
||||
|
||||
const iconName = computed(() => {
|
||||
if ((props.loading || isLoading.value) && props.loadingIcon) {
|
||||
return props.loadingIcon
|
||||
@@ -343,14 +336,13 @@ export default defineComponent({
|
||||
})
|
||||
|
||||
return {
|
||||
attrs: computed(() => omit(attrs, ['class'])),
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
ui,
|
||||
attrs,
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
groups,
|
||||
comboboxInput,
|
||||
query,
|
||||
wrapperClass,
|
||||
iconName,
|
||||
iconClass,
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
|
||||
@@ -76,12 +76,8 @@ import { ComboboxOption as HComboboxOption } from '@headlessui/vue'
|
||||
import UIcon from '../elements/Icon.vue'
|
||||
import UAvatar from '../elements/Avatar.vue'
|
||||
import UKbd from '../elements/Kbd.vue'
|
||||
import type { Group } from '../../types/command-palette'
|
||||
// TODO: Remove
|
||||
// @ts-expect-error
|
||||
import appConfig from '#build/app.config'
|
||||
|
||||
// const appConfig = useAppConfig()
|
||||
import type { Group } from '../../types'
|
||||
import { commandPalette } from '#ui/ui.config'
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -112,8 +108,8 @@ export default defineComponent({
|
||||
required: true
|
||||
},
|
||||
ui: {
|
||||
type: Object as PropType<Partial<typeof appConfig.ui.commandPalette>>,
|
||||
default: () => ({})
|
||||
type: Object as PropType<typeof commandPalette>,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
setup (props) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div :class="wrapperClass" v-bind="attrs">
|
||||
<div :class="ui.wrapper" v-bind="attrs">
|
||||
<slot name="prev" :on-click="onClickPrev">
|
||||
<UButton
|
||||
v-if="prevButton"
|
||||
@@ -42,17 +42,17 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import { omit } from '../../utils/lodash'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import UButton from '../elements/Button.vue'
|
||||
import { defuTwMerge } from '../../utils'
|
||||
import type { Button } from '../../types/button'
|
||||
import { useAppConfig } from '#imports'
|
||||
// TODO: Remove
|
||||
import { useUI } from '../../composables/useUI'
|
||||
import { mergeConfig } from '../../utils'
|
||||
import type { Button, Strategy } from '../../types'
|
||||
// @ts-expect-error
|
||||
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({
|
||||
components: {
|
||||
@@ -80,43 +80,40 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
size: {
|
||||
type: String,
|
||||
default: () => appConfig.ui.pagination.default.size,
|
||||
type: String as PropType<keyof typeof buttonConfig.size>,
|
||||
default: () => config.default.size,
|
||||
validator (value: string) {
|
||||
return Object.keys(appConfig.ui.button.size).includes(value)
|
||||
return Object.keys(buttonConfig.size).includes(value)
|
||||
}
|
||||
},
|
||||
activeButton: {
|
||||
type: Object as PropType<Button>,
|
||||
default: () => appConfig.ui.pagination.default.activeButton
|
||||
default: () => config.default.activeButton as Button
|
||||
},
|
||||
inactiveButton: {
|
||||
type: Object as PropType<Button>,
|
||||
default: () => appConfig.ui.pagination.default.inactiveButton
|
||||
default: () => config.default.inactiveButton as Button
|
||||
},
|
||||
prevButton: {
|
||||
type: Object as PropType<Button>,
|
||||
default: () => appConfig.ui.pagination.default.prevButton
|
||||
default: () => config.default.prevButton as Button
|
||||
},
|
||||
nextButton: {
|
||||
type: Object as PropType<Button>,
|
||||
default: () => appConfig.ui.pagination.default.nextButton
|
||||
default: () => config.default.nextButton as Button
|
||||
},
|
||||
divider: {
|
||||
type: String,
|
||||
default: '…'
|
||||
},
|
||||
ui: {
|
||||
type: Object as PropType<Partial<typeof appConfig.ui.pagination>>,
|
||||
default: () => ({})
|
||||
type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
emits: ['update:modelValue'],
|
||||
setup (props, { attrs, emit }) {
|
||||
// TODO: Remove
|
||||
const appConfig = useAppConfig()
|
||||
|
||||
const ui = computed<Partial<typeof appConfig.ui.pagination>>(() => defuTwMerge({}, props.ui, appConfig.ui.pagination))
|
||||
setup (props, { emit }) {
|
||||
const { ui, attrs } = useUI('pagination', props.ui, config, { mergeWrapper: true })
|
||||
|
||||
const currentPage = computed({
|
||||
get () {
|
||||
@@ -182,8 +179,6 @@ export default defineComponent({
|
||||
const canGoPrev = computed(() => currentPage.value > 1)
|
||||
const canGoNext = computed(() => currentPage.value < pages.value.length)
|
||||
|
||||
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
|
||||
|
||||
function onClickPage (page: number | string) {
|
||||
if (typeof page === 'string') {
|
||||
return
|
||||
@@ -209,15 +204,14 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
return {
|
||||
attrs: computed(() => omit(attrs, ['class'])),
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
ui,
|
||||
attrs,
|
||||
currentPage,
|
||||
pages,
|
||||
displayedPages,
|
||||
canGoPrev,
|
||||
canGoNext,
|
||||
wrapperClass,
|
||||
onClickPrev,
|
||||
onClickNext,
|
||||
onClickPage
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
:vertical="orientation === 'vertical'"
|
||||
:selected-index="selectedIndex"
|
||||
as="div"
|
||||
:class="wrapperClass"
|
||||
:class="ui.wrapper"
|
||||
v-bind="attrs"
|
||||
@change="onChange"
|
||||
>
|
||||
@@ -48,20 +48,18 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, computed, watch, onMounted, defineComponent } from 'vue'
|
||||
import { ref, watch, onMounted, defineComponent } 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 { useResizeObserver } from '@vueuse/core'
|
||||
import { omit } from '../../utils/lodash'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { defuTwMerge } from '../../utils'
|
||||
import type { TabItem } from '../../types/tabs'
|
||||
import { useAppConfig } from '#imports'
|
||||
// TODO: Remove
|
||||
import { useUI } from '../../composables/useUI'
|
||||
import { mergeConfig } from '../../utils'
|
||||
import type { TabItem, Strategy } from '../../types'
|
||||
// @ts-expect-error
|
||||
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({
|
||||
components: {
|
||||
@@ -91,16 +89,13 @@ export default defineComponent({
|
||||
default: () => []
|
||||
},
|
||||
ui: {
|
||||
type: Object as PropType<Partial<typeof appConfig.ui.tabs>>,
|
||||
default: () => ({})
|
||||
type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
emits: ['update:modelValue', 'change'],
|
||||
setup (props, { attrs, emit }) {
|
||||
// TODO: Remove
|
||||
const appConfig = useAppConfig()
|
||||
|
||||
const ui = computed<Partial<typeof appConfig.ui.tabs>>(() => defuTwMerge({}, props.ui, appConfig.ui.tabs))
|
||||
setup (props, { emit }) {
|
||||
const { ui, attrs } = useUI('tabs', props.ui, config, { mergeWrapper: true })
|
||||
|
||||
const listRef = ref<HTMLElement>()
|
||||
const itemRefs = ref<HTMLElement[]>([])
|
||||
@@ -108,8 +103,6 @@ export default defineComponent({
|
||||
|
||||
const selectedIndex = ref(props.modelValue || props.defaultIndex)
|
||||
|
||||
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class as string))
|
||||
|
||||
// Methods
|
||||
|
||||
function calcMarkerSize (index: number) {
|
||||
@@ -149,14 +142,13 @@ export default defineComponent({
|
||||
onMounted(() => calcMarkerSize(selectedIndex.value))
|
||||
|
||||
return {
|
||||
attrs: computed(() => omit(attrs, ['class'])),
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
ui,
|
||||
attrs,
|
||||
listRef,
|
||||
itemRefs,
|
||||
markerRef,
|
||||
selectedIndex,
|
||||
wrapperClass,
|
||||
onChange
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<nav :class="wrapperClass" v-bind="attrs">
|
||||
<nav :class="ui.wrapper" v-bind="attrs">
|
||||
<ULink
|
||||
v-for="(link, index) of links"
|
||||
v-slot="{ isActive }"
|
||||
@@ -38,21 +38,19 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent } from 'vue'
|
||||
import { defineComponent } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import { omit } from '../../utils/lodash'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import UIcon from '../elements/Icon.vue'
|
||||
import UAvatar from '../elements/Avatar.vue'
|
||||
import ULink from '../elements/Link.vue'
|
||||
import { defuTwMerge } from '../../utils'
|
||||
import type { VerticalNavigationLink } from '../../types/vertical-navigation'
|
||||
import { useAppConfig } from '#imports'
|
||||
// TODO: Remove
|
||||
import { useUI } from '../../composables/useUI'
|
||||
import { mergeConfig, omit } from '../../utils'
|
||||
import type { VerticalNavigationLink, Strategy } from '../../types'
|
||||
// @ts-expect-error
|
||||
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({
|
||||
components: {
|
||||
@@ -67,23 +65,17 @@ export default defineComponent({
|
||||
default: () => []
|
||||
},
|
||||
ui: {
|
||||
type: Object as PropType<Partial<typeof appConfig.ui.verticalNavigation>>,
|
||||
default: () => ({})
|
||||
type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
setup (props, { attrs }) {
|
||||
// TODO: Remove
|
||||
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))
|
||||
setup (props) {
|
||||
const { ui, attrs } = useUI('verticalNavigation', props.ui, config, { mergeWrapper: true })
|
||||
|
||||
return {
|
||||
attrs: computed(() => omit(attrs, ['class'])),
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
ui,
|
||||
wrapperClass,
|
||||
attrs,
|
||||
omit
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user