@tamagui/checkbox 1.88.13 → 1.89.0-1706308641099
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/esm/Checkbox.mjs +253 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/jsx/Checkbox.mjs +253 -0
- package/dist/jsx/index.mjs +1 -0
- package/package.json +15 -15
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb } from "@tamagui/constants";
|
|
3
|
+
import { createStyledContext, getVariableValue, styled, useProps, useTheme } from "@tamagui/core";
|
|
4
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
5
|
+
import { getFontSize } from "@tamagui/font-size";
|
|
6
|
+
import { getSize } from "@tamagui/get-token";
|
|
7
|
+
import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
|
|
8
|
+
import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
|
|
9
|
+
import { useLabelContext } from "@tamagui/label";
|
|
10
|
+
import { ButtonNestingContext, ThemeableStack } from "@tamagui/stacks";
|
|
11
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
12
|
+
import { usePrevious } from "@tamagui/use-previous";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
const CheckboxStyledContext = createStyledContext({
|
|
16
|
+
size: "$true",
|
|
17
|
+
scaleIcon: 1
|
|
18
|
+
});
|
|
19
|
+
function isIndeterminate(checked) {
|
|
20
|
+
return checked === "indeterminate";
|
|
21
|
+
}
|
|
22
|
+
function getState(checked) {
|
|
23
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
24
|
+
}
|
|
25
|
+
const BubbleInput = props => {
|
|
26
|
+
const {
|
|
27
|
+
checked,
|
|
28
|
+
bubbles = !0,
|
|
29
|
+
control,
|
|
30
|
+
isHidden,
|
|
31
|
+
...inputProps
|
|
32
|
+
} = props,
|
|
33
|
+
ref = React.useRef(null),
|
|
34
|
+
prevChecked = usePrevious(checked);
|
|
35
|
+
return React.useEffect(() => {
|
|
36
|
+
const input = ref.current,
|
|
37
|
+
inputProto = window.HTMLInputElement.prototype,
|
|
38
|
+
setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
39
|
+
if (prevChecked !== checked && setChecked) {
|
|
40
|
+
const event = new Event("click", {
|
|
41
|
+
bubbles
|
|
42
|
+
});
|
|
43
|
+
input.indeterminate = isIndeterminate(checked), setChecked.call(input, isIndeterminate(checked) ? !1 : checked), input.dispatchEvent(event);
|
|
44
|
+
}
|
|
45
|
+
}, [prevChecked, checked, bubbles]), /* @__PURE__ */jsx("input", {
|
|
46
|
+
type: "checkbox",
|
|
47
|
+
defaultChecked: isIndeterminate(checked) ? !1 : checked,
|
|
48
|
+
...inputProps,
|
|
49
|
+
tabIndex: -1,
|
|
50
|
+
ref,
|
|
51
|
+
"aria-hidden": isHidden,
|
|
52
|
+
style: {
|
|
53
|
+
...(isHidden ? {
|
|
54
|
+
// ...controlSize,
|
|
55
|
+
position: "absolute",
|
|
56
|
+
pointerEvents: "none",
|
|
57
|
+
opacity: 0,
|
|
58
|
+
margin: 0
|
|
59
|
+
} : {
|
|
60
|
+
appearance: "auto",
|
|
61
|
+
accentColor: "var(--color6)"
|
|
62
|
+
}),
|
|
63
|
+
...props.style
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
INDICATOR_NAME = "CheckboxIndicator",
|
|
68
|
+
CheckboxIndicatorFrame = styled(ThemeableStack, {
|
|
69
|
+
// use Checkbox for easier themes
|
|
70
|
+
name: INDICATOR_NAME,
|
|
71
|
+
context: CheckboxStyledContext
|
|
72
|
+
}),
|
|
73
|
+
CheckboxIndicator = CheckboxIndicatorFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
74
|
+
const {
|
|
75
|
+
__scopeCheckbox,
|
|
76
|
+
children: childrenProp,
|
|
77
|
+
forceMount,
|
|
78
|
+
disablePassStyles,
|
|
79
|
+
...indicatorProps
|
|
80
|
+
} = props;
|
|
81
|
+
process.env.NODE_ENV === "development" && !childrenProp && console.warn("Warning: You created a Checkbox.Indicator without passing an child prop for it to use as an icon.");
|
|
82
|
+
const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox),
|
|
83
|
+
styledContext = React.useContext(CheckboxStyledContext),
|
|
84
|
+
iconSize = (typeof styledContext.size == "number" ? styledContext.size * 0.65 : getFontSize(styledContext.size)) * styledContext.scaleIcon,
|
|
85
|
+
theme = useTheme(),
|
|
86
|
+
getThemedIcon = useGetThemedIcon({
|
|
87
|
+
size: iconSize,
|
|
88
|
+
color: theme.color
|
|
89
|
+
}),
|
|
90
|
+
children = React.Children.toArray(childrenProp).map(child => disablePassStyles || !React.isValidElement(child) ? child : getThemedIcon(child));
|
|
91
|
+
return forceMount || isIndeterminate(context.state) || context.state === !0 ? /* @__PURE__ */jsx(CheckboxIndicatorFrame, {
|
|
92
|
+
"data-state": getState(context.state),
|
|
93
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
94
|
+
pointerEvents: "none",
|
|
95
|
+
...indicatorProps,
|
|
96
|
+
ref: forwardedRef,
|
|
97
|
+
children
|
|
98
|
+
}) : null;
|
|
99
|
+
}));
|
|
100
|
+
CheckboxIndicator.displayName = INDICATOR_NAME;
|
|
101
|
+
const CHECKBOX_NAME = "Checkbox",
|
|
102
|
+
CheckboxFrame = styled(ThemeableStack, {
|
|
103
|
+
name: CHECKBOX_NAME,
|
|
104
|
+
tag: "button",
|
|
105
|
+
context: CheckboxStyledContext,
|
|
106
|
+
variants: {
|
|
107
|
+
unstyled: {
|
|
108
|
+
false: {
|
|
109
|
+
size: "$true",
|
|
110
|
+
backgroundColor: "$background",
|
|
111
|
+
alignItems: "center",
|
|
112
|
+
justifyContent: "center",
|
|
113
|
+
pressTheme: !0,
|
|
114
|
+
focusable: !0,
|
|
115
|
+
borderWidth: 1,
|
|
116
|
+
borderColor: "$borderColor",
|
|
117
|
+
hoverStyle: {
|
|
118
|
+
borderColor: "$borderColorHover"
|
|
119
|
+
},
|
|
120
|
+
focusStyle: {
|
|
121
|
+
borderColor: "$borderColorFocus",
|
|
122
|
+
outlineStyle: "solid",
|
|
123
|
+
outlineWidth: 2,
|
|
124
|
+
outlineColor: "$outlineColor"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
disabled: {
|
|
129
|
+
true: {
|
|
130
|
+
pointerEvents: "none",
|
|
131
|
+
userSelect: "none",
|
|
132
|
+
cursor: "not-allowed",
|
|
133
|
+
hoverStyle: {
|
|
134
|
+
borderColor: "$borderColor",
|
|
135
|
+
backgroundColor: "$background"
|
|
136
|
+
},
|
|
137
|
+
pressStyle: {
|
|
138
|
+
borderColor: "$borderColor",
|
|
139
|
+
backgroundColor: "$backgroundColor"
|
|
140
|
+
},
|
|
141
|
+
focusStyle: {
|
|
142
|
+
outlineWidth: 0
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
size: {
|
|
147
|
+
"...size": (val, {
|
|
148
|
+
tokens
|
|
149
|
+
}) => ({
|
|
150
|
+
borderRadius: getVariableValue(getSize(val)) / 8
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
defaultVariants: {
|
|
155
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
[createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME),
|
|
159
|
+
[CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME),
|
|
160
|
+
CheckboxComponent = CheckboxFrame.styleable(function (props, forwardedRef) {
|
|
161
|
+
const {
|
|
162
|
+
__scopeCheckbox,
|
|
163
|
+
labelledBy: ariaLabelledby,
|
|
164
|
+
name,
|
|
165
|
+
checked: checkedProp,
|
|
166
|
+
defaultChecked,
|
|
167
|
+
required,
|
|
168
|
+
scaleSize = 0.45,
|
|
169
|
+
sizeAdjust = 0,
|
|
170
|
+
disabled,
|
|
171
|
+
value = "on",
|
|
172
|
+
onCheckedChange,
|
|
173
|
+
native,
|
|
174
|
+
scaleIcon,
|
|
175
|
+
...checkboxProps
|
|
176
|
+
} = props,
|
|
177
|
+
isInsideButton = React.useContext(ButtonNestingContext),
|
|
178
|
+
[button, setButton] = React.useState(null),
|
|
179
|
+
composedRefs = useComposedRefs(forwardedRef, node => setButton(node)),
|
|
180
|
+
hasConsumerStoppedPropagationRef = React.useRef(!1),
|
|
181
|
+
propsActive = useProps(props),
|
|
182
|
+
isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
|
|
183
|
+
[checked = !1, setChecked] = useControllableState({
|
|
184
|
+
prop: checkedProp,
|
|
185
|
+
defaultProp: defaultChecked,
|
|
186
|
+
onChange: onCheckedChange
|
|
187
|
+
}),
|
|
188
|
+
styledContext = React.useContext(CheckboxStyledContext),
|
|
189
|
+
adjustedSize = getVariableValue(getSize(propsActive.size ?? styledContext?.size ?? "$true", {
|
|
190
|
+
shift: sizeAdjust
|
|
191
|
+
})),
|
|
192
|
+
size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize,
|
|
193
|
+
labelId = useLabelContext(button);
|
|
194
|
+
return /* @__PURE__ */jsx(CheckboxProvider, {
|
|
195
|
+
scope: __scopeCheckbox,
|
|
196
|
+
state: checked,
|
|
197
|
+
disabled: !!disabled,
|
|
198
|
+
children: isWeb && native ? /* @__PURE__ */jsx(BubbleInput, {
|
|
199
|
+
control: button,
|
|
200
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
201
|
+
name,
|
|
202
|
+
value,
|
|
203
|
+
checked,
|
|
204
|
+
required,
|
|
205
|
+
disabled,
|
|
206
|
+
id: props.id
|
|
207
|
+
}) : /* @__PURE__ */jsxs(Fragment, {
|
|
208
|
+
children: [/* @__PURE__ */jsx(CheckboxFrame, {
|
|
209
|
+
width: size,
|
|
210
|
+
height: size,
|
|
211
|
+
tag: isInsideButton ? "span" : "button",
|
|
212
|
+
role: "checkbox",
|
|
213
|
+
"aria-labelledby": ariaLabelledby || labelId,
|
|
214
|
+
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
215
|
+
"aria-required": required,
|
|
216
|
+
"data-state": getState(checked),
|
|
217
|
+
"data-disabled": disabled ? "" : void 0,
|
|
218
|
+
disabled,
|
|
219
|
+
...checkboxProps,
|
|
220
|
+
ref: composedRefs,
|
|
221
|
+
...(isWeb && {
|
|
222
|
+
type: "button",
|
|
223
|
+
value,
|
|
224
|
+
onKeyDown: composeEventHandlers(props.onKeyDown, event => {
|
|
225
|
+
event.key === "Enter" && event.preventDefault();
|
|
226
|
+
})
|
|
227
|
+
}),
|
|
228
|
+
onPress: composeEventHandlers(props.onPress, event => {
|
|
229
|
+
setChecked(prevChecked => isIndeterminate(prevChecked) ? !0 : !prevChecked), isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
230
|
+
}),
|
|
231
|
+
children: /* @__PURE__ */jsx(CheckboxStyledContext.Provider, {
|
|
232
|
+
size: propsActive.size ?? styledContext?.size ?? "$true",
|
|
233
|
+
scaleIcon: scaleIcon ?? styledContext?.scaleIcon ?? 1,
|
|
234
|
+
children: propsActive.children
|
|
235
|
+
})
|
|
236
|
+
}), isWeb && isFormControl ? /* @__PURE__ */jsx(BubbleInput, {
|
|
237
|
+
isHidden: !0,
|
|
238
|
+
control: button,
|
|
239
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
240
|
+
name,
|
|
241
|
+
value,
|
|
242
|
+
checked,
|
|
243
|
+
required,
|
|
244
|
+
disabled
|
|
245
|
+
}) : null]
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
}),
|
|
249
|
+
Checkbox2 = withStaticProperties(CheckboxComponent, {
|
|
250
|
+
Indicator: CheckboxIndicator,
|
|
251
|
+
Props: CheckboxStyledContext.Provider
|
|
252
|
+
});
|
|
253
|
+
export { BubbleInput, Checkbox2 as Checkbox, CheckboxFrame, CheckboxStyledContext, createCheckboxScope, getState, isIndeterminate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Checkbox.mjs";
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb } from "@tamagui/constants";
|
|
3
|
+
import { createStyledContext, getVariableValue, styled, useProps, useTheme } from "@tamagui/core";
|
|
4
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
5
|
+
import { getFontSize } from "@tamagui/font-size";
|
|
6
|
+
import { getSize } from "@tamagui/get-token";
|
|
7
|
+
import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
|
|
8
|
+
import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
|
|
9
|
+
import { useLabelContext } from "@tamagui/label";
|
|
10
|
+
import { ButtonNestingContext, ThemeableStack } from "@tamagui/stacks";
|
|
11
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
12
|
+
import { usePrevious } from "@tamagui/use-previous";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
const CheckboxStyledContext = createStyledContext({
|
|
16
|
+
size: "$true",
|
|
17
|
+
scaleIcon: 1
|
|
18
|
+
});
|
|
19
|
+
function isIndeterminate(checked) {
|
|
20
|
+
return checked === "indeterminate";
|
|
21
|
+
}
|
|
22
|
+
function getState(checked) {
|
|
23
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
24
|
+
}
|
|
25
|
+
const BubbleInput = props => {
|
|
26
|
+
const {
|
|
27
|
+
checked,
|
|
28
|
+
bubbles = !0,
|
|
29
|
+
control,
|
|
30
|
+
isHidden,
|
|
31
|
+
...inputProps
|
|
32
|
+
} = props,
|
|
33
|
+
ref = React.useRef(null),
|
|
34
|
+
prevChecked = usePrevious(checked);
|
|
35
|
+
return React.useEffect(() => {
|
|
36
|
+
const input = ref.current,
|
|
37
|
+
inputProto = window.HTMLInputElement.prototype,
|
|
38
|
+
setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
|
|
39
|
+
if (prevChecked !== checked && setChecked) {
|
|
40
|
+
const event = new Event("click", {
|
|
41
|
+
bubbles
|
|
42
|
+
});
|
|
43
|
+
input.indeterminate = isIndeterminate(checked), setChecked.call(input, isIndeterminate(checked) ? !1 : checked), input.dispatchEvent(event);
|
|
44
|
+
}
|
|
45
|
+
}, [prevChecked, checked, bubbles]), /* @__PURE__ */jsx("input", {
|
|
46
|
+
type: "checkbox",
|
|
47
|
+
defaultChecked: isIndeterminate(checked) ? !1 : checked,
|
|
48
|
+
...inputProps,
|
|
49
|
+
tabIndex: -1,
|
|
50
|
+
ref,
|
|
51
|
+
"aria-hidden": isHidden,
|
|
52
|
+
style: {
|
|
53
|
+
...(isHidden ? {
|
|
54
|
+
// ...controlSize,
|
|
55
|
+
position: "absolute",
|
|
56
|
+
pointerEvents: "none",
|
|
57
|
+
opacity: 0,
|
|
58
|
+
margin: 0
|
|
59
|
+
} : {
|
|
60
|
+
appearance: "auto",
|
|
61
|
+
accentColor: "var(--color6)"
|
|
62
|
+
}),
|
|
63
|
+
...props.style
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
INDICATOR_NAME = "CheckboxIndicator",
|
|
68
|
+
CheckboxIndicatorFrame = styled(ThemeableStack, {
|
|
69
|
+
// use Checkbox for easier themes
|
|
70
|
+
name: INDICATOR_NAME,
|
|
71
|
+
context: CheckboxStyledContext
|
|
72
|
+
}),
|
|
73
|
+
CheckboxIndicator = CheckboxIndicatorFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
74
|
+
const {
|
|
75
|
+
__scopeCheckbox,
|
|
76
|
+
children: childrenProp,
|
|
77
|
+
forceMount,
|
|
78
|
+
disablePassStyles,
|
|
79
|
+
...indicatorProps
|
|
80
|
+
} = props;
|
|
81
|
+
process.env.NODE_ENV === "development" && !childrenProp && console.warn("Warning: You created a Checkbox.Indicator without passing an child prop for it to use as an icon.");
|
|
82
|
+
const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox),
|
|
83
|
+
styledContext = React.useContext(CheckboxStyledContext),
|
|
84
|
+
iconSize = (typeof styledContext.size == "number" ? styledContext.size * 0.65 : getFontSize(styledContext.size)) * styledContext.scaleIcon,
|
|
85
|
+
theme = useTheme(),
|
|
86
|
+
getThemedIcon = useGetThemedIcon({
|
|
87
|
+
size: iconSize,
|
|
88
|
+
color: theme.color
|
|
89
|
+
}),
|
|
90
|
+
children = React.Children.toArray(childrenProp).map(child => disablePassStyles || !React.isValidElement(child) ? child : getThemedIcon(child));
|
|
91
|
+
return forceMount || isIndeterminate(context.state) || context.state === !0 ? /* @__PURE__ */jsx(CheckboxIndicatorFrame, {
|
|
92
|
+
"data-state": getState(context.state),
|
|
93
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
94
|
+
pointerEvents: "none",
|
|
95
|
+
...indicatorProps,
|
|
96
|
+
ref: forwardedRef,
|
|
97
|
+
children
|
|
98
|
+
}) : null;
|
|
99
|
+
}));
|
|
100
|
+
CheckboxIndicator.displayName = INDICATOR_NAME;
|
|
101
|
+
const CHECKBOX_NAME = "Checkbox",
|
|
102
|
+
CheckboxFrame = styled(ThemeableStack, {
|
|
103
|
+
name: CHECKBOX_NAME,
|
|
104
|
+
tag: "button",
|
|
105
|
+
context: CheckboxStyledContext,
|
|
106
|
+
variants: {
|
|
107
|
+
unstyled: {
|
|
108
|
+
false: {
|
|
109
|
+
size: "$true",
|
|
110
|
+
backgroundColor: "$background",
|
|
111
|
+
alignItems: "center",
|
|
112
|
+
justifyContent: "center",
|
|
113
|
+
pressTheme: !0,
|
|
114
|
+
focusable: !0,
|
|
115
|
+
borderWidth: 1,
|
|
116
|
+
borderColor: "$borderColor",
|
|
117
|
+
hoverStyle: {
|
|
118
|
+
borderColor: "$borderColorHover"
|
|
119
|
+
},
|
|
120
|
+
focusStyle: {
|
|
121
|
+
borderColor: "$borderColorFocus",
|
|
122
|
+
outlineStyle: "solid",
|
|
123
|
+
outlineWidth: 2,
|
|
124
|
+
outlineColor: "$outlineColor"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
disabled: {
|
|
129
|
+
true: {
|
|
130
|
+
pointerEvents: "none",
|
|
131
|
+
userSelect: "none",
|
|
132
|
+
cursor: "not-allowed",
|
|
133
|
+
hoverStyle: {
|
|
134
|
+
borderColor: "$borderColor",
|
|
135
|
+
backgroundColor: "$background"
|
|
136
|
+
},
|
|
137
|
+
pressStyle: {
|
|
138
|
+
borderColor: "$borderColor",
|
|
139
|
+
backgroundColor: "$backgroundColor"
|
|
140
|
+
},
|
|
141
|
+
focusStyle: {
|
|
142
|
+
outlineWidth: 0
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
size: {
|
|
147
|
+
"...size": (val, {
|
|
148
|
+
tokens
|
|
149
|
+
}) => ({
|
|
150
|
+
borderRadius: getVariableValue(getSize(val)) / 8
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
defaultVariants: {
|
|
155
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
[createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME),
|
|
159
|
+
[CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME),
|
|
160
|
+
CheckboxComponent = CheckboxFrame.styleable(function (props, forwardedRef) {
|
|
161
|
+
const {
|
|
162
|
+
__scopeCheckbox,
|
|
163
|
+
labelledBy: ariaLabelledby,
|
|
164
|
+
name,
|
|
165
|
+
checked: checkedProp,
|
|
166
|
+
defaultChecked,
|
|
167
|
+
required,
|
|
168
|
+
scaleSize = 0.45,
|
|
169
|
+
sizeAdjust = 0,
|
|
170
|
+
disabled,
|
|
171
|
+
value = "on",
|
|
172
|
+
onCheckedChange,
|
|
173
|
+
native,
|
|
174
|
+
scaleIcon,
|
|
175
|
+
...checkboxProps
|
|
176
|
+
} = props,
|
|
177
|
+
isInsideButton = React.useContext(ButtonNestingContext),
|
|
178
|
+
[button, setButton] = React.useState(null),
|
|
179
|
+
composedRefs = useComposedRefs(forwardedRef, node => setButton(node)),
|
|
180
|
+
hasConsumerStoppedPropagationRef = React.useRef(!1),
|
|
181
|
+
propsActive = useProps(props),
|
|
182
|
+
isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
|
|
183
|
+
[checked = !1, setChecked] = useControllableState({
|
|
184
|
+
prop: checkedProp,
|
|
185
|
+
defaultProp: defaultChecked,
|
|
186
|
+
onChange: onCheckedChange
|
|
187
|
+
}),
|
|
188
|
+
styledContext = React.useContext(CheckboxStyledContext),
|
|
189
|
+
adjustedSize = getVariableValue(getSize(propsActive.size ?? styledContext?.size ?? "$true", {
|
|
190
|
+
shift: sizeAdjust
|
|
191
|
+
})),
|
|
192
|
+
size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize,
|
|
193
|
+
labelId = useLabelContext(button);
|
|
194
|
+
return /* @__PURE__ */jsx(CheckboxProvider, {
|
|
195
|
+
scope: __scopeCheckbox,
|
|
196
|
+
state: checked,
|
|
197
|
+
disabled: !!disabled,
|
|
198
|
+
children: isWeb && native ? /* @__PURE__ */jsx(BubbleInput, {
|
|
199
|
+
control: button,
|
|
200
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
201
|
+
name,
|
|
202
|
+
value,
|
|
203
|
+
checked,
|
|
204
|
+
required,
|
|
205
|
+
disabled,
|
|
206
|
+
id: props.id
|
|
207
|
+
}) : /* @__PURE__ */jsxs(Fragment, {
|
|
208
|
+
children: [/* @__PURE__ */jsx(CheckboxFrame, {
|
|
209
|
+
width: size,
|
|
210
|
+
height: size,
|
|
211
|
+
tag: isInsideButton ? "span" : "button",
|
|
212
|
+
role: "checkbox",
|
|
213
|
+
"aria-labelledby": ariaLabelledby || labelId,
|
|
214
|
+
"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
|
|
215
|
+
"aria-required": required,
|
|
216
|
+
"data-state": getState(checked),
|
|
217
|
+
"data-disabled": disabled ? "" : void 0,
|
|
218
|
+
disabled,
|
|
219
|
+
...checkboxProps,
|
|
220
|
+
ref: composedRefs,
|
|
221
|
+
...(isWeb && {
|
|
222
|
+
type: "button",
|
|
223
|
+
value,
|
|
224
|
+
onKeyDown: composeEventHandlers(props.onKeyDown, event => {
|
|
225
|
+
event.key === "Enter" && event.preventDefault();
|
|
226
|
+
})
|
|
227
|
+
}),
|
|
228
|
+
onPress: composeEventHandlers(props.onPress, event => {
|
|
229
|
+
setChecked(prevChecked => isIndeterminate(prevChecked) ? !0 : !prevChecked), isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
|
|
230
|
+
}),
|
|
231
|
+
children: /* @__PURE__ */jsx(CheckboxStyledContext.Provider, {
|
|
232
|
+
size: propsActive.size ?? styledContext?.size ?? "$true",
|
|
233
|
+
scaleIcon: scaleIcon ?? styledContext?.scaleIcon ?? 1,
|
|
234
|
+
children: propsActive.children
|
|
235
|
+
})
|
|
236
|
+
}), isWeb && isFormControl ? /* @__PURE__ */jsx(BubbleInput, {
|
|
237
|
+
isHidden: !0,
|
|
238
|
+
control: button,
|
|
239
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
240
|
+
name,
|
|
241
|
+
value,
|
|
242
|
+
checked,
|
|
243
|
+
required,
|
|
244
|
+
disabled
|
|
245
|
+
}) : null]
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
}),
|
|
249
|
+
Checkbox2 = withStaticProperties(CheckboxComponent, {
|
|
250
|
+
Indicator: CheckboxIndicator,
|
|
251
|
+
Props: CheckboxStyledContext.Provider
|
|
252
|
+
});
|
|
253
|
+
export { BubbleInput, Checkbox2 as Checkbox, CheckboxFrame, CheckboxStyledContext, createCheckboxScope, getState, isIndeterminate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Checkbox.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/checkbox",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"clean:build": "tamagui-build clean:build"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tamagui/compose-refs": "1.
|
|
28
|
-
"@tamagui/constants": "1.
|
|
29
|
-
"@tamagui/core": "1.
|
|
30
|
-
"@tamagui/create-context": "1.
|
|
31
|
-
"@tamagui/focusable": "1.
|
|
32
|
-
"@tamagui/font-size": "1.
|
|
33
|
-
"@tamagui/get-token": "1.
|
|
34
|
-
"@tamagui/helpers": "1.
|
|
35
|
-
"@tamagui/helpers-tamagui": "1.
|
|
36
|
-
"@tamagui/label": "1.
|
|
37
|
-
"@tamagui/stacks": "1.
|
|
38
|
-
"@tamagui/use-controllable-state": "1.
|
|
39
|
-
"@tamagui/use-previous": "1.
|
|
27
|
+
"@tamagui/compose-refs": "1.89.0-1706308641099",
|
|
28
|
+
"@tamagui/constants": "1.89.0-1706308641099",
|
|
29
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
30
|
+
"@tamagui/create-context": "1.89.0-1706308641099",
|
|
31
|
+
"@tamagui/focusable": "1.89.0-1706308641099",
|
|
32
|
+
"@tamagui/font-size": "1.89.0-1706308641099",
|
|
33
|
+
"@tamagui/get-token": "1.89.0-1706308641099",
|
|
34
|
+
"@tamagui/helpers": "1.89.0-1706308641099",
|
|
35
|
+
"@tamagui/helpers-tamagui": "1.89.0-1706308641099",
|
|
36
|
+
"@tamagui/label": "1.89.0-1706308641099",
|
|
37
|
+
"@tamagui/stacks": "1.89.0-1706308641099",
|
|
38
|
+
"@tamagui/use-controllable-state": "1.89.0-1706308641099",
|
|
39
|
+
"@tamagui/use-previous": "1.89.0-1706308641099"
|
|
40
40
|
},
|
|
41
41
|
"exports": {
|
|
42
42
|
"./package.json": "./package.json",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"react": "*"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@tamagui/build": "1.
|
|
54
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
55
55
|
"react": "^18.2.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|