{"version":3,"file":"Switch.mjs","sources":["../../src/switch/Switch.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport type { KeyboardEventHandler, MouseEvent } from 'react';\n\nimport type { CommonProps } from '../common';\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type SwitchProps = CommonProps & {\n  /**\n   * Used to describe the purpose of the switch. To be used if there is no external label (i.e. aria-labelledby is null)\n   * @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead.\n   */\n  'aria-label'?: string;\n  /** A reference to a label that describes the purpose of the switch. Ignored if aria-label is provided */\n  'aria-labelledby'?: string;\n  /** Identifies the element(s) that describes the element on which the attribute is set */\n  'aria-describedby'?: string;\n  /** Whether the switch is checked or not */\n  checked?: boolean;\n  disabled?: boolean;\n  /** ID to apply to the switch container */\n  id?: string;\n  /** Function called when the switch is toggled */\n  onClick: (event?: MouseEvent<HTMLButtonElement>) => void;\n};\n\nconst Switch = (props: SwitchProps) => {\n  const inputAttributes = useInputAttributes({ nonLabelable: true });\n\n  const {\n    checked,\n    className,\n    id = inputAttributes.id,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledbyProp,\n    'aria-describedby': ariaDescribedbyProp,\n    onClick,\n    disabled,\n  } = props;\n\n  const ariaLabelledby =\n    (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];\n\n  return (\n    <button\n      className={clsx(\n        'np-switch',\n        {\n          'np-switch--unchecked': !checked,\n          'np-switch--checked': checked,\n          disabled,\n        },\n        className,\n      )}\n      type=\"button\"\n      role=\"switch\"\n      {...inputAttributes}\n      id={id}\n      aria-checked={Boolean(checked)}\n      aria-label={ariaLabel}\n      aria-labelledby={ariaLabelledby}\n      aria-describedby={ariaDescribedbyProp}\n      disabled={disabled}\n      onClick={!disabled ? onClick : undefined}\n    >\n      <span className=\"np-switch--thumb\" />\n    </button>\n  );\n};\n\nexport default Switch;\n"],"names":["Switch","props","inputAttributes","useInputAttributes","nonLabelable","checked","className","id","ariaLabel","ariaLabelledbyProp","ariaDescribedbyProp","onClick","disabled","ariaLabelledby","undefined","_jsx","clsx","type","role","Boolean","children"],"mappings":";;;;AAyBA,MAAMA,MAAM,GAAIC,KAAkB,IAAI;EACpC,MAAMC,eAAe,GAAGC,kBAAkB,CAAC;AAAEC,IAAAA,YAAY,EAAE;AAAI,GAAE,CAAC;EAElE,MAAM;IACJC,OAAO;IACPC,SAAS;IACTC,EAAE,GAAGL,eAAe,CAACK,EAAE;AACvB,IAAA,YAAY,EAAEC,SAAS;AACvB,IAAA,iBAAiB,EAAEC,kBAAkB;AACrC,IAAA,kBAAkB,EAAEC,mBAAmB;IACvCC,OAAO;AACPC,IAAAA;AAAQ,GACT,GAAGX,KAAK;AAET,EAAA,MAAMY,cAAc,GAClB,CAACL,SAAS,GAAGM,SAAS,GAAGL,kBAAkB,KAAKP,eAAe,CAAC,iBAAiB,CAAC;AAEpF,EAAA,oBACEa,GAAA,CAAA,QAAA,EAAA;AACET,IAAAA,SAAS,EAAEU,IAAI,CACb,WAAW,EACX;MACE,sBAAsB,EAAE,CAACX,OAAO;AAChC,MAAA,oBAAoB,EAAEA,OAAO;AAC7BO,MAAAA;KACD,EACDN,SAAS,CACT;AACFW,IAAAA,IAAI,EAAC,QAAQ;AACbC,IAAAA,IAAI,EAAC,QAAQ;AAAA,IAAA,GACThB,eAAe;AACnBK,IAAAA,EAAE,EAAEA,EAAG;IACP,cAAA,EAAcY,OAAO,CAACd,OAAO,CAAE;AAC/B,IAAA,YAAA,EAAYG,SAAU;AACtB,IAAA,iBAAA,EAAiBK,cAAe;AAChC,IAAA,kBAAA,EAAkBH,mBAAoB;AACtCE,IAAAA,QAAQ,EAAEA,QAAS;AACnBD,IAAAA,OAAO,EAAE,CAACC,QAAQ,GAAGD,OAAO,GAAGG,SAAU;AAAAM,IAAAA,QAAA,eAEzCL,GAAA,CAAA,MAAA,EAAA;AAAMT,MAAAA,SAAS,EAAC;KAAkB;AACpC,GAAQ,CAAC;AAEb;;;;"}