mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-02-01 12:47:57 +01:00
chore(Badge): add preset system
This commit is contained in:
@@ -78,7 +78,9 @@ const components = [
|
|||||||
{
|
{
|
||||||
label: 'Badge',
|
label: 'Badge',
|
||||||
to: '/components/Badge',
|
to: '/components/Badge',
|
||||||
nuxt3: true
|
nuxt3: true,
|
||||||
|
capi: true,
|
||||||
|
preset: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Button',
|
label: 'Button',
|
||||||
|
|||||||
@@ -95,6 +95,22 @@ const button = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const badge = {
|
||||||
|
base: 'inline-flex items-center font-medium',
|
||||||
|
size: {
|
||||||
|
sm: 'text-xs px-2 py-0.5',
|
||||||
|
md: 'text-sm px-2.5 py-0.5',
|
||||||
|
lg: 'text-sm px-3 py-0.5',
|
||||||
|
xl: 'text-sm px-4 py-1'
|
||||||
|
},
|
||||||
|
variant: {
|
||||||
|
...colors.reduce((acc: any, color) => {
|
||||||
|
acc[color] = `bg-${color}-100 dark:bg-${color}-700 text-${color}-800 dark:text-${color}-100`
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const formGroup = {
|
const formGroup = {
|
||||||
wrapper: '',
|
wrapper: '',
|
||||||
label: 'block text-sm font-medium u-text-gray-700',
|
label: 'block text-sm font-medium u-text-gray-700',
|
||||||
@@ -256,14 +272,15 @@ const verticalNavigation = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
card,
|
||||||
button,
|
button,
|
||||||
|
badge,
|
||||||
formGroup,
|
formGroup,
|
||||||
input,
|
input,
|
||||||
textarea,
|
textarea,
|
||||||
select,
|
select,
|
||||||
checkbox,
|
checkbox,
|
||||||
radio,
|
radio,
|
||||||
card,
|
|
||||||
container,
|
container,
|
||||||
toggle,
|
toggle,
|
||||||
verticalNavigation
|
verticalNavigation
|
||||||
|
|||||||
@@ -1,27 +1,34 @@
|
|||||||
<template>
|
<template>
|
||||||
<span class="inline-flex items-center font-medium" :class="badgeClass">
|
<span :class="badgeClass">
|
||||||
<slot>{{ label }}</slot>
|
<slot>{{ label }}</slot>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { classNames } from '../../utils'
|
||||||
|
import $ui from '#build/ui'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
size: {
|
size: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'md',
|
default: 'md',
|
||||||
validator (value) {
|
validator (value) {
|
||||||
return ['sm', 'md', 'lg'].includes(value)
|
return Object.keys($ui.badge.size).includes(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
variant: {
|
variant: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'primary',
|
default: 'primary',
|
||||||
validator (value) {
|
validator (value) {
|
||||||
return ['primary', 'gray', 'red', 'orange', 'yellow', 'green', 'teal', 'blue', 'indigo', 'purple', 'pink', 'gradient'].includes(value)
|
return Object.keys($ui.badge.variant).includes(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pill: {
|
baseClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.badge.base
|
||||||
|
},
|
||||||
|
rounded: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
@@ -30,42 +37,18 @@ export default {
|
|||||||
default: null
|
default: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
setup (props) {
|
||||||
sizeClass () {
|
const badgeClass = computed(() => {
|
||||||
return ({
|
return classNames(
|
||||||
sm: 'text-xs px-2 py-0.5',
|
props.baseClass,
|
||||||
md: 'text-sm px-2.5 py-0.5 leading-4',
|
$ui.badge.size[props.size],
|
||||||
lg: 'text-sm px-3 py-0.5 leading-5'
|
$ui.badge.variant[props.variant],
|
||||||
})[this.size]
|
props.rounded ? 'rounded-full' : 'rounded-md'
|
||||||
},
|
)
|
||||||
variantClass () {
|
})
|
||||||
return ({
|
|
||||||
primary: 'bg-primary-100 dark:bg-primary-700 text-primary-800 dark:text-primary-100',
|
return {
|
||||||
gray: 'bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-100',
|
badgeClass
|
||||||
red: 'bg-red-100 dark:bg-red-700 text-red-800 dark:text-red-100',
|
|
||||||
orange: 'bg-orange-100 dark:bg-orange-700 text-orange-800 dark:text-orange-100',
|
|
||||||
yellow: 'bg-yellow-100 dark:bg-yellow-700 text-yellow-800 dark:text-yellow-100',
|
|
||||||
green: 'bg-green-100 dark:bg-green-700 text-green-800 dark:text-green-100',
|
|
||||||
teal: 'bg-teal-100 dark:bg-teal-700 text-teal-800 dark:text-teal-100',
|
|
||||||
blue: 'bg-blue-100 dark:bg-blue-700 text-blue-800 dark:text-blue-100',
|
|
||||||
indigo: 'bg-indigo-100 dark:bg-indigo-700 text-indigo-800 dark:text-indigo-100',
|
|
||||||
purple: 'bg-purple-100 dark:bg-purple-700 text-purple-800 dark:text-purple-100',
|
|
||||||
pink: 'bg-pink-100 dark:bg-pink-700 text-pink-800 dark:text-pink-100',
|
|
||||||
gradient: 'bg-gradient-to-r from-indigo-600 to-blue-600 text-white'
|
|
||||||
})[this.variant]
|
|
||||||
},
|
|
||||||
roundedClass () {
|
|
||||||
return ({
|
|
||||||
false: 'rounded',
|
|
||||||
true: 'rounded-full'
|
|
||||||
})[this.pill]
|
|
||||||
},
|
|
||||||
badgeClass () {
|
|
||||||
return [
|
|
||||||
this.sizeClass,
|
|
||||||
this.variantClass,
|
|
||||||
this.roundedClass
|
|
||||||
].join(' ')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user