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