{"version":3,"file":"Checkbox.jsx","sources":["../src/Checkbox.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo, useState } from '@lynx-js/react'\nimport type { ReactNode } from '@lynx-js/react'\n\nimport { Button } from '@lynx-js/lynx-ui-button'\nimport {\n  renderContentWithExtraProps,\n  useMemoizedFn,\n} from '@lynx-js/lynx-ui-common'\nimport { clsx } from 'clsx'\n\nimport { CheckboxContext } from './CheckboxContext'\nimport type { CheckboxProps } from './types'\n\nexport type { CheckboxProps, CheckboxIndicatorProps } from './types'\nexport const Checkbox = (props: CheckboxProps): ReactNode => {\n  const {\n    style,\n    className,\n    children,\n    onChange,\n    checked,\n    defaultChecked = false,\n    disabled = false,\n    indeterminate = false,\n    checkboxProps,\n  } = props\n  const isControlled = checked !== undefined\n  const [uncontrolledChecked, setUncontrolledChecked] = useState<boolean>(\n    defaultChecked,\n  )\n  const actualChecked = isControlled ? checked : uncontrolledChecked\n\n  const handleValueChange = useMemoizedFn((newChecked: boolean) => {\n    if (!isControlled) {\n      setUncontrolledChecked(newChecked)\n    }\n    onChange?.(newChecked)\n  })\n\n  const handleClick = useMemoizedFn(() => {\n    if (indeterminate) {\n      handleValueChange(true)\n      return\n    }\n    handleValueChange(!actualChecked)\n  })\n\n  const checkboxContextValue = useMemo(() => ({\n    checked: actualChecked,\n    indeterminate,\n  }), [actualChecked, indeterminate])\n\n  return (\n    <CheckboxContext.Provider value={checkboxContextValue}>\n      <Button\n        disabled={disabled}\n        onClick={handleClick}\n        style={style}\n        className={clsx(className, {\n          'ui-indeterminate': indeterminate,\n          'ui-checked': actualChecked,\n        })}\n        buttonProps={checkboxProps}\n      >\n        {renderContentWithExtraProps(\n          { checked: actualChecked, indeterminate },\n          children,\n        )}\n      </Button>\n    </CheckboxContext.Provider>\n  )\n}\n"],"names":["Checkbox","props","style","className","children","onChange","checked","defaultChecked","disabled","indeterminate","checkboxProps","isControlled","undefined","uncontrolledChecked","setUncontrolledChecked","useState","actualChecked","handleValueChange","useMemoizedFn","newChecked","handleClick","checkboxContextValue","useMemo","CheckboxContext","Button","clsx","renderContentWithExtraProps"],"mappings":";;;;;AAkBO,MAAMA,WAAW,CAACC;IACvB,MAAM,EACJC,KAAK,EACLC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,OAAO,EACPC,iBAAiB,KAAK,EACtBC,WAAW,KAAK,EAChBC,gBAAgB,KAAK,EACrBC,aAAa,EACd,GAAGT;IACJ,MAAMU,eAAeL,AAAYM,WAAZN;IACrB,MAAM,CAACO,qBAAqBC,uBAAuB,GAAGC,SACpDR;IAEF,MAAMS,gBAAgBL,eAAeL,UAAUO;IAE/C,MAAMI,oBAAoBC,cAAc,CAACC;QACvC,IAAI,CAACR,cACHG,uBAAuBK;QAEzBd,WAAWc;IACb;IAEA,MAAMC,cAAcF,cAAc;QAChC,IAAIT,eAAe,YACjBQ,kBAAkB;QAGpBA,kBAAkB,CAACD;IACrB;IAEA,MAAMK,uBAAuBC,QAAQ,IAAO;YAC1C,SAASN;YACTP;QACF,IAAI;QAACO;QAAeP;KAAc;IAElC,QACGc,gBAAgB,SAAS,OAAOF,sBAAsB;MACrD,CAACG,OACC,UAAUhB,UACV,SAASY,aACT,OAAOlB,OACP,WAAWuB,KAAKtB,WAAW;QACzB,oBAAoBM;QACpB,cAAcO;IAChB,IACA,aAAaN,eACd;QACC,CAACgB,4BACC;QAAE,SAASV;QAAeP;IAAc,GACxCL,UACA;MACJ,EAAEoB,OAAO;IACX,EAAED,gBAAgB;AAEtB"}