@radix-ui/react-checkbox 0.1.6-rc.1 → 0.1.6-rc.4

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,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"}
1
+ {"mappings":";;;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;;;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","packages/react/checkbox/src/index.ts"],"sourcesContent":[null,null,"export * from './Checkbox';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,194 @@
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;
1
+ var $dKOox$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
2
+ var $dKOox$react = require("react");
3
+ var $dKOox$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
4
+ var $dKOox$radixuireactcontext = require("@radix-ui/react-context");
5
+ var $dKOox$radixuiprimitive = require("@radix-ui/primitive");
6
+ var $dKOox$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
7
+ var $dKOox$radixuireactuseprevious = require("@radix-ui/react-use-previous");
8
+ var $dKOox$radixuireactusesize = require("@radix-ui/react-use-size");
9
+ var $dKOox$radixuireactlabel = require("@radix-ui/react-label");
10
+ var $dKOox$radixuireactpresence = require("@radix-ui/react-presence");
11
+ var $dKOox$radixuireactprimitive = require("@radix-ui/react-primitive");
12
+
13
+ function $parcel$exportWildcard(dest, source) {
14
+ Object.keys(source).forEach(function(key) {
15
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
16
+ return;
17
+ }
18
+
19
+ Object.defineProperty(dest, key, {
20
+ enumerable: true,
21
+ get: function get() {
22
+ return source[key];
23
+ }
24
+ });
25
+ });
26
+
27
+ return dest;
28
+ }
29
+ function $parcel$interopDefault(a) {
30
+ return a && a.__esModule ? a.default : a;
31
+ }
32
+ function $parcel$export(e, n, v, s) {
33
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
34
+ }
35
+ var $a17f2c9fbf2ccf8c$exports = {};
36
+
37
+ $parcel$export($a17f2c9fbf2ccf8c$exports, "createCheckboxScope", () => $a17f2c9fbf2ccf8c$export$b566c4ff5488ea01);
38
+ $parcel$export($a17f2c9fbf2ccf8c$exports, "Checkbox", () => $a17f2c9fbf2ccf8c$export$48513f6b9f8ce62d);
39
+ $parcel$export($a17f2c9fbf2ccf8c$exports, "CheckboxIndicator", () => $a17f2c9fbf2ccf8c$export$59aad738f51d1c05);
40
+ $parcel$export($a17f2c9fbf2ccf8c$exports, "Root", () => $a17f2c9fbf2ccf8c$export$be92b6f5f03c0fe9);
41
+ $parcel$export($a17f2c9fbf2ccf8c$exports, "Indicator", () => $a17f2c9fbf2ccf8c$export$adb584737d712b70);
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ /* -------------------------------------------------------------------------------------------------
54
+ * Checkbox
55
+ * -----------------------------------------------------------------------------------------------*/ const $a17f2c9fbf2ccf8c$var$CHECKBOX_NAME = 'Checkbox';
56
+ const [$a17f2c9fbf2ccf8c$var$createCheckboxContext, $a17f2c9fbf2ccf8c$export$b566c4ff5488ea01] = $dKOox$radixuireactcontext.createContextScope($a17f2c9fbf2ccf8c$var$CHECKBOX_NAME);
57
+ const [$a17f2c9fbf2ccf8c$var$CheckboxProvider, $a17f2c9fbf2ccf8c$var$useCheckboxContext] = $a17f2c9fbf2ccf8c$var$createCheckboxContext($a17f2c9fbf2ccf8c$var$CHECKBOX_NAME);
58
+ const $a17f2c9fbf2ccf8c$export$48513f6b9f8ce62d = /*#__PURE__*/ $dKOox$react.forwardRef((props, forwardedRef)=>{
59
+ const { __scopeCheckbox: __scopeCheckbox , 'aria-labelledby': ariaLabelledby , name: name , checked: checkedProp , defaultChecked: defaultChecked , required: required , disabled: disabled , value: value = 'on' , onCheckedChange: onCheckedChange , ...checkboxProps } = props;
60
+ const [button, setButton] = $dKOox$react.useState(null);
61
+ const composedRefs = $dKOox$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setButton(node)
62
+ );
63
+ const labelId = $dKOox$radixuireactlabel.useLabelContext(button);
64
+ const labelledBy = ariaLabelledby || labelId;
65
+ const hasConsumerStoppedPropagationRef = $dKOox$react.useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
66
+ const isFormControl = button ? Boolean(button.closest('form')) : true;
67
+ const [checked = false, setChecked] = $dKOox$radixuireactusecontrollablestate.useControllableState({
68
+ prop: checkedProp,
69
+ defaultProp: defaultChecked,
70
+ onChange: onCheckedChange
71
+ });
72
+ return /*#__PURE__*/ $dKOox$react.createElement($a17f2c9fbf2ccf8c$var$CheckboxProvider, {
73
+ scope: __scopeCheckbox,
74
+ state: checked,
75
+ disabled: disabled
76
+ }, /*#__PURE__*/ $dKOox$react.createElement($dKOox$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($dKOox$babelruntimehelpersextends))({
77
+ type: "button",
78
+ role: "checkbox",
79
+ "aria-checked": $a17f2c9fbf2ccf8c$var$isIndeterminate(checked) ? 'mixed' : checked,
80
+ "aria-labelledby": labelledBy,
81
+ "aria-required": required,
82
+ "data-state": $a17f2c9fbf2ccf8c$var$getState(checked),
83
+ "data-disabled": disabled ? '' : undefined,
84
+ disabled: disabled,
85
+ value: value
86
+ }, checkboxProps, {
87
+ ref: composedRefs,
88
+ onKeyDown: $dKOox$radixuiprimitive.composeEventHandlers(props.onKeyDown, (event)=>{
89
+ // According to WAI ARIA, Checkboxes don't activate on enter keypress
90
+ if (event.key === 'Enter') event.preventDefault();
91
+ }),
92
+ onClick: $dKOox$radixuiprimitive.composeEventHandlers(props.onClick, (event)=>{
93
+ setChecked((prevChecked)=>$a17f2c9fbf2ccf8c$var$isIndeterminate(prevChecked) ? true : !prevChecked
94
+ );
95
+ if (isFormControl) {
96
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if checkbox is in a form, stop propagation from the button so that we only propagate
97
+ // one click event (from the input). We propagate changes from an input so that native
98
+ // form validation works and form events reflect checkbox updates.
99
+ if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
100
+ }
101
+ })
102
+ })), isFormControl && /*#__PURE__*/ $dKOox$react.createElement($a17f2c9fbf2ccf8c$var$BubbleInput, {
103
+ control: button,
104
+ bubbles: !hasConsumerStoppedPropagationRef.current,
105
+ name: name,
106
+ value: value,
107
+ checked: checked,
108
+ required: required,
109
+ disabled: disabled // We transform because the input is absolutely positioned but we have
110
+ ,
111
+ style: {
112
+ transform: 'translateX(-100%)'
113
+ }
114
+ }));
115
+ });
116
+ /*#__PURE__*/ Object.assign($a17f2c9fbf2ccf8c$export$48513f6b9f8ce62d, {
117
+ displayName: $a17f2c9fbf2ccf8c$var$CHECKBOX_NAME
118
+ });
119
+ /* -------------------------------------------------------------------------------------------------
120
+ * CheckboxIndicator
121
+ * -----------------------------------------------------------------------------------------------*/ const $a17f2c9fbf2ccf8c$var$INDICATOR_NAME = 'CheckboxIndicator';
122
+ const $a17f2c9fbf2ccf8c$export$59aad738f51d1c05 = /*#__PURE__*/ $dKOox$react.forwardRef((props, forwardedRef)=>{
123
+ const { __scopeCheckbox: __scopeCheckbox , forceMount: forceMount , ...indicatorProps } = props;
124
+ const context = $a17f2c9fbf2ccf8c$var$useCheckboxContext($a17f2c9fbf2ccf8c$var$INDICATOR_NAME, __scopeCheckbox);
125
+ return /*#__PURE__*/ $dKOox$react.createElement($dKOox$radixuireactpresence.Presence, {
126
+ present: forceMount || $a17f2c9fbf2ccf8c$var$isIndeterminate(context.state) || context.state === true
127
+ }, /*#__PURE__*/ $dKOox$react.createElement($dKOox$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($dKOox$babelruntimehelpersextends))({
128
+ "data-state": $a17f2c9fbf2ccf8c$var$getState(context.state),
129
+ "data-disabled": context.disabled ? '' : undefined
130
+ }, indicatorProps, {
131
+ ref: forwardedRef,
132
+ style: {
133
+ pointerEvents: 'none',
134
+ ...props.style
135
+ }
136
+ })));
137
+ });
138
+ /*#__PURE__*/ Object.assign($a17f2c9fbf2ccf8c$export$59aad738f51d1c05, {
139
+ displayName: $a17f2c9fbf2ccf8c$var$INDICATOR_NAME
140
+ });
141
+ /* ---------------------------------------------------------------------------------------------- */ const $a17f2c9fbf2ccf8c$var$BubbleInput = (props)=>{
142
+ const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
143
+ const ref = $dKOox$react.useRef(null);
144
+ const prevChecked = $dKOox$radixuireactuseprevious.usePrevious(checked);
145
+ const controlSize = $dKOox$radixuireactusesize.useSize(control); // Bubble checked change to parents (e.g form change event)
146
+ $dKOox$react.useEffect(()=>{
147
+ const input = ref.current;
148
+ const inputProto = window.HTMLInputElement.prototype;
149
+ const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
150
+ const setChecked = descriptor.set;
151
+ if (prevChecked !== checked && setChecked) {
152
+ const event = new Event('click', {
153
+ bubbles: bubbles
154
+ });
155
+ input.indeterminate = $a17f2c9fbf2ccf8c$var$isIndeterminate(checked);
156
+ setChecked.call(input, $a17f2c9fbf2ccf8c$var$isIndeterminate(checked) ? false : checked);
157
+ input.dispatchEvent(event);
158
+ }
159
+ }, [
160
+ prevChecked,
161
+ checked,
162
+ bubbles
163
+ ]);
164
+ return /*#__PURE__*/ $dKOox$react.createElement("input", ($parcel$interopDefault($dKOox$babelruntimehelpersextends))({
165
+ type: "checkbox",
166
+ "aria-hidden": true,
167
+ defaultChecked: $a17f2c9fbf2ccf8c$var$isIndeterminate(checked) ? false : checked
168
+ }, inputProps, {
169
+ tabIndex: -1,
170
+ ref: ref,
171
+ style: {
172
+ ...props.style,
173
+ ...controlSize,
174
+ position: 'absolute',
175
+ pointerEvents: 'none',
176
+ opacity: 0,
177
+ margin: 0
178
+ }
179
+ }));
180
+ };
181
+ function $a17f2c9fbf2ccf8c$var$isIndeterminate(checked) {
182
+ return checked === 'indeterminate';
183
+ }
184
+ function $a17f2c9fbf2ccf8c$var$getState(checked) {
185
+ return $a17f2c9fbf2ccf8c$var$isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';
186
+ }
187
+ const $a17f2c9fbf2ccf8c$export$be92b6f5f03c0fe9 = $a17f2c9fbf2ccf8c$export$48513f6b9f8ce62d;
188
+ const $a17f2c9fbf2ccf8c$export$adb584737d712b70 = $a17f2c9fbf2ccf8c$export$59aad738f51d1c05;
189
+
190
+
191
+ $parcel$exportWildcard(module.exports, $a17f2c9fbf2ccf8c$exports);
192
+
193
+
2
194
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"IAYgCA,EAAMC,EAZNC,6eAYAF,K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,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
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;;ACcA;;oGAEA,CAEA,MAAMU,mCAAa,GAAG,UAAtB,AAAA;AAGA,MAAM,CAACC,2CAAD,EAAwBC,yCAAxB,CAAA,GAA+CV,6CAAkB,CAACQ,mCAAD,CAAvE,AAAA;AASA,MAAM,CAACG,sCAAD,EAAmBC,wCAAnB,CAAA,GAC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AAAA;SACD;KAXH,EAYG;QAACpB,WAAD;QAAchC,OAAd;QAAuB+C,OAAvB;KAZH,CAYC,CAAA;IAED,OAAA,aACE,CAAA,0BADF,CAAA,OAAA,EAAA,2DAAA,CAAA;QAEI,IAAI,EAAC,UADP;QAEE,aAAA,EAAA,IAFF;QAGE,cAAc,EAAEvB,qCAAe,CAACxB,OAAD,CAAf,GAA2B,KAA3B,GAAmCA,OAAnD;KAHF,EAIMgD,UAJN,EAAA;QAKE,QAAQ,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAGtD,KAAK,CAACiD,KADJ;YAEL,GAAGM,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILtB,aAAa,EAAE,MAJV;YAKLuB,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CAtBJ,AAuCC;AAED,SAAS3C,qCAAT,CAAyBxB,OAAzB,EAA6E;IAC3E,OAAOA,OAAO,KAAK,eAAnB,CAAA;CACD;AAED,SAASyB,8BAAT,CAAkBzB,OAAlB,EAAyC;IACvC,OAAOwB,qCAAe,CAACxB,OAAD,CAAf,GAA2B,eAA3B,GAA6CA,OAAO,GAAG,SAAH,GAAe,WAA1E,CAAA;CACD;AAED,MAAMoE,yCAAI,GAAG3E,yCAAb,AAAA;AACA,MAAM4E,yCAAS,GAAG/B,yCAAlB,AAAA;;ADvNA","sources":["packages/react/checkbox/src/index.ts","packages/react/checkbox/src/Checkbox.tsx"],"sourcesContent":["export * from './Checkbox';\n","import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { 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":["React","useComposedRefs","createContextScope","composeEventHandlers","useControllableState","usePrevious","useSize","useLabelContext","Presence","Primitive","CHECKBOX_NAME","createCheckboxContext","createCheckboxScope","CheckboxProvider","useCheckboxContext","Checkbox","forwardRef","props","forwardedRef","__scopeCheckbox","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","checkboxProps","button","setButton","useState","composedRefs","node","labelId","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","prop","defaultProp","onChange","isIndeterminate","getState","undefined","onKeyDown","event","key","preventDefault","onClick","prevChecked","current","isPropagationStopped","stopPropagation","transform","INDICATOR_NAME","CheckboxIndicator","forceMount","indicatorProps","context","state","pointerEvents","style","BubbleInput","control","bubbles","inputProps","ref","controlSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","set","Event","indeterminate","call","dispatchEvent","position","opacity","margin","Root","Indicator"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,175 @@
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;
1
+ import $1bpvS$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
+ import {forwardRef as $1bpvS$forwardRef, useState as $1bpvS$useState, useRef as $1bpvS$useRef, createElement as $1bpvS$createElement, useEffect as $1bpvS$useEffect} from "react";
3
+ import {useComposedRefs as $1bpvS$useComposedRefs} from "@radix-ui/react-compose-refs";
4
+ import {createContextScope as $1bpvS$createContextScope} from "@radix-ui/react-context";
5
+ import {composeEventHandlers as $1bpvS$composeEventHandlers} from "@radix-ui/primitive";
6
+ import {useControllableState as $1bpvS$useControllableState} from "@radix-ui/react-use-controllable-state";
7
+ import {usePrevious as $1bpvS$usePrevious} from "@radix-ui/react-use-previous";
8
+ import {useSize as $1bpvS$useSize} from "@radix-ui/react-use-size";
9
+ import {useLabelContext as $1bpvS$useLabelContext} from "@radix-ui/react-label";
10
+ import {Presence as $1bpvS$Presence} from "@radix-ui/react-presence";
11
+ import {Primitive as $1bpvS$Primitive} from "@radix-ui/react-primitive";
12
+
13
+ function $parcel$export(e, n, v, s) {
14
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
+ }
16
+ var $e698a72e93240346$exports = {};
17
+
18
+ $parcel$export($e698a72e93240346$exports, "createCheckboxScope", () => $e698a72e93240346$export$b566c4ff5488ea01);
19
+ $parcel$export($e698a72e93240346$exports, "Checkbox", () => $e698a72e93240346$export$48513f6b9f8ce62d);
20
+ $parcel$export($e698a72e93240346$exports, "CheckboxIndicator", () => $e698a72e93240346$export$59aad738f51d1c05);
21
+ $parcel$export($e698a72e93240346$exports, "Root", () => $e698a72e93240346$export$be92b6f5f03c0fe9);
22
+ $parcel$export($e698a72e93240346$exports, "Indicator", () => $e698a72e93240346$export$adb584737d712b70);
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ /* -------------------------------------------------------------------------------------------------
35
+ * Checkbox
36
+ * -----------------------------------------------------------------------------------------------*/ const $e698a72e93240346$var$CHECKBOX_NAME = 'Checkbox';
37
+ const [$e698a72e93240346$var$createCheckboxContext, $e698a72e93240346$export$b566c4ff5488ea01] = $1bpvS$createContextScope($e698a72e93240346$var$CHECKBOX_NAME);
38
+ const [$e698a72e93240346$var$CheckboxProvider, $e698a72e93240346$var$useCheckboxContext] = $e698a72e93240346$var$createCheckboxContext($e698a72e93240346$var$CHECKBOX_NAME);
39
+ const $e698a72e93240346$export$48513f6b9f8ce62d = /*#__PURE__*/ $1bpvS$forwardRef((props, forwardedRef)=>{
40
+ const { __scopeCheckbox: __scopeCheckbox , 'aria-labelledby': ariaLabelledby , name: name , checked: checkedProp , defaultChecked: defaultChecked , required: required , disabled: disabled , value: value = 'on' , onCheckedChange: onCheckedChange , ...checkboxProps } = props;
41
+ const [button, setButton] = $1bpvS$useState(null);
42
+ const composedRefs = $1bpvS$useComposedRefs(forwardedRef, (node)=>setButton(node)
43
+ );
44
+ const labelId = $1bpvS$useLabelContext(button);
45
+ const labelledBy = ariaLabelledby || labelId;
46
+ const hasConsumerStoppedPropagationRef = $1bpvS$useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
47
+ const isFormControl = button ? Boolean(button.closest('form')) : true;
48
+ const [checked = false, setChecked] = $1bpvS$useControllableState({
49
+ prop: checkedProp,
50
+ defaultProp: defaultChecked,
51
+ onChange: onCheckedChange
52
+ });
53
+ return /*#__PURE__*/ $1bpvS$createElement($e698a72e93240346$var$CheckboxProvider, {
54
+ scope: __scopeCheckbox,
55
+ state: checked,
56
+ disabled: disabled
57
+ }, /*#__PURE__*/ $1bpvS$createElement($1bpvS$Primitive.button, $1bpvS$babelruntimehelpersesmextends({
58
+ type: "button",
59
+ role: "checkbox",
60
+ "aria-checked": $e698a72e93240346$var$isIndeterminate(checked) ? 'mixed' : checked,
61
+ "aria-labelledby": labelledBy,
62
+ "aria-required": required,
63
+ "data-state": $e698a72e93240346$var$getState(checked),
64
+ "data-disabled": disabled ? '' : undefined,
65
+ disabled: disabled,
66
+ value: value
67
+ }, checkboxProps, {
68
+ ref: composedRefs,
69
+ onKeyDown: $1bpvS$composeEventHandlers(props.onKeyDown, (event)=>{
70
+ // According to WAI ARIA, Checkboxes don't activate on enter keypress
71
+ if (event.key === 'Enter') event.preventDefault();
72
+ }),
73
+ onClick: $1bpvS$composeEventHandlers(props.onClick, (event)=>{
74
+ setChecked((prevChecked)=>$e698a72e93240346$var$isIndeterminate(prevChecked) ? true : !prevChecked
75
+ );
76
+ if (isFormControl) {
77
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if checkbox is in a form, stop propagation from the button so that we only propagate
78
+ // one click event (from the input). We propagate changes from an input so that native
79
+ // form validation works and form events reflect checkbox updates.
80
+ if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
81
+ }
82
+ })
83
+ })), isFormControl && /*#__PURE__*/ $1bpvS$createElement($e698a72e93240346$var$BubbleInput, {
84
+ control: button,
85
+ bubbles: !hasConsumerStoppedPropagationRef.current,
86
+ name: name,
87
+ value: value,
88
+ checked: checked,
89
+ required: required,
90
+ disabled: disabled // We transform because the input is absolutely positioned but we have
91
+ ,
92
+ style: {
93
+ transform: 'translateX(-100%)'
94
+ }
95
+ }));
96
+ });
97
+ /*#__PURE__*/ Object.assign($e698a72e93240346$export$48513f6b9f8ce62d, {
98
+ displayName: $e698a72e93240346$var$CHECKBOX_NAME
99
+ });
100
+ /* -------------------------------------------------------------------------------------------------
101
+ * CheckboxIndicator
102
+ * -----------------------------------------------------------------------------------------------*/ const $e698a72e93240346$var$INDICATOR_NAME = 'CheckboxIndicator';
103
+ const $e698a72e93240346$export$59aad738f51d1c05 = /*#__PURE__*/ $1bpvS$forwardRef((props, forwardedRef)=>{
104
+ const { __scopeCheckbox: __scopeCheckbox , forceMount: forceMount , ...indicatorProps } = props;
105
+ const context = $e698a72e93240346$var$useCheckboxContext($e698a72e93240346$var$INDICATOR_NAME, __scopeCheckbox);
106
+ return /*#__PURE__*/ $1bpvS$createElement($1bpvS$Presence, {
107
+ present: forceMount || $e698a72e93240346$var$isIndeterminate(context.state) || context.state === true
108
+ }, /*#__PURE__*/ $1bpvS$createElement($1bpvS$Primitive.span, $1bpvS$babelruntimehelpersesmextends({
109
+ "data-state": $e698a72e93240346$var$getState(context.state),
110
+ "data-disabled": context.disabled ? '' : undefined
111
+ }, indicatorProps, {
112
+ ref: forwardedRef,
113
+ style: {
114
+ pointerEvents: 'none',
115
+ ...props.style
116
+ }
117
+ })));
118
+ });
119
+ /*#__PURE__*/ Object.assign($e698a72e93240346$export$59aad738f51d1c05, {
120
+ displayName: $e698a72e93240346$var$INDICATOR_NAME
121
+ });
122
+ /* ---------------------------------------------------------------------------------------------- */ const $e698a72e93240346$var$BubbleInput = (props)=>{
123
+ const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
124
+ const ref = $1bpvS$useRef(null);
125
+ const prevChecked = $1bpvS$usePrevious(checked);
126
+ const controlSize = $1bpvS$useSize(control); // Bubble checked change to parents (e.g form change event)
127
+ $1bpvS$useEffect(()=>{
128
+ const input = ref.current;
129
+ const inputProto = window.HTMLInputElement.prototype;
130
+ const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
131
+ const setChecked = descriptor.set;
132
+ if (prevChecked !== checked && setChecked) {
133
+ const event = new Event('click', {
134
+ bubbles: bubbles
135
+ });
136
+ input.indeterminate = $e698a72e93240346$var$isIndeterminate(checked);
137
+ setChecked.call(input, $e698a72e93240346$var$isIndeterminate(checked) ? false : checked);
138
+ input.dispatchEvent(event);
139
+ }
140
+ }, [
141
+ prevChecked,
142
+ checked,
143
+ bubbles
144
+ ]);
145
+ return /*#__PURE__*/ $1bpvS$createElement("input", $1bpvS$babelruntimehelpersesmextends({
146
+ type: "checkbox",
147
+ "aria-hidden": true,
148
+ defaultChecked: $e698a72e93240346$var$isIndeterminate(checked) ? false : checked
149
+ }, inputProps, {
150
+ tabIndex: -1,
151
+ ref: ref,
152
+ style: {
153
+ ...props.style,
154
+ ...controlSize,
155
+ position: 'absolute',
156
+ pointerEvents: 'none',
157
+ opacity: 0,
158
+ margin: 0
159
+ }
160
+ }));
161
+ };
162
+ function $e698a72e93240346$var$isIndeterminate(checked) {
163
+ return checked === 'indeterminate';
164
+ }
165
+ function $e698a72e93240346$var$getState(checked) {
166
+ return $e698a72e93240346$var$isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';
167
+ }
168
+ const $e698a72e93240346$export$be92b6f5f03c0fe9 = $e698a72e93240346$export$48513f6b9f8ce62d;
169
+ const $e698a72e93240346$export$adb584737d712b70 = $e698a72e93240346$export$59aad738f51d1c05;
170
+
171
+
172
+
173
+
174
+ export {$e698a72e93240346$export$b566c4ff5488ea01 as createCheckboxScope, $e698a72e93240346$export$48513f6b9f8ce62d as Checkbox, $e698a72e93240346$export$59aad738f51d1c05 as CheckboxIndicator, $e698a72e93240346$export$be92b6f5f03c0fe9 as Root, $e698a72e93240346$export$adb584737d712b70 as Indicator};
2
175
  //# 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,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,Y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AAEA,EAAFnD,QAAWA,EAAXoD,QAAoBA,GAAU,KAASY,GAAerE,EACtD4C,EAAM9C,EAAMyB,OAAyB,MACrC4B,EAAcmB,EAAYjE,GAC1BkE,EAAcC,EAAQhB,GAiB5B,OAdA1D,EAAM2E,WAAU,KACd,MAAMC,EAAQ9B,EAAIQ,QACZuB,EAAaC,OAAOC,iBAAiBC,UAErCnD,EADaoD,OAAOC,yBAAyBL,EAAY,WACjCM,IAE9B,GAAI9B,IAAgB9C,GAAWsB,EAAY,CACzC,MAAMoB,EAAQ,IAAImC,MAAM,QAAS,CAAEzB,QAAAA,IACnCiB,EAAMS,cAAgB1C,EAAgBpC,GACtCsB,EAAWyD,KAAKV,GAAOjC,EAAgBpC,IAAmBA,GAC1DqE,EAAMW,cAActC,MAErB,CAACI,EAAa9C,EAASoD,iBAGxBzB,EAAAC,cAAA,QAAAK,EAAA,CACEC,KAAK,WACL,eAAA,EACAhC,gBAAgBkC,EAAgBpC,IAAmBA,GAC/CgE,EAJN,CAKEiB,UAAW,EACX1C,IAAKA,EACLc,MAAO,IACF1D,EAAM0D,SACNa,EACHgB,SAAU,WACVpB,cAAe,OACfqB,QAAS,EACTC,OAAQ,OAMhB,SAAShD,EAAgBpC,GACvB,MAAmB,kBAAZA,EAGT,SAASqC,EAASrC,GAChB,OAAOoC,EAAgBpC,GAAW,gBAAkBA,EAAU,UAAY,mBAG5E,MAAMqF,KAAO7F,gBACb,MAAM8F,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 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"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;;ACcA;;oGAEA,CAEA,MAAMU,mCAAa,GAAG,UAAtB,AAAA;AAGA,MAAM,CAACC,2CAAD,EAAwBC,yCAAxB,CAAA,GAA+CV,yBAAkB,CAACQ,mCAAD,CAAvE,AAAA;AASA,MAAM,CAACG,sCAAD,EAAmBC,wCAAnB,CAAA,GACJH,2CAAqB,CAAuBD,mCAAvB,CADvB,AAAA;AAYA,MAAMK,yCAAQ,GAAA,aAAGf,CAAAA,iBAAA,CACf,CAACiB,KAAD,EAAoCC,YAApC,GAAqD;IACnD,MAAM,E,iBACJC,eADI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UADP;QAEE,aAAA,EAAA,IAFF;QAGE,cAAc,EAAEvB,qCAAe,CAACxB,OAAD,CAAf,GAA2B,KAA3B,GAAmCA,OAAnD;KAHF,EAIMgD,UAJN,EAAA;QAKE,QAAQ,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAGtD,KAAK,CAACiD,KADJ;YAEL,GAAGM,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILtB,aAAa,EAAE,MAJV;YAKLuB,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CAtBJ,AAuCC;AAED,SAAS3C,qCAAT,CAAyBxB,OAAzB,EAA6E;IAC3E,OAAOA,OAAO,KAAK,eAAnB,CAAA;CACD;AAED,SAASyB,8BAAT,CAAkBzB,OAAlB,EAAyC;IACvC,OAAOwB,qCAAe,CAACxB,OAAD,CAAf,GAA2B,eAA3B,GAA6CA,OAAO,GAAG,SAAH,GAAe,WAA1E,CAAA;CACD;AAED,MAAMoE,yCAAI,GAAG3E,yCAAb,AAAA;AACA,MAAM4E,yCAAS,GAAG/B,yCAAlB,AAAA;;ADvNA","sources":["packages/react/checkbox/src/index.ts","packages/react/checkbox/src/Checkbox.tsx"],"sourcesContent":["export * from './Checkbox';\n","import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { 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":["React","useComposedRefs","createContextScope","composeEventHandlers","useControllableState","usePrevious","useSize","useLabelContext","Presence","Primitive","CHECKBOX_NAME","createCheckboxContext","createCheckboxScope","CheckboxProvider","useCheckboxContext","Checkbox","forwardRef","props","forwardedRef","__scopeCheckbox","ariaLabelledby","name","checked","checkedProp","defaultChecked","required","disabled","value","onCheckedChange","checkboxProps","button","setButton","useState","composedRefs","node","labelId","labelledBy","hasConsumerStoppedPropagationRef","useRef","isFormControl","Boolean","closest","setChecked","prop","defaultProp","onChange","isIndeterminate","getState","undefined","onKeyDown","event","key","preventDefault","onClick","prevChecked","current","isPropagationStopped","stopPropagation","transform","INDICATOR_NAME","CheckboxIndicator","forceMount","indicatorProps","context","state","pointerEvents","style","BubbleInput","control","bubbles","inputProps","ref","controlSize","useEffect","input","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","set","Event","indeterminate","call","dispatchEvent","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.6-rc.1",
3
+ "version": "0.1.6-rc.4",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -18,17 +18,18 @@
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
20
  "@radix-ui/primitive": "0.1.0",
21
- "@radix-ui/react-compose-refs": "0.1.1-rc.1",
22
- "@radix-ui/react-context": "0.1.2-rc.1",
23
- "@radix-ui/react-label": "0.1.6-rc.1",
24
- "@radix-ui/react-presence": "0.1.3-rc.1",
25
- "@radix-ui/react-primitive": "0.1.5-rc.1",
26
- "@radix-ui/react-use-controllable-state": "0.1.1-rc.1",
27
- "@radix-ui/react-use-previous": "0.1.2-rc.1",
28
- "@radix-ui/react-use-size": "0.1.2-rc.1"
21
+ "@radix-ui/react-compose-refs": "0.1.1-rc.4",
22
+ "@radix-ui/react-context": "0.1.2-rc.4",
23
+ "@radix-ui/react-label": "0.1.6-rc.4",
24
+ "@radix-ui/react-presence": "0.1.3-rc.4",
25
+ "@radix-ui/react-primitive": "0.1.5-rc.4",
26
+ "@radix-ui/react-use-controllable-state": "0.1.1-rc.4",
27
+ "@radix-ui/react-use-previous": "0.1.2-rc.4",
28
+ "@radix-ui/react-use-size": "0.1.2-rc.4"
29
29
  },
30
30
  "peerDependencies": {
31
- "react": "^16.8 || ^17.0 || ^18.0"
31
+ "react": "^16.8 || ^17.0 || ^18.0",
32
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
32
33
  },
33
34
  "homepage": "https://radix-ui.com/primitives",
34
35
  "repository": {