@tamagui/checkbox 1.28.1 → 1.28.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Checkbox.js +130 -124
- package/dist/cjs/Checkbox.js.map +1 -1
- package/dist/esm/Checkbox.js +130 -124
- package/dist/esm/Checkbox.js.map +1 -1
- package/dist/jsx/Checkbox.js +117 -112
- package/dist/jsx/Checkbox.js.map +1 -1
- package/dist/jsx/Checkbox.mjs +117 -112
- package/dist/jsx/Checkbox.mjs.map +1 -1
- package/package.json +11 -11
- package/src/Checkbox.tsx +150 -142
- package/types/Checkbox.d.ts +10 -0
- package/types/Checkbox.d.ts.map +1 -1
package/dist/cjs/Checkbox.js
CHANGED
|
@@ -29,8 +29,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var Checkbox_exports = {};
|
|
30
30
|
__export(Checkbox_exports, {
|
|
31
31
|
BubbleInput: () => BubbleInput,
|
|
32
|
-
Checkbox: () =>
|
|
32
|
+
Checkbox: () => Checkbox2,
|
|
33
33
|
CheckboxFrame: () => CheckboxFrame,
|
|
34
|
+
CheckboxStyledContext: () => CheckboxStyledContext,
|
|
34
35
|
createCheckboxScope: () => createCheckboxScope,
|
|
35
36
|
getState: () => getState,
|
|
36
37
|
isIndeterminate: () => isIndeterminate
|
|
@@ -48,6 +49,10 @@ var import_label = require("@tamagui/label");
|
|
|
48
49
|
var import_stacks = require("@tamagui/stacks");
|
|
49
50
|
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
50
51
|
var React = __toESM(require("react"));
|
|
52
|
+
const CheckboxStyledContext = (0, import_core.createStyledContext)({
|
|
53
|
+
size: "$true",
|
|
54
|
+
scaleIcon: 1
|
|
55
|
+
});
|
|
51
56
|
function isIndeterminate(checked) {
|
|
52
57
|
return checked === "indeterminate";
|
|
53
58
|
}
|
|
@@ -101,7 +106,8 @@ const BubbleInput = (props) => {
|
|
|
101
106
|
const INDICATOR_NAME = "CheckboxIndicator";
|
|
102
107
|
const CheckboxIndicatorFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
103
108
|
// use Checkbox for easier themes
|
|
104
|
-
name: INDICATOR_NAME
|
|
109
|
+
name: INDICATOR_NAME,
|
|
110
|
+
context: CheckboxStyledContext
|
|
105
111
|
});
|
|
106
112
|
const CheckboxIndicator = CheckboxIndicatorFrame.extractable(
|
|
107
113
|
React.forwardRef(
|
|
@@ -114,7 +120,8 @@ const CheckboxIndicator = CheckboxIndicatorFrame.extractable(
|
|
|
114
120
|
...indicatorProps
|
|
115
121
|
} = props;
|
|
116
122
|
const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
|
|
117
|
-
const
|
|
123
|
+
const styledContext = React.useContext(CheckboxStyledContext);
|
|
124
|
+
const iconSize = (typeof styledContext.size === "number" ? styledContext.size * 0.65 : (0, import_font_size.getFontSize)(styledContext.size)) * styledContext.scaleIcon;
|
|
118
125
|
const theme = (0, import_core.useTheme)();
|
|
119
126
|
const getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({ size: iconSize, color: theme.color });
|
|
120
127
|
const childrens = React.Children.toArray(childrenProp);
|
|
@@ -145,6 +152,7 @@ const CHECKBOX_NAME = "Checkbox";
|
|
|
145
152
|
const CheckboxFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
146
153
|
name: CHECKBOX_NAME,
|
|
147
154
|
tag: "button",
|
|
155
|
+
context: CheckboxStyledContext,
|
|
148
156
|
variants: {
|
|
149
157
|
unstyled: {
|
|
150
158
|
false: {
|
|
@@ -179,142 +187,140 @@ const CheckboxFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
179
187
|
});
|
|
180
188
|
const [createCheckboxContext, createCheckboxScope] = (0, import_create_context.createContextScope)(CHECKBOX_NAME);
|
|
181
189
|
const [CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
const CheckboxComponent = CheckboxFrame.extractable(
|
|
191
|
+
React.forwardRef(function Checkbox(props, forwardedRef) {
|
|
192
|
+
const {
|
|
193
|
+
__scopeCheckbox,
|
|
194
|
+
labelledBy: ariaLabelledby,
|
|
195
|
+
name,
|
|
196
|
+
checked: checkedProp,
|
|
197
|
+
defaultChecked,
|
|
198
|
+
required,
|
|
199
|
+
scaleSize = 0.45,
|
|
200
|
+
sizeAdjust = 0,
|
|
201
|
+
disabled,
|
|
202
|
+
value = "on",
|
|
203
|
+
onCheckedChange,
|
|
204
|
+
native,
|
|
205
|
+
...checkboxProps
|
|
206
|
+
} = props;
|
|
207
|
+
const [button, setButton] = React.useState(null);
|
|
208
|
+
const composedRefs = (0, import_core.useComposedRefs)(forwardedRef, (node) => setButton(node));
|
|
209
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
210
|
+
const propsActive = (0, import_core.useProps)(props);
|
|
211
|
+
const isFormControl = import_core.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
212
|
+
const [checked = false, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
213
|
+
prop: checkedProp,
|
|
214
|
+
defaultProp: defaultChecked,
|
|
215
|
+
onChange: onCheckedChange
|
|
216
|
+
});
|
|
217
|
+
const styledContext = React.useContext(CheckboxStyledContext);
|
|
218
|
+
const adjustedSize = (0, import_core.getVariableValue)(
|
|
219
|
+
(0, import_get_token.getSize)(propsActive.size ?? (styledContext == null ? void 0 : styledContext.size) ?? "$true", {
|
|
220
|
+
shift: sizeAdjust
|
|
221
|
+
})
|
|
222
|
+
);
|
|
223
|
+
const size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize;
|
|
224
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
225
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
226
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
227
|
+
React.useEffect(() => {
|
|
228
|
+
if (!props.id)
|
|
229
|
+
return;
|
|
230
|
+
return (0, import_focusable.registerFocusable)(props.id, {
|
|
231
|
+
focusAndSelect: () => {
|
|
232
|
+
setChecked((x) => !x);
|
|
233
|
+
},
|
|
234
|
+
focus: () => {
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}, [props.id, setChecked]);
|
|
238
|
+
}
|
|
239
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxProvider, { scope: __scopeCheckbox, state: checked, disabled, children: import_core.isWeb && native ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
240
|
+
BubbleInput,
|
|
241
|
+
{
|
|
242
|
+
control: button,
|
|
243
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
188
244
|
name,
|
|
189
|
-
|
|
190
|
-
|
|
245
|
+
value,
|
|
246
|
+
checked,
|
|
191
247
|
required,
|
|
192
|
-
scaleIcon = 1,
|
|
193
|
-
scaleSize = 0.45,
|
|
194
|
-
sizeAdjust = 0,
|
|
195
248
|
disabled,
|
|
196
|
-
|
|
197
|
-
onCheckedChange,
|
|
198
|
-
native,
|
|
199
|
-
...checkboxProps
|
|
200
|
-
} = props;
|
|
201
|
-
const [button, setButton] = React.useState(null);
|
|
202
|
-
const composedRefs = (0, import_core.useComposedRefs)(forwardedRef, (node) => setButton(node));
|
|
203
|
-
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
204
|
-
const propsActive = (0, import_core.useProps)(props);
|
|
205
|
-
const isFormControl = import_core.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
206
|
-
const [checked = false, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
207
|
-
prop: checkedProp,
|
|
208
|
-
defaultProp: defaultChecked,
|
|
209
|
-
onChange: onCheckedChange
|
|
210
|
-
});
|
|
211
|
-
const adjustedSize = (0, import_core.getVariableValue)(
|
|
212
|
-
(0, import_get_token.getSize)(propsActive.size, {
|
|
213
|
-
shift: sizeAdjust
|
|
214
|
-
})
|
|
215
|
-
);
|
|
216
|
-
const size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize;
|
|
217
|
-
const labelId = (0, import_label.useLabelContext)(button);
|
|
218
|
-
const labelledBy = ariaLabelledby || labelId;
|
|
219
|
-
if (process.env.TAMAGUI_TARGET === "native") {
|
|
220
|
-
React.useEffect(() => {
|
|
221
|
-
if (!props.id)
|
|
222
|
-
return;
|
|
223
|
-
return (0, import_focusable.registerFocusable)(props.id, {
|
|
224
|
-
focusAndSelect: () => {
|
|
225
|
-
setChecked((x) => !x);
|
|
226
|
-
},
|
|
227
|
-
focus: () => {
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}, [props.id, setChecked]);
|
|
249
|
+
id: props.id
|
|
231
250
|
}
|
|
232
|
-
|
|
233
|
-
|
|
251
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
252
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
253
|
+
CheckboxFrame,
|
|
234
254
|
{
|
|
235
|
-
|
|
236
|
-
|
|
255
|
+
width: size,
|
|
256
|
+
height: size,
|
|
257
|
+
tag: "button",
|
|
258
|
+
role: "checkbox",
|
|
259
|
+
"aria-labelledby": labelledBy,
|
|
260
|
+
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
261
|
+
"aria-required": required,
|
|
262
|
+
"data-state": getState(checked),
|
|
263
|
+
"data-disabled": disabled ? "" : void 0,
|
|
237
264
|
disabled,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
265
|
+
...checkboxProps,
|
|
266
|
+
ref: composedRefs,
|
|
267
|
+
...import_core.isWeb && {
|
|
268
|
+
type: "button",
|
|
269
|
+
value,
|
|
270
|
+
onKeyDown: (0, import_core.composeEventHandlers)(
|
|
271
|
+
props.onKeyDown,
|
|
272
|
+
(event) => {
|
|
273
|
+
if (event.key === "Enter")
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
},
|
|
278
|
+
onPress: (0, import_core.composeEventHandlers)(props.onPress, (event) => {
|
|
279
|
+
setChecked(
|
|
280
|
+
(prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
|
|
281
|
+
);
|
|
282
|
+
if (isFormControl) {
|
|
283
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
284
|
+
if (!hasConsumerStoppedPropagationRef.current)
|
|
285
|
+
event.stopPropagation();
|
|
286
|
+
}
|
|
287
|
+
}),
|
|
288
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
289
|
+
CheckboxStyledContext.Provider,
|
|
242
290
|
{
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
value,
|
|
247
|
-
checked,
|
|
248
|
-
required,
|
|
249
|
-
disabled,
|
|
250
|
-
id: props.id
|
|
291
|
+
size: propsActive.size ?? (styledContext == null ? void 0 : styledContext.size) ?? "$true",
|
|
292
|
+
scaleIcon: props.scaleIcon ?? (styledContext == null ? void 0 : styledContext.scaleIcon) ?? 1,
|
|
293
|
+
children: propsActive.children
|
|
251
294
|
}
|
|
252
|
-
)
|
|
253
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
254
|
-
CheckboxFrame,
|
|
255
|
-
{
|
|
256
|
-
width: size,
|
|
257
|
-
height: size,
|
|
258
|
-
tag: "button",
|
|
259
|
-
role: "checkbox",
|
|
260
|
-
"aria-labelledby": labelledBy,
|
|
261
|
-
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
262
|
-
"aria-required": required,
|
|
263
|
-
"data-state": getState(checked),
|
|
264
|
-
"data-disabled": disabled ? "" : void 0,
|
|
265
|
-
disabled,
|
|
266
|
-
...checkboxProps,
|
|
267
|
-
ref: composedRefs,
|
|
268
|
-
...import_core.isWeb && {
|
|
269
|
-
type: "button",
|
|
270
|
-
value,
|
|
271
|
-
onKeyDown: (0, import_core.composeEventHandlers)(
|
|
272
|
-
props.onKeyDown,
|
|
273
|
-
(event) => {
|
|
274
|
-
if (event.key === "Enter")
|
|
275
|
-
event.preventDefault();
|
|
276
|
-
}
|
|
277
|
-
)
|
|
278
|
-
},
|
|
279
|
-
onPress: (0, import_core.composeEventHandlers)(props.onPress, (event) => {
|
|
280
|
-
setChecked(
|
|
281
|
-
(prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
|
|
282
|
-
);
|
|
283
|
-
if (isFormControl) {
|
|
284
|
-
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
285
|
-
if (!hasConsumerStoppedPropagationRef.current)
|
|
286
|
-
event.stopPropagation();
|
|
287
|
-
}
|
|
288
|
-
})
|
|
289
|
-
}
|
|
290
|
-
),
|
|
291
|
-
import_core.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
292
|
-
BubbleInput,
|
|
293
|
-
{
|
|
294
|
-
isHidden: true,
|
|
295
|
-
control: button,
|
|
296
|
-
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
297
|
-
name,
|
|
298
|
-
value,
|
|
299
|
-
checked,
|
|
300
|
-
required,
|
|
301
|
-
disabled
|
|
302
|
-
}
|
|
303
|
-
) : null
|
|
304
|
-
] })
|
|
295
|
+
)
|
|
305
296
|
}
|
|
306
|
-
)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
297
|
+
),
|
|
298
|
+
import_core.isWeb && isFormControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
299
|
+
BubbleInput,
|
|
300
|
+
{
|
|
301
|
+
isHidden: true,
|
|
302
|
+
control: button,
|
|
303
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
304
|
+
name,
|
|
305
|
+
value,
|
|
306
|
+
checked,
|
|
307
|
+
required,
|
|
308
|
+
disabled
|
|
309
|
+
}
|
|
310
|
+
) : null
|
|
311
|
+
] }) });
|
|
312
|
+
})
|
|
312
313
|
);
|
|
314
|
+
const Checkbox2 = (0, import_core.withStaticProperties)(CheckboxComponent, {
|
|
315
|
+
Indicator: CheckboxIndicator,
|
|
316
|
+
Props: CheckboxStyledContext.Provider
|
|
317
|
+
});
|
|
313
318
|
// Annotate the CommonJS export names for ESM import in node:
|
|
314
319
|
0 && (module.exports = {
|
|
315
320
|
BubbleInput,
|
|
316
321
|
Checkbox,
|
|
317
322
|
CheckboxFrame,
|
|
323
|
+
CheckboxStyledContext,
|
|
318
324
|
createCheckboxScope,
|
|
319
325
|
getState,
|
|
320
326
|
isIndeterminate
|
package/dist/cjs/Checkbox.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Checkbox.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,kBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8EI;AA3EJ,gCAA4B;AAC5B,kBAaO;AAEP,4BAAmC;AACnC,uBAAkC;AAClC,uBAA4B;AAC5B,uBAA2C;AAC3C,6BAAiC;AACjC,mBAAgC;AAChC,oBAA+B;AAC/B,oCAAqC;AACrC,YAAuB;AAEhB,MAAM,4BAAwB,iCAAoB;AAAA,EACvD,MAAM;AAAA,EACN,WAAW;AACb,CAAC;AAIM,SAAS,gBAAgB,SAAoD;AAClF,SAAO,YAAY;AACrB;AAEO,SAAS,SAAS,SAAuB;AAC9C,SAAO,gBAAgB,OAAO,IAAI,kBAAkB,UAAU,YAAY;AAC5E;AAWO,MAAM,cAAc,CAAC,UAA4B;AACtD,QAAM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ACzC;AACA,gBAAI,eAAe;AACjB,+CAAiC,UAAU,MAAM,qBAAqB;AAItE,kBAAI,CAAC,iCAAiC;AAAS,sBAAM,gBAAgB;AAAA,YACvE;AAAA,UACF,CAAC;AAAA,UAED;AAAA,YAAC,sBAAsB;AAAA,YAAtB;AAAA,cACC,MAAM,YAAY,SAAQ,+CAAe,SAAQ;AAAA,cACjD,WAAW,MAAM,cAAa,+CAAe,cAAa;AAAA,cAEzD,sBAAY;AAAA;AAAA,UACf;AAAA;AAAA,MACF;AAAA,MAEC,qBAAS,gBACR;AAAA,QAAC;AAAA;AAAA,UACC,UAAQ;AAAA,UACR,SAAS;AAAA,UACT,SAAS,CAAC,iCAAiC;AAAA,UAC3C;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACF,IACE;AAAA,OACN,GAEJ;AAAA,EAEJ,CAAC;AACH;AAEO,MAAMA,gBAAW,kCAAqB,mBAAmB;AAAA,EAC9D,WAAW;AAAA,EACX,OAAO,sBAAsB;AAC/B,CAAC;",
|
|
5
5
|
"names": ["Checkbox"]
|
|
6
6
|
}
|
package/dist/esm/Checkbox.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { usePrevious } from "@radix-ui/react-use-previous";
|
|
3
3
|
import {
|
|
4
4
|
composeEventHandlers,
|
|
5
|
+
createStyledContext,
|
|
5
6
|
getVariableValue,
|
|
6
7
|
isWeb,
|
|
7
8
|
styled,
|
|
@@ -19,6 +20,10 @@ import { useLabelContext } from "@tamagui/label";
|
|
|
19
20
|
import { ThemeableStack } from "@tamagui/stacks";
|
|
20
21
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
21
22
|
import * as React from "react";
|
|
23
|
+
const CheckboxStyledContext = createStyledContext({
|
|
24
|
+
size: "$true",
|
|
25
|
+
scaleIcon: 1
|
|
26
|
+
});
|
|
22
27
|
function isIndeterminate(checked) {
|
|
23
28
|
return checked === "indeterminate";
|
|
24
29
|
}
|
|
@@ -72,7 +77,8 @@ const BubbleInput = (props) => {
|
|
|
72
77
|
const INDICATOR_NAME = "CheckboxIndicator";
|
|
73
78
|
const CheckboxIndicatorFrame = styled(ThemeableStack, {
|
|
74
79
|
// use Checkbox for easier themes
|
|
75
|
-
name: INDICATOR_NAME
|
|
80
|
+
name: INDICATOR_NAME,
|
|
81
|
+
context: CheckboxStyledContext
|
|
76
82
|
});
|
|
77
83
|
const CheckboxIndicator = CheckboxIndicatorFrame.extractable(
|
|
78
84
|
React.forwardRef(
|
|
@@ -85,7 +91,8 @@ const CheckboxIndicator = CheckboxIndicatorFrame.extractable(
|
|
|
85
91
|
...indicatorProps
|
|
86
92
|
} = props;
|
|
87
93
|
const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
|
|
88
|
-
const
|
|
94
|
+
const styledContext = React.useContext(CheckboxStyledContext);
|
|
95
|
+
const iconSize = (typeof styledContext.size === "number" ? styledContext.size * 0.65 : getFontSize(styledContext.size)) * styledContext.scaleIcon;
|
|
89
96
|
const theme = useTheme();
|
|
90
97
|
const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color });
|
|
91
98
|
const childrens = React.Children.toArray(childrenProp);
|
|
@@ -116,6 +123,7 @@ const CHECKBOX_NAME = "Checkbox";
|
|
|
116
123
|
const CheckboxFrame = styled(ThemeableStack, {
|
|
117
124
|
name: CHECKBOX_NAME,
|
|
118
125
|
tag: "button",
|
|
126
|
+
context: CheckboxStyledContext,
|
|
119
127
|
variants: {
|
|
120
128
|
unstyled: {
|
|
121
129
|
false: {
|
|
@@ -150,141 +158,139 @@ const CheckboxFrame = styled(ThemeableStack, {
|
|
|
150
158
|
});
|
|
151
159
|
const [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);
|
|
152
160
|
const [CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
const CheckboxComponent = CheckboxFrame.extractable(
|
|
162
|
+
React.forwardRef(function Checkbox(props, forwardedRef) {
|
|
163
|
+
const {
|
|
164
|
+
__scopeCheckbox,
|
|
165
|
+
labelledBy: ariaLabelledby,
|
|
166
|
+
name,
|
|
167
|
+
checked: checkedProp,
|
|
168
|
+
defaultChecked,
|
|
169
|
+
required,
|
|
170
|
+
scaleSize = 0.45,
|
|
171
|
+
sizeAdjust = 0,
|
|
172
|
+
disabled,
|
|
173
|
+
value = "on",
|
|
174
|
+
onCheckedChange,
|
|
175
|
+
native,
|
|
176
|
+
...checkboxProps
|
|
177
|
+
} = props;
|
|
178
|
+
const [button, setButton] = React.useState(null);
|
|
179
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
|
|
180
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
181
|
+
const propsActive = useProps(props);
|
|
182
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
183
|
+
const [checked = false, setChecked] = useControllableState({
|
|
184
|
+
prop: checkedProp,
|
|
185
|
+
defaultProp: defaultChecked,
|
|
186
|
+
onChange: onCheckedChange
|
|
187
|
+
});
|
|
188
|
+
const styledContext = React.useContext(CheckboxStyledContext);
|
|
189
|
+
const adjustedSize = getVariableValue(
|
|
190
|
+
getSize(propsActive.size ?? (styledContext == null ? void 0 : styledContext.size) ?? "$true", {
|
|
191
|
+
shift: sizeAdjust
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
const size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize;
|
|
195
|
+
const labelId = useLabelContext(button);
|
|
196
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
197
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
198
|
+
React.useEffect(() => {
|
|
199
|
+
if (!props.id)
|
|
200
|
+
return;
|
|
201
|
+
return registerFocusable(props.id, {
|
|
202
|
+
focusAndSelect: () => {
|
|
203
|
+
setChecked((x) => !x);
|
|
204
|
+
},
|
|
205
|
+
focus: () => {
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}, [props.id, setChecked]);
|
|
209
|
+
}
|
|
210
|
+
return /* @__PURE__ */ jsx(CheckboxProvider, { scope: __scopeCheckbox, state: checked, disabled, children: isWeb && native ? /* @__PURE__ */ jsx(
|
|
211
|
+
BubbleInput,
|
|
212
|
+
{
|
|
213
|
+
control: button,
|
|
214
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
159
215
|
name,
|
|
160
|
-
|
|
161
|
-
|
|
216
|
+
value,
|
|
217
|
+
checked,
|
|
162
218
|
required,
|
|
163
|
-
scaleIcon = 1,
|
|
164
|
-
scaleSize = 0.45,
|
|
165
|
-
sizeAdjust = 0,
|
|
166
219
|
disabled,
|
|
167
|
-
|
|
168
|
-
onCheckedChange,
|
|
169
|
-
native,
|
|
170
|
-
...checkboxProps
|
|
171
|
-
} = props;
|
|
172
|
-
const [button, setButton] = React.useState(null);
|
|
173
|
-
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
|
|
174
|
-
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
175
|
-
const propsActive = useProps(props);
|
|
176
|
-
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
177
|
-
const [checked = false, setChecked] = useControllableState({
|
|
178
|
-
prop: checkedProp,
|
|
179
|
-
defaultProp: defaultChecked,
|
|
180
|
-
onChange: onCheckedChange
|
|
181
|
-
});
|
|
182
|
-
const adjustedSize = getVariableValue(
|
|
183
|
-
getSize(propsActive.size, {
|
|
184
|
-
shift: sizeAdjust
|
|
185
|
-
})
|
|
186
|
-
);
|
|
187
|
-
const size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize;
|
|
188
|
-
const labelId = useLabelContext(button);
|
|
189
|
-
const labelledBy = ariaLabelledby || labelId;
|
|
190
|
-
if (process.env.TAMAGUI_TARGET === "native") {
|
|
191
|
-
React.useEffect(() => {
|
|
192
|
-
if (!props.id)
|
|
193
|
-
return;
|
|
194
|
-
return registerFocusable(props.id, {
|
|
195
|
-
focusAndSelect: () => {
|
|
196
|
-
setChecked((x) => !x);
|
|
197
|
-
},
|
|
198
|
-
focus: () => {
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}, [props.id, setChecked]);
|
|
220
|
+
id: props.id
|
|
202
221
|
}
|
|
203
|
-
|
|
204
|
-
|
|
222
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
223
|
+
/* @__PURE__ */ jsx(
|
|
224
|
+
CheckboxFrame,
|
|
205
225
|
{
|
|
206
|
-
|
|
207
|
-
|
|
226
|
+
width: size,
|
|
227
|
+
height: size,
|
|
228
|
+
tag: "button",
|
|
229
|
+
role: "checkbox",
|
|
230
|
+
"aria-labelledby": labelledBy,
|
|
231
|
+
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
232
|
+
"aria-required": required,
|
|
233
|
+
"data-state": getState(checked),
|
|
234
|
+
"data-disabled": disabled ? "" : void 0,
|
|
208
235
|
disabled,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
236
|
+
...checkboxProps,
|
|
237
|
+
ref: composedRefs,
|
|
238
|
+
...isWeb && {
|
|
239
|
+
type: "button",
|
|
240
|
+
value,
|
|
241
|
+
onKeyDown: composeEventHandlers(
|
|
242
|
+
props.onKeyDown,
|
|
243
|
+
(event) => {
|
|
244
|
+
if (event.key === "Enter")
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
},
|
|
249
|
+
onPress: composeEventHandlers(props.onPress, (event) => {
|
|
250
|
+
setChecked(
|
|
251
|
+
(prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
|
|
252
|
+
);
|
|
253
|
+
if (isFormControl) {
|
|
254
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
255
|
+
if (!hasConsumerStoppedPropagationRef.current)
|
|
256
|
+
event.stopPropagation();
|
|
257
|
+
}
|
|
258
|
+
}),
|
|
259
|
+
children: /* @__PURE__ */ jsx(
|
|
260
|
+
CheckboxStyledContext.Provider,
|
|
213
261
|
{
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
value,
|
|
218
|
-
checked,
|
|
219
|
-
required,
|
|
220
|
-
disabled,
|
|
221
|
-
id: props.id
|
|
262
|
+
size: propsActive.size ?? (styledContext == null ? void 0 : styledContext.size) ?? "$true",
|
|
263
|
+
scaleIcon: props.scaleIcon ?? (styledContext == null ? void 0 : styledContext.scaleIcon) ?? 1,
|
|
264
|
+
children: propsActive.children
|
|
222
265
|
}
|
|
223
|
-
)
|
|
224
|
-
/* @__PURE__ */ jsx(
|
|
225
|
-
CheckboxFrame,
|
|
226
|
-
{
|
|
227
|
-
width: size,
|
|
228
|
-
height: size,
|
|
229
|
-
tag: "button",
|
|
230
|
-
role: "checkbox",
|
|
231
|
-
"aria-labelledby": labelledBy,
|
|
232
|
-
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
233
|
-
"aria-required": required,
|
|
234
|
-
"data-state": getState(checked),
|
|
235
|
-
"data-disabled": disabled ? "" : void 0,
|
|
236
|
-
disabled,
|
|
237
|
-
...checkboxProps,
|
|
238
|
-
ref: composedRefs,
|
|
239
|
-
...isWeb && {
|
|
240
|
-
type: "button",
|
|
241
|
-
value,
|
|
242
|
-
onKeyDown: composeEventHandlers(
|
|
243
|
-
props.onKeyDown,
|
|
244
|
-
(event) => {
|
|
245
|
-
if (event.key === "Enter")
|
|
246
|
-
event.preventDefault();
|
|
247
|
-
}
|
|
248
|
-
)
|
|
249
|
-
},
|
|
250
|
-
onPress: composeEventHandlers(props.onPress, (event) => {
|
|
251
|
-
setChecked(
|
|
252
|
-
(prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
|
|
253
|
-
);
|
|
254
|
-
if (isFormControl) {
|
|
255
|
-
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
256
|
-
if (!hasConsumerStoppedPropagationRef.current)
|
|
257
|
-
event.stopPropagation();
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
}
|
|
261
|
-
),
|
|
262
|
-
isWeb && isFormControl ? /* @__PURE__ */ jsx(
|
|
263
|
-
BubbleInput,
|
|
264
|
-
{
|
|
265
|
-
isHidden: true,
|
|
266
|
-
control: button,
|
|
267
|
-
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
268
|
-
name,
|
|
269
|
-
value,
|
|
270
|
-
checked,
|
|
271
|
-
required,
|
|
272
|
-
disabled
|
|
273
|
-
}
|
|
274
|
-
) : null
|
|
275
|
-
] })
|
|
266
|
+
)
|
|
276
267
|
}
|
|
277
|
-
)
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
268
|
+
),
|
|
269
|
+
isWeb && isFormControl ? /* @__PURE__ */ jsx(
|
|
270
|
+
BubbleInput,
|
|
271
|
+
{
|
|
272
|
+
isHidden: true,
|
|
273
|
+
control: button,
|
|
274
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
275
|
+
name,
|
|
276
|
+
value,
|
|
277
|
+
checked,
|
|
278
|
+
required,
|
|
279
|
+
disabled
|
|
280
|
+
}
|
|
281
|
+
) : null
|
|
282
|
+
] }) });
|
|
283
|
+
})
|
|
283
284
|
);
|
|
285
|
+
const Checkbox2 = withStaticProperties(CheckboxComponent, {
|
|
286
|
+
Indicator: CheckboxIndicator,
|
|
287
|
+
Props: CheckboxStyledContext.Provider
|
|
288
|
+
});
|
|
284
289
|
export {
|
|
285
290
|
BubbleInput,
|
|
286
|
-
Checkbox,
|
|
291
|
+
Checkbox2 as Checkbox,
|
|
287
292
|
CheckboxFrame,
|
|
293
|
+
CheckboxStyledContext,
|
|
288
294
|
createCheckboxScope,
|
|
289
295
|
getState,
|
|
290
296
|
isIndeterminate
|