@tamagui/checkbox 1.27.1 → 1.27.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/checkbox",
3
- "version": "1.27.1",
3
+ "version": "1.27.3",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -20,15 +20,15 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@radix-ui/react-use-previous": "^0.1.1",
23
- "@tamagui/core": "1.27.1",
24
- "@tamagui/create-context": "1.27.1",
25
- "@tamagui/focusable": "1.27.1",
26
- "@tamagui/font-size": "1.27.1",
27
- "@tamagui/get-size": "1.27.1",
28
- "@tamagui/helpers-tamagui": "1.27.1",
29
- "@tamagui/label": "1.27.1",
30
- "@tamagui/stacks": "1.27.1",
31
- "@tamagui/use-controllable-state": "1.27.1"
23
+ "@tamagui/core": "1.27.3",
24
+ "@tamagui/create-context": "1.27.3",
25
+ "@tamagui/focusable": "1.27.3",
26
+ "@tamagui/font-size": "1.27.3",
27
+ "@tamagui/get-size": "1.27.3",
28
+ "@tamagui/helpers-tamagui": "1.27.3",
29
+ "@tamagui/label": "1.27.3",
30
+ "@tamagui/stacks": "1.27.3",
31
+ "@tamagui/use-controllable-state": "1.27.3"
32
32
  },
33
33
  "exports": {
34
34
  "./package.json": "./package.json",
@@ -42,7 +42,7 @@
42
42
  "react": "*"
43
43
  },
44
44
  "devDependencies": {
45
- "@tamagui/build": "1.27.1",
45
+ "@tamagui/build": "1.27.3",
46
46
  "react": "^18.2.0"
47
47
  },
48
48
  "publishConfig": {
@@ -1,290 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { usePrevious } from "@radix-ui/react-use-previous";
3
- import {
4
- composeEventHandlers,
5
- getVariableValue,
6
- isWeb,
7
- styled,
8
- useComposedRefs,
9
- useProps,
10
- useTheme,
11
- withStaticProperties
12
- } from "@tamagui/core";
13
- import { createContextScope } from "@tamagui/create-context";
14
- import { registerFocusable } from "@tamagui/focusable";
15
- import { getFontSize } from "@tamagui/font-size";
16
- import { getSize, stepTokenUpOrDown } from "@tamagui/get-size";
17
- import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
18
- import { useLabelContext } from "@tamagui/label";
19
- import { ThemeableStack } from "@tamagui/stacks";
20
- import { useControllableState } from "@tamagui/use-controllable-state";
21
- import * as React from "react";
22
- function isIndeterminate(checked) {
23
- return checked === "indeterminate";
24
- }
25
- function getState(checked) {
26
- return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
27
- }
28
- const BubbleInput = (props) => {
29
- const { checked, bubbles = true, control, isHidden, ...inputProps } = props;
30
- const ref = React.useRef(null);
31
- const prevChecked = usePrevious(checked);
32
- React.useEffect(() => {
33
- const input = ref.current;
34
- const inputProto = window.HTMLInputElement.prototype;
35
- const descriptor = Object.getOwnPropertyDescriptor(
36
- inputProto,
37
- "checked"
38
- );
39
- const setChecked = descriptor.set;
40
- if (prevChecked !== checked && setChecked) {
41
- const event = new Event("click", { bubbles });
42
- input.indeterminate = isIndeterminate(checked);
43
- setChecked.call(input, isIndeterminate(checked) ? false : checked);
44
- input.dispatchEvent(event);
45
- }
46
- }, [prevChecked, checked, bubbles]);
47
- return /* @__PURE__ */ jsx(
48
- "input",
49
- {
50
- type: "checkbox",
51
- defaultChecked: isIndeterminate(checked) ? false : checked,
52
- ...inputProps,
53
- tabIndex: -1,
54
- ref,
55
- "aria-hidden": isHidden,
56
- style: {
57
- ...isHidden ? {
58
- // ...controlSize,
59
- position: "absolute",
60
- pointerEvents: "none",
61
- opacity: 0,
62
- margin: 0
63
- } : {
64
- appearance: "auto",
65
- accentColor: "var(--color6)"
66
- },
67
- ...props.style
68
- }
69
- }
70
- );
71
- };
72
- const INDICATOR_NAME = "CheckboxIndicator";
73
- const CheckboxIndicatorFrame = styled(ThemeableStack, {
74
- // use Checkbox for easier themes
75
- name: INDICATOR_NAME
76
- });
77
- const CheckboxIndicator = CheckboxIndicatorFrame.extractable(
78
- React.forwardRef(
79
- (props, forwardedRef) => {
80
- const {
81
- __scopeCheckbox,
82
- children: childrenProp,
83
- forceMount,
84
- disablePassStyles,
85
- ...indicatorProps
86
- } = props;
87
- const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
88
- const iconSize = (typeof context.size === "number" ? context.size * 0.65 : getFontSize(context.size)) * context.scaleIcon;
89
- const theme = useTheme();
90
- const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color });
91
- const childrens = React.Children.toArray(childrenProp);
92
- const children = childrens.map((child) => {
93
- if (disablePassStyles || !React.isValidElement(child)) {
94
- return child;
95
- }
96
- return getThemedIcon(child);
97
- });
98
- if (forceMount || isIndeterminate(context.state) || context.state === true)
99
- return /* @__PURE__ */ jsx(
100
- CheckboxIndicatorFrame,
101
- {
102
- "data-state": getState(context.state),
103
- "data-disabled": context.disabled ? "" : void 0,
104
- pointerEvents: "none",
105
- ...indicatorProps,
106
- ref: forwardedRef,
107
- children
108
- }
109
- );
110
- return null;
111
- }
112
- )
113
- );
114
- CheckboxIndicator.displayName = INDICATOR_NAME;
115
- const CHECKBOX_NAME = "Checkbox";
116
- const CheckboxFrame = styled(ThemeableStack, {
117
- name: CHECKBOX_NAME,
118
- tag: "button",
119
- variants: {
120
- unstyled: {
121
- false: {
122
- size: "$true",
123
- backgroundColor: "$background",
124
- alignItems: "center",
125
- justifyContent: "center",
126
- pressTheme: true,
127
- focusable: true,
128
- borderWidth: 1,
129
- borderColor: "$borderColor",
130
- hoverStyle: {
131
- borderColor: "$borderColorHover"
132
- },
133
- focusStyle: {
134
- borderColor: "$borderColorFocus"
135
- }
136
- }
137
- },
138
- size: {
139
- "...size": (val, { tokens }) => {
140
- const radiusToken = getVariableValue(getSize(val)) / 8;
141
- return {
142
- borderRadius: radiusToken
143
- };
144
- }
145
- }
146
- },
147
- defaultVariants: {
148
- unstyled: false
149
- }
150
- });
151
- const [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);
152
- const [CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
153
- const Checkbox = withStaticProperties(
154
- CheckboxFrame.extractable(
155
- React.forwardRef(function Checkbox2(props, forwardedRef) {
156
- const {
157
- __scopeCheckbox,
158
- labelledBy: ariaLabelledby,
159
- name,
160
- checked: checkedProp,
161
- defaultChecked,
162
- required,
163
- scaleIcon = 1,
164
- scaleSize = 0.45,
165
- sizeAdjust = 0,
166
- disabled,
167
- value = "on",
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
- stepTokenUpOrDown("size", propsActive.size, sizeAdjust)
184
- );
185
- const size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize;
186
- const labelId = useLabelContext(button);
187
- const labelledBy = ariaLabelledby || labelId;
188
- if (process.env.TAMAGUI_TARGET === "native") {
189
- React.useEffect(() => {
190
- if (!props.id)
191
- return;
192
- return registerFocusable(props.id, {
193
- focusAndSelect: () => {
194
- setChecked((x) => !x);
195
- },
196
- focus: () => {
197
- }
198
- });
199
- }, [props.id, setChecked]);
200
- }
201
- return /* @__PURE__ */ jsx(
202
- CheckboxProvider,
203
- {
204
- scope: __scopeCheckbox,
205
- state: checked,
206
- disabled,
207
- size,
208
- scaleIcon,
209
- children: isWeb && native ? /* @__PURE__ */ jsx(
210
- BubbleInput,
211
- {
212
- control: button,
213
- bubbles: !hasConsumerStoppedPropagationRef.current,
214
- name,
215
- value,
216
- checked,
217
- required,
218
- disabled,
219
- id: props.id
220
- }
221
- ) : /* @__PURE__ */ jsxs(Fragment, { children: [
222
- /* @__PURE__ */ jsx(
223
- CheckboxFrame,
224
- {
225
- width: size,
226
- height: size,
227
- tag: "button",
228
- role: "checkbox",
229
- "aria-labelledby": labelledBy,
230
- "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
231
- "aria-required": required,
232
- "data-state": getState(checked),
233
- "data-disabled": disabled ? "" : void 0,
234
- disabled,
235
- ...checkboxProps,
236
- ref: composedRefs,
237
- ...isWeb && {
238
- type: "button",
239
- value,
240
- onKeyDown: composeEventHandlers(
241
- props.onKeyDown,
242
- (event) => {
243
- if (event.key === "Enter")
244
- event.preventDefault();
245
- }
246
- )
247
- },
248
- onPress: composeEventHandlers(props.onPress, (event) => {
249
- setChecked(
250
- (prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
251
- );
252
- if (isFormControl) {
253
- hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
254
- if (!hasConsumerStoppedPropagationRef.current)
255
- event.stopPropagation();
256
- }
257
- })
258
- }
259
- ),
260
- isWeb && isFormControl ? /* @__PURE__ */ jsx(
261
- BubbleInput,
262
- {
263
- isHidden: true,
264
- control: button,
265
- bubbles: !hasConsumerStoppedPropagationRef.current,
266
- name,
267
- value,
268
- checked,
269
- required,
270
- disabled
271
- }
272
- ) : null
273
- ] })
274
- }
275
- );
276
- })
277
- ),
278
- {
279
- Indicator: CheckboxIndicator
280
- }
281
- );
282
- export {
283
- BubbleInput,
284
- Checkbox,
285
- CheckboxFrame,
286
- createCheckboxScope,
287
- getState,
288
- isIndeterminate
289
- };
290
- //# sourceMappingURL=Checkbox.mjs.map
@@ -1,2 +0,0 @@
1
- export * from "./Checkbox";
2
- //# sourceMappingURL=index.mjs.map