@radix-ui/react-checkbox 1.4.0-rc.1791763750187 → 1.4.1

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/index.d.mts CHANGED
@@ -12,7 +12,9 @@ interface CheckboxProviderProps<State extends CheckedState = CheckedState> {
12
12
  checked?: State | boolean | undefined;
13
13
  defaultChecked?: State | boolean | undefined;
14
14
  required?: boolean | undefined;
15
- onCheckedChange?: ((checked: State | boolean) => void) | undefined;
15
+ onCheckedChange?: {
16
+ bivarianceHack(checked: State | boolean): void;
17
+ }['bivarianceHack'] | undefined;
16
18
  name?: string | undefined;
17
19
  form?: string | undefined;
18
20
  disabled?: boolean | undefined;
@@ -29,7 +31,9 @@ interface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultC
29
31
  checked?: CheckedState | undefined;
30
32
  defaultChecked?: CheckedState | undefined;
31
33
  required?: boolean | undefined;
32
- onCheckedChange?: ((checked: CheckedState) => void) | undefined;
34
+ onCheckedChange?: {
35
+ bivarianceHack(checked: CheckedState): void;
36
+ }['bivarianceHack'] | undefined;
33
37
  }
34
38
  declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLButtonElement>>;
35
39
  type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
package/dist/index.d.ts CHANGED
@@ -12,7 +12,9 @@ interface CheckboxProviderProps<State extends CheckedState = CheckedState> {
12
12
  checked?: State | boolean | undefined;
13
13
  defaultChecked?: State | boolean | undefined;
14
14
  required?: boolean | undefined;
15
- onCheckedChange?: ((checked: State | boolean) => void) | undefined;
15
+ onCheckedChange?: {
16
+ bivarianceHack(checked: State | boolean): void;
17
+ }['bivarianceHack'] | undefined;
16
18
  name?: string | undefined;
17
19
  form?: string | undefined;
18
20
  disabled?: boolean | undefined;
@@ -29,7 +31,9 @@ interface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultC
29
31
  checked?: CheckedState | undefined;
30
32
  defaultChecked?: CheckedState | undefined;
31
33
  required?: boolean | undefined;
32
- onCheckedChange?: ((checked: CheckedState) => void) | undefined;
34
+ onCheckedChange?: {
35
+ bivarianceHack(checked: CheckedState): void;
36
+ }['bivarianceHack'] | undefined;
33
37
  }
34
38
  declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLButtonElement>>;
35
39
  type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/checkbox.tsx"],
4
- "sourcesContent": ["'use client';\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxProvider as unstable_CheckboxProvider,\n CheckboxTrigger as unstable_CheckboxTrigger,\n CheckboxIndicator,\n CheckboxBubbleInput as unstable_CheckboxBubbleInput,\n //\n Root,\n Provider as unstable_Provider,\n Trigger as unstable_Trigger,\n Indicator,\n BubbleInput as unstable_BubbleInput,\n} from './checkbox';\nexport type {\n CheckboxProps,\n CheckboxProviderProps as unstable_CheckboxProviderProps,\n CheckboxTriggerProps as unstable_CheckboxTriggerProps,\n CheckboxIndicatorProps,\n CheckboxBubbleInputProps as unstable_CheckboxBubbleInputProps,\n CheckedState,\n} from './checkbox';\n", "import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope | undefined };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ninterface CheckboxUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ntype CheckboxContextValue<State extends CheckedState | boolean = CheckedState> = {\n checked: State | boolean;\n setChecked: React.Dispatch<React.SetStateAction<State | boolean>>;\n disabled: boolean | undefined;\n control: HTMLButtonElement | null;\n setControl: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;\n name: string | undefined;\n form: string | undefined;\n value: string | number | readonly string[];\n userClick: CheckboxUserClick | null;\n onUserClick: (userClick: CheckboxUserClick) => void;\n required: boolean | undefined;\n defaultChecked: boolean | undefined;\n isFormControl: boolean;\n bubbleInput: HTMLInputElement | null;\n setBubbleInput: React.Dispatch<React.SetStateAction<HTMLInputElement | null>>;\n};\n\nconst [CheckboxProviderImpl, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface CheckboxProviderProps<State extends CheckedState = CheckedState> {\n checked?: State | boolean | undefined;\n defaultChecked?: State | boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: State | boolean) => void) | undefined;\n name?: string | undefined;\n form?: string | undefined;\n disabled?: boolean | undefined;\n value?: string | number | readonly string[] | undefined;\n children?: React.ReactNode | undefined;\n}\n\nfunction CheckboxProvider<State extends CheckedState = CheckedState>(\n props: ScopedProps<CheckboxProviderProps<State>>,\n) {\n const {\n __scopeCheckbox,\n checked: checkedProp,\n children,\n defaultChecked,\n disabled,\n form,\n name,\n onCheckedChange,\n required,\n value = 'on',\n // @ts-expect-error\n internal_do_not_use_render,\n } = props;\n\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked ?? false,\n onChange: onCheckedChange,\n caller: CHECKBOX_NAME,\n });\n const [control, setControl] = React.useState<HTMLButtonElement | null>(null);\n const [bubbleInput, setBubbleInput] = React.useState<HTMLInputElement | null>(null);\n // The latest user click on the trigger. The bubble input dispatches the click\n // to the form once React has handled it, whether or not `checked` changes in\n // the same render.\n const [userClick, setUserClick] = React.useState<CheckboxUserClick | null>(null);\n const isFormControl = control\n ? !!form || !!control.closest('form')\n : // We set this to true by default so that events bubble to forms without JS (SSR)\n true;\n\n const context: CheckboxContextValue<State> = {\n checked: checked,\n disabled: disabled,\n setChecked: setChecked,\n control: control,\n setControl: setControl,\n name: name,\n form: form,\n value: value,\n userClick: userClick,\n onUserClick: setUserClick,\n required: required,\n defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,\n isFormControl: isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <CheckboxProviderImpl\n scope={__scopeCheckbox}\n {...(context as unknown as CheckboxContextValue<CheckedState>)}\n >\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </CheckboxProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CheckboxTrigger';\n\ninterface CheckboxTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof CheckboxProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst CheckboxTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, CheckboxTriggerProps>(\n function CheckboxTrigger(\n { __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }: ScopedProps<CheckboxTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const form = control?.form;\n if (form) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n form.addEventListener('reset', reset);\n return () => form.removeEventListener('reset', reset);\n }\n }, [control, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...checkboxProps}\n ref={composedRefs}\n onKeyDown={composeEventHandlers(onKeyDown, (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault();\n })}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({\n requestedChecked: isIndeterminate(checked) ? true : !checked,\n hasConsumerStoppedPropagation,\n });\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (bubbleInput && isFormControl) {\n // if checkbox has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event (from the input). We propagate changes from an input so\n // that native form validation works and form events reflect\n // checkbox updates.\n if (!hasConsumerStoppedPropagation) event.stopPropagation();\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\ntype CheckboxElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState | undefined;\n defaultChecked?: CheckedState | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: CheckedState) => void) | undefined;\n}\n\nconst Checkbox = /* @__PURE__ */ React.forwardRef<CheckboxElement, CheckboxProps>(\n // blank line to reduce diff noise\n function Checkbox(props: ScopedProps<CheckboxProps>, forwardedRef) {\n const {\n __scopeCheckbox,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...checkboxProps\n } = props;\n\n return (\n <CheckboxProvider\n __scopeCheckbox={__scopeCheckbox}\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n required={required}\n onCheckedChange={onCheckedChange}\n name={name}\n form={form}\n value={value}\n // @ts-expect-error\n internal_do_not_use_render={({ isFormControl }: CheckboxContextValue) => (\n <>\n <CheckboxTrigger\n {...checkboxProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n {isFormControl && (\n <CheckboxBubbleInput\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true | undefined;\n}\n\nconst CheckboxIndicator = /* @__PURE__ */ React.forwardRef<\n CheckboxIndicatorElement,\n CheckboxIndicatorProps\n>(\n // blank line to reduce diff noise\n function CheckboxIndicator(props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence\n present={forceMount || isIndeterminate(context.checked) || context.checked === true}\n >\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'CheckboxBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface CheckboxBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst CheckboxBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n CheckboxBubbleInputProps\n>(\n // blank line to reduce diff noise\n function CheckboxBubbleInput(\n { __scopeCheckbox, onClick, ...props }: ScopedProps<CheckboxBubbleInputProps>,\n forwardedRef,\n ) {\n const {\n control,\n userClick,\n checked,\n defaultChecked,\n required,\n disabled,\n name,\n value,\n form,\n bubbleInput,\n setBubbleInput,\n } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);\n\n const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);\n const controlSize = useSize(control);\n // When the checked change is not driven by a user interaction (e.g. a\n // controlled `checked` update), the `click` event we dispatch to notify\n // forms must not reach ancestor `onClick` handlers. We can't simply make it\n // non-bubbling because React derives the checkbox's `change` event from a\n // bubbling `click`. Instead we stop propagation of the synthetic click,\n // which still lets the `change` event reach the form.\n const shouldStopClickPropagationRef = React.useRef(false);\n const prevCheckedRef = React.useRef(checked);\n // The user click this input last dispatched, so each click is dispatched\n // once.\n const handledUserClickRef = React.useRef(userClick);\n // A dispatched user click whose `checked` change hasn't been applied yet\n // (e.g. a controlled parent applying it later). When it is applied, it\n // must still respect the consumer stopping the click's propagation.\n const pendingUserClickRef = React.useRef<CheckboxUserClick | null>(null);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = bubbleInput;\n if (!input) return;\n\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(\n inputProto,\n 'checked',\n ) as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (!setChecked) return;\n\n const checkedChanged = prevCheckedRef.current !== checked;\n prevCheckedRef.current = checked;\n const isNewUserClick = userClick !== null && userClick !== handledUserClickRef.current;\n handledUserClickRef.current = userClick;\n\n if (isNewUserClick) {\n // Dispatch the user's click even if `checked` hasn't changed (yet), so\n // ancestors are notified of every click on the trigger.\n pendingUserClickRef.current = checkedChanged ? null : userClick;\n if (checkedChanged) {\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n }\n input.dispatchEvent(\n new Event('click', { bubbles: !userClick.hasConsumerStoppedPropagation }),\n );\n } else if (checkedChanged) {\n const pendingUserClick = pendingUserClickRef.current;\n pendingUserClickRef.current = null;\n const isPendingUserChange = pendingUserClick?.requestedChecked === checked;\n // The user's click already reached ancestors, and programmatic\n // updates never do, so this click only notifies the form.\n shouldStopClickPropagationRef.current = true;\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(\n new Event('click', {\n bubbles: !(isPendingUserChange && pendingUserClick.hasConsumerStoppedPropagation),\n }),\n );\n shouldStopClickPropagationRef.current = false;\n }\n }, [bubbleInput, checked, userClick]);\n\n const defaultCheckedRef = React.useRef(isIndeterminate(checked) ? false : checked);\n return (\n <Primitive.input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={defaultChecked ?? defaultCheckedRef.current}\n required={required}\n disabled={disabled}\n name={name}\n value={value}\n form={form}\n {...props}\n tabIndex={-1}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n // Prevent the synthetic click dispatched on controlled/programmatic\n // updates from triggering ancestor `onClick` handlers, while still\n // allowing the resulting `change` event to reach the form.\n if (shouldStopClickPropagationRef.current) {\n event.stopPropagation();\n }\n })}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n transform: 'translateX(-100%)',\n }}\n />\n );\n },\n);\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n\nfunction isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxProvider,\n CheckboxTrigger,\n CheckboxIndicator,\n CheckboxBubbleInput,\n //\n Checkbox as Root,\n CheckboxProvider as Provider,\n CheckboxTrigger as Trigger,\n CheckboxIndicator as Indicator,\n CheckboxBubbleInput as BubbleInput,\n};\nexport type {\n CheckboxProps,\n CheckboxProviderProps,\n CheckboxTriggerProps,\n CheckboxIndicatorProps,\n CheckboxBubbleInputProps,\n CheckedState,\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,gCAAgC;AAChC,2BAAmC;AACnC,uBAAqC;AACrC,0CAAqC;AACrC,4BAAwB;AACxB,4BAAyB;AACzB,6BAA0B;AA2GtB;AAvGJ,IAAM,gBAAgB;AAGtB,IAAM,CAAC,uBAAuB,mBAAmB,QAAI,yCAAmB,aAAa;AA2BrF,IAAM,CAAC,sBAAsB,kBAAkB,IAC7C,sBAA4C,aAAa;AAkB3D,SAAS,iBACP,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA;AAAA,IAER;AAAA,EACF,IAAI;AAEJ,QAAM,CAAC,SAAS,UAAU,QAAI,0DAAqB;AAAA,IACjD,MAAM;AAAA,IACN,aAAa,kBAAkB;AAAA,IAC/B,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC;AACD,QAAM,CAAC,SAAS,UAAU,IAAU,eAAmC,IAAI;AAC3E,QAAM,CAAC,aAAa,cAAc,IAAU,eAAkC,IAAI;AAIlF,QAAM,CAAC,WAAW,YAAY,IA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gB;AAAA,UACxB;AAAA,QACF,CAAC;AAAA,QACD,OAAO;AAAA,UACL,GAAG,MAAM;AAAA,UACT,GAAG;AAAA,UACH,UAAU;AAAA,UACV,eAAe;AAAA,UACf,SAAS;AAAA,UACT,QAAQ;AAAA;AAAA;AAAA;AAAA,UAIR,WAAW;AAAA,QACb;AAAA;AAAA,IACF;AAAA,EAEJ,GAvHA;AAwHF;AAIA,SAAS,WAAW,OAAkD;AACpE,SAAO,OAAO,UAAU;AAC1B;AAFS;AAIT,SAAS,gBAAgB,SAAoD;AAC3E,SAAO,YAAY;AACrB;AAFS;AAIT,SAAS,SAAS,SAAuB;AACvC,SAAO,gBAAgB,OAAO,IAAI,kBAAkB,UAAU,YAAY;AAC5E;AAFS;",
4
+ "sourcesContent": ["'use client';\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxProvider as unstable_CheckboxProvider,\n CheckboxTrigger as unstable_CheckboxTrigger,\n CheckboxIndicator,\n CheckboxBubbleInput as unstable_CheckboxBubbleInput,\n //\n Root,\n Provider as unstable_Provider,\n Trigger as unstable_Trigger,\n Indicator,\n BubbleInput as unstable_BubbleInput,\n} from './checkbox';\nexport type {\n CheckboxProps,\n CheckboxProviderProps as unstable_CheckboxProviderProps,\n CheckboxTriggerProps as unstable_CheckboxTriggerProps,\n CheckboxIndicatorProps,\n CheckboxBubbleInputProps as unstable_CheckboxBubbleInputProps,\n CheckedState,\n} from './checkbox';\n", "import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope | undefined };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ninterface CheckboxUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ntype CheckboxContextValue<State extends CheckedState | boolean = CheckedState> = {\n checked: State | boolean;\n setChecked: React.Dispatch<React.SetStateAction<State | boolean>>;\n disabled: boolean | undefined;\n control: HTMLButtonElement | null;\n setControl: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;\n name: string | undefined;\n form: string | undefined;\n value: string | number | readonly string[];\n userClick: CheckboxUserClick | null;\n onUserClick: (userClick: CheckboxUserClick) => void;\n required: boolean | undefined;\n defaultChecked: boolean | undefined;\n isFormControl: boolean;\n bubbleInput: HTMLInputElement | null;\n setBubbleInput: React.Dispatch<React.SetStateAction<HTMLInputElement | null>>;\n};\n\nconst [CheckboxProviderImpl, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface CheckboxProviderProps<State extends CheckedState = CheckedState> {\n checked?: State | boolean | undefined;\n defaultChecked?: State | boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?:\n | { bivarianceHack(checked: State | boolean): void }['bivarianceHack']\n | undefined;\n name?: string | undefined;\n form?: string | undefined;\n disabled?: boolean | undefined;\n value?: string | number | readonly string[] | undefined;\n children?: React.ReactNode | undefined;\n}\n\nfunction CheckboxProvider<State extends CheckedState = CheckedState>(\n props: ScopedProps<CheckboxProviderProps<State>>,\n) {\n const {\n __scopeCheckbox,\n checked: checkedProp,\n children,\n defaultChecked,\n disabled,\n form,\n name,\n onCheckedChange,\n required,\n value = 'on',\n // @ts-expect-error\n internal_do_not_use_render,\n } = props;\n\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked ?? false,\n onChange: onCheckedChange,\n caller: CHECKBOX_NAME,\n });\n const [control, setControl] = React.useState<HTMLButtonElement | null>(null);\n const [bubbleInput, setBubbleInput] = React.useState<HTMLInputElement | null>(null);\n // The latest user click on the trigger. The bubble input dispatches the click\n // to the form once React has handled it, whether or not `checked` changes in\n // the same render.\n const [userClick, setUserClick] = React.useState<CheckboxUserClick | null>(null);\n const isFormControl = control\n ? !!form || !!control.closest('form')\n : // We set this to true by default so that events bubble to forms without JS (SSR)\n true;\n\n const context: CheckboxContextValue<State> = {\n checked: checked,\n disabled: disabled,\n setChecked: setChecked,\n control: control,\n setControl: setControl,\n name: name,\n form: form,\n value: value,\n userClick: userClick,\n onUserClick: setUserClick,\n required: required,\n defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,\n isFormControl: isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <CheckboxProviderImpl\n scope={__scopeCheckbox}\n {...(context as unknown as CheckboxContextValue<CheckedState>)}\n >\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </CheckboxProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CheckboxTrigger';\n\ninterface CheckboxTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof CheckboxProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst CheckboxTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, CheckboxTriggerProps>(\n function CheckboxTrigger(\n { __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }: ScopedProps<CheckboxTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const form = control?.form;\n if (form) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n form.addEventListener('reset', reset);\n return () => form.removeEventListener('reset', reset);\n }\n }, [control, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...checkboxProps}\n ref={composedRefs}\n onKeyDown={composeEventHandlers(onKeyDown, (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault();\n })}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({\n requestedChecked: isIndeterminate(checked) ? true : !checked,\n hasConsumerStoppedPropagation,\n });\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (bubbleInput && isFormControl) {\n // if checkbox has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event (from the input). We propagate changes from an input so\n // that native form validation works and form events reflect\n // checkbox updates.\n if (!hasConsumerStoppedPropagation) event.stopPropagation();\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\ntype CheckboxElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState | undefined;\n defaultChecked?: CheckedState | undefined;\n required?: boolean | undefined;\n onCheckedChange?: { bivarianceHack(checked: CheckedState): void }['bivarianceHack'] | undefined;\n}\n\nconst Checkbox = /* @__PURE__ */ React.forwardRef<CheckboxElement, CheckboxProps>(\n // blank line to reduce diff noise\n function Checkbox(props: ScopedProps<CheckboxProps>, forwardedRef) {\n const {\n __scopeCheckbox,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...checkboxProps\n } = props;\n\n return (\n <CheckboxProvider\n __scopeCheckbox={__scopeCheckbox}\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n required={required}\n onCheckedChange={onCheckedChange}\n name={name}\n form={form}\n value={value}\n // @ts-expect-error\n internal_do_not_use_render={({ isFormControl }: CheckboxContextValue) => (\n <>\n <CheckboxTrigger\n {...checkboxProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n {isFormControl && (\n <CheckboxBubbleInput\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true | undefined;\n}\n\nconst CheckboxIndicator = /* @__PURE__ */ React.forwardRef<\n CheckboxIndicatorElement,\n CheckboxIndicatorProps\n>(\n // blank line to reduce diff noise\n function CheckboxIndicator(props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence\n present={forceMount || isIndeterminate(context.checked) || context.checked === true}\n >\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'CheckboxBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface CheckboxBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst CheckboxBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n CheckboxBubbleInputProps\n>(\n // blank line to reduce diff noise\n function CheckboxBubbleInput(\n { __scopeCheckbox, onClick, ...props }: ScopedProps<CheckboxBubbleInputProps>,\n forwardedRef,\n ) {\n const {\n control,\n userClick,\n checked,\n defaultChecked,\n required,\n disabled,\n name,\n value,\n form,\n bubbleInput,\n setBubbleInput,\n } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);\n\n const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);\n const controlSize = useSize(control);\n // When the checked change is not driven by a user interaction (e.g. a\n // controlled `checked` update), the `click` event we dispatch to notify\n // forms must not reach ancestor `onClick` handlers. We can't simply make it\n // non-bubbling because React derives the checkbox's `change` event from a\n // bubbling `click`. Instead we stop propagation of the synthetic click,\n // which still lets the `change` event reach the form.\n const shouldStopClickPropagationRef = React.useRef(false);\n const prevCheckedRef = React.useRef(checked);\n // The user click this input last dispatched, so each click is dispatched\n // once.\n const handledUserClickRef = React.useRef(userClick);\n // A dispatched user click whose `checked` change hasn't been applied yet\n // (e.g. a controlled parent applying it later). When it is applied, it\n // must still respect the consumer stopping the click's propagation.\n const pendingUserClickRef = React.useRef<CheckboxUserClick | null>(null);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = bubbleInput;\n if (!input) return;\n\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(\n inputProto,\n 'checked',\n ) as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (!setChecked) return;\n\n const checkedChanged = prevCheckedRef.current !== checked;\n prevCheckedRef.current = checked;\n const isNewUserClick = userClick !== null && userClick !== handledUserClickRef.current;\n handledUserClickRef.current = userClick;\n\n if (isNewUserClick) {\n // Dispatch the user's click even if `checked` hasn't changed (yet), so\n // ancestors are notified of every click on the trigger.\n pendingUserClickRef.current = checkedChanged ? null : userClick;\n if (checkedChanged) {\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n }\n input.dispatchEvent(\n new Event('click', { bubbles: !userClick.hasConsumerStoppedPropagation }),\n );\n } else if (checkedChanged) {\n const pendingUserClick = pendingUserClickRef.current;\n pendingUserClickRef.current = null;\n const isPendingUserChange = pendingUserClick?.requestedChecked === checked;\n // The user's click already reached ancestors, and programmatic\n // updates never do, so this click only notifies the form.\n shouldStopClickPropagationRef.current = true;\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(\n new Event('click', {\n bubbles: !(isPendingUserChange && pendingUserClick.hasConsumerStoppedPropagation),\n }),\n );\n shouldStopClickPropagationRef.current = false;\n }\n }, [bubbleInput, checked, userClick]);\n\n const defaultCheckedRef = React.useRef(isIndeterminate(checked) ? false : checked);\n return (\n <Primitive.input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={defaultChecked ?? defaultCheckedRef.current}\n required={required}\n disabled={disabled}\n name={name}\n value={value}\n form={form}\n {...props}\n tabIndex={-1}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n // Prevent the synthetic click dispatched on controlled/programmatic\n // updates from triggering ancestor `onClick` handlers, while still\n // allowing the resulting `change` event to reach the form.\n if (shouldStopClickPropagationRef.current) {\n event.stopPropagation();\n }\n })}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n transform: 'translateX(-100%)',\n }}\n />\n );\n },\n);\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n\nfunction isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxProvider,\n CheckboxTrigger,\n CheckboxIndicator,\n CheckboxBubbleInput,\n //\n Checkbox as Root,\n CheckboxProvider as Provider,\n CheckboxTrigger as Trigger,\n CheckboxIndicator as Indicator,\n CheckboxBubbleInput as BubbleInput,\n};\nexport type {\n CheckboxProps,\n CheckboxProviderProps,\n CheckboxTriggerProps,\n CheckboxIndicatorProps,\n CheckboxBubbleInputProps,\n CheckedState,\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,gCAAgC;AAChC,2BAAmC;AACnC,uBAAqC;AACrC,0CAAqC;AACrC,4BAAwB;AACxB,4BAAyB;AACzB,6BAA0B;AA6GtB;AAzGJ,IAAM,gBAAgB;AAGtB,IAAM,CAAC,uBAAuB,mBAAmB,QAAI,yCAAmB,aAAa;AA2BrF,IAAM,CAAC,sBAAsB,kBAAkB,IAC7C,sBAA4C,aAAa;AAoB3D,SAAS,iBACP,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA;AAAA,IAER;AAAA,EACF,IAAI;AAEJ,QAAM,CAAC,SAAS,UAAU,QAAI,0DAAqB;AAAA,IACjD,MAAM;AAAA,IACN,aAAa,kBAAkB;AAAA,IAC/B,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC;AACD,QAAM,CAAC,SAAS,UAAU,I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A,QACV,KAAK;AAAA,QACL,aAAS,uCAAqB,SAAS,CAAC,UAAU;AAIhD,cAAI,8BAA8B,SAAS;AACzC,kBAAM,gBAAgB;AAAA,UACxB;AAAA,QACF,CAAC;AAAA,QACD,OAAO;AAAA,UACL,GAAG,MAAM;AAAA,UACT,GAAG;AAAA,UACH,UAAU;AAAA,UACV,eAAe;AAAA,UACf,SAAS;AAAA,UACT,QAAQ;AAAA;AAAA;AAAA;AAAA,UAIR,WAAW;AAAA,QACb;AAAA;AAAA,IACF;AAAA,EAEJ,GAvHA;AAwHF;AAIA,SAAS,WAAW,OAAkD;AACpE,SAAO,OAAO,UAAU;AAC1B;AAFS;AAIT,SAAS,gBAAgB,SAAoD;AAC3E,SAAO,YAAY;AACrB;AAFS;AAIT,SAAS,SAAS,SAAuB;AACvC,SAAO,gBAAgB,OAAO,IAAI,kBAAkB,UAAU,YAAY;AAC5E;AAFS;",
6
6
  "names": ["CheckboxTrigger", "Checkbox", "CheckboxIndicator", "CheckboxBubbleInput"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/checkbox.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope | undefined };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ninterface CheckboxUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ntype CheckboxContextValue<State extends CheckedState | boolean = CheckedState> = {\n checked: State | boolean;\n setChecked: React.Dispatch<React.SetStateAction<State | boolean>>;\n disabled: boolean | undefined;\n control: HTMLButtonElement | null;\n setControl: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;\n name: string | undefined;\n form: string | undefined;\n value: string | number | readonly string[];\n userClick: CheckboxUserClick | null;\n onUserClick: (userClick: CheckboxUserClick) => void;\n required: boolean | undefined;\n defaultChecked: boolean | undefined;\n isFormControl: boolean;\n bubbleInput: HTMLInputElement | null;\n setBubbleInput: React.Dispatch<React.SetStateAction<HTMLInputElement | null>>;\n};\n\nconst [CheckboxProviderImpl, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface CheckboxProviderProps<State extends CheckedState = CheckedState> {\n checked?: State | boolean | undefined;\n defaultChecked?: State | boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: State | boolean) => void) | undefined;\n name?: string | undefined;\n form?: string | undefined;\n disabled?: boolean | undefined;\n value?: string | number | readonly string[] | undefined;\n children?: React.ReactNode | undefined;\n}\n\nfunction CheckboxProvider<State extends CheckedState = CheckedState>(\n props: ScopedProps<CheckboxProviderProps<State>>,\n) {\n const {\n __scopeCheckbox,\n checked: checkedProp,\n children,\n defaultChecked,\n disabled,\n form,\n name,\n onCheckedChange,\n required,\n value = 'on',\n // @ts-expect-error\n internal_do_not_use_render,\n } = props;\n\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked ?? false,\n onChange: onCheckedChange,\n caller: CHECKBOX_NAME,\n });\n const [control, setControl] = React.useState<HTMLButtonElement | null>(null);\n const [bubbleInput, setBubbleInput] = React.useState<HTMLInputElement | null>(null);\n // The latest user click on the trigger. The bubble input dispatches the click\n // to the form once React has handled it, whether or not `checked` changes in\n // the same render.\n const [userClick, setUserClick] = React.useState<CheckboxUserClick | null>(null);\n const isFormControl = control\n ? !!form || !!control.closest('form')\n : // We set this to true by default so that events bubble to forms without JS (SSR)\n true;\n\n const context: CheckboxContextValue<State> = {\n checked: checked,\n disabled: disabled,\n setChecked: setChecked,\n control: control,\n setControl: setControl,\n name: name,\n form: form,\n value: value,\n userClick: userClick,\n onUserClick: setUserClick,\n required: required,\n defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,\n isFormControl: isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <CheckboxProviderImpl\n scope={__scopeCheckbox}\n {...(context as unknown as CheckboxContextValue<CheckedState>)}\n >\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </CheckboxProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CheckboxTrigger';\n\ninterface CheckboxTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof CheckboxProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst CheckboxTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, CheckboxTriggerProps>(\n function CheckboxTrigger(\n { __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }: ScopedProps<CheckboxTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const form = control?.form;\n if (form) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n form.addEventListener('reset', reset);\n return () => form.removeEventListener('reset', reset);\n }\n }, [control, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...checkboxProps}\n ref={composedRefs}\n onKeyDown={composeEventHandlers(onKeyDown, (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault();\n })}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({\n requestedChecked: isIndeterminate(checked) ? true : !checked,\n hasConsumerStoppedPropagation,\n });\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (bubbleInput && isFormControl) {\n // if checkbox has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event (from the input). We propagate changes from an input so\n // that native form validation works and form events reflect\n // checkbox updates.\n if (!hasConsumerStoppedPropagation) event.stopPropagation();\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\ntype CheckboxElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState | undefined;\n defaultChecked?: CheckedState | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: CheckedState) => void) | undefined;\n}\n\nconst Checkbox = /* @__PURE__ */ React.forwardRef<CheckboxElement, CheckboxProps>(\n // blank line to reduce diff noise\n function Checkbox(props: ScopedProps<CheckboxProps>, forwardedRef) {\n const {\n __scopeCheckbox,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...checkboxProps\n } = props;\n\n return (\n <CheckboxProvider\n __scopeCheckbox={__scopeCheckbox}\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n required={required}\n onCheckedChange={onCheckedChange}\n name={name}\n form={form}\n value={value}\n // @ts-expect-error\n internal_do_not_use_render={({ isFormControl }: CheckboxContextValue) => (\n <>\n <CheckboxTrigger\n {...checkboxProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n {isFormControl && (\n <CheckboxBubbleInput\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true | undefined;\n}\n\nconst CheckboxIndicator = /* @__PURE__ */ React.forwardRef<\n CheckboxIndicatorElement,\n CheckboxIndicatorProps\n>(\n // blank line to reduce diff noise\n function CheckboxIndicator(props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence\n present={forceMount || isIndeterminate(context.checked) || context.checked === true}\n >\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'CheckboxBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface CheckboxBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst CheckboxBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n CheckboxBubbleInputProps\n>(\n // blank line to reduce diff noise\n function CheckboxBubbleInput(\n { __scopeCheckbox, onClick, ...props }: ScopedProps<CheckboxBubbleInputProps>,\n forwardedRef,\n ) {\n const {\n control,\n userClick,\n checked,\n defaultChecked,\n required,\n disabled,\n name,\n value,\n form,\n bubbleInput,\n setBubbleInput,\n } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);\n\n const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);\n const controlSize = useSize(control);\n // When the checked change is not driven by a user interaction (e.g. a\n // controlled `checked` update), the `click` event we dispatch to notify\n // forms must not reach ancestor `onClick` handlers. We can't simply make it\n // non-bubbling because React derives the checkbox's `change` event from a\n // bubbling `click`. Instead we stop propagation of the synthetic click,\n // which still lets the `change` event reach the form.\n const shouldStopClickPropagationRef = React.useRef(false);\n const prevCheckedRef = React.useRef(checked);\n // The user click this input last dispatched, so each click is dispatched\n // once.\n const handledUserClickRef = React.useRef(userClick);\n // A dispatched user click whose `checked` change hasn't been applied yet\n // (e.g. a controlled parent applying it later). When it is applied, it\n // must still respect the consumer stopping the click's propagation.\n const pendingUserClickRef = React.useRef<CheckboxUserClick | null>(null);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = bubbleInput;\n if (!input) return;\n\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(\n inputProto,\n 'checked',\n ) as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (!setChecked) return;\n\n const checkedChanged = prevCheckedRef.current !== checked;\n prevCheckedRef.current = checked;\n const isNewUserClick = userClick !== null && userClick !== handledUserClickRef.current;\n handledUserClickRef.current = userClick;\n\n if (isNewUserClick) {\n // Dispatch the user's click even if `checked` hasn't changed (yet), so\n // ancestors are notified of every click on the trigger.\n pendingUserClickRef.current = checkedChanged ? null : userClick;\n if (checkedChanged) {\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n }\n input.dispatchEvent(\n new Event('click', { bubbles: !userClick.hasConsumerStoppedPropagation }),\n );\n } else if (checkedChanged) {\n const pendingUserClick = pendingUserClickRef.current;\n pendingUserClickRef.current = null;\n const isPendingUserChange = pendingUserClick?.requestedChecked === checked;\n // The user's click already reached ancestors, and programmatic\n // updates never do, so this click only notifies the form.\n shouldStopClickPropagationRef.current = true;\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(\n new Event('click', {\n bubbles: !(isPendingUserChange && pendingUserClick.hasConsumerStoppedPropagation),\n }),\n );\n shouldStopClickPropagationRef.current = false;\n }\n }, [bubbleInput, checked, userClick]);\n\n const defaultCheckedRef = React.useRef(isIndeterminate(checked) ? false : checked);\n return (\n <Primitive.input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={defaultChecked ?? defaultCheckedRef.current}\n required={required}\n disabled={disabled}\n name={name}\n value={value}\n form={form}\n {...props}\n tabIndex={-1}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n // Prevent the synthetic click dispatched on controlled/programmatic\n // updates from triggering ancestor `onClick` handlers, while still\n // allowing the resulting `change` event to reach the form.\n if (shouldStopClickPropagationRef.current) {\n event.stopPropagation();\n }\n })}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n transform: 'translateX(-100%)',\n }}\n />\n );\n },\n);\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n\nfunction isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxProvider,\n CheckboxTrigger,\n CheckboxIndicator,\n CheckboxBubbleInput,\n //\n Checkbox as Root,\n CheckboxProvider as Provider,\n CheckboxTrigger as Trigger,\n CheckboxIndicator as Indicator,\n CheckboxBubbleInput as BubbleInput,\n};\nexport type {\n CheckboxProps,\n CheckboxProviderProps,\n CheckboxTriggerProps,\n CheckboxIndicatorProps,\n CheckboxBubbleInputProps,\n CheckedState,\n};\n"],
5
- "mappings": ";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,4BAA4B;AACrC,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AA2GtB,SAkIM,UAlIN,KAkIM,YAlIN;AAvGJ,IAAM,gBAAgB;AAGtB,IAAM,CAAC,uBAAuB,mBAAmB,IAAI,mBAAmB,aAAa;AA2BrF,IAAM,CAAC,sBAAsB,kBAAkB,IAC7C,sBAA4C,aAAa;AAkB3D,SAAS,iBACP,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA;AAAA,IAER;AAAA,EACF,IAAI;AAEJ,QAAM,CAAC,SAAS,UAAU,IAAI,qBAAqB;AAAA,IACjD,MAAM;AAAA,IACN,aAAa,kBAAkB;AAAA,IAC/B,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC;AACD,QAAM,CAAC,SAAS,UAAU,IAAU,eAAmC,IAAI;AAC3E,QAAM,CAAC,aAAa,cAAc,IAAU,eAAkC,IAAI;AAIlF,QAAM,CAAC,WAAW,YAAY,IAAU,eAAmC,IAAI;AAC/E,QAAM,gBAAgB,UAClB,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,QAAQ,MAAM;AAAA;AAAA,IAElC;AAAA;AAEJ,QAAM,UAAuC;AAAA,IAC3C;AAAA,I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AAAA;AAAA,UAIR,WAAW;AAAA,QACb;AAAA;AAAA,IACF;AAAA,EAEJ,GAvHA;AAwHF;AAIA,SAAS,WAAW,OAAkD;AACpE,SAAO,OAAO,UAAU;AAC1B;AAFS;AAIT,SAAS,gBAAgB,SAAoD;AAC3E,SAAO,YAAY;AACrB;AAFS;AAIT,SAAS,SAAS,SAAuB;AACvC,SAAO,gBAAgB,OAAO,IAAI,kBAAkB,UAAU,YAAY;AAC5E;AAFS;",
4
+ "sourcesContent": ["import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope | undefined };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ninterface CheckboxUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ntype CheckboxContextValue<State extends CheckedState | boolean = CheckedState> = {\n checked: State | boolean;\n setChecked: React.Dispatch<React.SetStateAction<State | boolean>>;\n disabled: boolean | undefined;\n control: HTMLButtonElement | null;\n setControl: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;\n name: string | undefined;\n form: string | undefined;\n value: string | number | readonly string[];\n userClick: CheckboxUserClick | null;\n onUserClick: (userClick: CheckboxUserClick) => void;\n required: boolean | undefined;\n defaultChecked: boolean | undefined;\n isFormControl: boolean;\n bubbleInput: HTMLInputElement | null;\n setBubbleInput: React.Dispatch<React.SetStateAction<HTMLInputElement | null>>;\n};\n\nconst [CheckboxProviderImpl, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface CheckboxProviderProps<State extends CheckedState = CheckedState> {\n checked?: State | boolean | undefined;\n defaultChecked?: State | boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?:\n | { bivarianceHack(checked: State | boolean): void }['bivarianceHack']\n | undefined;\n name?: string | undefined;\n form?: string | undefined;\n disabled?: boolean | undefined;\n value?: string | number | readonly string[] | undefined;\n children?: React.ReactNode | undefined;\n}\n\nfunction CheckboxProvider<State extends CheckedState = CheckedState>(\n props: ScopedProps<CheckboxProviderProps<State>>,\n) {\n const {\n __scopeCheckbox,\n checked: checkedProp,\n children,\n defaultChecked,\n disabled,\n form,\n name,\n onCheckedChange,\n required,\n value = 'on',\n // @ts-expect-error\n internal_do_not_use_render,\n } = props;\n\n const [checked, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked ?? false,\n onChange: onCheckedChange,\n caller: CHECKBOX_NAME,\n });\n const [control, setControl] = React.useState<HTMLButtonElement | null>(null);\n const [bubbleInput, setBubbleInput] = React.useState<HTMLInputElement | null>(null);\n // The latest user click on the trigger. The bubble input dispatches the click\n // to the form once React has handled it, whether or not `checked` changes in\n // the same render.\n const [userClick, setUserClick] = React.useState<CheckboxUserClick | null>(null);\n const isFormControl = control\n ? !!form || !!control.closest('form')\n : // We set this to true by default so that events bubble to forms without JS (SSR)\n true;\n\n const context: CheckboxContextValue<State> = {\n checked: checked,\n disabled: disabled,\n setChecked: setChecked,\n control: control,\n setControl: setControl,\n name: name,\n form: form,\n value: value,\n userClick: userClick,\n onUserClick: setUserClick,\n required: required,\n defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,\n isFormControl: isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <CheckboxProviderImpl\n scope={__scopeCheckbox}\n {...(context as unknown as CheckboxContextValue<CheckedState>)}\n >\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </CheckboxProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CheckboxTrigger';\n\ninterface CheckboxTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof CheckboxProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst CheckboxTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, CheckboxTriggerProps>(\n function CheckboxTrigger(\n { __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }: ScopedProps<CheckboxTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const form = control?.form;\n if (form) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n form.addEventListener('reset', reset);\n return () => form.removeEventListener('reset', reset);\n }\n }, [control, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...checkboxProps}\n ref={composedRefs}\n onKeyDown={composeEventHandlers(onKeyDown, (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault();\n })}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({\n requestedChecked: isIndeterminate(checked) ? true : !checked,\n hasConsumerStoppedPropagation,\n });\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (bubbleInput && isFormControl) {\n // if checkbox has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event (from the input). We propagate changes from an input so\n // that native form validation works and form events reflect\n // checkbox updates.\n if (!hasConsumerStoppedPropagation) event.stopPropagation();\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\ntype CheckboxElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState | undefined;\n defaultChecked?: CheckedState | undefined;\n required?: boolean | undefined;\n onCheckedChange?: { bivarianceHack(checked: CheckedState): void }['bivarianceHack'] | undefined;\n}\n\nconst Checkbox = /* @__PURE__ */ React.forwardRef<CheckboxElement, CheckboxProps>(\n // blank line to reduce diff noise\n function Checkbox(props: ScopedProps<CheckboxProps>, forwardedRef) {\n const {\n __scopeCheckbox,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...checkboxProps\n } = props;\n\n return (\n <CheckboxProvider\n __scopeCheckbox={__scopeCheckbox}\n checked={checked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n required={required}\n onCheckedChange={onCheckedChange}\n name={name}\n form={form}\n value={value}\n // @ts-expect-error\n internal_do_not_use_render={({ isFormControl }: CheckboxContextValue) => (\n <>\n <CheckboxTrigger\n {...checkboxProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n {isFormControl && (\n <CheckboxBubbleInput\n // @ts-expect-error\n __scopeCheckbox={__scopeCheckbox}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true | undefined;\n}\n\nconst CheckboxIndicator = /* @__PURE__ */ React.forwardRef<\n CheckboxIndicatorElement,\n CheckboxIndicatorProps\n>(\n // blank line to reduce diff noise\n function CheckboxIndicator(props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence\n present={forceMount || isIndeterminate(context.checked) || context.checked === true}\n >\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'CheckboxBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface CheckboxBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst CheckboxBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n CheckboxBubbleInputProps\n>(\n // blank line to reduce diff noise\n function CheckboxBubbleInput(\n { __scopeCheckbox, onClick, ...props }: ScopedProps<CheckboxBubbleInputProps>,\n forwardedRef,\n ) {\n const {\n control,\n userClick,\n checked,\n defaultChecked,\n required,\n disabled,\n name,\n value,\n form,\n bubbleInput,\n setBubbleInput,\n } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);\n\n const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);\n const controlSize = useSize(control);\n // When the checked change is not driven by a user interaction (e.g. a\n // controlled `checked` update), the `click` event we dispatch to notify\n // forms must not reach ancestor `onClick` handlers. We can't simply make it\n // non-bubbling because React derives the checkbox's `change` event from a\n // bubbling `click`. Instead we stop propagation of the synthetic click,\n // which still lets the `change` event reach the form.\n const shouldStopClickPropagationRef = React.useRef(false);\n const prevCheckedRef = React.useRef(checked);\n // The user click this input last dispatched, so each click is dispatched\n // once.\n const handledUserClickRef = React.useRef(userClick);\n // A dispatched user click whose `checked` change hasn't been applied yet\n // (e.g. a controlled parent applying it later). When it is applied, it\n // must still respect the consumer stopping the click's propagation.\n const pendingUserClickRef = React.useRef<CheckboxUserClick | null>(null);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = bubbleInput;\n if (!input) return;\n\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(\n inputProto,\n 'checked',\n ) as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (!setChecked) return;\n\n const checkedChanged = prevCheckedRef.current !== checked;\n prevCheckedRef.current = checked;\n const isNewUserClick = userClick !== null && userClick !== handledUserClickRef.current;\n handledUserClickRef.current = userClick;\n\n if (isNewUserClick) {\n // Dispatch the user's click even if `checked` hasn't changed (yet), so\n // ancestors are notified of every click on the trigger.\n pendingUserClickRef.current = checkedChanged ? null : userClick;\n if (checkedChanged) {\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n }\n input.dispatchEvent(\n new Event('click', { bubbles: !userClick.hasConsumerStoppedPropagation }),\n );\n } else if (checkedChanged) {\n const pendingUserClick = pendingUserClickRef.current;\n pendingUserClickRef.current = null;\n const isPendingUserChange = pendingUserClick?.requestedChecked === checked;\n // The user's click already reached ancestors, and programmatic\n // updates never do, so this click only notifies the form.\n shouldStopClickPropagationRef.current = true;\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(\n new Event('click', {\n bubbles: !(isPendingUserChange && pendingUserClick.hasConsumerStoppedPropagation),\n }),\n );\n shouldStopClickPropagationRef.current = false;\n }\n }, [bubbleInput, checked, userClick]);\n\n const defaultCheckedRef = React.useRef(isIndeterminate(checked) ? false : checked);\n return (\n <Primitive.input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={defaultChecked ?? defaultCheckedRef.current}\n required={required}\n disabled={disabled}\n name={name}\n value={value}\n form={form}\n {...props}\n tabIndex={-1}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n // Prevent the synthetic click dispatched on controlled/programmatic\n // updates from triggering ancestor `onClick` handlers, while still\n // allowing the resulting `change` event to reach the form.\n if (shouldStopClickPropagationRef.current) {\n event.stopPropagation();\n }\n })}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n transform: 'translateX(-100%)',\n }}\n />\n );\n },\n);\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n\nfunction isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxProvider,\n CheckboxTrigger,\n CheckboxIndicator,\n CheckboxBubbleInput,\n //\n Checkbox as Root,\n CheckboxProvider as Provider,\n CheckboxTrigger as Trigger,\n CheckboxIndicator as Indicator,\n CheckboxBubbleInput as BubbleInput,\n};\nexport type {\n CheckboxProps,\n CheckboxProviderProps,\n CheckboxTriggerProps,\n CheckboxIndicatorProps,\n CheckboxBubbleInputProps,\n CheckedState,\n};\n"],
5
+ "mappings": ";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,4BAA4B;AAC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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-checkbox",
3
- "version": "1.4.0-rc.1791763750187",
3
+ "version": "1.4.1",
4
4
  "license": "MIT",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
@@ -11,13 +11,13 @@
11
11
  ],
12
12
  "sideEffects": false,
13
13
  "dependencies": {
14
+ "@radix-ui/primitive": "1.2.0",
14
15
  "@radix-ui/react-compose-refs": "1.1.5",
15
- "@radix-ui/primitive": "1.2.0-rc.1791763750187",
16
+ "@radix-ui/react-context": "1.3.0",
16
17
  "@radix-ui/react-presence": "1.1.11",
17
- "@radix-ui/react-use-controllable-state": "1.3.0-rc.1791763750187",
18
- "@radix-ui/react-use-size": "1.1.5",
19
- "@radix-ui/react-context": "1.3.0-rc.1791763750187",
20
- "@radix-ui/react-primitive": "2.2.0-rc.1791763750187"
18
+ "@radix-ui/react-primitive": "2.2.0",
19
+ "@radix-ui/react-use-controllable-state": "1.3.0",
20
+ "@radix-ui/react-use-size": "1.1.5"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "^19.3.0",
@@ -25,8 +25,8 @@
25
25
  "react": "^19.3.0",
26
26
  "react-dom": "^19.3.0",
27
27
  "typescript": "^5.9.3",
28
- "@repo/typescript-config": "0.0.0",
29
- "@repo/builder": "0.0.0"
28
+ "@repo/builder": "0.0.0",
29
+ "@repo/typescript-config": "0.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@types/react": "*",