@radix-ui/react-checkbox 0.1.5-rc.1 → 0.1.5-rc.13

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":"A;A;A;AAqBA,OAAA,0FAAsF,CAAC;AAEvF,oBAAoB,OAAO,GAAG,eAAe,CAAC;AAW9C,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,8BAAwB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,gBAAgB,CAAC;IACtF,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CAC/C;AAED,OAAA,MAAM,iGAsEL,CAAC;AAWF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,uCAAiC,SAAQ,kBAAkB;IACzD;A;A;OAGG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAED,OAAA,MAAM,iHAgBL,CAAC;AA8DF,OAAA,MAAM,6FAAe,CAAC;AACtB,OAAA,MAAM,yGAA6B,CAAC","sources":["./packages/react/checkbox/src/packages/react/checkbox/src/Checkbox.tsx","./packages/react/checkbox/src/packages/react/checkbox/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":"A;A;A;AAqBA,OAAA,0FAAsF,CAAC;AAEvF,oBAAoB,OAAO,GAAG,eAAe,CAAC;AAW9C,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,8BAAwB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,gBAAgB,CAAC;IACtF,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CAC/C;AAED,OAAA,MAAM,iGA0EL,CAAC;AAWF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,uCAAiC,SAAQ,kBAAkB;IACzD;A;A;OAGG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAED,OAAA,MAAM,iHAgBL,CAAC;AA8DF,OAAA,MAAM,6FAAe,CAAC;AACtB,OAAA,MAAM,yGAA6B,CAAC","sources":["./packages/react/checkbox/src/packages/react/checkbox/src/Checkbox.tsx","./packages/react/checkbox/src/packages/react/checkbox/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e,t,r,a=require("@radix-ui/react-primitive").Primitive,o=require("@radix-ui/react-presence").Presence,n=require("@radix-ui/react-label").useLabelContext,c=require("@radix-ui/react-use-size").useSize,i=require("@radix-ui/react-use-previous").usePrevious,s=require("@radix-ui/react-use-controllable-state").useControllableState,u=require("@radix-ui/primitive").composeEventHandlers,d=require("@radix-ui/react-context").createContextScope,l=require("@radix-ui/react-compose-refs").useComposedRefs,b=(e={},t=require("react"),Object.keys(t).forEach((function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e),p=(r=require("@babel/runtime/helpers/extends"))&&r.__esModule?r.default:r;const[x,f]=d("Checkbox");exports.createCheckboxScope=f;const[h,k]=x("Checkbox"),m=/*#__PURE__*/b.forwardRef(((e,t)=>{const{__scopeCheckbox:r,"aria-labelledby":o,name:c,checked:i,defaultChecked:d,required:x,disabled:f,value:k="on",onCheckedChange:m,...C}=e,[E,P]=b.useState(null),_=l(t,(e=>P(e))),g=n(E),w=o||g,R=b.useRef(!1),S=!E||Boolean(E.closest("form")),[I=!1,M]=s({prop:i,defaultProp:d,onChange:m});/*#__PURE__*/return b.createElement(h,{scope:r,state:I,disabled:f},/*#__PURE__*/b.createElement(a.button,p({type:"button",role:"checkbox","aria-checked":q(I)?"mixed":I,"aria-labelledby":w,"aria-required":x,"data-state":y(I),"data-disabled":f?"":void 0,disabled:f,value:k},C,{ref:_,onClick:u(e.onClick,(e=>{M((e=>!!q(e)||!e)),S&&(R.current=e.isPropagationStopped(),R.current||e.stopPropagation())}))})),S&&/*#__PURE__*/b.createElement(v,{control:E,bubbles:!R.current,name:c,value:k,checked:I,required:x,disabled:f,style:{transform:"translateX(-100%)"}}))}));exports.Checkbox=m;const C=/*#__PURE__*/b.forwardRef(((e,t)=>{const{__scopeCheckbox:r,forceMount:n,...c}=e,i=k("CheckboxIndicator",r);/*#__PURE__*/return b.createElement(o,{present:n||q(i.state)||!0===i.state},/*#__PURE__*/b.createElement(a.span,p({"data-state":y(i.state),"data-disabled":i.disabled?"":void 0},c,{ref:t,style:{pointerEvents:"none",...e.style}})))}));exports.CheckboxIndicator=C;const v=e=>{const{control:t,checked:r,bubbles:a=!0,...o}=e,n=b.useRef(null),s=i(r),u=c(t);return b.useEffect((()=>{const e=n.current,t=window.HTMLInputElement.prototype,o=Object.getOwnPropertyDescriptor(t,"checked").set;if(s!==r&&o){const t=new Event("click",{bubbles:a});e.indeterminate=q(r),o.call(e,!q(r)&&r),e.dispatchEvent(t)}}),[s,r,a]),/*#__PURE__*/b.createElement("input",p({type:"checkbox","aria-hidden":!0,defaultChecked:!q(r)&&r},o,{tabIndex:-1,ref:n,style:{...e.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function q(e){return"indeterminate"===e}function y(e){return q(e)?"indeterminate":e?"checked":"unchecked"}const E=m;exports.Root=E;const P=C;exports.Indicator=P;
1
+ var e,t,r,a=require("@radix-ui/react-primitive").Primitive,n=require("@radix-ui/react-presence").Presence,o=require("@radix-ui/react-label").useLabelContext,c=require("@radix-ui/react-use-size").useSize,i=require("@radix-ui/react-use-previous").usePrevious,s=require("@radix-ui/react-use-controllable-state").useControllableState,u=require("@radix-ui/primitive").composeEventHandlers,d=require("@radix-ui/react-context").createContextScope,l=require("@radix-ui/react-compose-refs").useComposedRefs,b=(e={},t=require("react"),Object.keys(t).forEach((function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e),p=(r=require("@babel/runtime/helpers/extends"))&&r.__esModule?r.default:r;const[x,f]=d("Checkbox");exports.createCheckboxScope=f;const[h,k]=x("Checkbox"),m=/*#__PURE__*/b.forwardRef(((e,t)=>{const{__scopeCheckbox:r,"aria-labelledby":n,name:c,checked:i,defaultChecked:d,required:x,disabled:f,value:k="on",onCheckedChange:m,...C}=e,[q,w]=b.useState(null),P=l(t,(e=>w(e))),_=o(q),g=n||_,R=b.useRef(!1),S=!q||Boolean(q.closest("form")),[I=!1,D]=s({prop:i,defaultProp:d,onChange:m});/*#__PURE__*/return b.createElement(h,{scope:r,state:I,disabled:f},/*#__PURE__*/b.createElement(a.button,p({type:"button",role:"checkbox","aria-checked":y(I)?"mixed":I,"aria-labelledby":g,"aria-required":x,"data-state":E(I),"data-disabled":f?"":void 0,disabled:f,value:k},C,{ref:P,onKeyDown:u(e.onKeyDown,(e=>{"Enter"===e.key&&e.preventDefault()})),onClick:u(e.onClick,(e=>{D((e=>!!y(e)||!e)),S&&(R.current=e.isPropagationStopped(),R.current||e.stopPropagation())}))})),S&&/*#__PURE__*/b.createElement(v,{control:q,bubbles:!R.current,name:c,value:k,checked:I,required:x,disabled:f,style:{transform:"translateX(-100%)"}}))}));exports.Checkbox=m;const C=/*#__PURE__*/b.forwardRef(((e,t)=>{const{__scopeCheckbox:r,forceMount:o,...c}=e,i=k("CheckboxIndicator",r);/*#__PURE__*/return b.createElement(n,{present:o||y(i.state)||!0===i.state},/*#__PURE__*/b.createElement(a.span,p({"data-state":E(i.state),"data-disabled":i.disabled?"":void 0},c,{ref:t,style:{pointerEvents:"none",...e.style}})))}));exports.CheckboxIndicator=C;const v=e=>{const{control:t,checked:r,bubbles:a=!0,...n}=e,o=b.useRef(null),s=i(r),u=c(t);return b.useEffect((()=>{const e=o.current,t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,"checked").set;if(s!==r&&n){const t=new Event("click",{bubbles:a});e.indeterminate=y(r),n.call(e,!y(r)&&r),e.dispatchEvent(t)}}),[s,r,a]),/*#__PURE__*/b.createElement("input",p({type:"checkbox","aria-hidden":!0,defaultChecked:!y(r)&&r},n,{tabIndex:-1,ref:o,style:{...e.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function y(e){return"indeterminate"===e}function E(e){return y(e)?"indeterminate":e?"checked":"unchecked"}const q=m;exports.Root=q;const w=C;exports.Indicator=w;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"IAYgCA,EAAMC,EAZNC,6eAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECiBzC,MAGOU,EAAuBC,GAAuBC,EAH/B,0CAYtB,MAAOC,EAAkBC,GACvBJ,EAboB,YAwBhBK,eAAWC,EAAMC,YACrB,CAACC,EAAmCC,KAClC,MAAMC,gBACJA,EACA,kBAAmBC,EAFfC,KAGJA,EACAC,QAASC,EAJLC,eAKJA,EALIC,SAMJA,EANIC,SAOJA,EAPIC,MAQJA,EAAQ,KARJC,gBASJA,KACGC,GACDZ,GACGa,EAAQC,GAAahB,EAAMiB,SAAmC,MAC/DC,EAAeC,EAAgBhB,GAAeiB,GAASJ,EAAUI,KACjEC,EAAUC,EAAgBP,GAC1BQ,E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AAES,cAAe,UAAWhE,EAAMuD,0CAkBnD,MAAMU,EAAejE,IACnB,MAAMqD,QAAEA,EAAFhD,QAAWA,EAAXiD,QAAoBA,GAAU,KAASY,GAAelE,EACtD4C,EAAM9C,EAAMyB,OAAyB,MACrCyB,EAAcmB,EAAY9D,GAC1B+D,EAAcC,EAAQhB,GAiB5B,OAdAvD,EAAMwE,WAAU,KACd,MAAMC,EAAQ3B,EAAIK,QACZuB,EAAaC,OAAOC,iBAAiBC,UAErChD,EADa5C,OAAO6F,yBAAyBJ,EAAY,WACjCK,IAE9B,GAAI7B,IAAgB3C,GAAWsB,EAAY,CACzC,MAAMoB,EAAQ,IAAI+B,MAAM,QAAS,CAAExB,QAAAA,IACnCiB,EAAMQ,cAAgBtC,EAAgBpC,GACtCsB,EAAWqD,KAAKT,GAAO9B,EAAgBpC,IAAmBA,GAC1DkE,EAAMU,cAAclC,MAErB,CAACC,EAAa3C,EAASiD,iBAGxBtB,EAAAC,cAAA,QAAAK,EAAA,CACEC,KAAK,WACL,eAAA,EACAhC,gBAAgBkC,EAAgBpC,IAAmBA,GAC/C6D,EAJN,CAKEgB,UAAW,EACXtC,IAAKA,EACLW,MAAO,IACFvD,EAAMuD,SACNa,EACHe,SAAU,WACVnB,cAAe,OACfoB,QAAS,EACTC,OAAQ,OAMhB,SAAS5C,EAAgBpC,GACvB,MAAmB,kBAAZA,EAGT,SAASqC,EAASrC,GAChB,OAAOoC,EAAgBpC,GAAW,gBAAkBA,EAAU,UAAY,YAG5E,MAAMiF,EAAOzF,iBACb,MAAM0F,EAAY9B","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/checkbox/src/Checkbox.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { useLabelContext } from '@radix-ui/react-label';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ntype CheckboxContextValue = {\n state: CheckedState;\n disabled?: boolean;\n};\n\nconst [CheckboxProvider, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\ntype CheckboxElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState;\n defaultChecked?: CheckedState;\n required?: boolean;\n onCheckedChange?(checked: CheckedState): void;\n}\n\nconst Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(\n (props: ScopedProps<CheckboxProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...checkboxProps\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 <CheckboxProvider scope={__scopeCheckbox} state={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : 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 {...checkboxProps}\n ref={composedRefs}\n onClick={composeEventHandlers(props.onClick, (event) => {\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if checkbox 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 checkbox 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 </CheckboxProvider>\n );\n }\n);\n\nCheckbox.displayName = CHECKBOX_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst CheckboxIndicator = React.forwardRef<CheckboxIndicatorElement, CheckboxIndicatorProps>(\n (props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) => {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence present={forceMount || isIndeterminate(context.state) || context.state === true}>\n <Primitive.span\n data-state={getState(context.state)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n }\n);\n\nCheckboxIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: CheckedState;\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\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={isIndeterminate(checked) ? false : 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 isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Checkbox;\nconst Indicator = CheckboxIndicator;\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxIndicator,\n //\n Root,\n Indicator,\n};\nexport type { CheckboxProps, CheckboxIndicatorProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","createCheckboxContext","createCheckboxScope","createContextScope","CheckboxProvider","useCheckboxContext","Checkbox","React","forwardRef","props","forwardedRef","__scopeCheckbox","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","checkboxProps","button","setButton","useState","composedRefs","useComposedRefs","node","labelId","useLabelContext","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","useControllableState","prop","defaultProp","onChange","_react","createElement","$eabaedc2140e2004adabe568fc5$var$CheckboxProvider","scope","state","Primitive","_babelRuntimeHelpersExtends","type","role","isIndeterminate","getState","undefined","ref","onClick","composeEventHandlers","event","prevChecked","current","isPropagationStopped","stopPropagation","$eabaedc2140e2004adabe568fc5$var$BubbleInput","control","bubbles","style","transform","CheckboxIndicator","forceMount","indicatorProps","context","Presence","present","span","pointerEvents","BubbleInput","inputProps","usePrevious","controlSize","useSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","getOwnPropertyDescriptor","set","Event","indeterminate","call","dispatchEvent","tabIndex","position","opacity","margin","Root","Indicator"],"version":3,"file":"index.js.map"}
1
+ {"mappings":"IAYgCA,EAAMC,EAZNC,6eAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECiBzC,MAGOU,EAAuBC,GAAuBC,EAH/B,0CAYtB,MAAOC,EAAkBC,GACvBJ,EAboB,YAwBhBK,eAAWC,EAAMC,YACrB,CAACC,EAAmCC,KAClC,MAAMC,gBACJA,EACA,kBAAmBC,EAFfC,KAGJA,EACAC,QAASC,EAJLC,eAKJA,EALIC,SAMJA,EANIC,SAOJA,EAPIC,MAQJA,EAAQ,KARJC,gBASJA,KACGC,GACDZ,GACGa,EAAQC,GAAahB,EAAMiB,SAAmC,MAC/DC,EAAeC,EAAgBhB,GAAeiB,GAASJ,EAAUI,KACjEC,EAAUC,EAAgBP,GAC1BQ,EAAalB,GAAkBgB,EAC/BG,EAAmCxB,EAAMyB,QAAO,GAEhDC,GAAgBX,GAASY,QAAQZ,EAAOa,QAAQ,UAC/CrB,GAAU,EAAOsB,GAAcC,EAAqB,CACzDC,KAAMvB,EACNwB,YAAavB,EACbwB,SAAUpB,iBAGZ,OACEqB,EAAAC,cAACC,EAAD,CAAkBC,MAAOjC,EAAiBkC,MAAO/B,EAASI,SAAUA,gBAClEuB,EAAAC,cAACI,EAAUxB,OAAXyB,EAAA,CACEC,KAAK,SACLC,KAAK,WACL,eAAcC,EAAgBpC,GAAW,QAAUA,EACnD,kBAAiBgB,EACjB,gBAAeb,EACf,aAAYkC,EAASrC,GACrB,gBAAeI,EAAW,QA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AE9B,GAAI7B,IAAgB7C,GAAWsB,EAAY,CACzC,MAAMoB,EAAQ,IAAIiC,MAAM,QAAS,CAAExB,QAAAA,IACnCiB,EAAMQ,cAAgBxC,EAAgBpC,GACtCsB,EAAWuD,KAAKT,GAAOhC,EAAgBpC,IAAmBA,GAC1DoE,EAAMU,cAAcpC,MAErB,CAACG,EAAa7C,EAASmD,iBAGxBxB,EAAAC,cAAA,QAAAK,EAAA,CACEC,KAAK,WACL,eAAA,EACAhC,gBAAgBkC,EAAgBpC,IAAmBA,GAC/C+D,EAJN,CAKEgB,UAAW,EACXxC,IAAKA,EACLa,MAAO,IACFzD,EAAMyD,SACNa,EACHe,SAAU,WACVnB,cAAe,OACfoB,QAAS,EACTC,OAAQ,OAMhB,SAAS9C,EAAgBpC,GACvB,MAAmB,kBAAZA,EAGT,SAASqC,EAASrC,GAChB,OAAOoC,EAAgBpC,GAAW,gBAAkBA,EAAU,UAAY,YAG5E,MAAMmF,EAAO3F,iBACb,MAAM4F,EAAY9B","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/checkbox/src/Checkbox.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { useLabelContext } from '@radix-ui/react-label';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ntype CheckboxContextValue = {\n state: CheckedState;\n disabled?: boolean;\n};\n\nconst [CheckboxProvider, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\ntype CheckboxElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState;\n defaultChecked?: CheckedState;\n required?: boolean;\n onCheckedChange?(checked: CheckedState): void;\n}\n\nconst Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(\n (props: ScopedProps<CheckboxProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...checkboxProps\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 <CheckboxProvider scope={__scopeCheckbox} state={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : 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 {...checkboxProps}\n ref={composedRefs}\n onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault();\n })}\n onClick={composeEventHandlers(props.onClick, (event) => {\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if checkbox 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 checkbox 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 </CheckboxProvider>\n );\n }\n);\n\nCheckbox.displayName = CHECKBOX_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst CheckboxIndicator = React.forwardRef<CheckboxIndicatorElement, CheckboxIndicatorProps>(\n (props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) => {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence present={forceMount || isIndeterminate(context.state) || context.state === true}>\n <Primitive.span\n data-state={getState(context.state)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n }\n);\n\nCheckboxIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: CheckedState;\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\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={isIndeterminate(checked) ? false : 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 isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Checkbox;\nconst Indicator = CheckboxIndicator;\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxIndicator,\n //\n Root,\n Indicator,\n};\nexport type { CheckboxProps, CheckboxIndicatorProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","createCheckboxContext","createCheckboxScope","createContextScope","CheckboxProvider","useCheckboxContext","Checkbox","React","forwardRef","props","forwardedRef","__scopeCheckbox","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","checkboxProps","button","setButton","useState","composedRefs","useComposedRefs","node","labelId","useLabelContext","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","useControllableState","prop","defaultProp","onChange","_react","createElement","$eabaedc2140e2004adabe568fc5$var$CheckboxProvider","scope","state","Primitive","_babelRuntimeHelpersExtends","type","role","isIndeterminate","getState","undefined","ref","onKeyDown","composeEventHandlers","event","preventDefault","onClick","prevChecked","current","isPropagationStopped","stopPropagation","$eabaedc2140e2004adabe568fc5$var$BubbleInput","control","bubbles","style","transform","CheckboxIndicator","forceMount","indicatorProps","context","Presence","present","span","pointerEvents","BubbleInput","inputProps","usePrevious","controlSize","useSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","getOwnPropertyDescriptor","set","Event","indeterminate","call","dispatchEvent","tabIndex","position","opacity","margin","Root","Indicator"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,2 @@
1
- import{Primitive as e}from"@radix-ui/react-primitive";import{Presence as t}from"@radix-ui/react-presence";import{useLabelContext as r}from"@radix-ui/react-label";import{useSize as o}from"@radix-ui/react-use-size";import{usePrevious as a}from"@radix-ui/react-use-previous";import{useControllableState as n}from"@radix-ui/react-use-controllable-state";import{composeEventHandlers as c}from"@radix-ui/primitive";import{createContextScope as i}from"@radix-ui/react-context";import{useComposedRefs as s}from"@radix-ui/react-compose-refs";import*as d from"react";import l from"@babel/runtime/helpers/esm/extends";const[u,p]=i("Checkbox");export{p as createCheckboxScope};const[m,b]=u("Checkbox");export const Checkbox=/*#__PURE__*/d.forwardRef(((t,o)=>{const{__scopeCheckbox:a,"aria-labelledby":i,name:u,checked:p,defaultChecked:b,required:k,disabled:C,value:v="on",onCheckedChange:y,...E}=t,[g,w]=d.useState(null),I=s(o,(e=>w(e))),R=r(g),P=i||R,_=d.useRef(!1),q=!g||Boolean(g.closest("form")),[M=!1,O]=n({prop:p,defaultProp:b,onChange:y});/*#__PURE__*/return d.createElement(m,{scope:a,state:M,disabled:C},/*#__PURE__*/d.createElement(e.button,l({type:"button",role:"checkbox","aria-checked":x(M)?"mixed":M,"aria-labelledby":P,"aria-required":k,"data-state":h(M),"data-disabled":C?"":void 0,disabled:C,value:v},E,{ref:I,onClick:c(t.onClick,(e=>{O((e=>!!x(e)||!e)),q&&(_.current=e.isPropagationStopped(),_.current||e.stopPropagation())}))})),q&&/*#__PURE__*/d.createElement(f,{control:g,bubbles:!_.current,name:u,value:v,checked:M,required:k,disabled:C,style:{transform:"translateX(-100%)"}}))}));/*#__PURE__*/export const CheckboxIndicator=/*#__PURE__*/d.forwardRef(((r,o)=>{const{__scopeCheckbox:a,forceMount:n,...c}=r,i=b("CheckboxIndicator",a);/*#__PURE__*/return d.createElement(t,{present:n||x(i.state)||!0===i.state},/*#__PURE__*/d.createElement(e.span,l({"data-state":h(i.state),"data-disabled":i.disabled?"":void 0},c,{ref:o,style:{pointerEvents:"none",...r.style}})))}));/*#__PURE__*/const f=e=>{const{control:t,checked:r,bubbles:n=!0,...c}=e,i=d.useRef(null),s=a(r),u=o(t);return d.useEffect((()=>{const e=i.current,t=window.HTMLInputElement.prototype,o=Object.getOwnPropertyDescriptor(t,"checked").set;if(s!==r&&o){const t=new Event("click",{bubbles:n});e.indeterminate=x(r),o.call(e,!x(r)&&r),e.dispatchEvent(t)}}),[s,r,n]),/*#__PURE__*/d.createElement("input",l({type:"checkbox","aria-hidden":!0,defaultChecked:!x(r)&&r},c,{tabIndex:-1,ref:i,style:{...e.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function x(e){return"indeterminate"===e}function h(e){return x(e)?"indeterminate":e?"checked":"unchecked"}export const Root=Checkbox;export const Indicator=CheckboxIndicator;
1
+ import{Primitive as e}from"@radix-ui/react-primitive";import{Presence as t}from"@radix-ui/react-presence";import{useLabelContext as r}from"@radix-ui/react-label";import{useSize as o}from"@radix-ui/react-use-size";import{usePrevious as a}from"@radix-ui/react-use-previous";import{useControllableState as n}from"@radix-ui/react-use-controllable-state";import{composeEventHandlers as c}from"@radix-ui/primitive";import{createContextScope as i}from"@radix-ui/react-context";import{useComposedRefs as s}from"@radix-ui/react-compose-refs";import*as d from"react";import l from"@babel/runtime/helpers/esm/extends";const[u,p]=i("Checkbox");export{p as createCheckboxScope};const[m,b]=u("Checkbox");export const Checkbox=/*#__PURE__*/d.forwardRef(((t,o)=>{const{__scopeCheckbox:a,"aria-labelledby":i,name:u,checked:p,defaultChecked:b,required:k,disabled:C,value:y="on",onCheckedChange:v,...E}=t,[w,g]=d.useState(null),I=s(o,(e=>g(e))),R=r(w),D=i||R,P=d.useRef(!1),_=!w||Boolean(w.closest("form")),[q=!1,K]=n({prop:p,defaultProp:b,onChange:v});/*#__PURE__*/return d.createElement(m,{scope:a,state:q,disabled:C},/*#__PURE__*/d.createElement(e.button,l({type:"button",role:"checkbox","aria-checked":x(q)?"mixed":q,"aria-labelledby":D,"aria-required":k,"data-state":h(q),"data-disabled":C?"":void 0,disabled:C,value:y},E,{ref:I,onKeyDown:c(t.onKeyDown,(e=>{"Enter"===e.key&&e.preventDefault()})),onClick:c(t.onClick,(e=>{K((e=>!!x(e)||!e)),_&&(P.current=e.isPropagationStopped(),P.current||e.stopPropagation())}))})),_&&/*#__PURE__*/d.createElement(f,{control:w,bubbles:!P.current,name:u,value:y,checked:q,required:k,disabled:C,style:{transform:"translateX(-100%)"}}))}));/*#__PURE__*/export const CheckboxIndicator=/*#__PURE__*/d.forwardRef(((r,o)=>{const{__scopeCheckbox:a,forceMount:n,...c}=r,i=b("CheckboxIndicator",a);/*#__PURE__*/return d.createElement(t,{present:n||x(i.state)||!0===i.state},/*#__PURE__*/d.createElement(e.span,l({"data-state":h(i.state),"data-disabled":i.disabled?"":void 0},c,{ref:o,style:{pointerEvents:"none",...r.style}})))}));/*#__PURE__*/const f=e=>{const{control:t,checked:r,bubbles:n=!0,...c}=e,i=d.useRef(null),s=a(r),u=o(t);return d.useEffect((()=>{const e=i.current,t=window.HTMLInputElement.prototype,o=Object.getOwnPropertyDescriptor(t,"checked").set;if(s!==r&&o){const t=new Event("click",{bubbles:n});e.indeterminate=x(r),o.call(e,!x(r)&&r),e.dispatchEvent(t)}}),[s,r,n]),/*#__PURE__*/d.createElement("input",l({type:"checkbox","aria-hidden":!0,defaultChecked:!x(r)&&r},c,{tabIndex:-1,ref:i,style:{...e.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function x(e){return"indeterminate"===e}function h(e){return x(e)?"indeterminate":e?"checked":"unchecked"}export const Root=Checkbox;export const Indicator=CheckboxIndicator;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"+lBAkBA,MAGOA,EAAuBC,GAAuBC,EAH/B,6CAYtB,MAAOC,EAAkBC,GACvBJ,EAboB,mBAwBtB,MAAMK,sBAAWC,EAAMC,YACrB,CAACC,EAAmCC,KAClC,MAAMC,gBACJA,EACA,kBAAmBC,EAFfC,KAGJA,EACAC,QAASC,EAJLC,eAKJA,EALIC,SAMJA,EANIC,SAOJA,EAPIC,MA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xB,oBACzEJ,EAAAC,cAACI,EAAU0B,KAAXzB,EAAA,CACE,aAAYI,EAASkB,EAAQxB,OAC7B,gBAAewB,EAAQnD,SAAW,QAAKkC,GACnCgB,EAHN,CAIEf,IAAK3C,EACLsD,MAAO,CAAES,cAAe,UAAWhE,EAAMuD,2BAkBnD,MAAMU,EAAejE,IACnB,MAAMqD,QAAEA,EAAFhD,QAAWA,EAAXiD,QAAoBA,GAAU,KAASY,GAAelE,EACtD4C,EAAM9C,EAAMyB,OAAyB,MACrCyB,EAAcmB,EAAY9D,GAC1B+D,EAAcC,EAAQhB,GAiB5B,OAdAvD,EAAMwE,WAAU,KACd,MAAMC,EAAQ3B,EAAIK,QACZuB,EAAaC,OAAOC,iBAAiBC,UAErChD,EADaiD,OAAOC,yBAAyBL,EAAY,WACjCM,IAE9B,GAAI9B,IAAgB3C,GAAWsB,EAAY,CACzC,MAAMoB,EAAQ,IAAIgC,MAAM,QAAS,CAAEzB,QAAAA,IACnCiB,EAAMS,cAAgBvC,EAAgBpC,GACtCsB,EAAWsD,KAAKV,GAAO9B,EAAgBpC,IAAmBA,GAC1DkE,EAAMW,cAAcnC,MAErB,CAACC,EAAa3C,EAASiD,iBAGxBtB,EAAAC,cAAA,QAAAK,EAAA,CACEC,KAAK,WACL,eAAA,EACAhC,gBAAgBkC,EAAgBpC,IAAmBA,GAC/C6D,EAJN,CAKEiB,UAAW,EACXvC,IAAKA,EACLW,MAAO,IACFvD,EAAMuD,SACNa,EACHgB,SAAU,WACVpB,cAAe,OACfqB,QAAS,EACTC,OAAQ,OAMhB,SAAS7C,EAAgBpC,GACvB,MAAmB,kBAAZA,EAGT,SAASqC,EAASrC,GAChB,OAAOoC,EAAgBpC,GAAW,gBAAkBA,EAAU,UAAY,mBAG5E,MAAMkF,KAAO1F,gBACb,MAAM2F,UAAY/B","sources":["./packages/react/checkbox/src/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { useLabelContext } from '@radix-ui/react-label';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ntype CheckboxContextValue = {\n state: CheckedState;\n disabled?: boolean;\n};\n\nconst [CheckboxProvider, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\ntype CheckboxElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState;\n defaultChecked?: CheckedState;\n required?: boolean;\n onCheckedChange?(checked: CheckedState): void;\n}\n\nconst Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(\n (props: ScopedProps<CheckboxProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...checkboxProps\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 <CheckboxProvider scope={__scopeCheckbox} state={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : 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 {...checkboxProps}\n ref={composedRefs}\n onClick={composeEventHandlers(props.onClick, (event) => {\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if checkbox 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 checkbox 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 </CheckboxProvider>\n );\n }\n);\n\nCheckbox.displayName = CHECKBOX_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst CheckboxIndicator = React.forwardRef<CheckboxIndicatorElement, CheckboxIndicatorProps>(\n (props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) => {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence present={forceMount || isIndeterminate(context.state) || context.state === true}>\n <Primitive.span\n data-state={getState(context.state)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n }\n);\n\nCheckboxIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: CheckedState;\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\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={isIndeterminate(checked) ? false : 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 isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Checkbox;\nconst Indicator = CheckboxIndicator;\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxIndicator,\n //\n Root,\n Indicator,\n};\nexport type { CheckboxProps, CheckboxIndicatorProps };\n"],"names":["createCheckboxContext","createCheckboxScope","createContextScope","CheckboxProvider","useCheckboxContext","Checkbox","React","forwardRef","props","forwardedRef","__scopeCheckbox","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","checkboxProps","button","setButton","useState","composedRefs","useComposedRefs","node","labelId","useLabelContext","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","useControllableState","prop","defaultProp","onChange","_react","createElement","$f07a3f5319a7ee6a4f4bbe0b3d490ca$var$CheckboxProvider","scope","state","Primitive","_babelRuntimeHelpersEsmExtends","type","role","isIndeterminate","getState","undefined","ref","onClick","composeEventHandlers","event","prevChecked","current","isPropagationStopped","stopPropagation","$f07a3f5319a7ee6a4f4bbe0b3d490ca$var$BubbleInput","control","bubbles","style","transform","CheckboxIndicator","forceMount","indicatorProps","context","Presence","present","span","pointerEvents","BubbleInput","inputProps","usePrevious","controlSize","useSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","Object","getOwnPropertyDescriptor","set","Event","indeterminate","call","dispatchEvent","tabIndex","position","opacity","margin","Root","Indicator"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"+lBAkBA,MAGOA,EAAuBC,GAAuBC,EAH/B,6CAYtB,MAAOC,EAAkBC,GACvBJ,EAboB,mBAwBtB,MAAMK,sBAAWC,EAAMC,YACrB,CAACC,EAAmCC,KAClC,MAAMC,gBACJA,EACA,kBAAmBC,EAFfC,KAGJA,EACAC,QAASC,EAJLC,eAKJA,EALIC,SAMJA,EANIC,SAOJA,EAPIC,MAQJA,EAAQ,KARJC,gBASJA,KACGC,GACDZ,G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';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { useLabelContext } from '@radix-ui/react-label';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\nconst CHECKBOX_NAME = 'Checkbox';\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope };\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);\n\ntype CheckedState = boolean | 'indeterminate';\n\ntype CheckboxContextValue = {\n state: CheckedState;\n disabled?: boolean;\n};\n\nconst [CheckboxProvider, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME);\n\ntype CheckboxElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface CheckboxProps extends Omit<PrimitiveButtonProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState;\n defaultChecked?: CheckedState;\n required?: boolean;\n onCheckedChange?(checked: CheckedState): void;\n}\n\nconst Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(\n (props: ScopedProps<CheckboxProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n 'aria-labelledby': ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n ...checkboxProps\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 <CheckboxProvider scope={__scopeCheckbox} state={checked} disabled={disabled}>\n <Primitive.button\n type=\"button\"\n role=\"checkbox\"\n aria-checked={isIndeterminate(checked) ? 'mixed' : 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 {...checkboxProps}\n ref={composedRefs}\n onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault();\n })}\n onClick={composeEventHandlers(props.onClick, (event) => {\n setChecked((prevChecked) => (isIndeterminate(prevChecked) ? true : !prevChecked));\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n // if checkbox 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 checkbox 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 </CheckboxProvider>\n );\n }\n);\n\nCheckbox.displayName = CHECKBOX_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator';\n\ntype CheckboxIndicatorElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface CheckboxIndicatorProps extends PrimitiveSpanProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst CheckboxIndicator = React.forwardRef<CheckboxIndicatorElement, CheckboxIndicatorProps>(\n (props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) => {\n const { __scopeCheckbox, forceMount, ...indicatorProps } = props;\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);\n return (\n <Presence present={forceMount || isIndeterminate(context.state) || context.state === true}>\n <Primitive.span\n data-state={getState(context.state)}\n data-disabled={context.disabled ? '' : undefined}\n {...indicatorProps}\n ref={forwardedRef}\n style={{ pointerEvents: 'none', ...props.style }}\n />\n </Presence>\n );\n }\n);\n\nCheckboxIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = Radix.ComponentPropsWithoutRef<'input'>;\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: CheckedState;\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\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles });\n input.indeterminate = isIndeterminate(checked);\n setChecked.call(input, isIndeterminate(checked) ? false : checked);\n input.dispatchEvent(event);\n }\n }, [prevChecked, checked, bubbles]);\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={isIndeterminate(checked) ? false : 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 isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate';\n}\n\nfunction getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';\n}\n\nconst Root = Checkbox;\nconst Indicator = CheckboxIndicator;\n\nexport {\n createCheckboxScope,\n //\n Checkbox,\n CheckboxIndicator,\n //\n Root,\n Indicator,\n};\nexport type { CheckboxProps, CheckboxIndicatorProps };\n"],"names":["createCheckboxContext","createCheckboxScope","createContextScope","CheckboxProvider","useCheckboxContext","Checkbox","React","forwardRef","props","forwardedRef","__scopeCheckbox","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","checkboxProps","button","setButton","useState","composedRefs","useComposedRefs","node","labelId","useLabelContext","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","useControllableState","prop","defaultProp","onChange","_react","createElement","$f07a3f5319a7ee6a4f4bbe0b3d490ca$var$CheckboxProvider","scope","state","Primitive","_babelRuntimeHelpersEsmExtends","type","role","isIndeterminate","getState","undefined","ref","onKeyDown","composeEventHandlers","event","key","preventDefault","onClick","prevChecked","current","isPropagationStopped","stopPropagation","$f07a3f5319a7ee6a4f4bbe0b3d490ca$var$BubbleInput","control","bubbles","style","transform","CheckboxIndicator","forceMount","indicatorProps","context","Presence","present","span","pointerEvents","BubbleInput","inputProps","usePrevious","controlSize","useSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","Object","getOwnPropertyDescriptor","set","Event","indeterminate","call","dispatchEvent","tabIndex","position","opacity","margin","Root","Indicator"],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-checkbox",
3
- "version": "0.1.5-rc.1",
3
+ "version": "0.1.5-rc.13",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -20,12 +20,12 @@
20
20
  "@radix-ui/primitive": "0.1.0",
21
21
  "@radix-ui/react-compose-refs": "0.1.0",
22
22
  "@radix-ui/react-context": "0.1.1",
23
- "@radix-ui/react-label": "0.1.4",
24
- "@radix-ui/react-presence": "0.1.1",
25
- "@radix-ui/react-primitive": "0.1.3",
23
+ "@radix-ui/react-label": "0.1.5-rc.13",
24
+ "@radix-ui/react-presence": "0.1.2-rc.5",
25
+ "@radix-ui/react-primitive": "0.1.4-rc.13",
26
26
  "@radix-ui/react-use-controllable-state": "0.1.0",
27
- "@radix-ui/react-use-previous": "0.1.1-rc.1",
28
- "@radix-ui/react-use-size": "0.1.0"
27
+ "@radix-ui/react-use-previous": "0.1.1-rc.13",
28
+ "@radix-ui/react-use-size": "0.1.1-rc.5"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "react": "^16.8 || ^17.0"