chore(Badge): add

This commit is contained in:
Benjamin Canac
2024-03-09 16:34:20 +01:00
parent b0222e5531
commit c65a623151
3 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<script lang="ts">
import { tv, type VariantProps } from 'tailwind-variants'
import appConfig from '#build/app.config'
import theme from '#build/ui/badge'
import type { LinkProps } from '#ui/components/Link.vue'
const badge = tv({ extend: tv(theme), ...(appConfig.ui?.badge || {}) })
type BadgeVariants = VariantProps<typeof badge>
export interface BadgeProps extends LinkProps {
as?: string
label?: string
color?: BadgeVariants['color']
variant?: BadgeVariants['variant']
size?: BadgeVariants['size']
class?: any
}
export interface BadgeSlots {
default(): any
}
</script>
<script setup lang="ts">
defineOptions({ inheritAttrs: false })
const props = withDefaults(defineProps<BadgeProps>(), {
as: 'span'
})
defineSlots<BadgeSlots>()
</script>
<template>
<component :is="as" v-bind="$attrs" :class="badge({ color, variant, size, class: props.class })">
<slot>
{{ label }}
</slot>
</component>
</template>

57
src/theme/badge.ts Normal file
View File

@@ -0,0 +1,57 @@
export default (config: { colors: string[] }) => ({
base: 'rounded-md font-medium inline-flex items-center',
variants: {
color: {
...Object.fromEntries(config.colors.map((color: string) => [color, ''])),
white: '',
gray: '',
black: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
size: {
xs: 'text-xs px-1.5 py-0.5',
sm: 'text-xs px-2 py-1',
md: 'text-sm px-2 py-1',
lg: 'text-sm px-2.5 py-1.5'
}
},
compoundVariants: [...config.colors.map((color: string) => ({
color,
variant: 'solid',
class: `bg-${color}-500 dark:bg-${color}-400 text-white dark:text-gray-900`
})), ...config.colors.map((color: string) => ({
color,
variant: 'outline',
class: `text-${color}-500 dark:text-${color}-400 ring-1 ring-inset ring-${color}-500 dark:ring-${color}-400`
})), ...config.colors.map((color: string) => ({
color,
variant: 'soft',
class: `bg-${color}-50 dark:bg-${color}-400/10 text-${color}-500 dark:text-${color}-400`
})), ...config.colors.map((color: string) => ({
color,
variant: 'subtle',
class: `bg-${color}-50 dark:bg-${color}-400/10 text-${color}-500 dark:text-${color}-400 ring-1 ring-inset ring-${color}-500/25 dark:ring-${color}-400/25`
})), {
color: 'white',
variant: 'solid',
class: 'ring-1 ring-inset ring-gray-300 dark:ring-gray-700 text-gray-900 dark:text-white bg-white dark:bg-gray-900'
}, {
color: 'gray',
variant: 'solid',
class: 'ring-1 ring-inset ring-gray-300 dark:ring-gray-700 text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-gray-800'
}, {
color: 'black',
variant: 'solid',
class: 'text-white dark:text-gray-900 bg-gray-900 dark:bg-white'
}],
defaultVariants: {
color: 'primary',
variant: 'solid',
size: 'sm'
}
})

View File

@@ -1,3 +1,4 @@
export { default as badge } from './badge'
export { default as button } from './button'
export { default as collapsible } from './collapsible'
export { default as container } from './container'