@tamagui/button 2.7.7 → 3.0.0-beta.643.1

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 (48) hide show
  1. package/dist/cjs/Button.cjs +180 -266
  2. package/dist/cjs/Button.native.cjs +224 -0
  3. package/dist/cjs/Button.native.js +200 -271
  4. package/dist/cjs/Button.native.js.map +1 -1
  5. package/dist/cjs/index.cjs +10 -11
  6. package/dist/cjs/index.native.cjs +21 -0
  7. package/dist/cjs/index.native.js +10 -10
  8. package/dist/cjs/index.native.js.map +1 -1
  9. package/dist/esm/Button.mjs +168 -255
  10. package/dist/esm/Button.mjs.map +1 -1
  11. package/dist/esm/Button.native.js +188 -261
  12. package/dist/esm/Button.native.js.map +1 -1
  13. package/dist/esm/index.js +1 -2
  14. package/dist/esm/index.mjs +1 -2
  15. package/dist/esm/index.native.js +1 -2
  16. package/dist/jsx/Button.mjs +168 -255
  17. package/dist/jsx/Button.mjs.map +1 -1
  18. package/dist/jsx/Button.native.cjs +224 -0
  19. package/dist/jsx/Button.native.js +200 -271
  20. package/dist/jsx/Button.native.js.map +1 -1
  21. package/dist/jsx/index.js +1 -2
  22. package/dist/jsx/index.mjs +1 -2
  23. package/dist/jsx/index.native.cjs +21 -0
  24. package/dist/jsx/index.native.js +10 -10
  25. package/dist/jsx/index.native.js.map +1 -1
  26. package/package.json +11 -12
  27. package/src/Button.tsx +222 -280
  28. package/types/Button.d.ts +218 -114
  29. package/types/Button.d.ts.map +1 -1
  30. package/dist/cjs/Button.test.cjs +0 -37
  31. package/dist/cjs/Button.test.native.js +0 -40
  32. package/dist/cjs/Button.test.native.js.map +0 -1
  33. package/dist/esm/Button.test.mjs +0 -38
  34. package/dist/esm/Button.test.mjs.map +0 -1
  35. package/dist/esm/Button.test.native.js +0 -38
  36. package/dist/esm/Button.test.native.js.map +0 -1
  37. package/dist/esm/index.js.map +0 -1
  38. package/dist/esm/index.mjs.map +0 -1
  39. package/dist/esm/index.native.js.map +0 -1
  40. package/dist/jsx/Button.test.mjs +0 -38
  41. package/dist/jsx/Button.test.mjs.map +0 -1
  42. package/dist/jsx/Button.test.native.js +0 -40
  43. package/dist/jsx/Button.test.native.js.map +0 -1
  44. package/dist/jsx/index.js.map +0 -1
  45. package/dist/jsx/index.mjs.map +0 -1
  46. package/src/Button.test.tsx +0 -45
  47. package/types/Button.test.d.ts +0 -2
  48. package/types/Button.test.d.ts.map +0 -1
@@ -1,289 +1,203 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var Button_exports = {};
24
23
  __export(Button_exports, {
25
- Button: () => Button,
26
- ButtonContext: () => ButtonContext
24
+ Button: () => Button2,
25
+ ButtonContext: () => ButtonContext,
26
+ ButtonFrame: () => ButtonFrame,
27
+ ButtonIcon: () => ButtonIcon,
28
+ ButtonText: () => ButtonText,
29
+ useButton: () => useButton
27
30
  });
28
31
  module.exports = __toCommonJS(Button_exports);
29
- var import_font_size = require("@tamagui/font-size");
30
- var import_get_button_sized = require("@tamagui/get-button-sized");
31
32
  var import_helpers_tamagui = require("@tamagui/helpers-tamagui");
32
33
  var import_stacks = require("@tamagui/stacks");
33
34
  var import_text = require("@tamagui/text");
34
35
  var import_web = require("@tamagui/web");
35
36
  var import_react = require("react");
36
37
  var import_jsx_runtime = require("react/jsx-runtime");
37
- const context = (0, import_web.createStyledContext)({
38
- size: void 0,
39
- variant: void 0,
40
- color: void 0,
41
- elevation: void 0,
42
- ellipsis: void 0,
43
- fontFamily: void 0,
44
- fontSize: void 0,
45
- fontStyle: void 0,
46
- fontWeight: void 0,
47
- letterSpacing: void 0,
48
- maxFontSizeMultiplier: void 0,
49
- textAlign: void 0
50
- });
51
- const Frame = (0, import_web.styled)(import_web.View, {
52
- context,
53
- name: "Button",
54
- role: "button",
55
- render: /* @__PURE__ */(0, import_jsx_runtime.jsx)("button", {
56
- type: "button"
57
- }),
58
- tabIndex: 0,
59
- variants: {
60
- unstyled: {
61
- true: {
62
- // reset browser <button> defaults
63
- outlineWidth: 0,
64
- borderWidth: 0,
65
- backgroundColor: "transparent"
66
- },
67
- false: {
68
- size: "$true",
69
- justifyContent: "center",
70
- alignItems: "center",
71
- flexWrap: "nowrap",
72
- flexDirection: "row",
73
- backgroundColor: "$background",
74
- borderWidth: 1,
75
- borderColor: "transparent",
76
- "$platform-web": {
77
- cursor: "pointer"
78
- },
79
- hoverStyle: {
80
- backgroundColor: "$backgroundHover",
81
- borderColor: "$borderColorHover"
82
- },
83
- pressStyle: {
84
- backgroundColor: "$backgroundPress",
85
- borderColor: "$borderColorHover"
86
- },
87
- focusVisibleStyle: {
88
- outlineColor: "$outlineColor",
89
- outlineStyle: "solid",
90
- outlineWidth: 2
91
- }
92
- }
93
- },
94
- variant: {
95
- outlined: process.env.TAMAGUI_HEADLESS === "1" ? {} : {
96
- backgroundColor: "transparent",
97
- borderWidth: 1,
98
- borderColor: "$borderColor",
99
- hoverStyle: {
100
- backgroundColor: "transparent",
101
- borderColor: "$borderColorHover"
102
- },
103
- pressStyle: {
104
- backgroundColor: "transparent",
105
- borderColor: "$borderColorPress"
106
- }
107
- }
108
- },
109
- circular: import_stacks.themeableVariants.circular,
110
- chromeless: import_stacks.themeableVariants.chromeless,
111
- size: {
112
- "...size": (val, extras) => {
113
- const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
114
- const gap = (0, import_web.getTokenValue)(val);
115
- return {
116
- ...buttonStyle,
117
- gap
118
- };
119
- },
120
- ":number": (val, extras) => {
121
- const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
122
- const gap = val * 0.4;
123
- return {
124
- ...buttonStyle,
125
- gap
126
- };
127
- }
128
- },
129
- elevation: {
130
- "...size": import_stacks.getElevation,
131
- ":number": import_stacks.getElevation
132
- },
133
- disabled: {
134
- true: {
135
- pointerEvents: "none",
136
- // @ts-ignore
137
- "aria-disabled": true
138
- }
139
- }
140
- },
141
- defaultVariants: {
142
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
143
- }
38
+ const buttonContextKeys = [
39
+ "color",
40
+ "ellipsis",
41
+ "fontFamily",
42
+ "fontSize",
43
+ "fontStyle",
44
+ "fontWeight",
45
+ "letterSpacing",
46
+ "maxFontSizeMultiplier",
47
+ "textAlign"
48
+ ];
49
+ const ButtonContext = (0, import_web.createStyledContext)({
50
+ color: void 0,
51
+ ellipsis: void 0,
52
+ fontFamily: void 0,
53
+ fontSize: void 0,
54
+ fontStyle: void 0,
55
+ fontWeight: void 0,
56
+ letterSpacing: void 0,
57
+ maxFontSizeMultiplier: void 0,
58
+ textAlign: void 0
59
+ }, { keys: buttonContextKeys });
60
+ const ButtonFrame = (0, import_web.styled)(import_web.View, {
61
+ context: ButtonContext,
62
+ displayName: "ButtonFrame",
63
+ role: "button",
64
+ render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button" }),
65
+ tabIndex: 0,
66
+ alignItems: "center",
67
+ flexDirection: "row",
68
+ flexWrap: "nowrap",
69
+ justifyContent: "center",
70
+ variants: { disabled: { true: { pointerEvents: "none" } } }
144
71
  });
145
- const Text = (0, import_web.styled)(import_text.SizableText, {
146
- context,
147
- variants: {
148
- unstyled: {
149
- false: {
150
- userSelect: "none",
151
- // flexGrow 1 leads to inconsistent native style where text pushes to start of view
152
- flexGrow: 0,
153
- flexShrink: 1,
154
- ellipsis: true,
155
- color: "$color",
156
- "$platform-web": {
157
- cursor: "pointer"
158
- }
159
- }
160
- }
161
- },
162
- defaultVariants: {
163
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
164
- }
72
+ const ButtonText = (0, import_web.styled)(import_web.Text, {
73
+ context: ButtonContext,
74
+ displayName: "ButtonText",
75
+ flexGrow: 0,
76
+ flexShrink: 1
165
77
  });
166
- const Icon = props => {
167
- const {
168
- children,
169
- scaleIcon = 1,
170
- size
171
- } = props;
172
- const styledContext = context.useStyledContext();
173
- if (!styledContext) {
174
- throw new Error("Button.Icon must be used within a Button");
175
- }
176
- const sizeToken = size ?? styledContext.size;
177
- const iconColorProp = styledContext.color === "unset" || typeof styledContext.color === "number" ? void 0 : styledContext.color;
178
- const iconColor = (0, import_helpers_tamagui.useCurrentColor)(iconColorProp);
179
- const iconSize = (typeof sizeToken === "number" ? sizeToken * 0.5 : (0, import_font_size.getFontSize)(sizeToken)) * scaleIcon;
180
- return (0, import_helpers_tamagui.getIcon)(children, {
181
- size: iconSize,
182
- color: iconColor
183
- });
78
+ const ButtonIcon = ({ children, color, scaleIcon = 1, size }) => {
79
+ const styledContext = ButtonContext.useStyledContext();
80
+ const iconColor = color ?? styledContext?.color;
81
+ const getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
82
+ color: iconColor === "unset" || typeof iconColor === "number" ? void 0 : iconColor,
83
+ size: size === void 0 ? void 0 : size * scaleIcon
84
+ });
85
+ return getThemedIcon(children);
184
86
  };
185
- const ButtonContext = (0, import_web.createStyledContext)({
186
- size: void 0,
187
- variant: void 0,
188
- color: void 0
87
+ const buttonInternalPropNames = [
88
+ "children",
89
+ "color",
90
+ "disabled",
91
+ "ellipsis",
92
+ "fontFamily",
93
+ "fontSize",
94
+ "fontStyle",
95
+ "fontWeight",
96
+ "icon",
97
+ "iconAfter",
98
+ "iconSize",
99
+ "letterSpacing",
100
+ "maxFontSizeMultiplier",
101
+ "noTextWrap",
102
+ "render",
103
+ "scaleIcon",
104
+ "textAlign",
105
+ "textProps"
106
+ ];
107
+ function useButton(propsIn, { Text: Text2 = ButtonText, iconColor: iconColorOption, iconSize: iconSizeOption, textProps: textPropsOption } = {}) {
108
+ const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext);
109
+ const styledContext = ButtonContext.useStyledContext();
110
+ const processedProps = (0, import_web.useProps)(propsIn, {
111
+ noNormalize: true,
112
+ noExpand: true
113
+ });
114
+ const { children, color, disabled, ellipsis, fontFamily, fontSize, fontStyle, fontWeight, icon, iconAfter, iconSize, letterSpacing, maxFontSizeMultiplier, noTextWrap, render, scaleIcon = 1, textAlign, textProps } = processedProps;
115
+ const frameProps = { ...propsIn };
116
+ for (const key of buttonInternalPropNames) {
117
+ delete frameProps[key];
118
+ }
119
+ const contextColor = color ?? styledContext?.color;
120
+ const iconColor = iconColorOption ?? contextColor;
121
+ const resolvedIconSize = iconSize ?? iconSizeOption;
122
+ const getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
123
+ color: iconColor === "unset" || typeof iconColor === "number" ? void 0 : iconColor,
124
+ size: resolvedIconSize === void 0 ? void 0 : resolvedIconSize * scaleIcon
125
+ });
126
+ const [themedIcon, themedIconAfter] = [icon, iconAfter].map((item) => {
127
+ return item ? getThemedIcon(item) : null;
128
+ });
129
+ const textContext = {
130
+ color: contextColor,
131
+ ellipsis: ellipsis ?? styledContext?.ellipsis,
132
+ fontFamily: fontFamily ?? styledContext?.fontFamily,
133
+ fontSize: fontSize ?? styledContext?.fontSize,
134
+ fontStyle: fontStyle ?? styledContext?.fontStyle,
135
+ fontWeight: fontWeight ?? styledContext?.fontWeight,
136
+ letterSpacing: letterSpacing ?? styledContext?.letterSpacing,
137
+ maxFontSizeMultiplier: maxFontSizeMultiplier ?? styledContext?.maxFontSizeMultiplier,
138
+ textAlign: textAlign ?? styledContext?.textAlign
139
+ };
140
+ const wrappedChildren = (0, import_text.wrapChildrenInText)(Text2, {
141
+ children,
142
+ ...textContext,
143
+ noTextWrap,
144
+ textProps
145
+ }, {
146
+ ...textPropsOption,
147
+ ...processedProps.size === void 0 ? null : { size: processedProps.size }
148
+ });
149
+ const resolvedRender = render ?? (isNested ? "span" : processedProps.accessibilityRole === "link" || processedProps.role === "link" ? "a" : disabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
150
+ type: "button",
151
+ disabled: true
152
+ }) : void 0);
153
+ const props = {
154
+ ...frameProps,
155
+ ...disabled && {
156
+ "aria-disabled": true,
157
+ disabled: true,
158
+ tabIndex: -1
159
+ },
160
+ ...resolvedRender === void 0 ? null : { render: resolvedRender },
161
+ ...isNested && {
162
+ role: "none",
163
+ tabIndex: -1,
164
+ "aria-disabled": void 0,
165
+ disabled: void 0,
166
+ onPress: void 0,
167
+ onPressIn: void 0,
168
+ onPressOut: void 0,
169
+ onLongPress: void 0,
170
+ onClick: void 0,
171
+ onKeyDown: void 0,
172
+ onKeyUp: void 0
173
+ },
174
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
175
+ value: true,
176
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ButtonContext.Provider, {
177
+ ...textContext,
178
+ children: [
179
+ themedIcon,
180
+ wrappedChildren,
181
+ themedIconAfter
182
+ ]
183
+ })
184
+ })
185
+ };
186
+ return {
187
+ isNested,
188
+ props
189
+ };
190
+ }
191
+ const ButtonComponent = (0, import_web.createStyledHOC)(ButtonFrame, function Button(props, ref) {
192
+ const { props: buttonProps } = useButton(props);
193
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonFrame, {
194
+ ref,
195
+ ...buttonProps
196
+ });
189
197
  });
190
- const ButtonComponent = Frame.styleable((propsIn, ref) => {
191
- const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext);
192
- const processedProps = (0, import_web.useProps)(propsIn, {
193
- noNormalize: true,
194
- noExpand: true
195
- });
196
- const {
197
- children,
198
- iconSize,
199
- icon,
200
- iconAfter,
201
- scaleIcon = 1,
202
- noTextWrap,
203
- textProps,
204
- color,
205
- ellipsis,
206
- fontFamily,
207
- fontSize,
208
- fontStyle,
209
- fontWeight,
210
- letterSpacing,
211
- maxFontSizeMultiplier,
212
- textAlign,
213
- ...props
214
- } = processedProps;
215
- const size = propsIn.size || (propsIn.unstyled ? void 0 : "$true");
216
- const styledContext = context.useStyledContext();
217
- const contextColor = color ?? propsIn.color ?? styledContext?.color;
218
- const iconColorProp = contextColor === "unset" || typeof contextColor === "number" ? void 0 : contextColor;
219
- const iconColor = (0, import_helpers_tamagui.useCurrentColor)(iconColorProp);
220
- const finalSize = iconSize ?? size ?? styledContext?.size;
221
- const iconSizeNumber = (typeof finalSize === "number" ? finalSize * 0.5 : (0, import_font_size.getFontSize)(finalSize)) * scaleIcon;
222
- const [themedIcon, themedIconAfter] = [icon, iconAfter].map(icon2 => {
223
- if (!icon2) return null;
224
- return (0, import_helpers_tamagui.getIcon)(icon2, {
225
- size: iconSizeNumber,
226
- color: iconColor
227
- // No marginLeft or marginRight needed - spacing is handled by the gap property in Frame's size variants
228
- });
229
- });
230
- const wrappedChildren = (0, import_text.wrapChildrenInText)(Text, {
231
- children,
232
- color: contextColor,
233
- ellipsis: ellipsis ?? propsIn.ellipsis ?? styledContext?.ellipsis,
234
- fontFamily: fontFamily ?? propsIn.fontFamily ?? styledContext?.fontFamily,
235
- fontSize: fontSize ?? propsIn.fontSize ?? styledContext?.fontSize,
236
- fontStyle: fontStyle ?? propsIn.fontStyle ?? styledContext?.fontStyle,
237
- fontWeight: fontWeight ?? propsIn.fontWeight ?? styledContext?.fontWeight,
238
- letterSpacing: letterSpacing ?? propsIn.letterSpacing ?? styledContext?.letterSpacing,
239
- maxFontSizeMultiplier: maxFontSizeMultiplier ?? propsIn.maxFontSizeMultiplier ?? styledContext?.maxFontSizeMultiplier,
240
- noTextWrap: noTextWrap ?? propsIn.noTextWrap,
241
- textAlign: textAlign ?? propsIn.textAlign ?? styledContext?.textAlign,
242
- textProps: textProps ?? propsIn.textProps
243
- }, {
244
- unstyled: process.env.TAMAGUI_HEADLESS === "1",
245
- size: finalSize ?? styledContext?.size
246
- });
247
- const textContext = {
248
- color: contextColor,
249
- ellipsis: ellipsis ?? propsIn.ellipsis ?? styledContext?.ellipsis,
250
- fontFamily: fontFamily ?? propsIn.fontFamily ?? styledContext?.fontFamily,
251
- fontSize: fontSize ?? propsIn.fontSize ?? styledContext?.fontSize,
252
- fontStyle: fontStyle ?? propsIn.fontStyle ?? styledContext?.fontStyle,
253
- fontWeight: fontWeight ?? propsIn.fontWeight ?? styledContext?.fontWeight,
254
- letterSpacing: letterSpacing ?? propsIn.letterSpacing ?? styledContext?.letterSpacing,
255
- maxFontSizeMultiplier: maxFontSizeMultiplier ?? propsIn.maxFontSizeMultiplier ?? styledContext?.maxFontSizeMultiplier,
256
- textAlign: textAlign ?? propsIn.textAlign ?? styledContext?.textAlign
257
- };
258
- const buttonContext = {
259
- ...styledContext,
260
- ...textContext,
261
- size: props.size ?? propsIn.size ?? styledContext?.size,
262
- variant: props.variant ?? propsIn.variant ?? styledContext?.variant,
263
- elevation: props.elevation ?? propsIn.elevation ?? styledContext?.elevation
264
- };
265
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
266
- value: true,
267
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(context.Provider, {
268
- ...buttonContext,
269
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(Frame, {
270
- ref,
271
- ...props,
272
- ...(isNested && {
273
- render: "span"
274
- }),
275
- ...(props.circular && !propsIn.size && {
276
- size
277
- }),
278
- tabIndex: 0,
279
- children: [themedIcon, wrappedChildren, themedIconAfter]
280
- })
281
- })
282
- });
198
+ const Button2 = (0, import_web.withStaticProperties)(ButtonComponent, {
199
+ Apply: ButtonContext.Provider,
200
+ Frame: ButtonFrame,
201
+ Icon: ButtonIcon,
202
+ Text: ButtonText
283
203
  });
284
- const Button = (0, import_web.withStaticProperties)(ButtonComponent, {
285
- Apply: context.Provider,
286
- Frame,
287
- Text,
288
- Icon
289
- });
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var Button_exports = {};
25
+ __export(Button_exports, {
26
+ Button: () => Button2,
27
+ ButtonContext: () => ButtonContext,
28
+ ButtonFrame: () => ButtonFrame,
29
+ ButtonIcon: () => ButtonIcon,
30
+ ButtonText: () => ButtonText,
31
+ useButton: () => useButton
32
+ });
33
+ module.exports = __toCommonJS(Button_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_helpers_tamagui = require("@tamagui/helpers-tamagui");
36
+ var import_stacks = require("@tamagui/stacks");
37
+ var import_text = require("@tamagui/text");
38
+ var import_web = require("@tamagui/web");
39
+ var import_react = require("react");
40
+ var buttonContextKeys = [
41
+ "color",
42
+ "ellipsis",
43
+ "fontFamily",
44
+ "fontSize",
45
+ "fontStyle",
46
+ "fontWeight",
47
+ "letterSpacing",
48
+ "maxFontSizeMultiplier",
49
+ "textAlign"
50
+ ];
51
+ var ButtonContext = (0, import_web.createStyledContext)({
52
+ color: void 0,
53
+ ellipsis: void 0,
54
+ fontFamily: void 0,
55
+ fontSize: void 0,
56
+ fontStyle: void 0,
57
+ fontWeight: void 0,
58
+ letterSpacing: void 0,
59
+ maxFontSizeMultiplier: void 0,
60
+ textAlign: void 0
61
+ }, { keys: buttonContextKeys });
62
+ var ButtonFrame = (0, import_web.styled)(import_web.View, {
63
+ context: ButtonContext,
64
+ displayName: "ButtonFrame",
65
+ role: "button",
66
+ render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button" }),
67
+ tabIndex: 0,
68
+ alignItems: "center",
69
+ flexDirection: "row",
70
+ flexWrap: "nowrap",
71
+ justifyContent: "center",
72
+ variants: { disabled: { true: { pointerEvents: "none" } } }
73
+ });
74
+ var ButtonText = (0, import_web.styled)(import_web.Text, {
75
+ context: ButtonContext,
76
+ displayName: "ButtonText",
77
+ flexGrow: 0,
78
+ flexShrink: 1
79
+ });
80
+ var ButtonIcon = function(param) {
81
+ var { children, color, scaleIcon = 1, size } = param;
82
+ var styledContext = ButtonContext.useStyledContext();
83
+ var iconColor = color !== null && color !== void 0 ? color : styledContext === null || styledContext === void 0 ? void 0 : styledContext.color;
84
+ var getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
85
+ color: iconColor === "unset" || typeof iconColor === "number" ? void 0 : iconColor,
86
+ size: size === void 0 ? void 0 : size * scaleIcon
87
+ });
88
+ return getThemedIcon(children);
89
+ };
90
+ var buttonInternalPropNames = [
91
+ "children",
92
+ "color",
93
+ "disabled",
94
+ "ellipsis",
95
+ "fontFamily",
96
+ "fontSize",
97
+ "fontStyle",
98
+ "fontWeight",
99
+ "icon",
100
+ "iconAfter",
101
+ "iconSize",
102
+ "letterSpacing",
103
+ "maxFontSizeMultiplier",
104
+ "noTextWrap",
105
+ "render",
106
+ "scaleIcon",
107
+ "textAlign",
108
+ "textProps"
109
+ ];
110
+ function useButton(propsIn) {
111
+ var { Text: _$Text = ButtonText, iconColor: iconColorOption, iconSize: iconSizeOption, textProps: textPropsOption } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
112
+ var isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext);
113
+ var styledContext = ButtonContext.useStyledContext();
114
+ var processedProps = (0, import_web.useProps)(propsIn, {
115
+ noNormalize: true,
116
+ noExpand: true
117
+ });
118
+ var { children, color, disabled, ellipsis, fontFamily, fontSize, fontStyle, fontWeight, icon, iconAfter, iconSize, letterSpacing, maxFontSizeMultiplier, noTextWrap, render, scaleIcon = 1, textAlign, textProps } = processedProps;
119
+ var frameProps = { ...propsIn };
120
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
121
+ try {
122
+ for (var _iterator = buttonInternalPropNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
123
+ var key = _step.value;
124
+ delete frameProps[key];
125
+ }
126
+ } catch (err) {
127
+ _didIteratorError = true;
128
+ _iteratorError = err;
129
+ } finally {
130
+ try {
131
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
132
+ _iterator.return();
133
+ }
134
+ } finally {
135
+ if (_didIteratorError) {
136
+ throw _iteratorError;
137
+ }
138
+ }
139
+ }
140
+ var contextColor = color !== null && color !== void 0 ? color : styledContext === null || styledContext === void 0 ? void 0 : styledContext.color;
141
+ var iconColor = iconColorOption !== null && iconColorOption !== void 0 ? iconColorOption : contextColor;
142
+ var resolvedIconSize = iconSize !== null && iconSize !== void 0 ? iconSize : iconSizeOption;
143
+ var getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
144
+ color: iconColor === "unset" || typeof iconColor === "number" ? void 0 : iconColor,
145
+ size: resolvedIconSize === void 0 ? void 0 : resolvedIconSize * scaleIcon
146
+ });
147
+ var [themedIcon, themedIconAfter] = [icon, iconAfter].map(function(item) {
148
+ return item ? getThemedIcon(item) : null;
149
+ });
150
+ var textContext = {
151
+ color: contextColor,
152
+ ellipsis: ellipsis !== null && ellipsis !== void 0 ? ellipsis : styledContext === null || styledContext === void 0 ? void 0 : styledContext.ellipsis,
153
+ fontFamily: fontFamily !== null && fontFamily !== void 0 ? fontFamily : styledContext === null || styledContext === void 0 ? void 0 : styledContext.fontFamily,
154
+ fontSize: fontSize !== null && fontSize !== void 0 ? fontSize : styledContext === null || styledContext === void 0 ? void 0 : styledContext.fontSize,
155
+ fontStyle: fontStyle !== null && fontStyle !== void 0 ? fontStyle : styledContext === null || styledContext === void 0 ? void 0 : styledContext.fontStyle,
156
+ fontWeight: fontWeight !== null && fontWeight !== void 0 ? fontWeight : styledContext === null || styledContext === void 0 ? void 0 : styledContext.fontWeight,
157
+ letterSpacing: letterSpacing !== null && letterSpacing !== void 0 ? letterSpacing : styledContext === null || styledContext === void 0 ? void 0 : styledContext.letterSpacing,
158
+ maxFontSizeMultiplier: maxFontSizeMultiplier !== null && maxFontSizeMultiplier !== void 0 ? maxFontSizeMultiplier : styledContext === null || styledContext === void 0 ? void 0 : styledContext.maxFontSizeMultiplier,
159
+ textAlign: textAlign !== null && textAlign !== void 0 ? textAlign : styledContext === null || styledContext === void 0 ? void 0 : styledContext.textAlign
160
+ };
161
+ var wrappedChildren = (0, import_text.wrapChildrenInText)(_$Text, {
162
+ children,
163
+ ...textContext,
164
+ noTextWrap,
165
+ textProps
166
+ }, {
167
+ ...textPropsOption,
168
+ ...processedProps.size === void 0 ? null : { size: processedProps.size }
169
+ });
170
+ var resolvedRender = render !== null && render !== void 0 ? render : isNested ? "span" : processedProps.accessibilityRole === "link" || processedProps.role === "link" ? "a" : disabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
171
+ type: "button",
172
+ disabled: true
173
+ }) : void 0;
174
+ var props = {
175
+ ...frameProps,
176
+ ...disabled && {
177
+ "aria-disabled": true,
178
+ disabled: true,
179
+ tabIndex: -1
180
+ },
181
+ ...resolvedRender === void 0 ? null : { render: resolvedRender },
182
+ ...isNested && {
183
+ role: "none",
184
+ tabIndex: -1,
185
+ "aria-disabled": void 0,
186
+ disabled: void 0,
187
+ onPress: void 0,
188
+ onPressIn: void 0,
189
+ onPressOut: void 0,
190
+ onLongPress: void 0,
191
+ onClick: void 0,
192
+ onKeyDown: void 0,
193
+ onKeyUp: void 0
194
+ },
195
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
196
+ value: true,
197
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ButtonContext.Provider, {
198
+ ...textContext,
199
+ children: [
200
+ themedIcon,
201
+ wrappedChildren,
202
+ themedIconAfter
203
+ ]
204
+ })
205
+ })
206
+ };
207
+ return {
208
+ isNested,
209
+ props
210
+ };
211
+ }
212
+ var ButtonComponent = (0, import_web.createStyledHOC)(ButtonFrame, function Button(props, ref) {
213
+ var { props: buttonProps } = useButton(props);
214
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonFrame, {
215
+ ref,
216
+ ...buttonProps
217
+ });
218
+ });
219
+ var Button2 = (0, import_web.withStaticProperties)(ButtonComponent, {
220
+ Apply: ButtonContext.Provider,
221
+ Frame: ButtonFrame,
222
+ Icon: ButtonIcon,
223
+ Text: ButtonText
224
+ });