@tamagui/checkbox 1.3.0

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './Checkbox'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Checkbox";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './Checkbox'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,269 @@
1
+ import { usePrevious } from "@radix-ui/react-use-previous";
2
+ import {
3
+ composeEventHandlers,
4
+ getConfig,
5
+ getVariableValue,
6
+ isWeb,
7
+ mergeProps,
8
+ styled,
9
+ useComposedRefs,
10
+ useMediaPropsActive,
11
+ useTheme,
12
+ withStaticProperties
13
+ } from "@tamagui/core";
14
+ import { createContextScope } from "@tamagui/create-context";
15
+ import { registerFocusable } from "@tamagui/focusable";
16
+ import { getFontSize } from "@tamagui/font-size";
17
+ import { getSize, stepTokenUpOrDown } from "@tamagui/get-size";
18
+ import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
19
+ import { useLabelContext } from "@tamagui/label";
20
+ import { ThemeableStack, YStack } from "@tamagui/stacks";
21
+ import { useControllableState } from "@tamagui/use-controllable-state";
22
+ import * as React from "react";
23
+ function isIndeterminate(checked) {
24
+ return checked === "indeterminate";
25
+ }
26
+ function getState(checked) {
27
+ return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
28
+ }
29
+ const BubbleInput = (props) => {
30
+ const { checked, bubbles = true, control, isHidden, ...inputProps } = props;
31
+ const ref = React.useRef(null);
32
+ const prevChecked = usePrevious(checked);
33
+ React.useEffect(() => {
34
+ const input = ref.current;
35
+ const inputProto = window.HTMLInputElement.prototype;
36
+ const descriptor = Object.getOwnPropertyDescriptor(
37
+ inputProto,
38
+ "checked"
39
+ );
40
+ const setChecked = descriptor.set;
41
+ if (prevChecked !== checked && setChecked) {
42
+ const event = new Event("click", { bubbles });
43
+ input.indeterminate = isIndeterminate(checked);
44
+ setChecked.call(input, isIndeterminate(checked) ? false : checked);
45
+ input.dispatchEvent(event);
46
+ }
47
+ }, [prevChecked, checked, bubbles]);
48
+ return <input
49
+ type="checkbox"
50
+ defaultChecked={isIndeterminate(checked) ? false : checked}
51
+ {...inputProps}
52
+ tabIndex={-1}
53
+ ref={ref}
54
+ aria-hidden={isHidden}
55
+ style={{
56
+ ...isHidden ? {
57
+ // ...controlSize,
58
+ position: "absolute",
59
+ pointerEvents: "none",
60
+ opacity: 0,
61
+ margin: 0
62
+ } : {
63
+ appearance: "auto",
64
+ accentColor: "var(--color6)"
65
+ },
66
+ ...props.style
67
+ }}
68
+ />;
69
+ };
70
+ const INDICATOR_NAME = "CheckboxIndicator";
71
+ const CheckboxIndicatorFrame = styled(ThemeableStack, {
72
+ name: INDICATOR_NAME
73
+ });
74
+ const CheckboxIndicator = React.forwardRef(
75
+ (props, forwardedRef) => {
76
+ const {
77
+ __scopeCheckbox,
78
+ children: childrenProp,
79
+ forceMount,
80
+ disablePassStyles,
81
+ ...indicatorProps
82
+ } = props;
83
+ const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
84
+ const iconSize = (typeof context.size === "number" ? context.size * 0.65 : getFontSize(context.size)) * context.scaleIcon;
85
+ const theme = useTheme();
86
+ const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color });
87
+ const childrens = React.Children.toArray(childrenProp);
88
+ const children = childrens.map((child) => {
89
+ if (disablePassStyles || !React.isValidElement(child)) {
90
+ return child;
91
+ }
92
+ return getThemedIcon(child);
93
+ });
94
+ if (forceMount || isIndeterminate(context.state) || context.state === true)
95
+ return <CheckboxIndicatorFrame
96
+ theme="active"
97
+ data-state={getState(context.state)}
98
+ data-disabled={context.disabled ? "" : void 0}
99
+ pointerEvents="none"
100
+ {...indicatorProps}
101
+ ref={forwardedRef}
102
+ >{children}</CheckboxIndicatorFrame>;
103
+ return null;
104
+ }
105
+ );
106
+ CheckboxIndicator.displayName = INDICATOR_NAME;
107
+ const CHECKBOX_NAME = "Checkbox";
108
+ const CheckboxFrame = styled(ThemeableStack, {
109
+ name: CHECKBOX_NAME,
110
+ tag: "button",
111
+ backgroundColor: "$background",
112
+ alignItems: "center",
113
+ justifyContent: "center",
114
+ pressTheme: true,
115
+ focusable: true,
116
+ borderWidth: 2,
117
+ borderColor: "transparent",
118
+ focusStyle: {
119
+ borderColor: "$borderColorFocus"
120
+ },
121
+ variants: {
122
+ size: {
123
+ "...size": (val, { tokens }) => {
124
+ const radiusToken = getVariableValue(getSize(val)) / 8;
125
+ return {
126
+ borderRadius: radiusToken
127
+ };
128
+ }
129
+ }
130
+ },
131
+ defaultVariants: {
132
+ size: "$true"
133
+ }
134
+ });
135
+ const [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);
136
+ const [CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
137
+ const Checkbox = withStaticProperties(
138
+ CheckboxFrame.extractable(
139
+ React.forwardRef(
140
+ (props, forwardedRef) => {
141
+ const {
142
+ __scopeCheckbox,
143
+ labelledBy: ariaLabelledby,
144
+ name,
145
+ checked: checkedProp,
146
+ defaultChecked,
147
+ required,
148
+ scaleIcon = 1,
149
+ sizeAdjust = 0,
150
+ disabled,
151
+ value = "on",
152
+ onCheckedChange,
153
+ native,
154
+ ...checkboxProps
155
+ } = props;
156
+ const [button, setButton] = React.useState(null);
157
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
158
+ const hasConsumerStoppedPropagationRef = React.useRef(false);
159
+ const propsActive = useMediaPropsActive(props);
160
+ const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
161
+ const [checked = false, setChecked] = useControllableState({
162
+ prop: checkedProp,
163
+ defaultProp: defaultChecked,
164
+ onChange: onCheckedChange
165
+ });
166
+ const adjustedSizeToken = stepTokenUpOrDown("size", propsActive.size, sizeAdjust);
167
+ const size = Math.floor(getVariableValue(adjustedSizeToken) * 0.5);
168
+ const labelId = useLabelContext(button);
169
+ const labelledBy = ariaLabelledby || labelId;
170
+ if (!isWeb) {
171
+ React.useEffect(() => {
172
+ if (!props.id)
173
+ return;
174
+ return registerFocusable(props.id, {
175
+ focusAndSelect: () => {
176
+ setChecked((x) => !x);
177
+ },
178
+ focus: () => {
179
+ }
180
+ });
181
+ }, [props.id, setChecked]);
182
+ }
183
+ return (
184
+ // YStack is here to provide theme for native input
185
+ <YStack asChild theme={checkboxProps.theme}><CheckboxProvider
186
+ scope={__scopeCheckbox}
187
+ state={checked}
188
+ disabled={disabled}
189
+ size={size}
190
+ scaleIcon={scaleIcon}
191
+ >{isWeb && native ? <BubbleInput
192
+ control={button}
193
+ bubbles={!hasConsumerStoppedPropagationRef.current}
194
+ name={name}
195
+ value={value}
196
+ checked={checked}
197
+ required={required}
198
+ disabled={disabled}
199
+ id={props.id}
200
+ /> : <>
201
+ <CheckboxFrame
202
+ width={size}
203
+ height={size}
204
+ theme={checked ? "active" : null}
205
+ tag="button"
206
+ role="checkbox"
207
+ aria-labelledby={labelledBy}
208
+ aria-checked={isIndeterminate(checked) ? "mixed" : checked}
209
+ aria-required={required}
210
+ data-state={getState(checked)}
211
+ data-disabled={disabled ? "" : void 0}
212
+ disabled={disabled}
213
+ {...checkboxProps}
214
+ ref={composedRefs}
215
+ {...isWeb && {
216
+ type: "button",
217
+ value,
218
+ onKeyDown: composeEventHandlers(
219
+ props.onKeyDown,
220
+ (event) => {
221
+ if (event.key === "Enter")
222
+ event.preventDefault();
223
+ }
224
+ )
225
+ }}
226
+ onPress={composeEventHandlers(props.onPress, (event) => {
227
+ setChecked(
228
+ (prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
229
+ );
230
+ if (isFormControl) {
231
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
232
+ if (!hasConsumerStoppedPropagationRef.current)
233
+ event.stopPropagation();
234
+ }
235
+ })}
236
+ />
237
+ {isWeb && isFormControl ? <BubbleInput
238
+ isHidden
239
+ control={button}
240
+ bubbles={!hasConsumerStoppedPropagationRef.current}
241
+ name={name}
242
+ value={value}
243
+ checked={checked}
244
+ required={required}
245
+ disabled={disabled}
246
+ /> : null}
247
+ </>}</CheckboxProvider></YStack>
248
+ );
249
+ }
250
+ )
251
+ ),
252
+ {
253
+ Indicator: CheckboxIndicator
254
+ }
255
+ );
256
+ Checkbox.displayName = CHECKBOX_NAME;
257
+ const cloneElementWithPropOrder = (child, props) => {
258
+ const next = mergeProps(child.props, props, false, getConfig().shorthands)[0];
259
+ return React.cloneElement({ ...child, props: null }, next);
260
+ };
261
+ export {
262
+ BubbleInput,
263
+ Checkbox,
264
+ CheckboxFrame,
265
+ createCheckboxScope,
266
+ getState,
267
+ isIndeterminate
268
+ };
269
+ //# sourceMappingURL=Checkbox.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/Checkbox.tsx"],
4
+ "sourcesContent": ["// fork of radix\n// https://github.com/radix-ui/primitives/tree/main/packages/react/checkbox/src/Checkbox.tsx\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n composeEventHandlers,\n getConfig,\n getVariableValue,\n isWeb,\n mergeProps,\n styled,\n useComposedRefs,\n useMediaPropsActive,\n useTheme,\n withStaticProperties,\n} from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport { createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getSize, stepTokenUpOrDown } from '@tamagui/get-size'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { useLabelContext } from '@tamagui/label'\nimport { ThemeableStack, YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\nexport type CheckedState = boolean | 'indeterminate'\n\nexport function isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate'\n}\n\nexport function getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked'\n}\n\ntype InputProps = any //Radix.ComponentPropsWithoutRef<'input'>\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: CheckedState\n control: HTMLElement | null\n bubbles: boolean\n\n isHidden?: boolean\n}\n\nexport const BubbleInput = (props: BubbleInputProps) => {\n const { checked, bubbles = true, control, isHidden, ...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(\n inputProto,\n 'checked'\n ) 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 defaultChecked={isIndeterminate(checked) ? false : checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n aria-hidden={isHidden}\n style={{\n ...(isHidden\n ? {\n // ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }\n : {\n appearance: 'auto',\n accentColor: 'var(--color6)',\n }),\n\n ...props.style,\n }}\n />\n )\n}\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator'\n\nconst CheckboxIndicatorFrame = styled(ThemeableStack, {\n name: INDICATOR_NAME,\n})\n\ntype CheckboxIndicatorFrameProps = GetProps<typeof CheckboxIndicatorFrame>\n\nexport type CheckboxIndicatorProps = CheckboxIndicatorFrameProps & {\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 * Used to disable passing styles down to children.\n */\n disablePassStyles?: boolean\n}\n\nconst CheckboxIndicator = React.forwardRef<TamaguiElement, CheckboxIndicatorProps>(\n (props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n children: childrenProp,\n forceMount,\n disablePassStyles,\n ...indicatorProps\n } = props\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox)\n const iconSize =\n (typeof context.size === 'number'\n ? context.size * 0.65\n : getFontSize(context.size)) * context.scaleIcon\n const theme = useTheme()\n const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color })\n\n const childrens = React.Children.toArray(childrenProp)\n const children = childrens.map((child) => {\n if (disablePassStyles || !React.isValidElement(child)) {\n return child\n }\n return getThemedIcon(child)\n })\n\n if (forceMount || isIndeterminate(context.state) || context.state === true)\n return (\n <CheckboxIndicatorFrame\n theme=\"active\"\n data-state={getState(context.state)}\n data-disabled={context.disabled ? '' : undefined}\n pointerEvents=\"none\"\n {...indicatorProps}\n ref={forwardedRef}\n >\n {children}\n </CheckboxIndicatorFrame>\n )\n\n return null\n }\n)\n\nCheckboxIndicator.displayName = INDICATOR_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\nconst CHECKBOX_NAME = 'Checkbox'\n\nexport const CheckboxFrame = styled(ThemeableStack, {\n name: CHECKBOX_NAME,\n tag: 'button',\n backgroundColor: '$background',\n alignItems: 'center',\n justifyContent: 'center',\n pressTheme: true,\n focusable: true,\n borderWidth: 2,\n borderColor: 'transparent',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n const radiusToken = getVariableValue(getSize(val)) / 8\n return {\n borderRadius: radiusToken,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\n },\n})\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope }\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME)\n\ntype CheckboxContextValue = {\n state: CheckedState\n disabled?: boolean\n size: SizeTokens\n scaleIcon: number\n}\n\nconst [CheckboxProvider, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME)\n\ntype CheckboxFrameProps = GetProps<typeof CheckboxFrame>\nexport interface CheckboxProps\n extends Omit<CheckboxFrameProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState\n defaultChecked?: CheckedState\n required?: boolean\n onCheckedChange?(checked: CheckedState): void\n labelledBy?: string\n name?: string\n value?: string\n native?: boolean\n scaleIcon?: number\n sizeAdjust?: number\n}\n\nexport const Checkbox = withStaticProperties(\n CheckboxFrame.extractable(\n React.forwardRef<HTMLButtonElement, CheckboxProps>(\n (props: ScopedProps<CheckboxProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n labelledBy: ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n scaleIcon = 1,\n sizeAdjust = 0,\n disabled,\n value = 'on',\n onCheckedChange,\n native,\n ...checkboxProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node))\n const hasConsumerStoppedPropagationRef = React.useRef(false)\n const propsActive = useMediaPropsActive(props)\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = isWeb\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked!,\n onChange: onCheckedChange,\n })\n\n const adjustedSizeToken = stepTokenUpOrDown('size', propsActive.size, sizeAdjust)\n const size = Math.floor(getVariableValue(adjustedSizeToken) * 0.5)\n\n const labelId = useLabelContext(button)\n const labelledBy = ariaLabelledby || labelId\n\n if (!isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (!props.id) return\n return registerFocusable(props.id, {\n focusAndSelect: () => {\n setChecked((x) => !x)\n },\n focus: () => {},\n })\n }, [props.id, setChecked])\n }\n\n return (\n // YStack is here to provide theme for native input\n <YStack asChild theme={checkboxProps.theme}>\n <CheckboxProvider\n scope={__scopeCheckbox}\n state={checked}\n disabled={disabled}\n size={size}\n scaleIcon={scaleIcon}\n >\n {isWeb && native ? (\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 id={props.id}\n />\n ) : (\n <>\n <CheckboxFrame\n width={size}\n height={size}\n theme={checked ? 'active' : null}\n tag=\"button\"\n role=\"checkbox\"\n aria-labelledby={labelledBy}\n aria-checked={isIndeterminate(checked) ? 'mixed' : checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n {...checkboxProps}\n ref={composedRefs}\n {...(isWeb && {\n type: 'button',\n value: value,\n onKeyDown: composeEventHandlers(\n (props as React.HTMLProps<HTMLButtonElement>).onKeyDown,\n (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault()\n }\n ),\n })}\n onPress={composeEventHandlers(props.onPress as any, (event) => {\n setChecked((prevChecked) =>\n isIndeterminate(prevChecked) ? true : !prevChecked\n )\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current =\n 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)\n event.stopPropagation()\n }\n })}\n />\n\n {isWeb && isFormControl ? (\n <BubbleInput\n isHidden\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\n />\n ) : null}\n </>\n )}\n </CheckboxProvider>\n </YStack>\n )\n }\n )\n ),\n {\n Indicator: CheckboxIndicator,\n }\n)\n\nCheckbox.displayName = CHECKBOX_NAME\n\nexport { createCheckboxScope }\n\nconst cloneElementWithPropOrder = (child: any, props: Object) => {\n const next = mergeProps(child.props, props, false, getConfig().shorthands)[0]\n return React.cloneElement({ ...child, props: null }, next)\n}\n"],
5
+ "mappings": "AAGA,SAAS,mBAAmB;AAC5B;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,SAAS,yBAAyB;AAC3C,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AACvC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAIhB,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,EAAE,SAAS,UAAU,MAAM,SAAS,UAAU,GAAG,WAAW,IAAI;AACtE,QAAM,MAAM,MAAM,OAAyB,IAAI;AAC/C,QAAM,cAAc,YAAY,OAAO;AAIvC,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI;AAClB,UAAM,aAAa,OAAO,iBAAiB;AAC3C,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AACA,UAAM,aAAa,WAAW;AAE9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AA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AAM,aAAa,EAAE,GAAG,OAAO,OAAO,KAAK,GAAG,IAAI;AAC3D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,269 @@
1
+ import { usePrevious } from "@radix-ui/react-use-previous";
2
+ import {
3
+ composeEventHandlers,
4
+ getConfig,
5
+ getVariableValue,
6
+ isWeb,
7
+ mergeProps,
8
+ styled,
9
+ useComposedRefs,
10
+ useMediaPropsActive,
11
+ useTheme,
12
+ withStaticProperties
13
+ } from "@tamagui/core";
14
+ import { createContextScope } from "@tamagui/create-context";
15
+ import { registerFocusable } from "@tamagui/focusable";
16
+ import { getFontSize } from "@tamagui/font-size";
17
+ import { getSize, stepTokenUpOrDown } from "@tamagui/get-size";
18
+ import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
19
+ import { useLabelContext } from "@tamagui/label";
20
+ import { ThemeableStack, YStack } from "@tamagui/stacks";
21
+ import { useControllableState } from "@tamagui/use-controllable-state";
22
+ import * as React from "react";
23
+ function isIndeterminate(checked) {
24
+ return checked === "indeterminate";
25
+ }
26
+ function getState(checked) {
27
+ return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
28
+ }
29
+ const BubbleInput = (props) => {
30
+ const { checked, bubbles = true, control, isHidden, ...inputProps } = props;
31
+ const ref = React.useRef(null);
32
+ const prevChecked = usePrevious(checked);
33
+ React.useEffect(() => {
34
+ const input = ref.current;
35
+ const inputProto = window.HTMLInputElement.prototype;
36
+ const descriptor = Object.getOwnPropertyDescriptor(
37
+ inputProto,
38
+ "checked"
39
+ );
40
+ const setChecked = descriptor.set;
41
+ if (prevChecked !== checked && setChecked) {
42
+ const event = new Event("click", { bubbles });
43
+ input.indeterminate = isIndeterminate(checked);
44
+ setChecked.call(input, isIndeterminate(checked) ? false : checked);
45
+ input.dispatchEvent(event);
46
+ }
47
+ }, [prevChecked, checked, bubbles]);
48
+ return <input
49
+ type="checkbox"
50
+ defaultChecked={isIndeterminate(checked) ? false : checked}
51
+ {...inputProps}
52
+ tabIndex={-1}
53
+ ref={ref}
54
+ aria-hidden={isHidden}
55
+ style={{
56
+ ...isHidden ? {
57
+ // ...controlSize,
58
+ position: "absolute",
59
+ pointerEvents: "none",
60
+ opacity: 0,
61
+ margin: 0
62
+ } : {
63
+ appearance: "auto",
64
+ accentColor: "var(--color6)"
65
+ },
66
+ ...props.style
67
+ }}
68
+ />;
69
+ };
70
+ const INDICATOR_NAME = "CheckboxIndicator";
71
+ const CheckboxIndicatorFrame = styled(ThemeableStack, {
72
+ name: INDICATOR_NAME
73
+ });
74
+ const CheckboxIndicator = React.forwardRef(
75
+ (props, forwardedRef) => {
76
+ const {
77
+ __scopeCheckbox,
78
+ children: childrenProp,
79
+ forceMount,
80
+ disablePassStyles,
81
+ ...indicatorProps
82
+ } = props;
83
+ const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
84
+ const iconSize = (typeof context.size === "number" ? context.size * 0.65 : getFontSize(context.size)) * context.scaleIcon;
85
+ const theme = useTheme();
86
+ const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color });
87
+ const childrens = React.Children.toArray(childrenProp);
88
+ const children = childrens.map((child) => {
89
+ if (disablePassStyles || !React.isValidElement(child)) {
90
+ return child;
91
+ }
92
+ return getThemedIcon(child);
93
+ });
94
+ if (forceMount || isIndeterminate(context.state) || context.state === true)
95
+ return <CheckboxIndicatorFrame
96
+ theme="active"
97
+ data-state={getState(context.state)}
98
+ data-disabled={context.disabled ? "" : void 0}
99
+ pointerEvents="none"
100
+ {...indicatorProps}
101
+ ref={forwardedRef}
102
+ >{children}</CheckboxIndicatorFrame>;
103
+ return null;
104
+ }
105
+ );
106
+ CheckboxIndicator.displayName = INDICATOR_NAME;
107
+ const CHECKBOX_NAME = "Checkbox";
108
+ const CheckboxFrame = styled(ThemeableStack, {
109
+ name: CHECKBOX_NAME,
110
+ tag: "button",
111
+ backgroundColor: "$background",
112
+ alignItems: "center",
113
+ justifyContent: "center",
114
+ pressTheme: true,
115
+ focusable: true,
116
+ borderWidth: 2,
117
+ borderColor: "transparent",
118
+ focusStyle: {
119
+ borderColor: "$borderColorFocus"
120
+ },
121
+ variants: {
122
+ size: {
123
+ "...size": (val, { tokens }) => {
124
+ const radiusToken = getVariableValue(getSize(val)) / 8;
125
+ return {
126
+ borderRadius: radiusToken
127
+ };
128
+ }
129
+ }
130
+ },
131
+ defaultVariants: {
132
+ size: "$true"
133
+ }
134
+ });
135
+ const [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);
136
+ const [CheckboxProvider, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
137
+ const Checkbox = withStaticProperties(
138
+ CheckboxFrame.extractable(
139
+ React.forwardRef(
140
+ (props, forwardedRef) => {
141
+ const {
142
+ __scopeCheckbox,
143
+ labelledBy: ariaLabelledby,
144
+ name,
145
+ checked: checkedProp,
146
+ defaultChecked,
147
+ required,
148
+ scaleIcon = 1,
149
+ sizeAdjust = 0,
150
+ disabled,
151
+ value = "on",
152
+ onCheckedChange,
153
+ native,
154
+ ...checkboxProps
155
+ } = props;
156
+ const [button, setButton] = React.useState(null);
157
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
158
+ const hasConsumerStoppedPropagationRef = React.useRef(false);
159
+ const propsActive = useMediaPropsActive(props);
160
+ const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
161
+ const [checked = false, setChecked] = useControllableState({
162
+ prop: checkedProp,
163
+ defaultProp: defaultChecked,
164
+ onChange: onCheckedChange
165
+ });
166
+ const adjustedSizeToken = stepTokenUpOrDown("size", propsActive.size, sizeAdjust);
167
+ const size = Math.floor(getVariableValue(adjustedSizeToken) * 0.5);
168
+ const labelId = useLabelContext(button);
169
+ const labelledBy = ariaLabelledby || labelId;
170
+ if (!isWeb) {
171
+ React.useEffect(() => {
172
+ if (!props.id)
173
+ return;
174
+ return registerFocusable(props.id, {
175
+ focusAndSelect: () => {
176
+ setChecked((x) => !x);
177
+ },
178
+ focus: () => {
179
+ }
180
+ });
181
+ }, [props.id, setChecked]);
182
+ }
183
+ return (
184
+ // YStack is here to provide theme for native input
185
+ <YStack asChild theme={checkboxProps.theme}><CheckboxProvider
186
+ scope={__scopeCheckbox}
187
+ state={checked}
188
+ disabled={disabled}
189
+ size={size}
190
+ scaleIcon={scaleIcon}
191
+ >{isWeb && native ? <BubbleInput
192
+ control={button}
193
+ bubbles={!hasConsumerStoppedPropagationRef.current}
194
+ name={name}
195
+ value={value}
196
+ checked={checked}
197
+ required={required}
198
+ disabled={disabled}
199
+ id={props.id}
200
+ /> : <>
201
+ <CheckboxFrame
202
+ width={size}
203
+ height={size}
204
+ theme={checked ? "active" : null}
205
+ tag="button"
206
+ role="checkbox"
207
+ aria-labelledby={labelledBy}
208
+ aria-checked={isIndeterminate(checked) ? "mixed" : checked}
209
+ aria-required={required}
210
+ data-state={getState(checked)}
211
+ data-disabled={disabled ? "" : void 0}
212
+ disabled={disabled}
213
+ {...checkboxProps}
214
+ ref={composedRefs}
215
+ {...isWeb && {
216
+ type: "button",
217
+ value,
218
+ onKeyDown: composeEventHandlers(
219
+ props.onKeyDown,
220
+ (event) => {
221
+ if (event.key === "Enter")
222
+ event.preventDefault();
223
+ }
224
+ )
225
+ }}
226
+ onPress={composeEventHandlers(props.onPress, (event) => {
227
+ setChecked(
228
+ (prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked
229
+ );
230
+ if (isFormControl) {
231
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
232
+ if (!hasConsumerStoppedPropagationRef.current)
233
+ event.stopPropagation();
234
+ }
235
+ })}
236
+ />
237
+ {isWeb && isFormControl ? <BubbleInput
238
+ isHidden
239
+ control={button}
240
+ bubbles={!hasConsumerStoppedPropagationRef.current}
241
+ name={name}
242
+ value={value}
243
+ checked={checked}
244
+ required={required}
245
+ disabled={disabled}
246
+ /> : null}
247
+ </>}</CheckboxProvider></YStack>
248
+ );
249
+ }
250
+ )
251
+ ),
252
+ {
253
+ Indicator: CheckboxIndicator
254
+ }
255
+ );
256
+ Checkbox.displayName = CHECKBOX_NAME;
257
+ const cloneElementWithPropOrder = (child, props) => {
258
+ const next = mergeProps(child.props, props, false, getConfig().shorthands)[0];
259
+ return React.cloneElement({ ...child, props: null }, next);
260
+ };
261
+ export {
262
+ BubbleInput,
263
+ Checkbox,
264
+ CheckboxFrame,
265
+ createCheckboxScope,
266
+ getState,
267
+ isIndeterminate
268
+ };
269
+ //# sourceMappingURL=Checkbox.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/Checkbox.tsx"],
4
+ "sourcesContent": ["// fork of radix\n// https://github.com/radix-ui/primitives/tree/main/packages/react/checkbox/src/Checkbox.tsx\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n composeEventHandlers,\n getConfig,\n getVariableValue,\n isWeb,\n mergeProps,\n styled,\n useComposedRefs,\n useMediaPropsActive,\n useTheme,\n withStaticProperties,\n} from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport { createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getSize, stepTokenUpOrDown } from '@tamagui/get-size'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { useLabelContext } from '@tamagui/label'\nimport { ThemeableStack, YStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\nexport type CheckedState = boolean | 'indeterminate'\n\nexport function isIndeterminate(checked?: CheckedState): checked is 'indeterminate' {\n return checked === 'indeterminate'\n}\n\nexport function getState(checked: CheckedState) {\n return isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked'\n}\n\ntype InputProps = any //Radix.ComponentPropsWithoutRef<'input'>\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: CheckedState\n control: HTMLElement | null\n bubbles: boolean\n\n isHidden?: boolean\n}\n\nexport const BubbleInput = (props: BubbleInputProps) => {\n const { checked, bubbles = true, control, isHidden, ...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(\n inputProto,\n 'checked'\n ) 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 defaultChecked={isIndeterminate(checked) ? false : checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n aria-hidden={isHidden}\n style={{\n ...(isHidden\n ? {\n // ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }\n : {\n appearance: 'auto',\n accentColor: 'var(--color6)',\n }),\n\n ...props.style,\n }}\n />\n )\n}\n\n/* -------------------------------------------------------------------------------------------------\n * CheckboxIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'CheckboxIndicator'\n\nconst CheckboxIndicatorFrame = styled(ThemeableStack, {\n name: INDICATOR_NAME,\n})\n\ntype CheckboxIndicatorFrameProps = GetProps<typeof CheckboxIndicatorFrame>\n\nexport type CheckboxIndicatorProps = CheckboxIndicatorFrameProps & {\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 * Used to disable passing styles down to children.\n */\n disablePassStyles?: boolean\n}\n\nconst CheckboxIndicator = React.forwardRef<TamaguiElement, CheckboxIndicatorProps>(\n (props: ScopedProps<CheckboxIndicatorProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n children: childrenProp,\n forceMount,\n disablePassStyles,\n ...indicatorProps\n } = props\n const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox)\n const iconSize =\n (typeof context.size === 'number'\n ? context.size * 0.65\n : getFontSize(context.size)) * context.scaleIcon\n const theme = useTheme()\n const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color })\n\n const childrens = React.Children.toArray(childrenProp)\n const children = childrens.map((child) => {\n if (disablePassStyles || !React.isValidElement(child)) {\n return child\n }\n return getThemedIcon(child)\n })\n\n if (forceMount || isIndeterminate(context.state) || context.state === true)\n return (\n <CheckboxIndicatorFrame\n theme=\"active\"\n data-state={getState(context.state)}\n data-disabled={context.disabled ? '' : undefined}\n pointerEvents=\"none\"\n {...indicatorProps}\n ref={forwardedRef}\n >\n {children}\n </CheckboxIndicatorFrame>\n )\n\n return null\n }\n)\n\nCheckboxIndicator.displayName = INDICATOR_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Checkbox\n * -----------------------------------------------------------------------------------------------*/\n\nconst CHECKBOX_NAME = 'Checkbox'\n\nexport const CheckboxFrame = styled(ThemeableStack, {\n name: CHECKBOX_NAME,\n tag: 'button',\n backgroundColor: '$background',\n alignItems: 'center',\n justifyContent: 'center',\n pressTheme: true,\n focusable: true,\n borderWidth: 2,\n borderColor: 'transparent',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n const radiusToken = getVariableValue(getSize(val)) / 8\n return {\n borderRadius: radiusToken,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\n },\n})\n\ntype ScopedProps<P> = P & { __scopeCheckbox?: Scope }\nconst [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME)\n\ntype CheckboxContextValue = {\n state: CheckedState\n disabled?: boolean\n size: SizeTokens\n scaleIcon: number\n}\n\nconst [CheckboxProvider, useCheckboxContext] =\n createCheckboxContext<CheckboxContextValue>(CHECKBOX_NAME)\n\ntype CheckboxFrameProps = GetProps<typeof CheckboxFrame>\nexport interface CheckboxProps\n extends Omit<CheckboxFrameProps, 'checked' | 'defaultChecked'> {\n checked?: CheckedState\n defaultChecked?: CheckedState\n required?: boolean\n onCheckedChange?(checked: CheckedState): void\n labelledBy?: string\n name?: string\n value?: string\n native?: boolean\n scaleIcon?: number\n sizeAdjust?: number\n}\n\nexport const Checkbox = withStaticProperties(\n CheckboxFrame.extractable(\n React.forwardRef<HTMLButtonElement, CheckboxProps>(\n (props: ScopedProps<CheckboxProps>, forwardedRef) => {\n const {\n __scopeCheckbox,\n labelledBy: ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n scaleIcon = 1,\n sizeAdjust = 0,\n disabled,\n value = 'on',\n onCheckedChange,\n native,\n ...checkboxProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node))\n const hasConsumerStoppedPropagationRef = React.useRef(false)\n const propsActive = useMediaPropsActive(props)\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = isWeb\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked!,\n onChange: onCheckedChange,\n })\n\n const adjustedSizeToken = stepTokenUpOrDown('size', propsActive.size, sizeAdjust)\n const size = Math.floor(getVariableValue(adjustedSizeToken) * 0.5)\n\n const labelId = useLabelContext(button)\n const labelledBy = ariaLabelledby || labelId\n\n if (!isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (!props.id) return\n return registerFocusable(props.id, {\n focusAndSelect: () => {\n setChecked((x) => !x)\n },\n focus: () => {},\n })\n }, [props.id, setChecked])\n }\n\n return (\n // YStack is here to provide theme for native input\n <YStack asChild theme={checkboxProps.theme}>\n <CheckboxProvider\n scope={__scopeCheckbox}\n state={checked}\n disabled={disabled}\n size={size}\n scaleIcon={scaleIcon}\n >\n {isWeb && native ? (\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 id={props.id}\n />\n ) : (\n <>\n <CheckboxFrame\n width={size}\n height={size}\n theme={checked ? 'active' : null}\n tag=\"button\"\n role=\"checkbox\"\n aria-labelledby={labelledBy}\n aria-checked={isIndeterminate(checked) ? 'mixed' : checked}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n {...checkboxProps}\n ref={composedRefs}\n {...(isWeb && {\n type: 'button',\n value: value,\n onKeyDown: composeEventHandlers(\n (props as React.HTMLProps<HTMLButtonElement>).onKeyDown,\n (event) => {\n // According to WAI ARIA, Checkboxes don't activate on enter keypress\n if (event.key === 'Enter') event.preventDefault()\n }\n ),\n })}\n onPress={composeEventHandlers(props.onPress as any, (event) => {\n setChecked((prevChecked) =>\n isIndeterminate(prevChecked) ? true : !prevChecked\n )\n if (isFormControl) {\n hasConsumerStoppedPropagationRef.current =\n 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)\n event.stopPropagation()\n }\n })}\n />\n\n {isWeb && isFormControl ? (\n <BubbleInput\n isHidden\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\n />\n ) : null}\n </>\n )}\n </CheckboxProvider>\n </YStack>\n )\n }\n )\n ),\n {\n Indicator: CheckboxIndicator,\n }\n)\n\nCheckbox.displayName = CHECKBOX_NAME\n\nexport { createCheckboxScope }\n\nconst cloneElementWithPropOrder = (child: any, props: Object) => {\n const next = mergeProps(child.props, props, false, getConfig().shorthands)[0]\n return React.cloneElement({ ...child, props: null }, next)\n}\n"],
5
+ "mappings": "AAGA,SAAS,mBAAmB;AAC5B;AAAA,EAIE;AAAA,EACA;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6C;AAAA,kBAC9C,CAAC,UAAU;AAET,wBAAI,MAAM,QAAQ;AAAS,4BAAM,eAAe;AAAA,kBAClD;AAAA,gBACF;AAAA,cACF;AAAA,cACA,SAAS,qBAAqB,MAAM,SAAgB,CAAC,UAAU;AAC7D;AAAA,kBAAW,CAAC,gBACV,gBAAgB,WAAW,IAAI,OAAO,CAAC;AAAA,gBACzC;AACA,oBAAI,eAAe;AACjB,mDAAiC,UAC/B,MAAM,qBAAqB;AAI7B,sBAAI,CAAC,iCAAiC;AACpC,0BAAM,gBAAgB;AAAA,gBAC1B;AAAA,cACF,CAAC;AAAA,YACH;AAAA,aAEC,SAAS,gBACR,CAAC;AAAA,cACC;AAAA,cACA,SAAS;AAAA,cACT,SAAS,CAAC,iCAAiC;AAAA,cAC3C,MAAM;AAAA,cACN,OAAO;AAAA,cACP,SAAS;AAAA,cACT,UAAU;AAAA,cACV,UAAU;AAAA,YACZ,KACE;AAAA,UACN,IAEJ,EA3EC,iBA4EH,EA7EC;AAAA;AAAA,MA+EL;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE,WAAW;AAAA,EACb;AACF;AAEA,SAAS,cAAc;AAIvB,MAAM,4BAA4B,CAAC,OAAY,UAAkB;AAC/D,QAAM,OAAO,WAAW,MAAM,OAAO,OAAO,OAAO,UAAU,EAAE,UAAU,EAAE,CAAC;AAC5E,SAAO,MAAM,aAAa,EAAE,GAAG,OAAO,OAAO,KAAK,GAAG,IAAI;AAC3D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Checkbox";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './Checkbox'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Checkbox";
2
+ //# sourceMappingURL=index.mjs.map