feat(Separator): new component (#46)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Sandro Circi
2024-04-10 18:40:08 +02:00
committed by GitHub
parent 78d5b32fd3
commit 8d76a8b195
8 changed files with 402 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<script lang="ts">
import { tv, type VariantProps } from 'tailwind-variants'
import type { SeparatorProps as _SeparatorProps } from 'radix-vue'
import type { AvatarProps } from '#ui/types'
import type { AppConfig } from '@nuxt/schema'
import _appConfig from '#build/app.config'
import theme from '#build/ui/separator'
const appConfig = _appConfig as AppConfig & { ui: { separator: Partial<typeof theme> } }
const separator = tv({ extend: tv(theme), ...(appConfig.ui?.separator || {}) })
type SeparatorVariants = VariantProps<typeof separator>
export interface SeparatorProps extends Omit<_SeparatorProps, 'asChild'> {
label?: string
icon?: string
avatar?: AvatarProps
color?: SeparatorVariants['color']
size?: SeparatorVariants['size']
type?: SeparatorVariants['type']
class?: any
ui?: Partial<typeof separator.slots>
}
export interface SeparatorSlots {
default(): any
}
</script>
<script setup lang="ts">
import { computed } from 'vue'
import { Separator, useForwardProps } from 'radix-vue'
import { reactivePick } from '@vueuse/core'
import { UAvatar, UIcon } from '#components'
const props = withDefaults(defineProps<SeparatorProps>(), {
as: 'div',
orientation: 'horizontal'
})
defineSlots<SeparatorSlots>()
const rootProps = useForwardProps(reactivePick(props, 'as', 'decorative', 'orientation'))
const ui = computed(() => tv({ extend: separator, slots: props.ui })({
color: props.color,
orientation: props.orientation,
size: props.size,
type: props.type
}))
</script>
<template>
<Separator v-bind="rootProps" :class="ui.root({ class: props.class })">
<div :class="ui.border()" />
<template v-if="label || icon || avatar || $slots.default">
<div :class="ui.container()">
<slot>
<span v-if="label" :class="ui.label()">{{ label }}</span>
<UIcon v-else-if="icon" :name="icon" :class="ui.icon()" />
<UAvatar v-else-if="avatar" size="2xs" v-bind="avatar" :class="ui.avatar()" />
</slot>
</div>
<div :class="ui.border()" />
</template>
</Separator>
</template>

View File

@@ -18,6 +18,8 @@ export * from '../components/Link.vue'
export * from '../components/Modal.vue'
export * from '../components/NavigationMenu.vue'
export * from '../components/Popover.vue'
export * from '../components/RadioGroup.vue'
export * from '../components/Separator.vue'
export * from '../components/Skeleton.vue'
export * from '../components/Slideover.vue'
export * from '../components/Switch.vue'

View File

@@ -17,6 +17,7 @@ export { default as modal } from './modal'
export { default as navigationMenu } from './navigation-menu'
export { default as popover } from './popover'
export { default as radioGroup } from './radio-group'
export { default as separator } from './separator'
export { default as skeleton } from './skeleton'
export { default as slideover } from './slideover'
export { default as switch } from './switch'

103
src/theme/separator.ts Normal file
View File

@@ -0,0 +1,103 @@
export default (config: { colors: string[] }) => ({
slots: {
root: 'flex items-center align-center text-center',
border: '',
container: 'font-medium text-gray-700 dark:text-gray-200 flex',
icon: 'shrink-0 size-5',
avatar: 'shrink-0',
label: 'text-sm'
},
variants: {
color: {
...Object.fromEntries(config.colors.map((color: string) => [color, { border: `border-${color}-500 dark:border-${color}-400` }])),
white: { border: 'border-white dark:border-gray-900' },
gray: { border: 'border-gray-200 dark:border-gray-800' },
black: { border: 'border-gray-900 dark:border-white' }
},
orientation: {
horizontal: {
root: 'w-full flex-row',
border: 'w-full',
container: 'mx-3 whitespace-nowrap'
},
vertical: {
root: 'h-full flex-col',
border: 'h-full',
container: 'my-2'
}
},
size: {
'2xs': '',
xs: '',
sm: '',
md: '',
lg: '',
xl: ''
},
type: {
solid: {
border: 'border-solid'
},
dashed: {
border: 'border-dashed'
},
dotted: {
border: 'border-dotted'
}
}
},
compoundVariants: [{
orientation: 'horizontal',
size: '2xs',
class: { border: 'border-t' }
}, {
orientation: 'horizontal',
size: 'xs',
class: { border: 'border-t-[2px]' }
}, {
orientation: 'horizontal',
size: 'sm',
class: { border: 'border-t-[3px]' }
}, {
orientation: 'horizontal',
size: 'md',
class: { border: 'border-t-[4px]' }
}, {
orientation: 'horizontal',
size: 'lg',
class: { border: 'border-t-[5px]' }
}, {
orientation: 'horizontal',
size: 'xl',
class: { border: 'border-t-[6px]' }
}, {
orientation: 'vertical',
size: '2xs',
class: { border: 'border-s' }
}, {
orientation: 'vertical',
size: 'xs',
class: { border: 'border-s-[2px]' }
}, {
orientation: 'vertical',
size: 'sm',
class: { border: 'border-s-[3px]' }
}, {
orientation: 'vertical',
size: 'md',
class: { border: 'border-s-[4px]' }
}, {
orientation: 'vertical',
size: 'lg',
class: { border: 'border-s-[5px]' }
}, {
orientation: 'vertical',
size: 'xl',
class: { border: 'border-s-[6px]' }
}],
defaultVariants: {
color: 'gray',
size: '2xs',
type: 'solid'
}
})