@tamagui/button 1.142.0 → 2.0.0-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 (81) hide show
  1. package/dist/cjs/Button.cjs +126 -158
  2. package/dist/cjs/Button.js +102 -120
  3. package/dist/cjs/Button.js.map +2 -2
  4. package/dist/cjs/Button.native.js +128 -160
  5. package/dist/cjs/Button.native.js.map +1 -1
  6. package/dist/cjs/v1/Button.cjs +259 -0
  7. package/dist/cjs/v1/Button.js +208 -0
  8. package/dist/cjs/v1/Button.js.map +6 -0
  9. package/dist/cjs/v1/Button.native.js +265 -0
  10. package/dist/cjs/v1/Button.native.js.map +1 -0
  11. package/dist/cjs/v1/Button.test.cjs +9 -0
  12. package/dist/cjs/v1/Button.test.js +8 -0
  13. package/dist/cjs/v1/Button.test.js.map +6 -0
  14. package/dist/cjs/v1/Button.test.native.js +12 -0
  15. package/dist/cjs/v1/Button.test.native.js.map +1 -0
  16. package/dist/cjs/v1/index.cjs +18 -0
  17. package/dist/cjs/v1/index.js +15 -0
  18. package/dist/cjs/v1/index.js.map +6 -0
  19. package/dist/cjs/v1/index.native.js +21 -0
  20. package/dist/cjs/v1/index.native.js.map +1 -0
  21. package/dist/esm/Button.js +108 -126
  22. package/dist/esm/Button.js.map +2 -2
  23. package/dist/esm/Button.mjs +127 -155
  24. package/dist/esm/Button.mjs.map +1 -1
  25. package/dist/esm/Button.native.js +130 -158
  26. package/dist/esm/Button.native.js.map +1 -1
  27. package/dist/esm/v1/Button.js +201 -0
  28. package/dist/esm/v1/Button.js.map +6 -0
  29. package/dist/esm/v1/Button.mjs +231 -0
  30. package/dist/esm/v1/Button.mjs.map +1 -0
  31. package/dist/esm/v1/Button.native.js +234 -0
  32. package/dist/esm/v1/Button.native.js.map +1 -0
  33. package/dist/esm/v1/Button.test.js +10 -0
  34. package/dist/esm/v1/Button.test.js.map +6 -0
  35. package/dist/esm/v1/Button.test.mjs +10 -0
  36. package/dist/esm/v1/Button.test.mjs.map +1 -0
  37. package/dist/esm/v1/Button.test.native.js +10 -0
  38. package/dist/esm/v1/Button.test.native.js.map +1 -0
  39. package/dist/esm/v1/index.js +2 -0
  40. package/dist/esm/v1/index.js.map +6 -0
  41. package/dist/esm/v1/index.mjs +2 -0
  42. package/dist/esm/v1/index.mjs.map +1 -0
  43. package/dist/esm/v1/index.native.js +2 -0
  44. package/dist/esm/v1/index.native.js.map +1 -0
  45. package/dist/jsx/Button.js +108 -126
  46. package/dist/jsx/Button.js.map +2 -2
  47. package/dist/jsx/Button.mjs +127 -155
  48. package/dist/jsx/Button.mjs.map +1 -1
  49. package/dist/jsx/Button.native.js +128 -160
  50. package/dist/jsx/Button.native.js.map +1 -1
  51. package/dist/jsx/v1/Button.js +201 -0
  52. package/dist/jsx/v1/Button.js.map +6 -0
  53. package/dist/jsx/v1/Button.mjs +231 -0
  54. package/dist/jsx/v1/Button.mjs.map +1 -0
  55. package/dist/jsx/v1/Button.native.js +265 -0
  56. package/dist/jsx/v1/Button.native.js.map +1 -0
  57. package/dist/jsx/v1/Button.test.js +10 -0
  58. package/dist/jsx/v1/Button.test.js.map +6 -0
  59. package/dist/jsx/v1/Button.test.mjs +10 -0
  60. package/dist/jsx/v1/Button.test.mjs.map +1 -0
  61. package/dist/jsx/v1/Button.test.native.js +12 -0
  62. package/dist/jsx/v1/Button.test.native.js.map +1 -0
  63. package/dist/jsx/v1/index.js +2 -0
  64. package/dist/jsx/v1/index.js.map +6 -0
  65. package/dist/jsx/v1/index.mjs +2 -0
  66. package/dist/jsx/v1/index.mjs.map +1 -0
  67. package/dist/jsx/v1/index.native.js +21 -0
  68. package/dist/jsx/v1/index.native.js.map +1 -0
  69. package/package.json +12 -11
  70. package/src/Button.tsx +172 -243
  71. package/src/v1/Button.test.tsx +21 -0
  72. package/src/v1/Button.tsx +336 -0
  73. package/src/v1/index.ts +1 -0
  74. package/types/Button.d.ts +80 -323
  75. package/types/Button.d.ts.map +1 -1
  76. package/types/v1/Button.d.ts +338 -0
  77. package/types/v1/Button.d.ts.map +1 -0
  78. package/types/v1/Button.test.d.ts +2 -0
  79. package/types/v1/Button.test.d.ts.map +1 -0
  80. package/types/v1/index.d.ts +2 -0
  81. package/types/v1/index.d.ts.map +1 -0
@@ -20,46 +20,32 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
20
20
  }), mod);
21
21
  var Button_exports = {};
22
22
  __export(Button_exports, {
23
- Button: () => Button2,
24
- ButtonContext: () => ButtonContext,
25
- ButtonFrame: () => ButtonFrame,
26
- ButtonIcon: () => ButtonIcon,
27
- ButtonText: () => ButtonText,
28
- useButton: () => useButton
23
+ Button: () => Button,
24
+ ButtonContext: () => ButtonContext
29
25
  });
30
26
  module.exports = __toCommonJS(Button_exports);
31
27
  var import_font_size = require("@tamagui/font-size"),
32
28
  import_get_button_sized = require("@tamagui/get-button-sized"),
33
- import_helpers = require("@tamagui/helpers"),
34
- import_helpers_tamagui = require("@tamagui/helpers-tamagui"),
35
29
  import_stacks = require("@tamagui/stacks"),
36
30
  import_text = require("@tamagui/text"),
37
31
  import_web = require("@tamagui/web"),
38
32
  import_react = require("react"),
33
+ import_helpers_tamagui = require("@tamagui/helpers-tamagui"),
39
34
  import_jsx_runtime = require("react/jsx-runtime");
40
- const ButtonContext = (0, import_web.createStyledContext)({
41
- // keeping these here means they work with styled() passing down color to text
42
- color: void 0,
43
- ellipse: void 0,
44
- fontFamily: void 0,
45
- fontSize: void 0,
46
- fontStyle: void 0,
47
- fontWeight: void 0,
48
- letterSpacing: void 0,
49
- maxFontSizeMultiplier: void 0,
35
+ const context = (0, import_web.createStyledContext)({
50
36
  size: void 0,
51
- textAlign: void 0,
52
- variant: void 0
37
+ variant: void 0,
38
+ color: void 0,
39
+ elevation: void 0
53
40
  }),
54
- BUTTON_NAME = "Button",
55
- ButtonFrame = (0, import_web.styled)(import_stacks.ThemeableStack, {
56
- name: BUTTON_NAME,
57
- tag: "button",
58
- context: ButtonContext,
41
+ Frame = (0, import_web.styled)(import_web.View, {
42
+ context,
43
+ name: "Button",
44
+ group: "Button",
45
+ containerType: "normal",
59
46
  role: "button",
47
+ tag: "button",
60
48
  focusable: !0,
61
- // forces runtime pressStyle so it passes through context text colors
62
- disableClassName: !0,
63
49
  variants: {
64
50
  unstyled: {
65
51
  false: {
@@ -69,11 +55,17 @@ const ButtonContext = (0, import_web.createStyledContext)({
69
55
  flexWrap: "nowrap",
70
56
  flexDirection: "row",
71
57
  cursor: "pointer",
72
- hoverTheme: !0,
73
- pressTheme: !0,
74
- backgrounded: !0,
58
+ backgroundColor: "$background",
75
59
  borderWidth: 1,
76
60
  borderColor: "transparent",
61
+ hoverStyle: {
62
+ backgroundColor: "$backgroundHover",
63
+ borderColor: "$borderColorHover"
64
+ },
65
+ pressStyle: {
66
+ backgroundColor: "$backgroundPress",
67
+ borderColor: "$borderColorHover"
68
+ },
77
69
  focusVisibleStyle: {
78
70
  outlineColor: "$outlineColor",
79
71
  outlineStyle: "solid",
@@ -82,7 +74,7 @@ const ButtonContext = (0, import_web.createStyledContext)({
82
74
  }
83
75
  },
84
76
  variant: {
85
- outlined: {
77
+ outlined: process.env.TAMAGUI_HEADLESS === "1" ? {} : {
86
78
  backgroundColor: "transparent",
87
79
  borderWidth: 2,
88
80
  borderColor: "$borderColor",
@@ -96,13 +88,37 @@ const ButtonContext = (0, import_web.createStyledContext)({
96
88
  },
97
89
  focusVisibleStyle: {
98
90
  backgroundColor: "transparent",
99
- borderColor: "$borderColorFocus"
91
+ borderColor: "$borderColorFocus",
92
+ outlineColor: "$outlineColor",
93
+ outlineStyle: "solid",
94
+ outlineWidth: 2
100
95
  }
101
96
  }
102
97
  },
98
+ circular: import_stacks.themeableVariants.circular,
99
+ chromeless: import_stacks.themeableVariants.chromeless,
100
+ bordered: import_stacks.themeableVariants.bordered,
103
101
  size: {
104
- "...size": import_get_button_sized.getButtonSized,
105
- ":number": import_get_button_sized.getButtonSized
102
+ "...size": (val, extras) => {
103
+ const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras),
104
+ gap = (0, import_web.getTokenValue)(val) * 0.4;
105
+ return {
106
+ ...buttonStyle,
107
+ gap
108
+ };
109
+ },
110
+ ":number": (val, extras) => {
111
+ const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras),
112
+ gap = val * 0.4;
113
+ return {
114
+ ...buttonStyle,
115
+ gap
116
+ };
117
+ }
118
+ },
119
+ elevation: {
120
+ "...size": import_stacks.getElevation,
121
+ ":number": import_stacks.getElevation
106
122
  },
107
123
  disabled: {
108
124
  true: {
@@ -114,9 +130,8 @@ const ButtonContext = (0, import_web.createStyledContext)({
114
130
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
115
131
  }
116
132
  }),
117
- ButtonText = (0, import_web.styled)(import_text.SizableText, {
118
- name: "Button",
119
- context: ButtonContext,
133
+ Text = (0, import_web.styled)(import_text.SizableText, {
134
+ context,
120
135
  variants: {
121
136
  unstyled: {
122
137
  false: {
@@ -125,7 +140,7 @@ const ButtonContext = (0, import_web.createStyledContext)({
125
140
  // flexGrow 1 leads to inconsistent native style where text pushes to start of view
126
141
  flexGrow: 0,
127
142
  flexShrink: 1,
128
- ellipse: !0,
143
+ ellipsis: !0,
129
144
  color: "$color"
130
145
  }
131
146
  }
@@ -134,130 +149,83 @@ const ButtonContext = (0, import_web.createStyledContext)({
134
149
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
135
150
  }
136
151
  }),
137
- ButtonIcon = props => {
152
+ Icon = props => {
138
153
  const {
139
154
  children,
140
- scaleIcon = 1
155
+ scaleIcon = 1,
156
+ marginLeft,
157
+ marginRight,
158
+ size
141
159
  } = props,
142
- {
143
- size,
144
- color
145
- } = (0, import_react.useContext)(ButtonContext),
146
- iconSize = (typeof size == "number" ? size * 0.5 : (0, import_font_size.getFontSize)(size)) * scaleIcon;
147
- return (0, import_helpers_tamagui.useGetThemedIcon)({
160
+ styledContext = context.useStyledContext();
161
+ if (!styledContext) throw new Error("Button.Icon must be used within a Button");
162
+ const getIcon = (0, import_helpers_tamagui.useGetIcon)(),
163
+ sizeToken = size ?? styledContext.size,
164
+ iconSize = (typeof sizeToken == "number" ? sizeToken * 0.5 : (0, import_font_size.getFontSize)(sizeToken)) * scaleIcon;
165
+ return getIcon(children, {
148
166
  size: iconSize,
149
- color
150
- })(children);
151
- },
152
- ButtonComponent = ButtonFrame.styleable(function (props, ref) {
153
- const {
154
- props: buttonProps
155
- } = useButton(props);
156
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ButtonFrame, {
157
- "data-disable-theme": !0,
158
- ...buttonProps,
159
- ref
167
+ color: styledContext.color,
168
+ marginLeft,
169
+ marginRight
160
170
  });
171
+ },
172
+ ButtonContext = (0, import_web.createStyledContext)({
173
+ size: void 0,
174
+ variant: void 0,
175
+ color: void 0
161
176
  }),
162
- Button2 = (0, import_helpers.withStaticProperties)(ButtonComponent, {
163
- Text: ButtonText,
164
- Icon: ButtonIcon
165
- });
166
- function useButton({
167
- textProps,
168
- ...propsIn
169
- }, {
170
- Text = Button2.Text
171
- } = {
172
- Text: Button2.Text
173
- }) {
174
- const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext),
175
- propsActive = (0, import_web.useProps)(propsIn, {
176
- noNormalize: !0,
177
- noExpand: !0
178
- }),
179
- {
180
- icon,
181
- iconAfter,
182
- space,
183
- spaceFlex,
184
- scaleIcon = 1,
185
- scaleSpace = 0.66,
186
- separator,
187
- noTextWrap,
188
- fontFamily,
189
- fontSize,
190
- fontWeight,
191
- fontStyle,
192
- letterSpacing,
193
- tag,
194
- ellipse,
195
- maxFontSizeMultiplier,
196
- ...restProps
197
- } = propsActive,
198
- size = propsActive.size || (propsActive.unstyled ? void 0 : "$true"),
199
- color = propsActive.color,
200
- iconSize = (typeof size == "number" ? size * 0.5 : (0, import_font_size.getFontSize)(size, {
201
- font: fontFamily?.[0] === "$" ? fontFamily : void 0
202
- })) * scaleIcon,
203
- getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
204
- size: iconSize,
205
- color
206
- }),
207
- [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon),
208
- spaceSize = space ?? (0, import_web.getVariableValue)(iconSize) * scaleSpace,
209
- contents = noTextWrap ? [propsIn.children] : (0, import_text.wrapChildrenInText)(Text, {
210
- children: propsIn.children,
211
- color,
212
- fontFamily,
213
- fontSize,
214
- textProps,
215
- fontWeight,
216
- fontStyle,
217
- letterSpacing,
218
- ellipse,
219
- maxFontSizeMultiplier
220
- }, Text === ButtonText && propsActive.unstyled !== !0 ? {
221
- unstyled: process.env.TAMAGUI_HEADLESS === "1",
222
- size
223
- } : void 0),
224
- inner = (0, import_web.spacedChildren)({
225
- // a bit arbitrary but scaling to font size is necessary so long as button does
226
- space: spaceSize === !1 ? 0 : spaceSize == !0 ? "$true" : spaceSize,
227
- spaceFlex,
228
- ensureKeys: !0,
229
- separator,
230
- direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
231
- // for keys to stay the same we keep indices as similar a possible
232
- // so even if icons are undefined we still pass them
233
- children: [themedIcon, ...contents, themedIconAfter]
234
- }),
235
- props = {
236
- size,
237
- ...(propsIn.disabled && {
238
- // in rnw - false still has keyboard tabIndex, undefined = not actually focusable
239
- focusable: void 0,
240
- // even with tabIndex unset, it will keep focusVisibleStyle on web so disable it here
241
- focusVisibleStyle: {
242
- borderColor: "$background"
243
- }
244
- }),
245
- // fixes SSR issue + DOM nesting issue of not allowing button in button
246
- tag: tag ?? (isNested ? "span" :
247
- // defaults to <a /> when accessibilityRole = link
248
- // see https://github.com/tamagui/tamagui/issues/505
249
- propsActive.accessibilityRole === "link" || propsActive.role === "link" ? "a" : "button"),
250
- ...restProps,
251
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
252
- value: !0,
253
- children: inner
177
+ ButtonComponent = Frame.styleable((propsIn, ref) => {
178
+ const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext),
179
+ processedProps = (0, import_web.useProps)(propsIn, {
180
+ noNormalize: !0,
181
+ noExpand: !0
254
182
  }),
255
- // forces it to be a runtime pressStyle so it passes through context text colors
256
- disableClassName: !0
257
- };
258
- return {
259
- spaceSize,
260
- isNested,
261
- props
262
- };
263
- }
183
+ {
184
+ children,
185
+ iconSize,
186
+ icon,
187
+ iconAfter,
188
+ scaleIcon = 1,
189
+ noTextWrap,
190
+ ...props
191
+ } = processedProps,
192
+ size = propsIn.size || (propsIn.unstyled ? void 0 : "$true"),
193
+ styledContext = context.useStyledContext(),
194
+ finalSize = iconSize ?? size ?? styledContext?.size,
195
+ iconSizeNumber = (typeof finalSize == "number" ? finalSize * 0.5 : (0, import_font_size.getFontSize)(finalSize)) * scaleIcon,
196
+ getIcon = (0, import_helpers_tamagui.useGetIcon)(),
197
+ [themedIcon, themedIconAfter] = [icon, iconAfter].map(icon2 => icon2 ? getIcon(icon2, {
198
+ size: iconSizeNumber,
199
+ color: styledContext?.color
200
+ // No marginLeft or marginRight needed - spacing is handled by the gap property in Frame's size variants
201
+ }) : null),
202
+ wrappedChildren = (0, import_text.wrapChildrenInText)(Text, {
203
+ children,
204
+ noTextWrap
205
+ }, {
206
+ unstyled: process.env.TAMAGUI_HEADLESS === "1",
207
+ size: finalSize ?? styledContext?.size
208
+ });
209
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
210
+ value: !0,
211
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(Frame, {
212
+ ref,
213
+ ...props,
214
+ ...(isNested && {
215
+ tag: "span"
216
+ }),
217
+ ...(props.circular && !propsIn.size && {
218
+ size
219
+ }),
220
+ tabIndex: 0,
221
+ focusable: !0,
222
+ children: [themedIcon, wrappedChildren, themedIconAfter]
223
+ })
224
+ });
225
+ }),
226
+ Button = (0, import_web.withStaticProperties)(ButtonComponent, {
227
+ Apply: context.Provider,
228
+ Frame,
229
+ Text,
230
+ Icon
231
+ });
@@ -14,36 +14,24 @@ var __export = (target, all) => {
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
15
  var Button_exports = {};
16
16
  __export(Button_exports, {
17
- Button: () => Button2,
18
- ButtonContext: () => ButtonContext,
19
- ButtonFrame: () => ButtonFrame,
20
- ButtonIcon: () => ButtonIcon,
21
- ButtonText: () => ButtonText,
22
- useButton: () => useButton
17
+ Button: () => Button,
18
+ ButtonContext: () => ButtonContext
23
19
  });
24
20
  module.exports = __toCommonJS(Button_exports);
25
- var import_font_size = require("@tamagui/font-size"), import_get_button_sized = require("@tamagui/get-button-sized"), import_helpers = require("@tamagui/helpers"), import_helpers_tamagui = require("@tamagui/helpers-tamagui"), import_stacks = require("@tamagui/stacks"), import_text = require("@tamagui/text"), import_web = require("@tamagui/web"), import_react = require("react"), import_jsx_runtime = require("react/jsx-runtime");
26
- const ButtonContext = (0, import_web.createStyledContext)({
27
- // keeping these here means they work with styled() passing down color to text
28
- color: void 0,
29
- ellipse: void 0,
30
- fontFamily: void 0,
31
- fontSize: void 0,
32
- fontStyle: void 0,
33
- fontWeight: void 0,
34
- letterSpacing: void 0,
35
- maxFontSizeMultiplier: void 0,
21
+ var import_font_size = require("@tamagui/font-size"), import_get_button_sized = require("@tamagui/get-button-sized"), import_stacks = require("@tamagui/stacks"), import_text = require("@tamagui/text"), import_web = require("@tamagui/web"), import_react = require("react"), import_helpers_tamagui = require("@tamagui/helpers-tamagui"), import_jsx_runtime = require("react/jsx-runtime");
22
+ const context = (0, import_web.createStyledContext)({
36
23
  size: void 0,
37
- textAlign: void 0,
38
- variant: void 0
39
- }), BUTTON_NAME = "Button", ButtonFrame = (0, import_web.styled)(import_stacks.ThemeableStack, {
40
- name: BUTTON_NAME,
41
- tag: "button",
42
- context: ButtonContext,
24
+ variant: void 0,
25
+ color: void 0,
26
+ elevation: void 0
27
+ }), Frame = (0, import_web.styled)(import_web.View, {
28
+ context,
29
+ name: "Button",
30
+ group: "Button",
31
+ containerType: "normal",
43
32
  role: "button",
33
+ tag: "button",
44
34
  focusable: !0,
45
- // forces runtime pressStyle so it passes through context text colors
46
- disableClassName: !0,
47
35
  variants: {
48
36
  unstyled: {
49
37
  false: {
@@ -53,11 +41,17 @@ const ButtonContext = (0, import_web.createStyledContext)({
53
41
  flexWrap: "nowrap",
54
42
  flexDirection: "row",
55
43
  cursor: "pointer",
56
- hoverTheme: !0,
57
- pressTheme: !0,
58
- backgrounded: !0,
44
+ backgroundColor: "$background",
59
45
  borderWidth: 1,
60
46
  borderColor: "transparent",
47
+ hoverStyle: {
48
+ backgroundColor: "$backgroundHover",
49
+ borderColor: "$borderColorHover"
50
+ },
51
+ pressStyle: {
52
+ backgroundColor: "$backgroundPress",
53
+ borderColor: "$borderColorHover"
54
+ },
61
55
  focusVisibleStyle: {
62
56
  outlineColor: "$outlineColor",
63
57
  outlineStyle: "solid",
@@ -66,7 +60,7 @@ const ButtonContext = (0, import_web.createStyledContext)({
66
60
  }
67
61
  },
68
62
  variant: {
69
- outlined: {
63
+ outlined: process.env.TAMAGUI_HEADLESS === "1" ? {} : {
70
64
  backgroundColor: "transparent",
71
65
  borderWidth: 2,
72
66
  borderColor: "$borderColor",
@@ -80,13 +74,35 @@ const ButtonContext = (0, import_web.createStyledContext)({
80
74
  },
81
75
  focusVisibleStyle: {
82
76
  backgroundColor: "transparent",
83
- borderColor: "$borderColorFocus"
77
+ borderColor: "$borderColorFocus",
78
+ outlineColor: "$outlineColor",
79
+ outlineStyle: "solid",
80
+ outlineWidth: 2
84
81
  }
85
82
  }
86
83
  },
84
+ circular: import_stacks.themeableVariants.circular,
85
+ chromeless: import_stacks.themeableVariants.chromeless,
86
+ bordered: import_stacks.themeableVariants.bordered,
87
87
  size: {
88
- "...size": import_get_button_sized.getButtonSized,
89
- ":number": import_get_button_sized.getButtonSized
88
+ "...size": (val, extras) => {
89
+ const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras), gap = (0, import_web.getTokenValue)(val) * 0.4;
90
+ return {
91
+ ...buttonStyle,
92
+ gap
93
+ };
94
+ },
95
+ ":number": (val, extras) => {
96
+ const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras), gap = val * 0.4;
97
+ return {
98
+ ...buttonStyle,
99
+ gap
100
+ };
101
+ }
102
+ },
103
+ elevation: {
104
+ "...size": import_stacks.getElevation,
105
+ ":number": import_stacks.getElevation
90
106
  },
91
107
  disabled: {
92
108
  true: {
@@ -97,9 +113,8 @@ const ButtonContext = (0, import_web.createStyledContext)({
97
113
  defaultVariants: {
98
114
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
99
115
  }
100
- }), ButtonText = (0, import_web.styled)(import_text.SizableText, {
101
- name: "Button",
102
- context: ButtonContext,
116
+ }), Text = (0, import_web.styled)(import_text.SizableText, {
117
+ context,
103
118
  variants: {
104
119
  unstyled: {
105
120
  false: {
@@ -108,7 +123,7 @@ const ButtonContext = (0, import_web.createStyledContext)({
108
123
  // flexGrow 1 leads to inconsistent native style where text pushes to start of view
109
124
  flexGrow: 0,
110
125
  flexShrink: 1,
111
- ellipse: !0,
126
+ ellipsis: !0,
112
127
  color: "$color"
113
128
  }
114
129
  }
@@ -116,98 +131,65 @@ const ButtonContext = (0, import_web.createStyledContext)({
116
131
  defaultVariants: {
117
132
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
118
133
  }
119
- }), ButtonIcon = (props) => {
120
- const { children, scaleIcon = 1 } = props, { size, color } = (0, import_react.useContext)(ButtonContext), iconSize = (typeof size == "number" ? size * 0.5 : (0, import_font_size.getFontSize)(size)) * scaleIcon;
121
- return (0, import_helpers_tamagui.useGetThemedIcon)({ size: iconSize, color })(children);
122
- }, ButtonComponent = ButtonFrame.styleable(
123
- function(props, ref) {
124
- const { props: buttonProps } = useButton(props);
125
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonFrame, { "data-disable-theme": !0, ...buttonProps, ref });
126
- }
127
- ), Button2 = (0, import_helpers.withStaticProperties)(ButtonComponent, {
128
- Text: ButtonText,
129
- Icon: ButtonIcon
130
- });
131
- function useButton({ textProps, ...propsIn }, { Text = Button2.Text } = { Text: Button2.Text }) {
132
- const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext), propsActive = (0, import_web.useProps)(propsIn, {
134
+ }), Icon = (props) => {
135
+ const { children, scaleIcon = 1, marginLeft, marginRight, size } = props, styledContext = context.useStyledContext();
136
+ if (!styledContext)
137
+ throw new Error("Button.Icon must be used within a Button");
138
+ const getIcon = (0, import_helpers_tamagui.useGetIcon)(), sizeToken = size ?? styledContext.size, iconSize = (typeof sizeToken == "number" ? sizeToken * 0.5 : (0, import_font_size.getFontSize)(sizeToken)) * scaleIcon;
139
+ return getIcon(children, {
140
+ size: iconSize,
141
+ color: styledContext.color,
142
+ marginLeft,
143
+ marginRight
144
+ });
145
+ }, ButtonContext = (0, import_web.createStyledContext)({
146
+ size: void 0,
147
+ variant: void 0,
148
+ color: void 0
149
+ }), ButtonComponent = Frame.styleable((propsIn, ref) => {
150
+ const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext), processedProps = (0, import_web.useProps)(propsIn, {
133
151
  noNormalize: !0,
134
152
  noExpand: !0
135
153
  }), {
154
+ children,
155
+ iconSize,
136
156
  icon,
137
157
  iconAfter,
138
- space,
139
- spaceFlex,
140
158
  scaleIcon = 1,
141
- scaleSpace = 0.66,
142
- separator,
143
159
  noTextWrap,
144
- fontFamily,
145
- fontSize,
146
- fontWeight,
147
- fontStyle,
148
- letterSpacing,
149
- tag,
150
- ellipse,
151
- maxFontSizeMultiplier,
152
- ...restProps
153
- } = propsActive, size = propsActive.size || (propsActive.unstyled ? void 0 : "$true"), color = propsActive.color, iconSize = (typeof size == "number" ? size * 0.5 : (0, import_font_size.getFontSize)(size, {
154
- font: fontFamily?.[0] === "$" ? fontFamily : void 0
155
- })) * scaleIcon, getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({
156
- size: iconSize,
157
- color
158
- }), [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon), spaceSize = space ?? (0, import_web.getVariableValue)(iconSize) * scaleSpace, contents = noTextWrap ? [propsIn.children] : (0, import_text.wrapChildrenInText)(
160
+ ...props
161
+ } = processedProps, size = propsIn.size || (propsIn.unstyled ? void 0 : "$true"), styledContext = context.useStyledContext(), finalSize = iconSize ?? size ?? styledContext?.size, iconSizeNumber = (typeof finalSize == "number" ? finalSize * 0.5 : (0, import_font_size.getFontSize)(finalSize)) * scaleIcon, getIcon = (0, import_helpers_tamagui.useGetIcon)(), [themedIcon, themedIconAfter] = [icon, iconAfter].map((icon2) => icon2 ? getIcon(icon2, {
162
+ size: iconSizeNumber,
163
+ color: styledContext?.color
164
+ // No marginLeft or marginRight needed - spacing is handled by the gap property in Frame's size variants
165
+ }) : null), wrappedChildren = (0, import_text.wrapChildrenInText)(
159
166
  Text,
167
+ { children, noTextWrap },
160
168
  {
161
- children: propsIn.children,
162
- color,
163
- fontFamily,
164
- fontSize,
165
- textProps,
166
- fontWeight,
167
- fontStyle,
168
- letterSpacing,
169
- ellipse,
170
- maxFontSizeMultiplier
171
- },
172
- Text === ButtonText && propsActive.unstyled !== !0 ? {
173
169
  unstyled: process.env.TAMAGUI_HEADLESS === "1",
174
- size
175
- } : void 0
176
- ), inner = (0, import_web.spacedChildren)({
177
- // a bit arbitrary but scaling to font size is necessary so long as button does
178
- space: spaceSize === !1 ? 0 : spaceSize == !0 ? "$true" : spaceSize,
179
- spaceFlex,
180
- ensureKeys: !0,
181
- separator,
182
- direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
183
- // for keys to stay the same we keep indices as similar a possible
184
- // so even if icons are undefined we still pass them
185
- children: [themedIcon, ...contents, themedIconAfter]
186
- }), props = {
187
- size,
188
- ...propsIn.disabled && {
189
- // in rnw - false still has keyboard tabIndex, undefined = not actually focusable
190
- focusable: void 0,
191
- // even with tabIndex unset, it will keep focusVisibleStyle on web so disable it here
192
- focusVisibleStyle: {
193
- borderColor: "$background"
194
- }
195
- },
196
- // fixes SSR issue + DOM nesting issue of not allowing button in button
197
- tag: tag ?? (isNested ? "span" : (
198
- // defaults to <a /> when accessibilityRole = link
199
- // see https://github.com/tamagui/tamagui/issues/505
200
- propsActive.accessibilityRole === "link" || propsActive.role === "link" ? "a" : "button"
201
- )),
202
- ...restProps,
203
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, { value: !0, children: inner }),
204
- // forces it to be a runtime pressStyle so it passes through context text colors
205
- disableClassName: !0
206
- };
207
- return {
208
- spaceSize,
209
- isNested,
210
- props
211
- };
212
- }
170
+ size: finalSize ?? styledContext?.size
171
+ }
172
+ );
173
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, { value: !0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
174
+ Frame,
175
+ {
176
+ ref,
177
+ ...props,
178
+ ...isNested && { tag: "span" },
179
+ ...props.circular && !propsIn.size && { size },
180
+ tabIndex: 0,
181
+ focusable: !0,
182
+ children: [
183
+ themedIcon,
184
+ wrappedChildren,
185
+ themedIconAfter
186
+ ]
187
+ }
188
+ ) });
189
+ }), Button = (0, import_web.withStaticProperties)(ButtonComponent, {
190
+ Apply: context.Provider,
191
+ Frame,
192
+ Text,
193
+ Icon
194
+ });
213
195
  //# sourceMappingURL=Button.js.map