{"version":3,"file":"Switch.cjs","sources":["../../../../src/components/forms/switch/Switch.tsx"],"sourcesContent":["import { Switch as BaseSwitch } from '@base-ui/react/switch'\r\nimport { memo, useId, type FC } from 'react'\r\n\r\nimport FormLabel from '@components/forms/_shared/components/form-label/FormLabel.tsx'\r\nimport HelperText from '@components/forms/_shared/components/helper-text/HelperText.tsx'\r\nimport { Flex } from '@components/layout/flex'\r\nimport { cn } from '@utils/cn.ts'\r\nimport { SWITCH_STYLES } from '@components/forms/switch/styles/Switch.css.ts'\r\nimport type { SwitchProps } from '@components/forms/switch/types/Switch.props.ts'\r\n\r\n/**\r\n * A styled switch control built on top of `@base-ui/react/switch`.\r\n *\r\n * Supports controlled (`checked` + `onCheckedChange`) and uncontrolled\r\n * (`defaultChecked`) modes, plus an optional inline `label`.\r\n *\r\n * @example\r\n * ```tsx\r\n * <Switch label=\"Airplane mode\" checked={enabled} onCheckedChange={setEnabled} />\r\n * ```\r\n */\r\nconst Switch: FC<SwitchProps> = memo(({ label, helperText, error, id, className, disabled, size = 'md', onCheckedChange, ...props }) => {\r\n    const generatedId = useId()\r\n    const labelId = useId()\r\n    const switchId = id ?? (label ? generatedId : undefined)\r\n    const hasError = Boolean(error)\r\n    const helperId = (helperText || error) ? `${switchId}-helper` : undefined\r\n\r\n    return (\r\n        <Flex\r\n            as={'span'}\r\n            inline\r\n            flexDirection={'column'}\r\n            gap={'xs'}\r\n            alignItems={'start'}\r\n            className={cn(SWITCH_STYLES.wrapper, disabled && SWITCH_STYLES.wrapperDisabled)}\r\n        >\r\n            <Flex\r\n                as={'span'}\r\n                inline\r\n                gap={'sm'}\r\n                alignItems={'center'}\r\n            >\r\n                <BaseSwitch.Root\r\n                    id={switchId}\r\n                    disabled={disabled}\r\n                    aria-labelledby={label ? labelId : undefined}\r\n                    aria-describedby={helperId}\r\n                    aria-invalid={hasError || undefined}\r\n                    className={cn(SWITCH_STYLES.root({ size, error: hasError }), className)}\r\n                    onCheckedChange={onCheckedChange}\r\n                    {...props}\r\n                >\r\n                    <BaseSwitch.Thumb className={SWITCH_STYLES.thumb({ size })} />\r\n                </BaseSwitch.Root>\r\n\r\n                {label && (\r\n                    <FormLabel\r\n                        id={labelId}\r\n                        className={cn(SWITCH_STYLES.label, disabled && SWITCH_STYLES.labelDisabled)}\r\n                    >\r\n                        {label}\r\n                    </FormLabel>\r\n                )}\r\n            </Flex>\r\n\r\n            {(error || helperText) && (\r\n                <HelperText\r\n                    id={helperId}\r\n                    hasError={hasError}\r\n                >\r\n                    {error ?? helperText}\r\n                </HelperText>\r\n            )}\r\n        </Flex>\r\n    )\r\n})\r\n\r\nSwitch.displayName = 'Switch'\r\n\r\nexport default Switch\r\n"],"names":["Switch","memo","label","helperText","error","id","className","disabled","size","onCheckedChange","props","generatedId","useId","labelId","switchId","hasError","helperId","jsxs","Flex","cn","SWITCH_STYLES","jsx","BaseSwitch","FormLabel","HelperText"],"mappings":"yYAqBMA,EAA0BC,EAAAA,KAAK,CAAC,CAAE,MAAAC,EAAO,WAAAC,EAAY,MAAAC,EAAO,GAAAC,EAAI,UAAAC,EAAW,SAAAC,EAAU,KAAAC,EAAO,KAAM,gBAAAC,EAAiB,GAAGC,KAAY,CACpI,MAAMC,EAAcC,EAAAA,MAAA,EACdC,EAAUD,EAAAA,MAAA,EACVE,EAAWT,IAAOH,EAAQS,EAAc,QACxCI,EAAW,EAAQX,EACnBY,EAAYb,GAAcC,EAAS,GAAGU,CAAQ,UAAY,OAEhE,OACIG,EAAAA,KAACC,EAAA,CACG,GAAI,OACJ,OAAM,GACN,cAAe,SACf,IAAK,KACL,WAAY,QACZ,UAAWC,EAAAA,GAAGC,EAAAA,cAAc,QAASb,GAAYa,EAAAA,cAAc,eAAe,EAE9E,SAAA,CAAAH,EAAAA,KAACC,EAAA,CACG,GAAI,OACJ,OAAM,GACN,IAAK,KACL,WAAY,SAEZ,SAAA,CAAAG,EAAAA,IAACC,EAAAA,OAAW,KAAX,CACG,GAAIR,EACJ,SAAAP,EACA,kBA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