@tamagui/checkbox 2.0.0-rc.4 → 2.0.0-rc.40

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.
Files changed (62) hide show
  1. package/dist/cjs/Checkbox.cjs +93 -88
  2. package/dist/cjs/Checkbox.native.js +93 -91
  3. package/dist/cjs/Checkbox.native.js.map +1 -1
  4. package/dist/cjs/CheckboxStyledContext.cjs +14 -12
  5. package/dist/cjs/CheckboxStyledContext.native.js +20 -18
  6. package/dist/cjs/CheckboxStyledContext.native.js.map +1 -1
  7. package/dist/cjs/createCheckbox.cjs +163 -153
  8. package/dist/cjs/createCheckbox.native.js +180 -176
  9. package/dist/cjs/createCheckbox.native.js.map +1 -1
  10. package/dist/cjs/index.cjs +15 -13
  11. package/dist/cjs/index.native.js +15 -13
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/esm/Checkbox.mjs +77 -74
  14. package/dist/esm/Checkbox.mjs.map +1 -1
  15. package/dist/esm/Checkbox.native.js +77 -77
  16. package/dist/esm/Checkbox.native.js.map +1 -1
  17. package/dist/esm/CheckboxStyledContext.mjs +2 -2
  18. package/dist/esm/CheckboxStyledContext.native.js +2 -2
  19. package/dist/esm/createCheckbox.mjs +119 -114
  20. package/dist/esm/createCheckbox.mjs.map +1 -1
  21. package/dist/esm/createCheckbox.native.js +134 -136
  22. package/dist/esm/createCheckbox.native.js.map +1 -1
  23. package/dist/esm/index.js +6 -8
  24. package/dist/esm/index.js.map +1 -6
  25. package/dist/jsx/Checkbox.mjs +77 -74
  26. package/dist/jsx/Checkbox.mjs.map +1 -1
  27. package/dist/jsx/Checkbox.native.js +93 -91
  28. package/dist/jsx/Checkbox.native.js.map +1 -1
  29. package/dist/jsx/CheckboxStyledContext.mjs +2 -2
  30. package/dist/jsx/CheckboxStyledContext.native.js +20 -18
  31. package/dist/jsx/CheckboxStyledContext.native.js.map +1 -1
  32. package/dist/jsx/createCheckbox.mjs +119 -114
  33. package/dist/jsx/createCheckbox.mjs.map +1 -1
  34. package/dist/jsx/createCheckbox.native.js +180 -176
  35. package/dist/jsx/createCheckbox.native.js.map +1 -1
  36. package/dist/jsx/index.js +6 -8
  37. package/dist/jsx/index.js.map +1 -6
  38. package/dist/jsx/index.native.js +15 -13
  39. package/dist/jsx/index.native.js.map +1 -1
  40. package/package.json +19 -22
  41. package/types/createCheckbox.d.ts +3 -3
  42. package/types/index.d.ts +3 -3
  43. package/dist/cjs/Checkbox.js +0 -108
  44. package/dist/cjs/Checkbox.js.map +0 -6
  45. package/dist/cjs/CheckboxStyledContext.js +0 -28
  46. package/dist/cjs/CheckboxStyledContext.js.map +0 -6
  47. package/dist/cjs/createCheckbox.js +0 -165
  48. package/dist/cjs/createCheckbox.js.map +0 -6
  49. package/dist/cjs/index.js +0 -28
  50. package/dist/cjs/index.js.map +0 -6
  51. package/dist/esm/Checkbox.js +0 -95
  52. package/dist/esm/Checkbox.js.map +0 -6
  53. package/dist/esm/CheckboxStyledContext.js +0 -12
  54. package/dist/esm/CheckboxStyledContext.js.map +0 -6
  55. package/dist/esm/createCheckbox.js +0 -158
  56. package/dist/esm/createCheckbox.js.map +0 -6
  57. package/dist/jsx/Checkbox.js +0 -95
  58. package/dist/jsx/Checkbox.js.map +0 -6
  59. package/dist/jsx/CheckboxStyledContext.js +0 -12
  60. package/dist/jsx/CheckboxStyledContext.js.map +0 -6
  61. package/dist/jsx/createCheckbox.js +0 -158
  62. package/dist/jsx/createCheckbox.js.map +0 -6
@@ -2,182 +2,192 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var createCheckbox_exports = {};
33
35
  __export(createCheckbox_exports, {
34
36
  CheckboxContext: () => CheckboxContext,
35
37
  createCheckbox: () => createCheckbox
36
38
  });
37
39
  module.exports = __toCommonJS(createCheckbox_exports);
38
- var import_checkbox_headless = require("@tamagui/checkbox-headless"),
39
- import_core = require("@tamagui/core"),
40
- import_focusable = require("@tamagui/focusable"),
41
- import_font_size = require("@tamagui/font-size"),
42
- import_get_token = require("@tamagui/get-token"),
43
- import_helpers_tamagui = require("@tamagui/helpers-tamagui"),
44
- import_use_controllable_state = require("@tamagui/use-controllable-state"),
45
- import_react = __toESM(require("react"), 1),
46
- import_Checkbox = require("./Checkbox.cjs"),
47
- import_CheckboxStyledContext = require("./CheckboxStyledContext.cjs"),
48
- import_jsx_runtime = require("react/jsx-runtime");
40
+ var import_checkbox_headless = require("@tamagui/checkbox-headless");
41
+ var import_core = require("@tamagui/core");
42
+ require("@tamagui/focusable");
43
+ var import_font_size = require("@tamagui/font-size");
44
+ var import_get_token = require("@tamagui/get-token");
45
+ var import_helpers_tamagui = require("@tamagui/helpers-tamagui");
46
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
47
+ var import_react = __toESM(require("react"), 1);
48
+ var import_Checkbox = require("./Checkbox.cjs");
49
+ var import_CheckboxStyledContext = require("./CheckboxStyledContext.cjs");
50
+ var import_jsx_runtime = require("react/jsx-runtime");
49
51
  const CheckboxContext = import_react.default.createContext({
50
- checked: !1,
51
- disabled: !1
52
- }),
53
- ensureContext = x => {
54
- x.context || (x.context = CheckboxContext);
55
- };
52
+ checked: false,
53
+ disabled: false
54
+ });
55
+ const ensureContext = x => {
56
+ if (!x.context) x.context = CheckboxContext;
57
+ };
56
58
  function createCheckbox(createProps) {
57
59
  const {
58
60
  Frame = import_Checkbox.CheckboxFrame,
59
61
  Indicator = import_Checkbox.CheckboxIndicatorFrame
60
62
  } = createProps;
61
- ensureContext(Frame), ensureContext(Indicator);
62
- const FrameComponent = Frame.styleable(function (_props, forwardedRef) {
63
- const {
64
- scaleSize = 0.45,
65
- sizeAdjust = 0,
66
- scaleIcon,
67
- checked: checkedProp,
68
- defaultChecked,
69
- onCheckedChange,
70
- native,
71
- unstyled = !1,
72
- activeStyle,
73
- activeTheme,
74
- ...props
75
- } = _props,
76
- propsActive = (0, import_core.useProps)(props),
77
- styledContext = import_react.default.useContext(import_CheckboxStyledContext.CheckboxStyledContext.context);
78
- let adjustedSize = 0,
79
- size = 0;
80
- unstyled || (adjustedSize = (0, import_core.getVariableValue)((0, import_get_token.getSize)(propsActive.size ?? styledContext?.size ?? "$true", {
63
+ ensureContext(Frame);
64
+ ensureContext(Indicator);
65
+ const FrameComponent = Frame.styleable(function Checkbox(_props, forwardedRef) {
66
+ const {
67
+ scaleSize = .45,
68
+ sizeAdjust = 0,
69
+ scaleIcon,
70
+ checked: checkedProp,
71
+ defaultChecked,
72
+ onCheckedChange,
73
+ native,
74
+ unstyled = false,
75
+ activeStyle,
76
+ activeTheme,
77
+ ...props
78
+ } = _props;
79
+ const propsActive = (0, import_core.useProps)(props);
80
+ const styledContext = import_react.default.useContext(import_CheckboxStyledContext.CheckboxStyledContext.context);
81
+ let adjustedSize = 0;
82
+ let size = 0;
83
+ if (!unstyled) {
84
+ adjustedSize = (0, import_core.getVariableValue)((0, import_get_token.getSize)(propsActive.size ?? styledContext?.size ?? "$true", {
81
85
  shift: sizeAdjust
82
- })), size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize);
83
- const [checked = !1, setChecked] = (0, import_use_controllable_state.useControllableState)({
84
- prop: checkedProp,
85
- defaultProp: defaultChecked,
86
- onChange: onCheckedChange
87
- }),
88
- {
89
- checkboxProps,
90
- checkboxRef,
91
- bubbleInput
92
- } = (0, import_checkbox_headless.useCheckbox)(
93
- // @ts-ignore
94
- propsActive, [checked, setChecked], forwardedRef);
95
- if ((0, import_core.shouldRenderNativePlatform)(native) === "web") return /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
96
- type: "checkbox",
97
- defaultChecked: (0, import_checkbox_headless.isIndeterminate)(checked) ? !1 : checked,
98
- tabIndex: -1,
99
- ref: checkboxRef,
100
- disabled: checkboxProps.disabled,
101
- style: {
102
- appearance: "auto",
103
- accentColor: "var(--color6)",
104
- ...checkboxProps.style
105
- }
106
- });
107
- const memoizedContext = (0, import_react.useMemo)(() => ({
108
- checked,
109
- disabled: checkboxProps.disabled
110
- }), [checked, checkboxProps.disabled]),
111
- isActive = !!checked,
112
- disabled = checkboxProps.disabled;
113
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(CheckboxContext.Provider, {
114
- value: memoizedContext,
115
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_CheckboxStyledContext.CheckboxStyledContext.Provider, {
116
- size: propsActive.size ?? styledContext?.size ?? "$true",
117
- scaleIcon: scaleIcon ?? styledContext?.scaleIcon ?? 1,
86
+ }));
87
+ size = scaleSize ? Math.round(adjustedSize * scaleSize) : adjustedSize;
88
+ }
89
+ const [checked = false, setChecked] = (0, import_use_controllable_state.useControllableState)({
90
+ prop: checkedProp,
91
+ defaultProp: defaultChecked,
92
+ onChange: onCheckedChange
93
+ });
94
+ const {
95
+ checkboxProps,
96
+ checkboxRef,
97
+ bubbleInput
98
+ } = (0, import_checkbox_headless.useCheckbox)(
99
+ // @ts-ignore
100
+ propsActive, [checked, setChecked], forwardedRef);
101
+ if ((0, import_core.shouldRenderNativePlatform)(native) === "web") return /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
102
+ type: "checkbox",
103
+ defaultChecked: (0, import_checkbox_headless.isIndeterminate)(checked) ? false : checked,
104
+ tabIndex: -1,
105
+ ref: checkboxRef,
106
+ disabled: checkboxProps.disabled,
107
+ style: {
108
+ appearance: "auto",
109
+ accentColor: "var(--color6)",
110
+ ...checkboxProps.style
111
+ }
112
+ });
113
+ const memoizedContext = (0, import_react.useMemo)(() => ({
114
+ checked,
115
+ disabled: checkboxProps.disabled
116
+ }), [checked, checkboxProps.disabled]);
117
+ const isActive = !!checked;
118
+ const disabled = checkboxProps.disabled;
119
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(CheckboxContext.Provider, {
120
+ value: memoizedContext,
121
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_CheckboxStyledContext.CheckboxStyledContext.Provider, {
122
+ size: propsActive.size ?? styledContext?.size ?? "$true",
123
+ scaleIcon: scaleIcon ?? styledContext?.scaleIcon ?? 1,
124
+ unstyled,
125
+ active: isActive,
126
+ disabled,
127
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
128
+ render: "button",
129
+ ref: checkboxRef,
118
130
  unstyled,
119
- active: isActive,
131
+ theme: activeTheme ?? null,
132
+ ...(import_core.isWeb && {
133
+ type: "button"
134
+ }),
135
+ ...(!unstyled && {
136
+ width: size,
137
+ height: size,
138
+ size
139
+ }),
140
+ checked,
120
141
  disabled,
121
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(Frame, {
122
- render: "button",
123
- ref: checkboxRef,
124
- unstyled,
125
- theme: activeTheme ?? null,
126
- ...(import_core.isWeb && {
127
- type: "button"
128
- }),
129
- ...(!unstyled && {
130
- width: size,
131
- height: size,
132
- size
142
+ ...checkboxProps,
143
+ ...props,
144
+ ...(isActive && {
145
+ ...(!unstyled && !activeStyle && {
146
+ backgroundColor: "$backgroundActive"
133
147
  }),
134
- checked,
135
- disabled,
136
- ...checkboxProps,
137
- ...props,
138
- ...(isActive && {
139
- ...(!unstyled && !activeStyle && {
140
- backgroundColor: "$backgroundActive"
141
- }),
142
- ...activeStyle
143
- }),
144
- children: propsActive.children
145
- }), bubbleInput]
146
- })
148
+ ...activeStyle
149
+ }),
150
+ children: propsActive.children
151
+ }), bubbleInput]
152
+ })
153
+ });
154
+ });
155
+ const IndicatorComponent = Indicator.styleable((props, forwardedRef) => {
156
+ const {
157
+ children: childrenProp,
158
+ forceMount,
159
+ disablePassStyles,
160
+ unstyled = false,
161
+ activeStyle,
162
+ ...indicatorProps
163
+ } = props;
164
+ const styledContext = import_CheckboxStyledContext.CheckboxStyledContext.useStyledContext();
165
+ const {
166
+ active
167
+ } = styledContext;
168
+ let children = childrenProp;
169
+ if (!unstyled) {
170
+ const iconSize = (typeof styledContext.size === "number" ? styledContext.size * .65 : (0, import_font_size.getFontSize)(styledContext.size)) * styledContext.scaleIcon;
171
+ const theme = (0, import_core.useTheme)();
172
+ const getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
173
+ size: iconSize,
174
+ color: theme.color
147
175
  });
148
- }),
149
- IndicatorComponent = Indicator.styleable((props, forwardedRef) => {
150
- const {
151
- children: childrenProp,
152
- forceMount,
153
- disablePassStyles,
154
- unstyled = !1,
155
- activeStyle,
156
- ...indicatorProps
157
- } = props,
158
- styledContext = import_CheckboxStyledContext.CheckboxStyledContext.useStyledContext(),
159
- {
160
- active
161
- } = styledContext;
162
- let children = childrenProp;
163
- if (!unstyled) {
164
- const iconSize = (typeof styledContext.size == "number" ? styledContext.size * 0.65 : (0, import_font_size.getFontSize)(styledContext.size)) * styledContext.scaleIcon,
165
- theme = (0, import_core.useTheme)(),
166
- getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
167
- size: iconSize,
168
- color: theme.color
169
- });
170
- children = import_react.default.Children.toArray(childrenProp).map(child => disablePassStyles || !import_react.default.isValidElement(child) ? child : getThemedIcon(child));
171
- }
172
- const context = import_react.default.useContext(CheckboxContext);
173
- return forceMount || (0, import_checkbox_headless.isIndeterminate)(context.checked) || context.checked === !0 ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(Indicator, {
174
- pointerEvents: "none",
175
- ...indicatorProps,
176
- ...(active && activeStyle),
177
- ref: forwardedRef,
178
- children
179
- }) : null;
176
+ children = import_react.default.Children.toArray(childrenProp).map(child => {
177
+ if (disablePassStyles || !import_react.default.isValidElement(child)) return child;
178
+ return getThemedIcon(child);
179
+ });
180
+ }
181
+ const context = import_react.default.useContext(CheckboxContext);
182
+ if (forceMount || (0, import_checkbox_headless.isIndeterminate)(context.checked) || context.checked === true) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Indicator, {
183
+ pointerEvents: "none",
184
+ ...indicatorProps,
185
+ ...(active && activeStyle),
186
+ ref: forwardedRef,
187
+ children
180
188
  });
189
+ return null;
190
+ });
181
191
  return (0, import_core.withStaticProperties)(FrameComponent, {
182
192
  Indicator: IndicatorComponent
183
193
  });