@tamagui/checkbox 2.0.0-rc.3 → 2.0.0-rc.31
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/index.js +6 -8
- package/dist/esm/index.js.map +1 -6
- package/dist/jsx/index.js +6 -8
- package/dist/jsx/index.js.map +1 -6
- package/package.json +19 -22
- package/types/createCheckbox.d.ts +3 -3
- package/types/index.d.ts +3 -3
- package/dist/cjs/Checkbox.js +0 -108
- package/dist/cjs/Checkbox.js.map +0 -6
- package/dist/cjs/CheckboxStyledContext.js +0 -28
- package/dist/cjs/CheckboxStyledContext.js.map +0 -6
- package/dist/cjs/createCheckbox.js +0 -165
- package/dist/cjs/createCheckbox.js.map +0 -6
- package/dist/cjs/index.js +0 -28
- package/dist/cjs/index.js.map +0 -6
- package/dist/esm/Checkbox.js +0 -95
- package/dist/esm/Checkbox.js.map +0 -6
- package/dist/esm/CheckboxStyledContext.js +0 -12
- package/dist/esm/CheckboxStyledContext.js.map +0 -6
- package/dist/esm/createCheckbox.js +0 -158
- package/dist/esm/createCheckbox.js.map +0 -6
- package/dist/jsx/Checkbox.js +0 -95
- package/dist/jsx/Checkbox.js.map +0 -6
- package/dist/jsx/CheckboxStyledContext.js +0 -12
- package/dist/jsx/CheckboxStyledContext.js.map +0 -6
- package/dist/jsx/createCheckbox.js +0 -158
- package/dist/jsx/createCheckbox.js.map +0 -6
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { isIndeterminate, useCheckbox } from "@tamagui/checkbox-headless";
|
|
2
|
-
import {
|
|
3
|
-
getVariableValue,
|
|
4
|
-
isWeb,
|
|
5
|
-
shouldRenderNativePlatform,
|
|
6
|
-
useProps,
|
|
7
|
-
useTheme,
|
|
8
|
-
withStaticProperties
|
|
9
|
-
} from "@tamagui/core";
|
|
10
|
-
|
|
11
|
-
import { getFontSize } from "@tamagui/font-size";
|
|
12
|
-
import { getSize } from "@tamagui/get-token";
|
|
13
|
-
import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
|
|
14
|
-
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
15
|
-
import React, { useMemo } from "react";
|
|
16
|
-
import { CheckboxFrame, CheckboxIndicatorFrame } from "./Checkbox";
|
|
17
|
-
import { CheckboxStyledContext } from "./CheckboxStyledContext";
|
|
18
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
-
const CheckboxContext = React.createContext({
|
|
20
|
-
checked: !1,
|
|
21
|
-
disabled: !1
|
|
22
|
-
}), ensureContext = (x) => {
|
|
23
|
-
x.context || (x.context = CheckboxContext);
|
|
24
|
-
};
|
|
25
|
-
function createCheckbox(createProps) {
|
|
26
|
-
const { Frame = CheckboxFrame, Indicator = CheckboxIndicatorFrame } = createProps;
|
|
27
|
-
ensureContext(Frame), ensureContext(Indicator);
|
|
28
|
-
const FrameComponent = Frame.styleable(
|
|
29
|
-
function(_props, forwardedRef) {
|
|
30
|
-
const {
|
|
31
|
-
scaleSize = 0.45,
|
|
32
|
-
sizeAdjust = 0,
|
|
33
|
-
scaleIcon,
|
|
34
|
-
checked: checkedProp,
|
|
35
|
-
defaultChecked,
|
|
36
|
-
onCheckedChange,
|
|
37
|
-
native,
|
|
38
|
-
unstyled = !1,
|
|
39
|
-
activeStyle,
|
|
40
|
-
activeTheme,
|
|
41
|
-
...props
|
|
42
|
-
} = _props, propsActive = useProps(props), styledContext = React.useContext(CheckboxStyledContext.context);
|
|
43
|
-
let adjustedSize = 0, size = 0;
|
|
44
|
-
unstyled || (adjustedSize = getVariableValue(
|
|
45
|
-
getSize(propsActive.size ?? styledContext?.size ?? "$true", {
|
|
46
|
-
shift: sizeAdjust
|
|
47
|
-
})
|
|
48
|
-
), size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize);
|
|
49
|
-
const [checked = !1, setChecked] = useControllableState({
|
|
50
|
-
prop: checkedProp,
|
|
51
|
-
defaultProp: defaultChecked,
|
|
52
|
-
onChange: onCheckedChange
|
|
53
|
-
}), { checkboxProps, checkboxRef, bubbleInput } = useCheckbox(
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
propsActive,
|
|
56
|
-
[checked, setChecked],
|
|
57
|
-
forwardedRef
|
|
58
|
-
);
|
|
59
|
-
if (shouldRenderNativePlatform(native) === "web")
|
|
60
|
-
return /* @__PURE__ */ jsx(
|
|
61
|
-
"input",
|
|
62
|
-
{
|
|
63
|
-
type: "checkbox",
|
|
64
|
-
defaultChecked: isIndeterminate(checked) ? !1 : checked,
|
|
65
|
-
tabIndex: -1,
|
|
66
|
-
ref: checkboxRef,
|
|
67
|
-
disabled: checkboxProps.disabled,
|
|
68
|
-
style: {
|
|
69
|
-
appearance: "auto",
|
|
70
|
-
accentColor: "var(--color6)",
|
|
71
|
-
...checkboxProps.style
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
const memoizedContext = useMemo(
|
|
76
|
-
() => ({
|
|
77
|
-
checked,
|
|
78
|
-
disabled: checkboxProps.disabled
|
|
79
|
-
}),
|
|
80
|
-
[checked, checkboxProps.disabled]
|
|
81
|
-
), isActive = !!checked, disabled = checkboxProps.disabled;
|
|
82
|
-
return /* @__PURE__ */ jsx(CheckboxContext.Provider, { value: memoizedContext, children: /* @__PURE__ */ jsxs(
|
|
83
|
-
CheckboxStyledContext.Provider,
|
|
84
|
-
{
|
|
85
|
-
size: propsActive.size ?? styledContext?.size ?? "$true",
|
|
86
|
-
scaleIcon: scaleIcon ?? styledContext?.scaleIcon ?? 1,
|
|
87
|
-
unstyled,
|
|
88
|
-
active: isActive,
|
|
89
|
-
disabled,
|
|
90
|
-
children: [
|
|
91
|
-
/* @__PURE__ */ jsx(
|
|
92
|
-
Frame,
|
|
93
|
-
{
|
|
94
|
-
render: "button",
|
|
95
|
-
ref: checkboxRef,
|
|
96
|
-
unstyled,
|
|
97
|
-
theme: activeTheme ?? null,
|
|
98
|
-
...isWeb && { type: "button" },
|
|
99
|
-
...!unstyled && {
|
|
100
|
-
width: size,
|
|
101
|
-
height: size,
|
|
102
|
-
size
|
|
103
|
-
},
|
|
104
|
-
checked,
|
|
105
|
-
disabled,
|
|
106
|
-
...checkboxProps,
|
|
107
|
-
...props,
|
|
108
|
-
...isActive && {
|
|
109
|
-
...!unstyled && !activeStyle && {
|
|
110
|
-
backgroundColor: "$backgroundActive"
|
|
111
|
-
},
|
|
112
|
-
...activeStyle
|
|
113
|
-
},
|
|
114
|
-
children: propsActive.children
|
|
115
|
-
}
|
|
116
|
-
),
|
|
117
|
-
bubbleInput
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
) });
|
|
121
|
-
}
|
|
122
|
-
), IndicatorComponent = Indicator.styleable(
|
|
123
|
-
(props, forwardedRef) => {
|
|
124
|
-
const {
|
|
125
|
-
children: childrenProp,
|
|
126
|
-
forceMount,
|
|
127
|
-
disablePassStyles,
|
|
128
|
-
unstyled = !1,
|
|
129
|
-
activeStyle,
|
|
130
|
-
...indicatorProps
|
|
131
|
-
} = props, styledContext = CheckboxStyledContext.useStyledContext(), { active } = styledContext;
|
|
132
|
-
let children = childrenProp;
|
|
133
|
-
if (!unstyled) {
|
|
134
|
-
const iconSize = (typeof styledContext.size == "number" ? styledContext.size * 0.65 : getFontSize(styledContext.size)) * styledContext.scaleIcon, theme = useTheme(), getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color });
|
|
135
|
-
children = React.Children.toArray(childrenProp).map((child) => disablePassStyles || !React.isValidElement(child) ? child : getThemedIcon(child));
|
|
136
|
-
}
|
|
137
|
-
const context = React.useContext(CheckboxContext);
|
|
138
|
-
return forceMount || isIndeterminate(context.checked) || context.checked === !0 ? /* @__PURE__ */ jsx(
|
|
139
|
-
Indicator,
|
|
140
|
-
{
|
|
141
|
-
pointerEvents: "none",
|
|
142
|
-
...indicatorProps,
|
|
143
|
-
...active && activeStyle,
|
|
144
|
-
ref: forwardedRef,
|
|
145
|
-
children
|
|
146
|
-
}
|
|
147
|
-
) : null;
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
return withStaticProperties(FrameComponent, {
|
|
151
|
-
Indicator: IndicatorComponent
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
export {
|
|
155
|
-
CheckboxContext,
|
|
156
|
-
createCheckbox
|
|
157
|
-
};
|
|
158
|
-
//# sourceMappingURL=createCheckbox.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/createCheckbox.tsx"],
|
|
4
|
-
"mappings": "AAIA,SAAS,iBAAiB,mBAAmB;AAE7C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAkC;AAClC,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,OAAO,SAAS,eAAe;AAE/B,SAAS,eAAe,8BAA8B;AACtD,SAAS,6BAA6B;AA2I5B,cA4BA,YA5BA;AAtFH,MAAM,kBAAkB,MAAM,cAGlC;AAAA,EACD,SAAS;AAAA,EACT,UAAU;AACZ,CAAC,GAEK,gBAAgB,CAAC,MAAW;AAChC,EAAK,EAAE,YACL,EAAE,UAAU;AAEhB;AAEO,SAAS,eAGd,aAA2C;AAC3C,QAAM,EAAE,QAAQ,eAAe,YAAY,uBAAuB,IAChE;AAKF,gBAAc,KAAK,GACnB,cAAc,SAAS;AAEvB,QAAM,iBAAiB,MAAM;AAAA,IAC3B,SAAkB,QAAQ,cAAc;AACtC,YAAM;AAAA,QACJ,YAAY;AAAA,QACZ,aAAa;AAAA,QACb;AAAA,QACA,SAAS;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL,IAAI,QACE,cAAc,SAAS,KAAK,GAE5B,gBAAgB,MAAM,WAAW,sBAAsB,OAAO;AACpE,UAAI,eAA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