@radix-ui/react-switch 0.1.6-rc.8 → 1.0.0

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.
@@ -1 +1 @@
1
- {"mappings":";;;AAoBA,OAAA,wFAAgF,CAAC;AAMjF,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,4BAAsB,SAAQ,oBAAoB;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AAED,OAAA,MAAM,6FAsEL,CAAC;AAWF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,iCAA2B,SAAQ,kBAAkB;CAAG;AAExD,OAAA,MAAM,qGAaL,CAAC;AAwDF,OAAA,MAAM,2FAAa,CAAC;AACpB,OAAA,MAAM,+FAAmB,CAAC","sources":["packages/react/switch/src/packages/react/switch/src/Switch.tsx","packages/react/switch/src/packages/react/switch/src/index.ts","packages/react/switch/src/index.ts"],"sourcesContent":[null,null,"export * from './Switch';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;;AAoBA,OAAA,wFAAgF,CAAC;AAMjF,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,4BAAsB,SAAQ,oBAAoB;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AAED,OAAA,MAAM,6FAsEL,CAAC;AAWF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,iCAA2B,SAAQ,kBAAkB;CAAG;AAExD,OAAA,MAAM,qGAaL,CAAC;AAwDF,OAAA,MAAM,2FAAa,CAAC;AACpB,OAAA,MAAM,+FAAmB,CAAC","sources":["packages/react/switch/src/packages/react/switch/src/Switch.tsx","packages/react/switch/src/packages/react/switch/src/index.ts","packages/react/switch/src/index.ts"],"sourcesContent":[null,null,"export {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n} from './Switch';\nexport type { SwitchProps, SwitchThumbProps } from './Switch';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -9,35 +9,18 @@ var $cWV9h$radixuireactusesize = require("@radix-ui/react-use-size");
9
9
  var $cWV9h$radixuireactprimitive = require("@radix-ui/react-primitive");
10
10
  var $cWV9h$radixuireactlabel = require("@radix-ui/react-label");
11
11
 
12
- function $parcel$exportWildcard(dest, source) {
13
- Object.keys(source).forEach(function(key) {
14
- if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
15
- return;
16
- }
17
-
18
- Object.defineProperty(dest, key, {
19
- enumerable: true,
20
- get: function get() {
21
- return source[key];
22
- }
23
- });
24
- });
25
-
26
- return dest;
12
+ function $parcel$export(e, n, v, s) {
13
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
27
14
  }
28
15
  function $parcel$interopDefault(a) {
29
16
  return a && a.__esModule ? a.default : a;
30
17
  }
31
- function $parcel$export(e, n, v, s) {
32
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
33
- }
34
- var $4465bdeb0ef4ccd7$exports = {};
35
18
 
36
- $parcel$export($4465bdeb0ef4ccd7$exports, "createSwitchScope", () => $4465bdeb0ef4ccd7$export$cf7f5f17f69cbd43);
37
- $parcel$export($4465bdeb0ef4ccd7$exports, "Switch", () => $4465bdeb0ef4ccd7$export$b5d5cf8927ab7262);
38
- $parcel$export($4465bdeb0ef4ccd7$exports, "SwitchThumb", () => $4465bdeb0ef4ccd7$export$4d07bf653ea69106);
39
- $parcel$export($4465bdeb0ef4ccd7$exports, "Root", () => $4465bdeb0ef4ccd7$export$be92b6f5f03c0fe9);
40
- $parcel$export($4465bdeb0ef4ccd7$exports, "Thumb", () => $4465bdeb0ef4ccd7$export$6521433ed15a34db);
19
+ $parcel$export(module.exports, "createSwitchScope", () => $4465bdeb0ef4ccd7$export$cf7f5f17f69cbd43);
20
+ $parcel$export(module.exports, "Switch", () => $4465bdeb0ef4ccd7$export$b5d5cf8927ab7262);
21
+ $parcel$export(module.exports, "SwitchThumb", () => $4465bdeb0ef4ccd7$export$4d07bf653ea69106);
22
+ $parcel$export(module.exports, "Root", () => $4465bdeb0ef4ccd7$export$be92b6f5f03c0fe9);
23
+ $parcel$export(module.exports, "Thumb", () => $4465bdeb0ef4ccd7$export$6521433ed15a34db);
41
24
 
42
25
 
43
26
 
@@ -172,7 +155,6 @@ const $4465bdeb0ef4ccd7$export$be92b6f5f03c0fe9 = $4465bdeb0ef4ccd7$export$b5d5c
172
155
  const $4465bdeb0ef4ccd7$export$6521433ed15a34db = $4465bdeb0ef4ccd7$export$4d07bf653ea69106;
173
156
 
174
157
 
175
- $parcel$exportWildcard(module.exports, $4465bdeb0ef4ccd7$exports);
176
158
 
177
159
 
178
160
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;ACaA;;oGAEA,CAEA,MAAMS,iCAAW,GAAG,QAApB,AAAA;AAGA,MAAM,CAACC,yCAAD,EAAsBC,yCAAtB,CAAA,GAA2CR,6CAAkB,CAACM,iCAAD,CAAnE,AAAA;AAGA,MAAM,CAACG,oCAAD,EAAiBC,sCAAjB,CAAA,GAAqCH,yCAAmB,CAAqBD,iCAArB,CAA9D,AAAA;AAWA,MAAMK,yCAAM,GAAA,aAAGd,CAAAA,uBAAA,CACb,CAACgB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MAAMC,UAAU,GAAGC,MAAM,CAACC,wBAAP,CAAgCN,UAAhC,EAA4C,SAA5C,CAAnB,AAAA;QACA,MAAMzB,UAAU,GAAG6B,UAAU,CAACG,GAA9B,AAAA;QACA,IAAIxB,WAAW,KAAK5B,OAAhB,IAA2BoB,UAA/B,EAA2C;YACzC,MAAMO,KAAK,GAAG,IAAI0B,KAAJ,CAAU,OAAV,EAAmB;gB,SAAEd,OAAAA;aAArB,CAAd,AAAiC;YACjCnB,UAAU,CAACkC,IAAX,CAAgBV,KAAhB,EAAuB5C,OAAvB,CAAAoB,CAAAA;YACAwB,KAAK,CAACW,aAAN,CAAoB5B,KAApB,CAAAiB,CAAAA;SACD;KATH,EAUG;QAAChB,WAAD;QAAc5B,OAAd;QAAuBuC,OAAvB;KAVH,CAUC,CAAA;IAED,OAAA,aACE,CAAA,0BADF,CAAA,OAAA,EAAA,2DAAA,CAAA;QAEI,IAAI,EAAC,UADP;QAEE,aAAA,EAAA,IAFF;QAGE,cAAc,EAAEvC,OAAhB;KAHF,EAIMwC,UAJN,EAAA;QAKE,QAAQ,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAG9C,KAAK,CAAC6D,KADJ;YAEL,GAAGd,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILC,aAAa,EAAE,MAJV;YAKLC,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CApBJ,AAqCC;AAED,SAASpC,8BAAT,CAAkBxB,OAAlB,EAAoC;IAClC,OAAOA,OAAO,GAAG,SAAH,GAAe,WAA7B,CAAA;CACD;AAED,MAAM6D,yCAAI,GAAGpE,yCAAb,AAAA;AACA,MAAMqE,yCAAK,GAAG5B,yCAAd,AAAA;;AD5LA","sources":["packages/react/switch/src/index.ts","packages/react/switch/src/Switch.tsx"],"sourcesContent":["export * 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 { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useLabelContext } from '@radix-ui/react-label';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ntype SwitchContextValue = { checked: boolean; disabled?: boolean };\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\ntype SwitchElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends PrimitiveButtonProps {\n checked?: boolean;\n defaultChecked?: boolean;\n required?: boolean;\n onCheckedChange?(checked: boolean): void;\n}\n\nconst Switch = React.forwardRef<SwitchElement, SwitchProps>(\n (props: ScopedProps<SwitchProps>, forwardedRef) => {\n const {\n __scopeSwitch,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...switchProps\n } = props;\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null);\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));\n const labelId = useLabelContext(button);\n const labelledBy = ariaLabelledby || labelId;\n const hasConsumerStoppedPropagationRef = React.useRef(false);\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = button ? Boolean(button.closest('form')) : true;\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked,\n onChange: onCheckedChange,\n });\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\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(props.onClick, (event) => {\n setChecked((prevChecked) => !prevChecked);\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n }\n })}\n />\n {isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\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 style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n );\n }\n);\n\nSwitch.displayName = SWITCH_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n (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\nSwitchThumb.displayName = THUMB_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean;\n control: HTMLElement | null;\n bubbles: boolean;\n}\n\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props;\n const ref = React.useRef<HTMLInputElement>(null);\n const prevChecked = usePrevious(checked);\n const controlSize = useSize(control);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!;\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n setChecked.call(input, checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n );\n};\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Switch;\nconst Thumb = SwitchThumb;\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n};\nexport type { SwitchProps, SwitchThumbProps };\n"],"names":["React","composeEventHandlers","useComposedRefs","createContextScope","useControllableState","usePrevious","useSize","Primitive","useLabelContext","SWITCH_NAME","createSwitchContext","createSwitchScope","SwitchProvider","useSwitchContext","Switch","forwardRef","props","forwardedRef","__scopeSwitch","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","switchProps","button","setButton","useState","composedRefs","node","labelId","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","prop","defaultProp","onChange","getState","undefined","onClick","event","prevChecked","current","isPropagationStopped","stopPropagation","transform","THUMB_NAME","SwitchThumb","thumbProps","context","BubbleInput","control","bubbles","inputProps","ref","controlSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","set","Event","call","dispatchEvent","style","position","pointerEvents","opacity","margin","Root","Thumb"],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;ACaA;;oGAEA,CAEA,MAAMc,iCAAW,GAAG,QAApB,AAAA;AAGA,MAAM,CAACC,yCAAD,EAAsBf,yCAAtB,CAAA,GAA2CQ,6CAAkB,CAACM,iCAAD,CAAnE,AAAA;AAGA,MAAM,CAACE,oCAAD,EAAiBC,sCAAjB,CAAA,GAAqCF,yCAAmB,CAAqBD,iCAArB,CAA9D,AAAA;AAWA,MAAMb,yCAAM,GAAA,aAAGI,CAAAA,uBAAA,CACb,CAACc,KAAD,EAAkCC,YAAlC,GAAmD;IACjD,MAAM,E,eACJC,aADI,CAAA,EAEJ,iBAAA,EAAmBC,cAFf,CAAA,E,MAGJC,IAHI,CAAA,EAIJC,OAAO,EAAEC,WAJL,CAAA,E,gBAKJC,cALI,CAAA,E,UAMJC,QANI,CAAA,E,UAOJC,QAPI,CAAA,SAQJC,KAAK,GAAG,IARJ,G,iBASJC,eATI,CAAA,EAUJ,GAAGC,WAAH,EAVI,GAWFZ,KAXJ,AAAM;IAYN,MAAM,CAACa,MAAD,EAASC,SAAT,CAAA,GAAsB5B,qBAAA,CAAyC,IAAzC,CAA5B,AAAA;IACA,MAAM8B,YAAY,GAAG5B,8CAAe,CAACa,YAAD,EAAgBgB,CAAAA,IAAD,GAAUH,SAAS,CAACG,IAAD,CAAlC;IAAA,CAApC,AAAA;IACA,MAAMC,OAAO,GAAGxB,wCAAe,CAACmB,MAAD,CAA/B,AAAA;IACA,MAAMM,UAAU,GAAGhB,cAAc,IAAIe,OAArC,AAAA;IACA,MAAME,gCAAgC,GAAGlC,mBAAA,CAAa,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,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAG7C,KAAK,CAAC4D,KADJ;YAEL,GAAGd,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILC,aAAa,EAAE,MAJV;YAKLC,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CApBJ,AAqCC;AAED,SAASnC,8BAAT,CAAkBxB,OAAlB,EAAoC;IAClC,OAAOA,OAAO,GAAG,SAAH,GAAe,WAA7B,CAAA;CACD;AAED,MAAMrB,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAK,GAAGF,yCAAd,AAAA;;AD5LA","sources":["packages/react/switch/src/index.ts","packages/react/switch/src/Switch.tsx"],"sourcesContent":["export {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n} from './Switch';\nexport type { SwitchProps, SwitchThumbProps } 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 { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useLabelContext } from '@radix-ui/react-label';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ntype SwitchContextValue = { checked: boolean; disabled?: boolean };\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\ntype SwitchElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends PrimitiveButtonProps {\n checked?: boolean;\n defaultChecked?: boolean;\n required?: boolean;\n onCheckedChange?(checked: boolean): void;\n}\n\nconst Switch = React.forwardRef<SwitchElement, SwitchProps>(\n (props: ScopedProps<SwitchProps>, forwardedRef) => {\n const {\n __scopeSwitch,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...switchProps\n } = props;\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null);\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));\n const labelId = useLabelContext(button);\n const labelledBy = ariaLabelledby || labelId;\n const hasConsumerStoppedPropagationRef = React.useRef(false);\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = button ? Boolean(button.closest('form')) : true;\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked,\n onChange: onCheckedChange,\n });\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\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(props.onClick, (event) => {\n setChecked((prevChecked) => !prevChecked);\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n }\n })}\n />\n {isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\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 style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n );\n }\n);\n\nSwitch.displayName = SWITCH_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n (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\nSwitchThumb.displayName = THUMB_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean;\n control: HTMLElement | null;\n bubbles: boolean;\n}\n\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props;\n const ref = React.useRef<HTMLInputElement>(null);\n const prevChecked = usePrevious(checked);\n const controlSize = useSize(control);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!;\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n setChecked.call(input, checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n );\n};\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Switch;\nconst Thumb = SwitchThumb;\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n};\nexport type { SwitchProps, SwitchThumbProps };\n"],"names":["createSwitchScope","Switch","SwitchThumb","Root","Thumb","React","composeEventHandlers","useComposedRefs","createContextScope","useControllableState","usePrevious","useSize","Primitive","useLabelContext","SWITCH_NAME","createSwitchContext","SwitchProvider","useSwitchContext","forwardRef","props","forwardedRef","__scopeSwitch","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","switchProps","button","setButton","useState","composedRefs","node","labelId","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","prop","defaultProp","onChange","getState","undefined","onClick","event","prevChecked","current","isPropagationStopped","stopPropagation","transform","THUMB_NAME","thumbProps","context","BubbleInput","control","bubbles","inputProps","ref","controlSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","set","Event","call","dispatchEvent","style","position","pointerEvents","opacity","margin"],"version":3,"file":"index.js.map"}
@@ -9,16 +9,6 @@ import {useSize as $irPIl$useSize} from "@radix-ui/react-use-size";
9
9
  import {Primitive as $irPIl$Primitive} from "@radix-ui/react-primitive";
10
10
  import {useLabelContext as $irPIl$useLabelContext} from "@radix-ui/react-label";
11
11
 
12
- function $parcel$export(e, n, v, s) {
13
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
- }
15
- var $6be4966fd9bbc698$exports = {};
16
-
17
- $parcel$export($6be4966fd9bbc698$exports, "createSwitchScope", () => $6be4966fd9bbc698$export$cf7f5f17f69cbd43);
18
- $parcel$export($6be4966fd9bbc698$exports, "Switch", () => $6be4966fd9bbc698$export$b5d5cf8927ab7262);
19
- $parcel$export($6be4966fd9bbc698$exports, "SwitchThumb", () => $6be4966fd9bbc698$export$4d07bf653ea69106);
20
- $parcel$export($6be4966fd9bbc698$exports, "Root", () => $6be4966fd9bbc698$export$be92b6f5f03c0fe9);
21
- $parcel$export($6be4966fd9bbc698$exports, "Thumb", () => $6be4966fd9bbc698$export$6521433ed15a34db);
22
12
 
23
13
 
24
14
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;ACaA;;oGAEA,CAEA,MAAMS,iCAAW,GAAG,QAApB,AAAA;AAGA,MAAM,CAACC,yCAAD,EAAsBC,yCAAtB,CAAA,GAA2CR,yBAAkB,CAACM,iCAAD,CAAnE,AAAA;AAGA,MAAM,CAACG,oCAAD,EAAiBC,sCAAjB,CAAA,GAAqCH,yCAAmB,CAAqBD,iCAArB,CAA9D,AAAA;AAWA,MAAMK,yCAAM,GAAA,aAAGd,CAAAA,iBAAA,CACb,CAACgB,KAAD,EAAkCC,YAAlC,GAAmD;IACjD,MAAM,E,eACJC,aADI,CAAA,EAEJ,iBAAA,EAAmBC,cAFf,CAAA,E,MAGJC,IAHI,CAAA,EAIJC,OAAO,EAAEC,WAJL,CAAA,E,gBAKJC,cALI,CAAA,E,UAMJC,QANI,CAAA,E,UAOJC,QAPI,CAAA,SAQJC,KAAK,GAAG,IARJ,G,iBASJC,eATI,CAAA,EAUJ,GAAGC,WAAH,EAVI,GAWFZ,KAXJ,AAAM;IAYN,MAAM,CAACa,MAAD,EAASC,SAAT,CAAA,GAAsB9B,eAAA,CAAyC,IAAzC,CAA5B,AAAA;IACA,MAAMgC,YAAY,GAAG9B,sBAAe,CAACe,YAAD,EAAgBgB,CAAAA,IAAD,GAAUH,SAAS,CAACG,IAAD,CAAlC;IAAA,CAApC,AAAA;IACA,MAAMC,OAAO,GAAG1B,sBAAe,CAACqB,MAAD,CAA/B,AAAA;IACA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P;QAEE,aAAA,EAAA,IAFF;QAGE,cAAc,EAAEvC,OAAhB;KAHF,EAIMwC,UAJN,EAAA;QAKE,QAAQ,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAG9C,KAAK,CAAC6D,KADJ;YAEL,GAAGd,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILC,aAAa,EAAE,MAJV;YAKLC,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CApBJ,AAqCC;AAED,SAASpC,8BAAT,CAAkBxB,OAAlB,EAAoC;IAClC,OAAOA,OAAO,GAAG,SAAH,GAAe,WAA7B,CAAA;CACD;AAED,MAAM6D,yCAAI,GAAGpE,yCAAb,AAAA;AACA,MAAMqE,yCAAK,GAAG5B,yCAAd,AAAA;;AD5LA","sources":["packages/react/switch/src/index.ts","packages/react/switch/src/Switch.tsx"],"sourcesContent":["export * 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 { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useLabelContext } from '@radix-ui/react-label';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ntype SwitchContextValue = { checked: boolean; disabled?: boolean };\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\ntype SwitchElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends PrimitiveButtonProps {\n checked?: boolean;\n defaultChecked?: boolean;\n required?: boolean;\n onCheckedChange?(checked: boolean): void;\n}\n\nconst Switch = React.forwardRef<SwitchElement, SwitchProps>(\n (props: ScopedProps<SwitchProps>, forwardedRef) => {\n const {\n __scopeSwitch,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...switchProps\n } = props;\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null);\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));\n const labelId = useLabelContext(button);\n const labelledBy = ariaLabelledby || labelId;\n const hasConsumerStoppedPropagationRef = React.useRef(false);\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = button ? Boolean(button.closest('form')) : true;\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked,\n onChange: onCheckedChange,\n });\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\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(props.onClick, (event) => {\n setChecked((prevChecked) => !prevChecked);\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n }\n })}\n />\n {isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\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 style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n );\n }\n);\n\nSwitch.displayName = SWITCH_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n (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\nSwitchThumb.displayName = THUMB_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean;\n control: HTMLElement | null;\n bubbles: boolean;\n}\n\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props;\n const ref = React.useRef<HTMLInputElement>(null);\n const prevChecked = usePrevious(checked);\n const controlSize = useSize(control);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!;\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n setChecked.call(input, checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n );\n};\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Switch;\nconst Thumb = SwitchThumb;\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n};\nexport type { SwitchProps, SwitchThumbProps };\n"],"names":["React","composeEventHandlers","useComposedRefs","createContextScope","useControllableState","usePrevious","useSize","Primitive","useLabelContext","SWITCH_NAME","createSwitchContext","createSwitchScope","SwitchProvider","useSwitchContext","Switch","forwardRef","props","forwardedRef","__scopeSwitch","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","switchProps","button","setButton","useState","composedRefs","node","labelId","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","prop","defaultProp","onChange","getState","undefined","onClick","event","prevChecked","current","isPropagationStopped","stopPropagation","transform","THUMB_NAME","SwitchThumb","thumbProps","context","BubbleInput","control","bubbles","inputProps","ref","controlSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","set","Event","call","dispatchEvent","style","position","pointerEvents","opacity","margin","Root","Thumb"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;A;;;;;;;;;;ACaA;;oGAEA,CAEA,MAAMc,iCAAW,GAAG,QAApB,AAAA;AAGA,MAAM,CAACC,yCAAD,EAAsBf,yCAAtB,CAAA,GAA2CQ,yBAAkB,CAACM,iCAAD,CAAnE,AAAA;AAGA,MAAM,CAACE,oCAAD,EAAiBC,sCAAjB,CAAA,GAAqCF,yCAAmB,CAAqBD,iCAArB,CAA9D,AAAA;AAWA,MAAMb,yCAAM,GAAA,aAAGI,CAAAA,iBAAA,CACb,CAACc,KAAD,EAAkCC,YAAlC,GAAmD;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CAAgCN,UAAhC,EAA4C,SAA5C,CAAnB,AAAA;QACA,MAAMxB,UAAU,GAAG4B,UAAU,CAACG,GAA9B,AAAA;QACA,IAAIvB,WAAW,KAAK5B,OAAhB,IAA2BoB,UAA/B,EAA2C;YACzC,MAAMO,KAAK,GAAG,IAAIyB,KAAJ,CAAU,OAAV,EAAmB;gB,SAAEd,OAAAA;aAArB,CAAd,AAAiC;YACjClB,UAAU,CAACiC,IAAX,CAAgBV,KAAhB,EAAuB3C,OAAvB,CAAAoB,CAAAA;YACAuB,KAAK,CAACW,aAAN,CAAoB3B,KAApB,CAAAgB,CAAAA;SACD;KATH,EAUG;QAACf,WAAD;QAAc5B,OAAd;QAAuBsC,OAAvB;KAVH,CAUC,CAAA;IAED,OAAA,aACE,CAAA,oBADF,CAAA,OAAA,EAAA,oCAAA,CAAA;QAEI,IAAI,EAAC,UADP;QAEE,aAAA,EAAA,IAFF;QAGE,cAAc,EAAEtC,OAAhB;KAHF,EAIMuC,UAJN,EAAA;QAKE,QAAQ,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAG7C,KAAK,CAAC4D,KADJ;YAEL,GAAGd,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILC,aAAa,EAAE,MAJV;YAKLC,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CApBJ,AAqCC;AAED,SAASnC,8BAAT,CAAkBxB,OAAlB,EAAoC;IAClC,OAAOA,OAAO,GAAG,SAAH,GAAe,WAA7B,CAAA;CACD;AAED,MAAMrB,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAK,GAAGF,yCAAd,AAAA;;AD5LA","sources":["packages/react/switch/src/index.ts","packages/react/switch/src/Switch.tsx"],"sourcesContent":["export {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n} from './Switch';\nexport type { SwitchProps, SwitchThumbProps } 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 { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useLabelContext } from '@radix-ui/react-label';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nconst SWITCH_NAME = 'Switch';\n\ntype ScopedProps<P> = P & { __scopeSwitch?: Scope };\nconst [createSwitchContext, createSwitchScope] = createContextScope(SWITCH_NAME);\n\ntype SwitchContextValue = { checked: boolean; disabled?: boolean };\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<SwitchContextValue>(SWITCH_NAME);\n\ntype SwitchElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface SwitchProps extends PrimitiveButtonProps {\n checked?: boolean;\n defaultChecked?: boolean;\n required?: boolean;\n onCheckedChange?(checked: boolean): void;\n}\n\nconst Switch = React.forwardRef<SwitchElement, SwitchProps>(\n (props: ScopedProps<SwitchProps>, forwardedRef) => {\n const {\n __scopeSwitch,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...switchProps\n } = props;\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null);\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));\n const labelId = useLabelContext(button);\n const labelledBy = ariaLabelledby || labelId;\n const hasConsumerStoppedPropagationRef = React.useRef(false);\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = button ? Boolean(button.closest('form')) : true;\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked,\n onChange: onCheckedChange,\n });\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\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(props.onClick, (event) => {\n setChecked((prevChecked) => !prevChecked);\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n }\n })}\n />\n {isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\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 style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n );\n }\n);\n\nSwitch.displayName = SWITCH_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb';\n\ntype SwitchThumbElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface SwitchThumbProps extends PrimitiveSpanProps {}\n\nconst SwitchThumb = React.forwardRef<SwitchThumbElement, SwitchThumbProps>(\n (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\nSwitchThumb.displayName = THUMB_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean;\n control: HTMLElement | null;\n bubbles: boolean;\n}\n\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props;\n const ref = React.useRef<HTMLInputElement>(null);\n const prevChecked = usePrevious(checked);\n const controlSize = useSize(control);\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!;\n const inputProto = window.HTMLInputElement.prototype;\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor;\n const setChecked = descriptor.set;\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n setChecked.call(input, checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n );\n};\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Switch;\nconst Thumb = SwitchThumb;\n\nexport {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n};\nexport type { SwitchProps, SwitchThumbProps };\n"],"names":["createSwitchScope","Switch","SwitchThumb","Root","Thumb","React","composeEventHandlers","useComposedRefs","createContextScope","useControllableState","usePrevious","useSize","Primitive","useLabelContext","SWITCH_NAME","createSwitchContext","SwitchProvider","useSwitchContext","forwardRef","props","forwardedRef","__scopeSwitch","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","switchProps","button","setButton","useState","composedRefs","node","labelId","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","prop","defaultProp","onChange","getState","undefined","onClick","event","prevChecked","current","isPropagationStopped","stopPropagation","transform","THUMB_NAME","thumbProps","context","BubbleInput","control","bubbles","inputProps","ref","controlSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","set","Event","call","dispatchEvent","style","position","pointerEvents","opacity","margin"],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-switch",
3
- "version": "0.1.6-rc.8",
3
+ "version": "1.0.0",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -17,17 +17,18 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
- "@radix-ui/primitive": "0.1.0",
21
- "@radix-ui/react-compose-refs": "0.1.1-rc.8",
22
- "@radix-ui/react-context": "0.1.2-rc.8",
23
- "@radix-ui/react-label": "0.1.6-rc.8",
24
- "@radix-ui/react-primitive": "0.1.5-rc.8",
25
- "@radix-ui/react-use-controllable-state": "0.1.1-rc.8",
26
- "@radix-ui/react-use-previous": "0.1.2-rc.8",
27
- "@radix-ui/react-use-size": "0.1.2-rc.8"
20
+ "@radix-ui/primitive": "1.0.0",
21
+ "@radix-ui/react-compose-refs": "1.0.0",
22
+ "@radix-ui/react-context": "1.0.0",
23
+ "@radix-ui/react-label": "1.0.0",
24
+ "@radix-ui/react-primitive": "1.0.0",
25
+ "@radix-ui/react-use-controllable-state": "1.0.0",
26
+ "@radix-ui/react-use-previous": "1.0.0",
27
+ "@radix-ui/react-use-size": "1.0.0"
28
28
  },
29
29
  "peerDependencies": {
30
- "react": "^16.8 || ^17.0 || ^18.0"
30
+ "react": "^16.8 || ^17.0 || ^18.0",
31
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
31
32
  },
32
33
  "homepage": "https://radix-ui.com/primitives",
33
34
  "repository": {
@@ -36,6 +37,5 @@
36
37
  },
37
38
  "bugs": {
38
39
  "url": "https://github.com/radix-ui/primitives/issues"
39
- },
40
- "stableVersion": "0.1.5"
40
+ }
41
41
  }