feat(Switch): add label and description props (#60)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Romain Hamel
2024-04-15 11:56:30 +02:00
committed by GitHub
parent 1535313596
commit 2fe91f3847
6 changed files with 112 additions and 53 deletions

View File

@@ -6,7 +6,7 @@ export default (config: { colors: string[] }) => ({
wrapper: 'ms-2',
indicator: 'flex',
icon: 'size-full',
label: 'font-medium text-gray-700 dark:text-gray-200',
label: 'block font-medium text-gray-700 dark:text-gray-200',
description: 'text-gray-500 dark:text-gray-400'
},
variants: {

View File

@@ -1,43 +1,60 @@
export default (config: { colors: string[] }) => ({
slots: {
root: 'peer inline-flex shrink-0 items-center rounded-full border-2 border-transparent transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900 disabled:cursor-not-allowed disabled:opacity-75 data-[state=unchecked]:bg-gray-200 dark:data-[state=unchecked]:bg-gray-700',
root: 'relative flex items-start',
base: 'peer inline-flex shrink-0 items-center rounded-full border-2 border-transparent transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900 data-[state=unchecked]:bg-gray-200 dark:data-[state=unchecked]:bg-gray-700',
container: 'flex items-center',
thumb: 'group pointer-events-none block rounded-full bg-white dark:bg-gray-900 shadow-lg ring-0 transition-transform duration-200 data-[state=unchecked]:translate-x-0 flex items-center justify-center',
icon: 'absolute shrink-0 group-data-[state=unchecked]:text-gray-400 dark:group-data-[state=unchecked]:text-gray-500 transition-[color,opacity] duration-200 opacity-0'
icon: 'absolute shrink-0 group-data-[state=unchecked]:text-gray-400 dark:group-data-[state=unchecked]:text-gray-500 transition-[color,opacity] duration-200 opacity-0',
wrapper: 'ms-2',
label: 'block font-medium text-gray-700 dark:text-gray-200',
description: 'text-gray-500 dark:text-gray-400'
},
variants: {
color: Object.fromEntries(config.colors.map((color: string) => [color, {
root: `data-[state=checked]:bg-${color}-500 dark:data-[state=checked]:bg-${color}-400 focus-visible:ring-${color}-500 dark:focus-visible:ring-${color}-400`,
base: `data-[state=checked]:bg-${color}-500 dark:data-[state=checked]:bg-${color}-400 focus-visible:ring-${color}-500 dark:focus-visible:ring-${color}-400`,
icon: `group-data-[state=checked]:text-${color}-500 dark:group-data-[state=checked]:text-${color}-400`
}])),
size: {
'2xs': {
root: 'h-3 w-5',
base: 'h-3 w-5',
container: 'h-4',
thumb: 'size-2 data-[state=checked]:translate-x-2',
wrapper: 'text-xs',
icon: 'size-1'
},
'xs': {
root: 'h-4 w-7',
base: 'h-4 w-7',
container: 'h-4',
thumb: 'size-3 data-[state=checked]:translate-x-3',
wrapper: 'text-xs',
icon: 'size-2'
},
'sm': {
root: 'h-5 w-9',
base: 'h-5 w-9',
container: 'h-5',
thumb: 'size-4 data-[state=checked]:translate-x-4',
wrapper: 'text-sm',
icon: 'size-3'
},
'md': {
root: 'h-6 w-11',
base: 'h-6 w-11',
container: 'h-5',
thumb: 'size-5 data-[state=checked]:translate-x-5',
wrapper: 'text-sm',
icon: 'size-4'
},
'lg': {
root: 'h-7 w-[52px]',
base: 'h-7 w-[52px]',
container: 'h-6',
thumb: 'size-6 data-[state=checked]:translate-x-6',
wrapper: 'text-base',
icon: 'size-5'
},
'xl': {
root: 'h-8 w-[60px]',
base: 'h-8 w-[60px]',
container: 'h-6',
thumb: 'size-7 data-[state=checked]:translate-x-7',
wrapper: 'text-base',
icon: 'size-6'
}
},
@@ -55,6 +72,18 @@ export default (config: { colors: string[] }) => ({
true: {
icon: 'animate-spin'
}
},
required: {
true: {
label: 'after:content-[\'*\'] after:ms-0.5 after:text-red-500 dark:after:text-red-400'
}
},
disabled: {
true: {
base: 'cursor-not-allowed opacity-75',
label: 'cursor-not-allowed opacity-75',
description: 'cursor-not-allowed opacity-75'
}
}
},
defaultVariants: {