@radix-ui/react-switch 1.4.0 → 1.4.2-rc.1791897977948

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
@@ -11,7 +11,9 @@ interface SwitchProviderProps {
11
11
  checked?: boolean | undefined;
12
12
  defaultChecked?: boolean | undefined;
13
13
  required?: boolean | undefined;
14
- onCheckedChange?: ((checked: boolean) => void) | undefined;
14
+ onCheckedChange?: {
15
+ bivarianceHack(checked: boolean): void;
16
+ }['bivarianceHack'] | undefined;
15
17
  name?: string | undefined;
16
18
  form?: string | undefined;
17
19
  disabled?: boolean | undefined;
@@ -28,7 +30,9 @@ interface SwitchProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChe
28
30
  checked?: boolean | undefined;
29
31
  defaultChecked?: boolean | undefined;
30
32
  required?: boolean | undefined;
31
- onCheckedChange?: ((checked: boolean) => void) | undefined;
33
+ onCheckedChange?: {
34
+ bivarianceHack(checked: boolean): void;
35
+ }['bivarianceHack'] | undefined;
32
36
  }
33
37
  declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
34
38
  type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
package/dist/index.d.ts CHANGED
@@ -11,7 +11,9 @@ interface SwitchProviderProps {
11
11
  checked?: boolean | undefined;
12
12
  defaultChecked?: boolean | undefined;
13
13
  required?: boolean | undefined;
14
- onCheckedChange?: ((checked: boolean) => void) | undefined;
14
+ onCheckedChange?: {
15
+ bivarianceHack(checked: boolean): void;
16
+ }['bivarianceHack'] | undefined;
15
17
  name?: string | undefined;
16
18
  form?: string | undefined;
17
19
  disabled?: boolean | undefined;
@@ -28,7 +30,9 @@ interface SwitchProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChe
28
30
  checked?: boolean | undefined;
29
31
  defaultChecked?: boolean | undefined;
30
32
  required?: boolean | undefined;
31
- onCheckedChange?: ((checked: boolean) => void) | undefined;
33
+ onCheckedChange?: {
34
+ bivarianceHack(checked: boolean): void;
35
+ }['bivarianceHack'] | undefined;
32
36
  }
33
37
  declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
34
38
  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/switch.tsx"],
4
- "sourcesContent": ["'use client';\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchProvider as unstable_SwitchProvider,\n SwitchTrigger as unstable_SwitchTrigger,\n SwitchThumb,\n SwitchBubbleInput as unstable_SwitchBubbleInput,\n //\n Root,\n Provider as unstable_Provider,\n Trigger as unstable_Trigger,\n Thumb,\n BubbleInput as unstable_BubbleInput,\n} from './switch';\nexport type {\n SwitchProps,\n SwitchProviderProps as unstable_SwitchProviderProps,\n SwitchTriggerProps as unstable_SwitchTriggerProps,\n SwitchThumbProps,\n SwitchBubbleInputProps as unstable_SwitchBubbleInputProps,\n} from './switch';\n", "import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope | undefined };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ninterface SwitchUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ninterface SwitchContextValue {\n checked: boolean;\n setChecked: React.Dispatch<React.SetStateAction<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: SwitchUserClick | null;\n onUserClick: (userClick: SwitchUserClick) => 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 [SwitchProviderImpl, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SwitchProviderProps {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: 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 SwitchProvider(props: ScopedProps<SwitchProviderProps>) {\n const {\n __scopeSwitch,\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: SWITCH_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<SwitchUserClick | null>(null);\n\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: SwitchContextValue = {\n checked,\n setChecked,\n disabled,\n control,\n setControl,\n name,\n form,\n value,\n userClick,\n onUserClick: setUserClick,\n required,\n defaultChecked,\n isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <SwitchProviderImpl scope={__scopeSwitch} {...context}>\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </SwitchProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'SwitchTrigger';\n\ninterface SwitchTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof SwitchProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst SwitchTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, SwitchTriggerProps>(\n function SwitchTrigger(\n { __scopeSwitch, onClick, ...switchProps }: ScopedProps<SwitchTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n form,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useSwitchContext(TRIGGER_NAME, __scopeSwitch);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const associatedForm = form ? control?.ownerDocument.getElementById(form) : control?.form;\n if (associatedForm instanceof HTMLFormElement) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n associatedForm.addEventListener('reset', reset);\n return () => associatedForm.removeEventListener('reset', reset);\n }\n }, [control, form, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...switchProps}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({ requestedChecked: !checked, hasConsumerStoppedPropagation });\n setChecked((prevChecked) => !prevChecked);\n if (bubbleInput && isFormControl) {\n // if switch has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event. We propagate changes from an input so that native form\n // validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagation) {\n event.stopPropagation();\n }\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\ntype SwitchElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: boolean) => void) | undefined;\n}\n\nconst Switch = /* @__PURE__ */ React.forwardRef<SwitchElement, SwitchProps>(\n // blank line to reduce diff noise\n function Switch(props: ScopedProps<SwitchProps>, forwardedRef) {\n const {\n __scopeSwitch,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...switchProps\n } = props;\n\n return (\n <SwitchProvider\n __scopeSwitch={__scopeSwitch}\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 }: SwitchContextValue) => (\n <>\n <SwitchTrigger\n {...switchProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n {isFormControl && (\n <SwitchBubbleInput\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = /* @__PURE__ */ React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n function SwitchThumb(props: ScopedProps<SwitchThumbProps>, forwardedRef) {\n const { __scopeSwitch, ...thumbProps } = props;\n const context = useSwitchContext(THUMB_NAME, __scopeSwitch);\n return (\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...thumbProps}\n ref={forwardedRef}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'SwitchBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface SwitchBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst SwitchBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n SwitchBubbleInputProps\n>(\n // blank line to reduce diff noise\n function SwitchBubbleInput(\n { __scopeSwitch, onClick, ...props }: ScopedProps<SwitchBubbleInputProps>,\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 } = useSwitchContext(BUBBLE_INPUT_NAME, __scopeSwitch);\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 switch'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\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<SwitchUserClick | 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) {\n return;\n }\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 setChecked.call(input, 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 setChecked.call(input, 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(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 getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchProvider,\n SwitchTrigger,\n SwitchThumb,\n SwitchBubbleInput,\n //\n Switch as Root,\n SwitchProvider as Provider,\n SwitchTrigger as Trigger,\n SwitchThumb as Thumb,\n SwitchBubbleInput as BubbleInput,\n};\nexport type {\n SwitchProps,\n SwitchProviderProps,\n SwitchTriggerProps,\n SwitchThumbProps,\n SwitchBubbleInputProps,\n};\n"],
4
+ "sourcesContent": ["'use client';\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchProvider as unstable_SwitchProvider,\n SwitchTrigger as unstable_SwitchTrigger,\n SwitchThumb,\n SwitchBubbleInput as unstable_SwitchBubbleInput,\n //\n Root,\n Provider as unstable_Provider,\n Trigger as unstable_Trigger,\n Thumb,\n BubbleInput as unstable_BubbleInput,\n} from './switch';\nexport type {\n SwitchProps,\n SwitchProviderProps as unstable_SwitchProviderProps,\n SwitchTriggerProps as unstable_SwitchTriggerProps,\n SwitchThumbProps,\n SwitchBubbleInputProps as unstable_SwitchBubbleInputProps,\n} from './switch';\n", "import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope | undefined };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ninterface SwitchUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ninterface SwitchContextValue {\n checked: boolean;\n setChecked: React.Dispatch<React.SetStateAction<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: SwitchUserClick | null;\n onUserClick: (userClick: SwitchUserClick) => 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 [SwitchProviderImpl, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SwitchProviderProps {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: { bivarianceHack(checked: boolean): void }['bivarianceHack'] | 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 SwitchProvider(props: ScopedProps<SwitchProviderProps>) {\n const {\n __scopeSwitch,\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: SWITCH_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<SwitchUserClick | null>(null);\n\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: SwitchContextValue = {\n checked,\n setChecked,\n disabled,\n control,\n setControl,\n name,\n form,\n value,\n userClick,\n onUserClick: setUserClick,\n required,\n defaultChecked,\n isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <SwitchProviderImpl scope={__scopeSwitch} {...context}>\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </SwitchProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'SwitchTrigger';\n\ninterface SwitchTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof SwitchProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst SwitchTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, SwitchTriggerProps>(\n function SwitchTrigger(\n { __scopeSwitch, onClick, ...switchProps }: ScopedProps<SwitchTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n form,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useSwitchContext(TRIGGER_NAME, __scopeSwitch);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const associatedForm = form ? control?.ownerDocument.getElementById(form) : control?.form;\n if (associatedForm instanceof HTMLFormElement) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n associatedForm.addEventListener('reset', reset);\n return () => associatedForm.removeEventListener('reset', reset);\n }\n }, [control, form, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...switchProps}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({ requestedChecked: !checked, hasConsumerStoppedPropagation });\n setChecked((prevChecked) => !prevChecked);\n if (bubbleInput && isFormControl) {\n // if switch has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event. We propagate changes from an input so that native form\n // validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagation) {\n event.stopPropagation();\n }\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\ntype SwitchElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: { bivarianceHack(checked: boolean): void }['bivarianceHack'] | undefined;\n}\n\nconst Switch = /* @__PURE__ */ React.forwardRef<SwitchElement, SwitchProps>(\n // blank line to reduce diff noise\n function Switch(props: ScopedProps<SwitchProps>, forwardedRef) {\n const {\n __scopeSwitch,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...switchProps\n } = props;\n\n return (\n <SwitchProvider\n __scopeSwitch={__scopeSwitch}\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 }: SwitchContextValue) => (\n <>\n <SwitchTrigger\n {...switchProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n {isFormControl && (\n <SwitchBubbleInput\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = /* @__PURE__ */ React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n function SwitchThumb(props: ScopedProps<SwitchThumbProps>, forwardedRef) {\n const { __scopeSwitch, ...thumbProps } = props;\n const context = useSwitchContext(THUMB_NAME, __scopeSwitch);\n return (\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...thumbProps}\n ref={forwardedRef}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'SwitchBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface SwitchBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst SwitchBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n SwitchBubbleInputProps\n>(\n // blank line to reduce diff noise\n function SwitchBubbleInput(\n { __scopeSwitch, onClick, ...props }: ScopedProps<SwitchBubbleInputProps>,\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 } = useSwitchContext(BUBBLE_INPUT_NAME, __scopeSwitch);\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 switch'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\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<SwitchUserClick | 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) {\n return;\n }\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 setChecked.call(input, 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 setChecked.call(input, 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(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 getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchProvider,\n SwitchTrigger,\n SwitchThumb,\n SwitchBubbleInput,\n //\n Switch as Root,\n SwitchProvider as Provider,\n SwitchTrigger as Trigger,\n SwitchThumb as Thumb,\n SwitchBubbleInput as BubbleInput,\n};\nexport type {\n SwitchProps,\n SwitchProviderProps,\n SwitchTriggerProps,\n SwitchThumbProps,\n SwitchBubbleInputProps,\n};\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAAqC;AACrC,gCAAgC;AAChC,2BAAmC;AACnC,0CAAqC;AACrC,4BAAwB;AACxB,6BAA0B;AAuGtB;AAnGJ,IAAM,cAAc;AAGpB,IAAM,CAAC,qBAAqB,iBAAiB,QAAI,yCAAmB,WAAW;AAyB/E,IAAM,CAAC,oBAAoB,gBAAgB,IAAI,oBAAwC,WAAW;AAkBlG,SAAS,eAAe,OAAyC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,I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f,SAAS;AAAA,UACT,QAAQ;AAAA;AAAA;AAAA;AAAA,UAIR,WAAW;AAAA,QACb;AAAA;AAAA,IACF;AAAA,EAEJ,GAxHA;AAyHF;AAIA,SAAS,WAAW,OAAkD;AACpE,SAAO,OAAO,UAAU;AAC1B;AAFS;AAIT,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;AAFS;",
6
6
  "names": ["SwitchTrigger", "Switch", "SwitchThumb", "SwitchBubbleInput"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/switch.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope | undefined };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ninterface SwitchUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ninterface SwitchContextValue {\n checked: boolean;\n setChecked: React.Dispatch<React.SetStateAction<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: SwitchUserClick | null;\n onUserClick: (userClick: SwitchUserClick) => 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 [SwitchProviderImpl, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SwitchProviderProps {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: 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 SwitchProvider(props: ScopedProps<SwitchProviderProps>) {\n const {\n __scopeSwitch,\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: SWITCH_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<SwitchUserClick | null>(null);\n\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: SwitchContextValue = {\n checked,\n setChecked,\n disabled,\n control,\n setControl,\n name,\n form,\n value,\n userClick,\n onUserClick: setUserClick,\n required,\n defaultChecked,\n isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <SwitchProviderImpl scope={__scopeSwitch} {...context}>\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </SwitchProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'SwitchTrigger';\n\ninterface SwitchTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof SwitchProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst SwitchTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, SwitchTriggerProps>(\n function SwitchTrigger(\n { __scopeSwitch, onClick, ...switchProps }: ScopedProps<SwitchTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n form,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useSwitchContext(TRIGGER_NAME, __scopeSwitch);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const associatedForm = form ? control?.ownerDocument.getElementById(form) : control?.form;\n if (associatedForm instanceof HTMLFormElement) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n associatedForm.addEventListener('reset', reset);\n return () => associatedForm.removeEventListener('reset', reset);\n }\n }, [control, form, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...switchProps}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({ requestedChecked: !checked, hasConsumerStoppedPropagation });\n setChecked((prevChecked) => !prevChecked);\n if (bubbleInput && isFormControl) {\n // if switch has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event. We propagate changes from an input so that native form\n // validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagation) {\n event.stopPropagation();\n }\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\ntype SwitchElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: ((checked: boolean) => void) | undefined;\n}\n\nconst Switch = /* @__PURE__ */ React.forwardRef<SwitchElement, SwitchProps>(\n // blank line to reduce diff noise\n function Switch(props: ScopedProps<SwitchProps>, forwardedRef) {\n const {\n __scopeSwitch,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...switchProps\n } = props;\n\n return (\n <SwitchProvider\n __scopeSwitch={__scopeSwitch}\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 }: SwitchContextValue) => (\n <>\n <SwitchTrigger\n {...switchProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n {isFormControl && (\n <SwitchBubbleInput\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = /* @__PURE__ */ React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n function SwitchThumb(props: ScopedProps<SwitchThumbProps>, forwardedRef) {\n const { __scopeSwitch, ...thumbProps } = props;\n const context = useSwitchContext(THUMB_NAME, __scopeSwitch);\n return (\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...thumbProps}\n ref={forwardedRef}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'SwitchBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface SwitchBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst SwitchBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n SwitchBubbleInputProps\n>(\n // blank line to reduce diff noise\n function SwitchBubbleInput(\n { __scopeSwitch, onClick, ...props }: ScopedProps<SwitchBubbleInputProps>,\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 } = useSwitchContext(BUBBLE_INPUT_NAME, __scopeSwitch);\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 switch'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\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<SwitchUserClick | 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) {\n return;\n }\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 setChecked.call(input, 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 setChecked.call(input, 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(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 getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchProvider,\n SwitchTrigger,\n SwitchThumb,\n SwitchBubbleInput,\n //\n Switch as Root,\n SwitchProvider as Provider,\n SwitchTrigger as Trigger,\n SwitchThumb as Thumb,\n SwitchBubbleInput as BubbleInput,\n};\nexport type {\n SwitchProps,\n SwitchProviderProps,\n SwitchTriggerProps,\n SwitchThumbProps,\n SwitchBubbleInputProps,\n};\n"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope | undefined };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ninterface SwitchUserClick {\n requestedChecked: boolean;\n hasConsumerStoppedPropagation: boolean;\n}\n\ninterface SwitchContextValue {\n checked: boolean;\n setChecked: React.Dispatch<React.SetStateAction<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: SwitchUserClick | null;\n onUserClick: (userClick: SwitchUserClick) => 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 [SwitchProviderImpl, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SwitchProviderProps {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: { bivarianceHack(checked: boolean): void }['bivarianceHack'] | 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 SwitchProvider(props: ScopedProps<SwitchProviderProps>) {\n const {\n __scopeSwitch,\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: SWITCH_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<SwitchUserClick | null>(null);\n\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: SwitchContextValue = {\n checked,\n setChecked,\n disabled,\n control,\n setControl,\n name,\n form,\n value,\n userClick,\n onUserClick: setUserClick,\n required,\n defaultChecked,\n isFormControl,\n bubbleInput,\n setBubbleInput,\n };\n\n return (\n <SwitchProviderImpl scope={__scopeSwitch} {...context}>\n {isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children}\n </SwitchProviderImpl>\n );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'SwitchTrigger';\n\ninterface SwitchTriggerProps extends Omit<\n React.ComponentPropsWithoutRef<typeof Primitive.button>,\n keyof SwitchProviderProps\n> {\n children?: React.ReactNode | undefined;\n}\n\nconst SwitchTrigger = /* @__PURE__ */ React.forwardRef<HTMLButtonElement, SwitchTriggerProps>(\n function SwitchTrigger(\n { __scopeSwitch, onClick, ...switchProps }: ScopedProps<SwitchTriggerProps>,\n forwardedRef,\n ) {\n const {\n control,\n form,\n value,\n disabled,\n checked,\n required,\n setControl,\n setChecked,\n onUserClick,\n isFormControl,\n bubbleInput,\n } = useSwitchContext(TRIGGER_NAME, __scopeSwitch);\n const composedRefs = useComposedRefs(forwardedRef, setControl);\n\n const initialCheckedStateRef = React.useRef(checked);\n React.useEffect(() => {\n const associatedForm = form ? control?.ownerDocument.getElementById(form) : control?.form;\n if (associatedForm instanceof HTMLFormElement) {\n const reset = () => setChecked(initialCheckedStateRef.current);\n associatedForm.addEventListener('reset', reset);\n return () => associatedForm.removeEventListener('reset', reset);\n }\n }, [control, form, setChecked]);\n\n return (\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n value={value}\n {...switchProps}\n ref={composedRefs}\n onClick={composeEventHandlers(onClick, (event) => {\n const hasConsumerStoppedPropagation = event.isPropagationStopped();\n onUserClick({ requestedChecked: !checked, hasConsumerStoppedPropagation });\n setChecked((prevChecked) => !prevChecked);\n if (bubbleInput && isFormControl) {\n // if switch has a bubble input and is a form control, stop\n // propagation from the button so that we only propagate one click\n // event. We propagate changes from an input so that native form\n // validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagation) {\n event.stopPropagation();\n }\n }\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\ntype SwitchElement = React.ComponentRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: boolean | undefined;\n defaultChecked?: boolean | undefined;\n required?: boolean | undefined;\n onCheckedChange?: { bivarianceHack(checked: boolean): void }['bivarianceHack'] | undefined;\n}\n\nconst Switch = /* @__PURE__ */ React.forwardRef<SwitchElement, SwitchProps>(\n // blank line to reduce diff noise\n function Switch(props: ScopedProps<SwitchProps>, forwardedRef) {\n const {\n __scopeSwitch,\n name,\n checked,\n defaultChecked,\n required,\n disabled,\n value,\n onCheckedChange,\n form,\n ...switchProps\n } = props;\n\n return (\n <SwitchProvider\n __scopeSwitch={__scopeSwitch}\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 }: SwitchContextValue) => (\n <>\n <SwitchTrigger\n {...switchProps}\n ref={forwardedRef}\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n {isFormControl && (\n <SwitchBubbleInput\n // @ts-expect-error\n __scopeSwitch={__scopeSwitch}\n />\n )}\n </>\n )}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ComponentRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = /* @__PURE__ */ React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n function SwitchThumb(props: ScopedProps<SwitchThumbProps>, forwardedRef) {\n const { __scopeSwitch, ...thumbProps } = props;\n const context = useSwitchContext(THUMB_NAME, __scopeSwitch);\n return (\n <Primitive.span\n data-state={getState(context.checked)}\n data-disabled={context.disabled ? '' : undefined}\n {...thumbProps}\n ref={forwardedRef}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchBubbleInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst BUBBLE_INPUT_NAME = 'SwitchBubbleInput';\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;\ninterface SwitchBubbleInputProps extends Omit<InputProps, 'checked'> {}\n\nconst SwitchBubbleInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n SwitchBubbleInputProps\n>(\n // blank line to reduce diff noise\n function SwitchBubbleInput(\n { __scopeSwitch, onClick, ...props }: ScopedProps<SwitchBubbleInputProps>,\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 } = useSwitchContext(BUBBLE_INPUT_NAME, __scopeSwitch);\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 switch'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\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<SwitchUserClick | 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) {\n return;\n }\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 setChecked.call(input, 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 setChecked.call(input, 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(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 getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchProvider,\n SwitchTrigger,\n SwitchThumb,\n SwitchBubbleInput,\n //\n Switch as Root,\n SwitchProvider as Provider,\n SwitchTrigger as Trigger,\n SwitchThumb as Thumb,\n SwitchBubbleInput as BubbleInput,\n};\nexport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AAS,CAAC;AAEpC,UAAM,oBAA0B,aAAO,OAAO;AAC9C,WACE;AAAA,MAAC,UAAU;AAAA,MAAV;AAAA,QACC,MAAK;AAAA,QACL,eAAW;AAAA,QACX,gBAAgB,kBAAkB,kBAAkB;AAAA,QACpD;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,UAAU;AAAA,QACV,KAAK;AAAA,QACL,SAAS,qBAAqB,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,GAxHA;AAyHF;AAIA,SAAS,WAAW,OAAkD;AACpE,SAAO,OAAO,UAAU;AAC1B;AAFS;AAIT,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;AAFS;",
6
6
  "names": ["SwitchTrigger", "Switch", "SwitchThumb", "SwitchBubbleInput"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-switch",
3
- "version": "1.4.0",
3
+ "version": "1.4.2-rc.1791897977948",
4
4
  "license": "MIT",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
@@ -11,11 +11,11 @@
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/react-context": "1.3.0",
16
- "@radix-ui/react-primitive": "2.2.0",
16
+ "@radix-ui/react-context": "1.3.1-rc.1791897977948",
17
17
  "@radix-ui/react-use-controllable-state": "1.3.0",
18
- "@radix-ui/primitive": "1.2.0",
18
+ "@radix-ui/react-primitive": "2.2.0",
19
19
  "@radix-ui/react-use-size": "1.1.5"
20
20
  },
21
21
  "devDependencies": {
@@ -24,8 +24,8 @@
24
24
  "react": "^19.3.0",
25
25
  "react-dom": "^19.3.0",
26
26
  "typescript": "^5.9.3",
27
- "@repo/builder": "0.0.0",
28
- "@repo/typescript-config": "0.0.0"
27
+ "@repo/typescript-config": "0.0.0",
28
+ "@repo/builder": "0.0.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@types/react": "*",