|
| 1 | +// @unocss-include |
| 2 | +import { tv } from 'tailwind-variants'; |
| 3 | +import type { VariantProps } from 'tailwind-variants'; |
| 4 | + |
| 5 | +export const switchVariants = tv({ |
| 6 | + base: [], |
| 7 | + defaultVariants: { |
| 8 | + color: 'primary', |
| 9 | + shape: 'rounded', |
| 10 | + size: 'md' |
| 11 | + }, |
| 12 | + slots: { |
| 13 | + root: [ |
| 14 | + `peer shrink-0 inline-flex items-center rounded-full border-0 shadow-sm transition-colors duration-200`, |
| 15 | + `focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background`, |
| 16 | + `disabled:cursor-not-allowed disabled:opacity-50`, |
| 17 | + `data-[state=unchecked]:bg-input` |
| 18 | + ], |
| 19 | + thumb: `flex justify-center items-center rounded-full shadow-lg transition-transform duration-200 bg-background pointer-events-none data-[state=unchecked]:translate-x-0.5` |
| 20 | + }, |
| 21 | + variants: { |
| 22 | + color: { |
| 23 | + accent: { |
| 24 | + root: `data-[state=checked]:bg-accent-foreground/20 focus-visible:ring-accent-foreground/20` |
| 25 | + }, |
| 26 | + carbon: { |
| 27 | + root: `data-[state=checked]:bg-carbon focus-visible:ring-carbon` |
| 28 | + }, |
| 29 | + destructive: { |
| 30 | + root: `data-[state=checked]:bg-destructive focus-visible:ring-destructive` |
| 31 | + }, |
| 32 | + info: { |
| 33 | + root: `data-[state=checked]:bg-info focus-visible:ring-info` |
| 34 | + }, |
| 35 | + primary: { |
| 36 | + root: `data-[state=checked]:bg-primary focus-visible:ring-primary` |
| 37 | + }, |
| 38 | + secondary: { |
| 39 | + root: `data-[state=checked]:bg-secondary-foreground/20 focus-visible:ring-secondary-foreground/20` |
| 40 | + }, |
| 41 | + success: { |
| 42 | + root: `data-[state=checked]:bg-success focus-visible:ring-success` |
| 43 | + }, |
| 44 | + warning: { |
| 45 | + root: `data-[state=checked]:bg-warning focus-visible:ring-warning` |
| 46 | + } |
| 47 | + }, |
| 48 | + shape: { |
| 49 | + rounded: { |
| 50 | + root: 'rounded-full', |
| 51 | + thumb: 'rounded-full' |
| 52 | + }, |
| 53 | + square: { |
| 54 | + root: 'rounded-md', |
| 55 | + thumb: 'rounded-sm' |
| 56 | + } |
| 57 | + }, |
| 58 | + size: { |
| 59 | + '2xl': { |
| 60 | + root: 'h-7 w-13', |
| 61 | + thumb: 'size-6 data-[state=checked]:translate-x-6.5' |
| 62 | + }, |
| 63 | + lg: { |
| 64 | + root: 'h-5.5 w-10', |
| 65 | + thumb: 'size-4.5 data-[state=checked]:translate-x-5' |
| 66 | + }, |
| 67 | + md: { |
| 68 | + root: 'h-5 w-9', |
| 69 | + thumb: 'size-4 data-[state=checked]:translate-x-4.5' |
| 70 | + }, |
| 71 | + sm: { |
| 72 | + root: 'h-4.5 w-8', |
| 73 | + thumb: 'size-3.5 data-[state=checked]:translate-x-4' |
| 74 | + }, |
| 75 | + xl: { |
| 76 | + root: 'h-6 w-11', |
| 77 | + thumb: 'size-5 data-[state=checked]:translate-x-5.5' |
| 78 | + }, |
| 79 | + xs: { |
| 80 | + root: 'h-4 w-7', |
| 81 | + thumb: 'size-3 data-[state=checked]:translate-x-3.5' |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | +}); |
| 86 | + |
| 87 | +type SwitchVariants = VariantProps<typeof switchVariants>; |
| 88 | + |
| 89 | +export type SwitchSlots = keyof typeof switchVariants.slots; |
| 90 | + |
| 91 | +export type SwitchShape = NonNullable<SwitchVariants['shape']>; |
0 commit comments