@spark-ui/components 16.2.2 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Button-DPncfbbM.mjs → Button-1M9DcZl0.mjs} +25 -79
- package/dist/Button-1M9DcZl0.mjs.map +1 -0
- package/dist/Button-FZceRWG2.js +2 -0
- package/dist/Button-FZceRWG2.js.map +1 -0
- package/dist/{Icon-C23-htlD.mjs → Icon-BO327oHU.mjs} +8 -9
- package/dist/Icon-BO327oHU.mjs.map +1 -0
- package/dist/Icon-C-cNTnzd.js +2 -0
- package/dist/Icon-C-cNTnzd.js.map +1 -0
- package/dist/{IconButton-D3g86WpZ.js → IconButton-BR1bJSQA.js} +2 -2
- package/dist/{IconButton-D3g86WpZ.js.map → IconButton-BR1bJSQA.js.map} +1 -1
- package/dist/{IconButton-Bfd-6BAD.mjs → IconButton-DdB3Pq13.mjs} +2 -2
- package/dist/{IconButton-Bfd-6BAD.mjs.map → IconButton-DdB3Pq13.mjs.map} +1 -1
- package/dist/Spinner-Br4Rp9V2.js +2 -0
- package/dist/Spinner-Br4Rp9V2.js.map +1 -0
- package/dist/{Spinner-aLrtE2JN.mjs → Spinner-Co3AjkQV.mjs} +7 -8
- package/dist/Spinner-Co3AjkQV.mjs.map +1 -0
- package/dist/TextLink-5MvP0P8D.js +2 -0
- package/dist/TextLink-5MvP0P8D.js.map +1 -0
- package/dist/{TextLink-D7mOCjY_.mjs → TextLink-Cc_LeVcx.mjs} +10 -11
- package/dist/TextLink-Cc_LeVcx.mjs.map +1 -0
- package/dist/accordion/index.js +1 -1
- package/dist/accordion/index.mjs +1 -1
- package/dist/avatar/index.js +1 -1
- package/dist/avatar/index.mjs +2 -2
- package/dist/badge/BadgeItem.styles.d.ts +1 -1
- package/dist/badge/index.js +1 -1
- package/dist/badge/index.js.map +1 -1
- package/dist/badge/index.mjs +10 -11
- package/dist/badge/index.mjs.map +1 -1
- package/dist/breadcrumb/index.js +1 -1
- package/dist/breadcrumb/index.mjs +2 -2
- package/dist/button/Button.styles.d.ts +1 -1
- package/dist/button/index.js +1 -1
- package/dist/button/index.mjs +1 -1
- package/dist/button/variants/contrast.d.ts +0 -4
- package/dist/button/variants/filled.d.ts +0 -4
- package/dist/button/variants/ghost.d.ts +0 -4
- package/dist/button/variants/outlined.d.ts +0 -4
- package/dist/button/variants/tinted.d.ts +0 -4
- package/dist/card/Backdrop.d.ts +1 -1
- package/dist/card/Card.styles.d.ts +1 -1
- package/dist/card/Content.styles.d.ts +1 -1
- package/dist/card/index.js +1 -1
- package/dist/card/index.js.map +1 -1
- package/dist/card/index.mjs +12 -31
- package/dist/card/index.mjs.map +1 -1
- package/dist/carousel/CarouselPageIndicator.d.ts +1 -1
- package/dist/carousel/index.js +1 -1
- package/dist/carousel/index.js.map +1 -1
- package/dist/carousel/index.mjs +29 -29
- package/dist/carousel/index.mjs.map +1 -1
- package/dist/checkbox/CheckboxInput.styles.d.ts +1 -1
- package/dist/checkbox/index.js +1 -1
- package/dist/checkbox/index.js.map +1 -1
- package/dist/checkbox/index.mjs +26 -33
- package/dist/checkbox/index.mjs.map +1 -1
- package/dist/chip/Chip.styles.d.ts +1 -1
- package/dist/chip/index.js +1 -1
- package/dist/chip/index.js.map +1 -1
- package/dist/chip/index.mjs +33 -68
- package/dist/chip/index.mjs.map +1 -1
- package/dist/chip/variants/dashed.d.ts +0 -4
- package/dist/chip/variants/outlined.d.ts +0 -4
- package/dist/chip/variants/tinted.d.ts +0 -4
- package/dist/combobox/index.js +1 -1
- package/dist/combobox/index.mjs +3 -3
- package/dist/dialog/index.js +1 -1
- package/dist/dialog/index.mjs +2 -2
- package/dist/drawer/index.js +1 -1
- package/dist/drawer/index.mjs +2 -2
- package/dist/dropdown/index.js +1 -1
- package/dist/dropdown/index.mjs +1 -1
- package/dist/file-upload/index.js +1 -1
- package/dist/file-upload/index.js.map +1 -1
- package/dist/file-upload/index.mjs +4 -4
- package/dist/file-upload/index.mjs.map +1 -1
- package/dist/form-field/index.js +1 -1
- package/dist/form-field/index.mjs +1 -1
- package/dist/icon/Icon.styles.d.ts +1 -1
- package/dist/icon/index.js +1 -1
- package/dist/icon/index.mjs +1 -1
- package/dist/icon-button/index.js +1 -1
- package/dist/icon-button/index.mjs +1 -1
- package/dist/input/index.js +1 -1
- package/dist/input/index.mjs +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/pagination/index.mjs +3 -3
- package/dist/popover/PopoverContent.styles.d.ts +1 -1
- package/dist/popover/PopoverContext.d.ts +1 -1
- package/dist/popover/index.js +1 -1
- package/dist/popover/index.js.map +1 -1
- package/dist/popover/index.mjs +33 -35
- package/dist/popover/index.mjs.map +1 -1
- package/dist/progress/ProgressIndicator.d.ts +1 -1
- package/dist/progress/index.js +1 -1
- package/dist/progress/index.js.map +1 -1
- package/dist/progress/index.mjs +42 -43
- package/dist/progress/index.mjs.map +1 -1
- package/dist/progress-tracker/ProgressTrackerStep.styles.d.ts +1 -1
- package/dist/progress-tracker/ProgressTrackerStepIndicator.styles.d.ts +1 -1
- package/dist/progress-tracker/index.js +1 -1
- package/dist/progress-tracker/index.js.map +1 -1
- package/dist/progress-tracker/index.mjs +38 -38
- package/dist/progress-tracker/index.mjs.map +1 -1
- package/dist/radio-group/RadioIndicator.styles.d.ts +1 -1
- package/dist/radio-group/RadioInput.styles.d.ts +1 -1
- package/dist/radio-group/index.js +1 -1
- package/dist/radio-group/index.js.map +1 -1
- package/dist/radio-group/index.mjs +47 -53
- package/dist/radio-group/index.mjs.map +1 -1
- package/dist/rating/index.js +1 -1
- package/dist/rating/index.mjs +1 -1
- package/dist/rating-display/index.js +1 -1
- package/dist/rating-display/index.mjs +1 -1
- package/dist/scrolling-list/index.js +1 -1
- package/dist/scrolling-list/index.mjs +3 -3
- package/dist/segmented-gauge/SegmentedGauge.d.ts +1 -1
- package/dist/segmented-gauge/SegmentedGaugeContext.d.ts +1 -1
- package/dist/segmented-gauge/index.js +1 -1
- package/dist/segmented-gauge/index.js.map +1 -1
- package/dist/segmented-gauge/index.mjs +14 -16
- package/dist/segmented-gauge/index.mjs.map +1 -1
- package/dist/select/index.js +1 -1
- package/dist/select/index.mjs +1 -1
- package/dist/slider/SliderThumb.styles.d.ts +1 -1
- package/dist/slider/SliderTrack.styles.d.ts +1 -1
- package/dist/slider/index.js +1 -1
- package/dist/slider/index.js.map +1 -1
- package/dist/slider/index.mjs +3 -5
- package/dist/slider/index.mjs.map +1 -1
- package/dist/snackbar/SnackbarItem.styles.d.ts +1 -1
- package/dist/snackbar/index.js +1 -1
- package/dist/snackbar/index.js.map +1 -1
- package/dist/snackbar/index.mjs +24 -35
- package/dist/snackbar/index.mjs.map +1 -1
- package/dist/snackbar/snackbarVariants.d.ts +0 -8
- package/dist/spinner/Spinner.styles.d.ts +1 -1
- package/dist/spinner/index.js +1 -1
- package/dist/spinner/index.mjs +1 -1
- package/dist/stepper/index.js +1 -1
- package/dist/stepper/index.mjs +2 -2
- package/dist/switch/SwitchInput.d.ts +7 -5
- package/dist/switch/SwitchInput.styles.d.ts +1 -1
- package/dist/switch/index.js +1 -1
- package/dist/switch/index.js.map +1 -1
- package/dist/switch/index.mjs +80 -91
- package/dist/switch/index.mjs.map +1 -1
- package/dist/tabs/TabsTrigger.styles.d.ts +1 -1
- package/dist/tabs/index.js +1 -1
- package/dist/tabs/index.js.map +1 -1
- package/dist/tabs/index.mjs +20 -21
- package/dist/tabs/index.mjs.map +1 -1
- package/dist/tag/Tag.styles.d.ts +1 -1
- package/dist/tag/index.js +1 -1
- package/dist/tag/index.js.map +1 -1
- package/dist/tag/index.mjs +15 -31
- package/dist/tag/index.mjs.map +1 -1
- package/dist/tag/variants/filled.d.ts +0 -4
- package/dist/tag/variants/outlined.d.ts +0 -4
- package/dist/tag/variants/tinted.d.ts +0 -4
- package/dist/text-link/TextLink.d.ts +1 -1
- package/dist/text-link/index.js +1 -1
- package/dist/text-link/index.mjs +1 -1
- package/dist/toast/Toast.styles.d.ts +1 -1
- package/dist/toast/index.js +1 -1
- package/dist/toast/index.js.map +1 -1
- package/dist/toast/index.mjs +25 -37
- package/dist/toast/index.mjs.map +1 -1
- package/dist/toast/types.d.ts +1 -1
- package/package.json +4 -4
- package/dist/Button-B6rA3-e5.js +0 -2
- package/dist/Button-B6rA3-e5.js.map +0 -1
- package/dist/Button-DPncfbbM.mjs.map +0 -1
- package/dist/Icon-C23-htlD.mjs.map +0 -1
- package/dist/Icon-CF0W0LKr.js +0 -2
- package/dist/Icon-CF0W0LKr.js.map +0 -1
- package/dist/Spinner-_Kffli3B.js +0 -2
- package/dist/Spinner-_Kffli3B.js.map +0 -1
- package/dist/Spinner-aLrtE2JN.mjs.map +0 -1
- package/dist/TextLink-C3xDLsbC.js +0 -2
- package/dist/TextLink-C3xDLsbC.js.map +0 -1
- package/dist/TextLink-D7mOCjY_.mjs.map +0 -1
package/dist/switch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-[state=unchecked]:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'basic', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['data-[state=checked]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: [\n 'data-[state=checked]:bg-support',\n 'hover:ring-support-container',\n 'text-support',\n ],\n accent: ['data-[state=checked]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n basic: ['data-[state=checked]:bg-basic', 'hover:ring-basic-container', 'text-basic'],\n success: [\n 'data-[state=checked]:bg-success',\n 'hover:ring-success-container',\n 'text-success',\n ],\n alert: ['data-[state=checked]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['data-[state=checked]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['data-[state=checked]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: [\n 'data-[state=checked]:bg-neutral',\n 'hover:ring-neutral-container',\n 'text-neutral',\n ],\n }),\n },\n defaultVariants: {\n intent: 'basic',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { Switch as RadixSwitch } from 'radix-ui'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<'button'>, 'value'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * When true, prevents the user from interacting with the switch.\n */\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n value = 'on',\n onCheckedChange,\n className,\n required,\n ref,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <RadixSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n className={styles({ intent, size, className })}\n value={value}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n name={name}\n required={required || isRequired}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <RadixSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </RadixSwitch.Thumb>\n </span>\n </RadixSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('default:text-on-surface', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","value","onCheckedChange","className","required","ref","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","handleCheckedChange","updatedValue","jsx","RadixSwitch","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":"6cAGaA,EAASC,EAAAA,IACpBC,KAAG,CACD,kCACA,iBACA,kCACA,eACA,6CACA,qFACA,0BACA,6CACA,6BACA,mBAAA,CACD,EACD,CACE,SAAU,CAIR,KA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EAEAX,EAAO,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-unchecked:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['[&[data-checked]]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: ['[&[data-checked]]:bg-support', 'hover:ring-support-container', 'text-support'],\n accent: ['[&[data-checked]]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n success: ['[&[data-checked]]:bg-success', 'hover:ring-success-container', 'text-success'],\n alert: ['[&[data-checked]]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['[&[data-checked]]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['[&[data-checked]]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: ['[&[data-checked]]:bg-neutral', 'hover:ring-neutral-container', 'text-neutral'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { Switch as BaseSwitch } from '@base-ui/react/switch'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRenderSlot } from '../drawer/useRenderSlot'\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<typeof BaseSwitch.Root>, 'value' | 'render' | 'onCheckedChange'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n onCheckedChange,\n className,\n required,\n ref,\n asChild = false,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n const renderSlot = useRenderSlot(asChild, 'span')\n const isRequiredComputed = Boolean(required || isRequired)\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <BaseSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n render={renderSlot}\n className={styles({ intent, size, className })}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={nextChecked => handleCheckedChange(nextChecked)}\n name={name}\n required={isRequiredComputed}\n aria-required={isRequiredComputed ? true : undefined}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <BaseSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </BaseSwitch.Thumb>\n </span>\n </BaseSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('default:text-on-surface', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","onCheckedChange","className","required","ref","asChild","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","renderSlot","useRenderSlot","isRequiredComputed","handleCheckedChange","updatedValue","jsx","BaseSwitch","nextChecked","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":"ogBAGaA,EAASC,EAAAA,IACpBC,KAAG,CACD,kCACA,iBACA,kCACA,eACA,6CACA,qFACA,0BACA,qCACA,6BACA,mBAAA,CACD,EACD,CACE,SAAU,CAIR,KAAMC,EAAAA,aAAmC,CACvC,GAAID,EAAAA,GAAG,CAAC,UAAW,UAAW,WAAW,CAAC,EAC1C,GAAIA,EAAAA,GAAG,CAAC,UAAW,UAAW,cAAc,CAAC,CAAA,CAC9C,EAID,OAAQC,EAAAA,aAGN,CACA,KAAM,CAAC,4BAA6B,4BAA6B,WAAW,EAC5E,QAAS,CAAC,+BAAgC,+BAAgC,cAAc,EACxF,OAAQ,CAAC,8BAA+B,8BAA+B,aAAa,EACpF,QAAS,CAAC,+BAAgC,+BAAgC,cAAc,EACxF,MAAO,CAAC,6BAA8B,6BAA8B,YAAY,EAChF,MAAO,CAAC,6BAA8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AE,SAAAE,EAAU,UAAA3B,EAAW,EAC7C,GAAG4B,CAAA,CACN,ECdIE,EAAY,UAELC,EAAS,CAAC,CACrB,KAAAjC,EAAO,KACP,SAAAkC,EACA,UAAAhC,EACA,GAAAiC,EACA,SAAAN,EACA,QAAAO,EAAU,GACV,IAAAhC,EACA,GAAGE,CACL,IAAmB,CACjB,MAAM+B,EAAQtB,EAAAA,oBAAA,EAERuB,EAAU,GAAGN,CAAS,UAAUO,EAAAA,OAAO,GACvCC,EAAU,GAAGR,CAAS,UAAUO,EAAAA,OAAO,GACvCE,EAAUJ,EAAM,IAAMF,GAAMK,EAE5BE,EAAcR,GAClBZ,EAAAA,IAACM,EAAA,CAAY,SAAAC,EAAoB,QAASY,EAAS,GAAIH,EACpD,SAAAJ,CAAA,CACH,EAGIS,EACJrB,EAAAA,IAAC9B,EAAA,CACC,IAAAY,EACA,KAAAJ,EACA,GAAIyC,EACJ,SAAAZ,EAMA,kBAAiBK,EAAWI,EAAUD,EAAM,QAC3C,GAAG/B,CAAA,CAAA,EAIFsC,EAAUR,EACdX,EAAAA,KAAAoB,EAAAA,SAAA,CACG,SAAA,CAAAH,EACAC,CAAA,CAAA,CACH,EAEAlB,EAAAA,KAAAoB,EAAAA,SAAA,CACG,SAAA,CAAAF,EACAD,CAAA,EACH,EAGF,OACEpB,EAAAA,IAAC,MAAA,CACC,uBAAqB,SACrB,UAAWwB,EAAAA,GAAG,uCAAwC5C,CAAS,EAE9D,SAAA0C,CAAA,CAAA,CAGP,EAEAX,EAAO,YAAc"}
|
package/dist/switch/index.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { jsx as e, jsxs as
|
|
2
|
-
import { useFormFieldControl as
|
|
3
|
-
import { cva as o, cx as
|
|
1
|
+
import { jsx as e, jsxs as w, Fragment as S } from "react/jsx-runtime";
|
|
2
|
+
import { useFormFieldControl as F } from "@spark-ui/components/form-field";
|
|
3
|
+
import { cva as o, cx as E } from "class-variance-authority";
|
|
4
4
|
import { useId as z } from "react";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { Switch as y } from "@base-ui/react/switch";
|
|
6
|
+
import { useCombinedState as G } from "@spark-ui/hooks/use-combined-state";
|
|
7
|
+
import { Check as P } from "@spark-ui/icons/Check";
|
|
8
|
+
import { Close as T } from "@spark-ui/icons/Close";
|
|
9
|
+
import { u as W } from "../useRenderSlot-Bta2kdp4.mjs";
|
|
10
|
+
import { S as C } from "../Slot-DLY1rJrG.mjs";
|
|
11
|
+
import { tw as v, makeVariants as h } from "@spark-ui/internal-utils";
|
|
12
|
+
import { Label as X } from "../label/index.mjs";
|
|
13
|
+
const _ = o(
|
|
14
|
+
v([
|
|
14
15
|
"relative shrink-0 self-baseline",
|
|
15
16
|
"cursor-pointer",
|
|
16
17
|
"rounded-full border-transparent",
|
|
@@ -18,7 +19,7 @@ const W = o(
|
|
|
18
19
|
"transition-colors duration-200 ease-in-out",
|
|
19
20
|
"disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3",
|
|
20
21
|
"focus-visible:u-outline",
|
|
21
|
-
"data-
|
|
22
|
+
"data-unchecked:bg-on-surface/dim-3",
|
|
22
23
|
"u-shadow-border-transition",
|
|
23
24
|
"overflow-x-hidden"
|
|
24
25
|
]),
|
|
@@ -28,42 +29,29 @@ const W = o(
|
|
|
28
29
|
* Size of the switch input.
|
|
29
30
|
*/
|
|
30
31
|
size: h({
|
|
31
|
-
sm:
|
|
32
|
-
md:
|
|
32
|
+
sm: v(["h-sz-24", "w-sz-40", "border-md"]),
|
|
33
|
+
md: v(["h-sz-32", "w-sz-56", "border-[4px]"])
|
|
33
34
|
}),
|
|
34
35
|
/**
|
|
35
36
|
* Color scheme of the switch input.
|
|
36
37
|
*/
|
|
37
38
|
intent: h({
|
|
38
|
-
main: ["data-
|
|
39
|
-
support: [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
success: [
|
|
47
|
-
"data-[state=checked]:bg-success",
|
|
48
|
-
"hover:ring-success-container",
|
|
49
|
-
"text-success"
|
|
50
|
-
],
|
|
51
|
-
alert: ["data-[state=checked]:bg-alert", "hover:ring-alert-container", "text-alert"],
|
|
52
|
-
error: ["data-[state=checked]:bg-error", "hover:ring-error-container", "text-error"],
|
|
53
|
-
info: ["data-[state=checked]:bg-info", "hover:ring-info-container", "text-info"],
|
|
54
|
-
neutral: [
|
|
55
|
-
"data-[state=checked]:bg-neutral",
|
|
56
|
-
"hover:ring-neutral-container",
|
|
57
|
-
"text-neutral"
|
|
58
|
-
]
|
|
39
|
+
main: ["[&[data-checked]]:bg-main", "hover:ring-main-container", "text-main"],
|
|
40
|
+
support: ["[&[data-checked]]:bg-support", "hover:ring-support-container", "text-support"],
|
|
41
|
+
accent: ["[&[data-checked]]:bg-accent", "hover:ring-accent-container", "text-accent"],
|
|
42
|
+
success: ["[&[data-checked]]:bg-success", "hover:ring-success-container", "text-success"],
|
|
43
|
+
alert: ["[&[data-checked]]:bg-alert", "hover:ring-alert-container", "text-alert"],
|
|
44
|
+
error: ["[&[data-checked]]:bg-error", "hover:ring-error-container", "text-error"],
|
|
45
|
+
info: ["[&[data-checked]]:bg-info", "hover:ring-info-container", "text-info"],
|
|
46
|
+
neutral: ["[&[data-checked]]:bg-neutral", "hover:ring-neutral-container", "text-neutral"]
|
|
59
47
|
})
|
|
60
48
|
},
|
|
61
49
|
defaultVariants: {
|
|
62
|
-
intent: "
|
|
50
|
+
intent: "support",
|
|
63
51
|
size: "sm"
|
|
64
52
|
}
|
|
65
53
|
}
|
|
66
|
-
),
|
|
54
|
+
), A = o(
|
|
67
55
|
[
|
|
68
56
|
"pointer-events-none absolute inset-0 flex items-center",
|
|
69
57
|
"transition-all duration-200 ease-in-out"
|
|
@@ -76,7 +64,7 @@ const W = o(
|
|
|
76
64
|
}
|
|
77
65
|
}
|
|
78
66
|
}
|
|
79
|
-
),
|
|
67
|
+
), H = o(
|
|
80
68
|
[
|
|
81
69
|
"absolute left-0 top-0 flex items-center justify-center",
|
|
82
70
|
"bg-surface",
|
|
@@ -100,7 +88,7 @@ const W = o(
|
|
|
100
88
|
checked: !1
|
|
101
89
|
}
|
|
102
90
|
}
|
|
103
|
-
),
|
|
91
|
+
), I = o(["transition-opacity duration-200"], {
|
|
104
92
|
variants: {
|
|
105
93
|
size: h({
|
|
106
94
|
sm: ["h-sz-10 w-sz-10"],
|
|
@@ -110,47 +98,48 @@ const W = o(
|
|
|
110
98
|
defaultVariants: {
|
|
111
99
|
size: "sm"
|
|
112
100
|
}
|
|
113
|
-
}),
|
|
114
|
-
checked:
|
|
115
|
-
checkedIcon: t = /* @__PURE__ */ e(
|
|
116
|
-
defaultChecked:
|
|
117
|
-
intent:
|
|
118
|
-
uncheckedIcon: i = /* @__PURE__ */ e(
|
|
101
|
+
}), R = ({
|
|
102
|
+
checked: a,
|
|
103
|
+
checkedIcon: t = /* @__PURE__ */ e(P, {}),
|
|
104
|
+
defaultChecked: s,
|
|
105
|
+
intent: p,
|
|
106
|
+
uncheckedIcon: i = /* @__PURE__ */ e(T, {}),
|
|
119
107
|
size: n = "md",
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
108
|
+
onCheckedChange: f,
|
|
109
|
+
className: b,
|
|
110
|
+
required: c,
|
|
111
|
+
ref: l,
|
|
112
|
+
asChild: g = !1,
|
|
125
113
|
...d
|
|
126
114
|
}) => {
|
|
127
|
-
const [
|
|
128
|
-
m(
|
|
115
|
+
const [r, m] = G(a, s), { name: x, description: V, state: $, isRequired: q, isInvalid: D } = F(), j = $ ?? p, L = W(g, "span"), k = !!(c || q), B = (u) => {
|
|
116
|
+
m(u), f?.(u);
|
|
129
117
|
};
|
|
130
118
|
return /* @__PURE__ */ e(
|
|
131
|
-
|
|
119
|
+
y.Root,
|
|
132
120
|
{
|
|
133
121
|
"data-spark-component": "switch-input",
|
|
134
|
-
ref:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
checked:
|
|
138
|
-
defaultChecked:
|
|
139
|
-
onCheckedChange:
|
|
140
|
-
name:
|
|
141
|
-
required:
|
|
142
|
-
"aria-
|
|
122
|
+
ref: l,
|
|
123
|
+
render: L,
|
|
124
|
+
className: _({ intent: j, size: n, className: b }),
|
|
125
|
+
checked: a,
|
|
126
|
+
defaultChecked: s,
|
|
127
|
+
onCheckedChange: (u) => B(u),
|
|
128
|
+
name: x,
|
|
129
|
+
required: k,
|
|
130
|
+
"aria-required": k ? !0 : void 0,
|
|
131
|
+
"aria-invalid": D,
|
|
143
132
|
"aria-describedby": V,
|
|
144
133
|
...d,
|
|
145
|
-
children: /* @__PURE__ */ e("span", { className:
|
|
146
|
-
|
|
147
|
-
!
|
|
134
|
+
children: /* @__PURE__ */ e("span", { className: A({ checked: r }), children: /* @__PURE__ */ w(y.Thumb, { className: H({ size: n, checked: r }), children: [
|
|
135
|
+
r && t && /* @__PURE__ */ e(C, { className: I({ size: n }), children: t }),
|
|
136
|
+
!r && i && /* @__PURE__ */ e(C, { className: I({ size: n }), children: i })
|
|
148
137
|
] }) })
|
|
149
138
|
}
|
|
150
139
|
);
|
|
151
140
|
};
|
|
152
|
-
|
|
153
|
-
const
|
|
141
|
+
R.displayName = "SwitchInput";
|
|
142
|
+
const J = o("default:text-on-surface", {
|
|
154
143
|
variants: {
|
|
155
144
|
disabled: {
|
|
156
145
|
true: ["text-neutral/dim-2", "cursor-not-allowed"],
|
|
@@ -160,51 +149,51 @@ const A = o("default:text-on-surface", {
|
|
|
160
149
|
defaultVariants: {
|
|
161
150
|
disabled: !1
|
|
162
151
|
}
|
|
163
|
-
}),
|
|
164
|
-
|
|
152
|
+
}), K = ({ className: a, disabled: t, ...s }) => /* @__PURE__ */ e(
|
|
153
|
+
X,
|
|
165
154
|
{
|
|
166
155
|
"data-spark-component": "switch-label",
|
|
167
|
-
className:
|
|
168
|
-
...
|
|
156
|
+
className: J({ disabled: t, className: a }),
|
|
157
|
+
...s
|
|
169
158
|
}
|
|
170
|
-
),
|
|
171
|
-
size:
|
|
159
|
+
), N = ":switch", M = ({
|
|
160
|
+
size: a = "md",
|
|
172
161
|
children: t,
|
|
173
|
-
className:
|
|
174
|
-
id:
|
|
162
|
+
className: s,
|
|
163
|
+
id: p,
|
|
175
164
|
disabled: i,
|
|
176
165
|
reverse: n = !1,
|
|
177
|
-
ref:
|
|
178
|
-
...
|
|
166
|
+
ref: f,
|
|
167
|
+
...b
|
|
179
168
|
}) => {
|
|
180
|
-
const c =
|
|
181
|
-
|
|
169
|
+
const c = F(), l = `${N}-label-${z()}`, g = `${N}-input-${z()}`, d = c.id || p || g, r = t && /* @__PURE__ */ e(K, { disabled: i, htmlFor: d, id: l, children: t }), m = /* @__PURE__ */ e(
|
|
170
|
+
R,
|
|
182
171
|
{
|
|
183
|
-
ref:
|
|
184
|
-
size:
|
|
172
|
+
ref: f,
|
|
173
|
+
size: a,
|
|
185
174
|
id: d,
|
|
186
175
|
disabled: i,
|
|
187
176
|
"aria-labelledby": t ? l : c.labelId,
|
|
188
|
-
...
|
|
177
|
+
...b
|
|
189
178
|
}
|
|
190
|
-
),
|
|
191
|
-
|
|
179
|
+
), x = n ? /* @__PURE__ */ w(S, { children: [
|
|
180
|
+
r,
|
|
192
181
|
m
|
|
193
|
-
] }) : /* @__PURE__ */
|
|
182
|
+
] }) : /* @__PURE__ */ w(S, { children: [
|
|
194
183
|
m,
|
|
195
|
-
|
|
184
|
+
r
|
|
196
185
|
] });
|
|
197
186
|
return /* @__PURE__ */ e(
|
|
198
187
|
"div",
|
|
199
188
|
{
|
|
200
189
|
"data-spark-component": "switch",
|
|
201
|
-
className:
|
|
202
|
-
children:
|
|
190
|
+
className: E("gap-md text-body-1 flex items-center", s),
|
|
191
|
+
children: x
|
|
203
192
|
}
|
|
204
193
|
);
|
|
205
194
|
};
|
|
206
|
-
|
|
195
|
+
M.displayName = "Switch";
|
|
207
196
|
export {
|
|
208
|
-
|
|
197
|
+
M as Switch
|
|
209
198
|
};
|
|
210
199
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-[state=unchecked]:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'basic', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['data-[state=checked]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: [\n 'data-[state=checked]:bg-support',\n 'hover:ring-support-container',\n 'text-support',\n ],\n accent: ['data-[state=checked]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n basic: ['data-[state=checked]:bg-basic', 'hover:ring-basic-container', 'text-basic'],\n success: [\n 'data-[state=checked]:bg-success',\n 'hover:ring-success-container',\n 'text-success',\n ],\n alert: ['data-[state=checked]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['data-[state=checked]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['data-[state=checked]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: [\n 'data-[state=checked]:bg-neutral',\n 'hover:ring-neutral-container',\n 'text-neutral',\n ],\n }),\n },\n defaultVariants: {\n intent: 'basic',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { Switch as RadixSwitch } from 'radix-ui'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<'button'>, 'value'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * When true, prevents the user from interacting with the switch.\n */\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n value = 'on',\n onCheckedChange,\n className,\n required,\n ref,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <RadixSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n className={styles({ intent, size, className })}\n value={value}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n name={name}\n required={required || isRequired}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <RadixSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </RadixSwitch.Thumb>\n </span>\n </RadixSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('default:text-on-surface', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","value","onCheckedChange","className","required","ref","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","handleCheckedChange","updatedValue","jsx","RadixSwitch","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":";;;;;;;;;;;AAGO,MAAMA,IAASC;AAAA,EACpBC,EAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAAA,EACD;AAAA,IACE,UAAU;AAAA;AAAA;AAAA;AAAA,MAIR,MAAMC,EAAmC;AAAA,QACvC,IAAID,EAAG,CAAC,WAAW,WAAW,WAAW,CAAC;AAAA,QAC1C,IAAIA,EAAG,CAAC,WAAW,WAAW,cAAc,CAAC;AAAA,MAAA,CAC9C;AAAA;AAAA;AAAA;AAAA,MAID,QAAQC,EAGN;AAAA,QACA,MAAM,CAAC,gCAAgC,6BAA6B,WAAW;AAAA,QAC/E,SAAS;AAAA,UACP;AAAA,UACA;AAAA,U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AA,MACC,KAAAa;AAAA,MACA,MAAAL;AAAA,MACA,IAAIqC;AAAA,MACJ,UAAAZ;AAAA,MAMA,mBAAiBK,IAAWI,IAAUD,EAAM;AAAA,MAC3C,GAAG3B;AAAA,IAAA;AAAA,EAAA,GAIFkC,IAAUR,IACd,gBAAAX,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAH;AAAA,IACAC;AAAA,EAAA,EAAA,CACH,IAEA,gBAAAlB,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAF;AAAA,IACAD;AAAA,EAAA,GACH;AAGF,SACE,gBAAAnB;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWuB,EAAG,wCAAwCvC,CAAS;AAAA,MAE9D,UAAAqC;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAX,EAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-unchecked:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['[&[data-checked]]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: ['[&[data-checked]]:bg-support', 'hover:ring-support-container', 'text-support'],\n accent: ['[&[data-checked]]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n success: ['[&[data-checked]]:bg-success', 'hover:ring-success-container', 'text-success'],\n alert: ['[&[data-checked]]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['[&[data-checked]]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['[&[data-checked]]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: ['[&[data-checked]]:bg-neutral', 'hover:ring-neutral-container', 'text-neutral'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { Switch as BaseSwitch } from '@base-ui/react/switch'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRenderSlot } from '../drawer/useRenderSlot'\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<typeof BaseSwitch.Root>, 'value' | 'render' | 'onCheckedChange'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n onCheckedChange,\n className,\n required,\n ref,\n asChild = false,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n const renderSlot = useRenderSlot(asChild, 'span')\n const isRequiredComputed = Boolean(required || isRequired)\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <BaseSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n render={renderSlot}\n className={styles({ intent, size, className })}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={nextChecked => handleCheckedChange(nextChecked)}\n name={name}\n required={isRequiredComputed}\n aria-required={isRequiredComputed ? true : undefined}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <BaseSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </BaseSwitch.Thumb>\n </span>\n </BaseSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('default:text-on-surface', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","onCheckedChange","className","required","ref","asChild","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","renderSlot","useRenderSlot","isRequiredComputed","handleCheckedChange","updatedValue","jsx","BaseSwitch","nextChecked","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":";;;;;;;;;;;;AAGO,MA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AAAA,EAAA;AACN,GCdIE,IAAY,WAELC,IAAS,CAAC;AAAA,EACrB,MAAAjC,IAAO;AAAA,EACP,UAAAkC;AAAA,EACA,WAAAhC;AAAA,EACA,IAAAiC;AAAA,EACA,UAAAN;AAAA,EACA,SAAAO,IAAU;AAAA,EACV,KAAAhC;AAAA,EACA,GAAGE;AACL,MAAmB;AACjB,QAAM+B,IAAQtB,EAAA,GAERuB,IAAU,GAAGN,CAAS,UAAUO,GAAO,IACvCC,IAAU,GAAGR,CAAS,UAAUO,GAAO,IACvCE,IAAUJ,EAAM,MAAMF,KAAMK,GAE5BE,IAAcR,KAClB,gBAAAZ,EAACM,GAAA,EAAY,UAAAC,GAAoB,SAASY,GAAS,IAAIH,GACpD,UAAAJ,EAAA,CACH,GAGIS,IACJ,gBAAArB;AAAA,IAAC9B;AAAA,IAAA;AAAA,MACC,KAAAY;AAAA,MACA,MAAAJ;AAAA,MACA,IAAIyC;AAAA,MACJ,UAAAZ;AAAA,MAMA,mBAAiBK,IAAWI,IAAUD,EAAM;AAAA,MAC3C,GAAG/B;AAAA,IAAA;AAAA,EAAA,GAIFsC,IAAUR,IACd,gBAAAX,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAH;AAAA,IACAC;AAAA,EAAA,EAAA,CACH,IAEA,gBAAAlB,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAF;AAAA,IACAD;AAAA,EAAA,GACH;AAGF,SACE,gBAAApB;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWwB,EAAG,wCAAwC5C,CAAS;AAAA,MAE9D,UAAA0C;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAX,EAAO,cAAc;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VariantProps } from 'class-variance-authority';
|
|
2
2
|
export declare const triggerVariants: (props?: ({
|
|
3
|
-
intent?: "main" | "support" |
|
|
3
|
+
intent?: "main" | "support" | null | undefined;
|
|
4
4
|
size?: "sm" | "md" | "xs" | null | undefined;
|
|
5
5
|
hasMenu?: boolean | null | undefined;
|
|
6
6
|
orientation?: "horizontal" | "vertical" | null | undefined;
|
package/dist/tabs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),T=require("radix-ui"),s=require("react"),m=require("class-variance-authority"),D=require("@spark-ui/icons/ArrowVerticalLeft"),F=require("@spark-ui/icons/ArrowVerticalRight"),M=require("../Button-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),T=require("radix-ui"),s=require("react"),m=require("class-variance-authority"),D=require("@spark-ui/icons/ArrowVerticalLeft"),F=require("@spark-ui/icons/ArrowVerticalRight"),M=require("../Button-FZceRWG2.js"),j=require("../Icon-C-cNTnzd.js"),q=require("@spark-ui/hooks/use-merge-refs"),K=require("@spark-ui/icons/MoreMenuHorizontal"),H=require("../IconButton-BR1bJSQA.js"),g=require("../popover/index.js"),U=require("@spark-ui/internal-utils"),W=s.createContext({}),R=()=>{const t=s.useContext(W);if(!t)throw Error("useTabsContext must be used within a TabsContext Provider");return t},$=m.cva(["flex","data-[orientation=horizontal]:flex-col","data-[orientation=vertical]:flex-row","max-w-full"]),V=({intent:t="support",size:o="md",asChild:c=!1,forceMount:a=!1,orientation:n="horizontal",children:i,className:l,ref:d,...e})=>r.jsx(W.Provider,{value:{intent:t,size:o,orientation:n,forceMount:a},children:r.jsx(T.Tabs.Root,{ref:d,asChild:c,orientation:n,className:$({className:l}),"data-spark-component":"tabs",activationMode:"automatic",...e,children:i})});V.displayName="Tabs";const G=m.cva(["w-full p-lg","focus-visible:u-outline-inset"],{variants:{forceMount:{true:"data-[state=inactive]:hidden",false:""}}}),P=({children:t,asChild:o=!1,className:c,ref:a,...n})=>{const{forceMount:i}=R();return r.jsx(T.Tabs.Content,{"data-spark-component":"tabs-content",ref:a,forceMount:i||n.forceMount,className:G({className:c,forceMount:i}),asChild:o,...n,children:t})};P.displayName="Tabs.Content";const J=m.cva(["relative flex"]),Q=m.cva(["flex w-full","data-[orientation=horizontal]:flex-row","data-[orientation=vertical]:flex-col","overflow-y-hidden u-no-scrollbar data-[orientation=vertical]:overflow-x-hidden","after:flex after:shrink after:grow after:border-outline","data-[orientation=horizontal]:after:border-b-sm","data-[orientation=vertical]:after:border-r-sm"]),S=m.cva(["h-auto! flex-none","border-b-sm border-outline","outline-hidden","focus-visible:border-none focus-visible:bg-surface-hovered focus-visible:u-outline-inset!"]),X=(t,o)=>{const[c,a]=s.useState({width:void 0,height:void 0}),n=s.useRef(null),i=s.useRef(o);return s.useEffect(()=>{i.current=o},[o]),s.useEffect(()=>{const l=t&&"current"in t?t.current:t;if(!(!l||n.current))return n.current=new ResizeObserver(([d])=>{const{inlineSize:e,blockSize:x}=d?.borderBoxSize?.[0]??{};i.current?.(d),a({width:e,height:x})}),n.current.observe(l),()=>{n.current&&n.current.unobserve(l)}},[t,n,i]),c},N=({asChild:t=!1,loop:o=!1,children:c,className:a,ref:n,...i})=>{const l=s.useRef(null),d=s.useRef(null),e=n||d,{orientation:x}=R(),{width:w}=X(l),[u,b]=s.useState({prev:"hidden",next:"hidden"});s.useEffect(()=>{typeof e=="function"||!e.current||b(x!=="horizontal"?{prev:"hidden",next:"hidden"}:{prev:e.current.scrollWidth>e.current.clientWidth?"visible":"hidden",next:e.current.scrollWidth>e.current.clientWidth?"visible":"hidden"})},[x,e,w]),s.useEffect(()=>{if(typeof e=="function"||!e.current||u.prev==="hidden"||o)return;const v=f=>{b({prev:f.scrollLeft>0?"visible":"disabled",next:f.scrollLeft+f.clientWidth<f.scrollWidth?"visible":"disabled"})},p=e.current;return v(p),p.addEventListener("scroll",({target:f})=>v(f)),()=>p.removeEventListener("scroll",({target:f})=>v(f))},[e,u.prev,o]);const z=()=>{if(typeof e=="function"||!e.current)return;const v=o&&e.current.scrollLeft<=0;e.current.scrollTo({left:v?e.current.scrollLeft+e.current.scrollWidth-e.current.clientWidth:e.current.scrollLeft-e.current.clientWidth,behavior:"smooth"})},y=()=>{if(typeof e=="function"||!e.current)return;const v=o&&e.current.scrollLeft+e.current.clientWidth>=e.current.scrollWidth;e.current.scrollTo({left:v?0:e.current.scrollLeft+e.current.clientWidth,behavior:"smooth"})};return r.jsxs("div",{className:J({className:a}),ref:l,children:[u.prev!=="hidden"&&r.jsx(M.Button,{shape:"square",intent:"surface",size:"sm",className:S(),onClick:z,disabled:u.prev==="disabled","aria-label":"Scroll left",children:r.jsx(j.Icon,{children:r.jsx(D.ArrowVerticalLeft,{})})}),r.jsx(T.Tabs.List,{"data-spark-component":"tabs-list",ref:e,className:Q(),asChild:t,loop:o,...i,children:c}),u.next!=="hidden"&&r.jsx(M.Button,{shape:"square",intent:"surface",size:"sm",className:S(),onClick:y,disabled:u.next==="disabled","aria-label":"Scroll right",children:r.jsx(j.Icon,{children:r.jsx(F.ArrowVerticalRight,{})})})]})};N.displayName="Tabs.List";const C=s.createContext(void 0),E=()=>{const t=s.useContext(C);if(!t)throw new Error("TabsPopover components must be used within TabsPopover");return t},I=s.forwardRef(({"aria-label":t,children:o,...c},a)=>{const{popoverTriggerRef:n}=E(),i=q.useMergeRefs(a,n);return r.jsx(g.Popover.Trigger,{asChild:!0,...c,children:r.jsx(H.IconButton,{ref:i,size:"sm",intent:"surfaceInverse",design:"ghost","aria-label":t,tabIndex:-1,children:r.jsx(j.Icon,{children:o||r.jsx(K.MoreMenuHorizontal,{})})})})});I.displayName="Popover.Trigger";const A=s.forwardRef(({side:t,align:o="start",className:c,...a},n)=>{const{popoverSide:i}=E(),l=m.cx("gap-sm flex flex-col",c);return r.jsx(g.Popover.Content,{ref:n,...a,side:t??i,align:o,className:l})});A.displayName="Popover.Content";const B=({popoverSide:t,popoverTriggerRef:o,children:c})=>{const a=s.useMemo(()=>({popoverSide:t,popoverTriggerRef:o}),[t,o]),i=Object.assign((l=>r.jsx(C.Provider,{value:a,children:r.jsx(g.Popover,{...l,children:l.children})})),g.Popover,{Content:A,Trigger:I});return r.jsx(C.Provider,{value:a,children:c(i)})};B.displayName="Popover";const Y=m.cva(["px-md","relative flex flex-none items-center","border-outline","hover:not-disabled:bg-surface-hovered","after:absolute","data-[state=active]:font-bold","data-[state=inactive]:not-disabled:cursor-pointer","data-[orientation=horizontal]:border-b-sm data-[orientation=horizontal]:after:inset-x-0 data-[orientation=horizontal]:after:bottom-[-1px] data-[orientation=horizontal]:after:h-sz-2","data-[orientation=vertical]:border-r-sm data-[orientation=vertical]:after:inset-y-0 data-[orientation=vertical]:after:right-[-1px] data-[orientation=vertical]:after:w-sz-2","focus-visible:border-none focus-visible:bg-surface-hovered focus-visible:u-outline-inset","disabled:cursor-not-allowed disabled:opacity-dim-3","gap-md [&>*:first-child]:ml-md [&>*:last-child]:mr-md","[&>svg:last-child:first-child]:mx-auto"],{variants:{intent:U.makeVariants({main:["data-[state=active]:text-main data-[state=active]:after:bg-main"],support:["data-[state=active]:text-support data-[state=active]:after:bg-support"]}),size:{xs:["h-sz-32 min-w-sz-32 text-caption"],sm:["h-sz-36 min-w-sz-36 text-body-2"],md:["h-sz-40 min-w-sz-40 text-body-1"]},hasMenu:{true:"pr-3xl"},orientation:{horizontal:"",vertical:""}},compoundVariants:[{hasMenu:!0,orientation:"vertical",class:"w-full"}],defaultVariants:{intent:"support",size:"md",hasMenu:!1,orientation:"horizontal"}}),L=({asChild:t=!1,value:o,disabled:c=!1,children:a,className:n,ref:i,onKeyDown:l,renderMenu:d,...e})=>{const{intent:x,size:w,orientation:u}=R(),b=s.useRef(null),z=s.useRef(null),y=q.useMergeRefs(i,z),v=h=>{h.key==="F10"&&h.shiftKey&&d&&b.current&&(h.preventDefault(),b.current.click()),l?.(h)},p=!!d,f=u==="vertical"?"right":"bottom",k=r.jsx(T.Tabs.Trigger,{"data-spark-component":"tabs-trigger",ref:y,className:Y({intent:x,size:w,hasMenu:p,orientation:u??"horizontal",className:n}),asChild:t,disabled:c,value:o,onFocus:({target:h})=>h.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),onKeyDown:v,"aria-haspopup":p?"true":void 0,...e,children:a});return p?r.jsxs("div",{className:u==="vertical"?"relative w-full":"relative",children:[k,r.jsx("div",{className:"right-md mr-md pointer-events-auto absolute top-1/2 -translate-y-1/2",children:r.jsx(B,{popoverSide:f,popoverTriggerRef:b,children:h=>d?.({Popover:h})})})]}):k};L.displayName="Tabs.Trigger";const O=Object.assign(V,{List:N,Trigger:L,Content:P});O.displayName="Tabs";N.displayName="Tabs.List";L.displayName="Tabs.Trigger";P.displayName="Tabs.Content";exports.Tabs=O;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|