@tamagui/button 1.88.13 → 1.89.0-1706308641099

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,229 @@
1
+ import { getFontSize } from "@tamagui/font-size";
2
+ import { getButtonSized } from "@tamagui/get-button-sized";
3
+ import { withStaticProperties } from "@tamagui/helpers";
4
+ import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
5
+ import { ButtonNestingContext, ThemeableStack } from "@tamagui/stacks";
6
+ import { SizableText, wrapChildrenInText } from "@tamagui/text";
7
+ import { createStyledContext, getVariableValue, spacedChildren, styled, useProps } from "@tamagui/web";
8
+ import { useContext } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ const ButtonContext = createStyledContext({
11
+ // keeping these here means they work with styled() passing down color to text
12
+ color: void 0,
13
+ ellipse: void 0,
14
+ fontFamily: void 0,
15
+ fontSize: void 0,
16
+ fontStyle: void 0,
17
+ fontWeight: void 0,
18
+ letterSpacing: void 0,
19
+ maxFontSizeMultiplier: void 0,
20
+ size: void 0,
21
+ textAlign: void 0,
22
+ variant: void 0
23
+ }),
24
+ BUTTON_NAME = "Button",
25
+ ButtonFrame = styled(ThemeableStack, {
26
+ name: BUTTON_NAME,
27
+ tag: "button",
28
+ context: ButtonContext,
29
+ role: "button",
30
+ focusable: !0,
31
+ variants: {
32
+ unstyled: {
33
+ false: {
34
+ size: "$true",
35
+ justifyContent: "center",
36
+ alignItems: "center",
37
+ flexWrap: "nowrap",
38
+ flexDirection: "row",
39
+ cursor: "pointer",
40
+ hoverTheme: !0,
41
+ pressTheme: !0,
42
+ backgrounded: !0,
43
+ borderWidth: 1,
44
+ borderColor: "transparent",
45
+ focusStyle: {
46
+ outlineColor: "$outlineColor",
47
+ outlineStyle: "solid",
48
+ outlineWidth: 2
49
+ }
50
+ }
51
+ },
52
+ variant: {
53
+ outlined: {
54
+ backgroundColor: "transparent",
55
+ borderWidth: 2,
56
+ borderColor: "$borderColor",
57
+ hoverStyle: {
58
+ backgroundColor: "transparent",
59
+ borderColor: "$borderColorHover"
60
+ },
61
+ pressStyle: {
62
+ backgroundColor: "transparent",
63
+ borderColor: "$borderColorPress"
64
+ },
65
+ focusStyle: {
66
+ backgroundColor: "transparent",
67
+ borderColor: "$borderColorFocus"
68
+ }
69
+ }
70
+ },
71
+ size: {
72
+ "...size": getButtonSized
73
+ },
74
+ disabled: {
75
+ true: {
76
+ pointerEvents: "none"
77
+ }
78
+ }
79
+ },
80
+ defaultVariants: {
81
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
82
+ }
83
+ }),
84
+ ButtonText = styled(SizableText, {
85
+ name: "Button",
86
+ context: ButtonContext,
87
+ variants: {
88
+ unstyled: {
89
+ false: {
90
+ userSelect: "none",
91
+ cursor: "pointer",
92
+ // flexGrow 1 leads to inconsistent native style where text pushes to start of view
93
+ flexGrow: 0,
94
+ flexShrink: 1,
95
+ ellipse: !0,
96
+ color: "$color"
97
+ }
98
+ }
99
+ },
100
+ defaultVariants: {
101
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
102
+ }
103
+ }),
104
+ ButtonIcon = props => {
105
+ const {
106
+ children,
107
+ scaleIcon = 1
108
+ } = props,
109
+ {
110
+ size,
111
+ color
112
+ } = useContext(ButtonContext),
113
+ iconSize = (typeof size == "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
114
+ return useGetThemedIcon({
115
+ size: iconSize,
116
+ color
117
+ })(children);
118
+ },
119
+ ButtonComponent = ButtonFrame.styleable(function (props, ref) {
120
+ const {
121
+ props: buttonProps
122
+ } = useButton(props);
123
+ return /* @__PURE__ */jsx(ButtonFrame, {
124
+ ...buttonProps,
125
+ ref
126
+ });
127
+ }),
128
+ buttonStaticConfig = {
129
+ inlineProps: /* @__PURE__ */new Set([
130
+ // text props go here (can't really optimize them, but we never fully extract button anyway)
131
+ // may be able to remove this entirely, as the compiler / runtime have gotten better
132
+ "color", "fontWeight", "fontSize", "fontFamily", "fontStyle", "letterSpacing", "textAlign", "unstyled"])
133
+ },
134
+ Button2 = withStaticProperties(ButtonComponent, {
135
+ Text: ButtonText,
136
+ Icon: ButtonIcon
137
+ });
138
+ function useButton({
139
+ textProps,
140
+ ...propsIn
141
+ }, {
142
+ Text = Button2.Text
143
+ } = {
144
+ Text: Button2.Text
145
+ }) {
146
+ const isNested = useContext(ButtonNestingContext),
147
+ propsActive = useProps(propsIn),
148
+ {
149
+ icon,
150
+ iconAfter,
151
+ space,
152
+ spaceFlex,
153
+ scaleIcon = 1,
154
+ scaleSpace = 0.66,
155
+ separator,
156
+ noTextWrap,
157
+ fontFamily,
158
+ fontSize,
159
+ fontWeight,
160
+ fontStyle,
161
+ letterSpacing,
162
+ tag,
163
+ ellipse,
164
+ maxFontSizeMultiplier,
165
+ ...restProps
166
+ } = propsActive,
167
+ size = propsActive.size || (propsActive.unstyled ? void 0 : "$true"),
168
+ color = propsActive.color,
169
+ iconSize = (typeof size == "number" ? size * 0.5 : getFontSize(size, {
170
+ font: fontFamily?.[0] === "$" ? fontFamily : void 0
171
+ })) * scaleIcon,
172
+ getThemedIcon = useGetThemedIcon({
173
+ size: iconSize,
174
+ color
175
+ }),
176
+ [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon),
177
+ spaceSize = space ?? getVariableValue(iconSize) * scaleSpace,
178
+ contents = noTextWrap ? [propsIn.children] : wrapChildrenInText(Text, {
179
+ children: propsIn.children,
180
+ fontFamily,
181
+ fontSize,
182
+ textProps,
183
+ fontWeight,
184
+ fontStyle,
185
+ letterSpacing,
186
+ ellipse,
187
+ maxFontSizeMultiplier
188
+ }, Text === ButtonText && propsActive.unstyled !== !0 ? {
189
+ unstyled: process.env.TAMAGUI_HEADLESS === "1",
190
+ size
191
+ } : void 0),
192
+ inner = spacedChildren({
193
+ // a bit arbitrary but scaling to font size is necessary so long as button does
194
+ space: spaceSize,
195
+ spaceFlex,
196
+ separator,
197
+ direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
198
+ children: [themedIcon, ...contents, themedIconAfter]
199
+ }),
200
+ props = {
201
+ size,
202
+ ...(propsIn.disabled && {
203
+ // in rnw - false still has keyboard tabIndex, undefined = not actually focusable
204
+ focusable: void 0,
205
+ // even with tabIndex unset, it will keep focusStyle on web so disable it here
206
+ focusStyle: {
207
+ borderColor: "$background"
208
+ }
209
+ }),
210
+ // fixes SSR issue + DOM nesting issue of not allowing button in button
211
+ tag: tag ?? (isNested ? "span" :
212
+ // defaults to <a /> when accessibilityRole = link
213
+ // see https://github.com/tamagui/tamagui/issues/505
214
+ propsActive.accessibilityRole === "link" || propsActive.role === "link" ? "a" : "button"),
215
+ ...restProps,
216
+ children: /* @__PURE__ */jsx(ButtonNestingContext.Provider, {
217
+ value: !0,
218
+ children: inner
219
+ }),
220
+ // forces it to be a runtime pressStyle so it passes through context text colors
221
+ disableClassName: !0
222
+ };
223
+ return {
224
+ spaceSize,
225
+ isNested,
226
+ props
227
+ };
228
+ }
229
+ export { Button2 as Button, ButtonContext, ButtonFrame, ButtonIcon, ButtonText, buttonStaticConfig, useButton };
@@ -0,0 +1,9 @@
1
+ import { getDefaultTamaguiConfig } from "@tamagui/config-default";
2
+ import { createTamagui } from "@tamagui/core";
3
+ import { describe, expect, test } from "vitest";
4
+ const conf = createTamagui(getDefaultTamaguiConfig());
5
+ describe("Button", () => {
6
+ test("123", () => {
7
+ expect(!0).toBeTruthy();
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "./Button.mjs";
@@ -0,0 +1,229 @@
1
+ import { getFontSize } from "@tamagui/font-size";
2
+ import { getButtonSized } from "@tamagui/get-button-sized";
3
+ import { withStaticProperties } from "@tamagui/helpers";
4
+ import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
5
+ import { ButtonNestingContext, ThemeableStack } from "@tamagui/stacks";
6
+ import { SizableText, wrapChildrenInText } from "@tamagui/text";
7
+ import { createStyledContext, getVariableValue, spacedChildren, styled, useProps } from "@tamagui/web";
8
+ import { useContext } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ const ButtonContext = createStyledContext({
11
+ // keeping these here means they work with styled() passing down color to text
12
+ color: void 0,
13
+ ellipse: void 0,
14
+ fontFamily: void 0,
15
+ fontSize: void 0,
16
+ fontStyle: void 0,
17
+ fontWeight: void 0,
18
+ letterSpacing: void 0,
19
+ maxFontSizeMultiplier: void 0,
20
+ size: void 0,
21
+ textAlign: void 0,
22
+ variant: void 0
23
+ }),
24
+ BUTTON_NAME = "Button",
25
+ ButtonFrame = styled(ThemeableStack, {
26
+ name: BUTTON_NAME,
27
+ tag: "button",
28
+ context: ButtonContext,
29
+ role: "button",
30
+ focusable: !0,
31
+ variants: {
32
+ unstyled: {
33
+ false: {
34
+ size: "$true",
35
+ justifyContent: "center",
36
+ alignItems: "center",
37
+ flexWrap: "nowrap",
38
+ flexDirection: "row",
39
+ cursor: "pointer",
40
+ hoverTheme: !0,
41
+ pressTheme: !0,
42
+ backgrounded: !0,
43
+ borderWidth: 1,
44
+ borderColor: "transparent",
45
+ focusStyle: {
46
+ outlineColor: "$outlineColor",
47
+ outlineStyle: "solid",
48
+ outlineWidth: 2
49
+ }
50
+ }
51
+ },
52
+ variant: {
53
+ outlined: {
54
+ backgroundColor: "transparent",
55
+ borderWidth: 2,
56
+ borderColor: "$borderColor",
57
+ hoverStyle: {
58
+ backgroundColor: "transparent",
59
+ borderColor: "$borderColorHover"
60
+ },
61
+ pressStyle: {
62
+ backgroundColor: "transparent",
63
+ borderColor: "$borderColorPress"
64
+ },
65
+ focusStyle: {
66
+ backgroundColor: "transparent",
67
+ borderColor: "$borderColorFocus"
68
+ }
69
+ }
70
+ },
71
+ size: {
72
+ "...size": getButtonSized
73
+ },
74
+ disabled: {
75
+ true: {
76
+ pointerEvents: "none"
77
+ }
78
+ }
79
+ },
80
+ defaultVariants: {
81
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
82
+ }
83
+ }),
84
+ ButtonText = styled(SizableText, {
85
+ name: "Button",
86
+ context: ButtonContext,
87
+ variants: {
88
+ unstyled: {
89
+ false: {
90
+ userSelect: "none",
91
+ cursor: "pointer",
92
+ // flexGrow 1 leads to inconsistent native style where text pushes to start of view
93
+ flexGrow: 0,
94
+ flexShrink: 1,
95
+ ellipse: !0,
96
+ color: "$color"
97
+ }
98
+ }
99
+ },
100
+ defaultVariants: {
101
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
102
+ }
103
+ }),
104
+ ButtonIcon = props => {
105
+ const {
106
+ children,
107
+ scaleIcon = 1
108
+ } = props,
109
+ {
110
+ size,
111
+ color
112
+ } = useContext(ButtonContext),
113
+ iconSize = (typeof size == "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
114
+ return useGetThemedIcon({
115
+ size: iconSize,
116
+ color
117
+ })(children);
118
+ },
119
+ ButtonComponent = ButtonFrame.styleable(function (props, ref) {
120
+ const {
121
+ props: buttonProps
122
+ } = useButton(props);
123
+ return /* @__PURE__ */jsx(ButtonFrame, {
124
+ ...buttonProps,
125
+ ref
126
+ });
127
+ }),
128
+ buttonStaticConfig = {
129
+ inlineProps: /* @__PURE__ */new Set([
130
+ // text props go here (can't really optimize them, but we never fully extract button anyway)
131
+ // may be able to remove this entirely, as the compiler / runtime have gotten better
132
+ "color", "fontWeight", "fontSize", "fontFamily", "fontStyle", "letterSpacing", "textAlign", "unstyled"])
133
+ },
134
+ Button2 = withStaticProperties(ButtonComponent, {
135
+ Text: ButtonText,
136
+ Icon: ButtonIcon
137
+ });
138
+ function useButton({
139
+ textProps,
140
+ ...propsIn
141
+ }, {
142
+ Text = Button2.Text
143
+ } = {
144
+ Text: Button2.Text
145
+ }) {
146
+ const isNested = useContext(ButtonNestingContext),
147
+ propsActive = useProps(propsIn),
148
+ {
149
+ icon,
150
+ iconAfter,
151
+ space,
152
+ spaceFlex,
153
+ scaleIcon = 1,
154
+ scaleSpace = 0.66,
155
+ separator,
156
+ noTextWrap,
157
+ fontFamily,
158
+ fontSize,
159
+ fontWeight,
160
+ fontStyle,
161
+ letterSpacing,
162
+ tag,
163
+ ellipse,
164
+ maxFontSizeMultiplier,
165
+ ...restProps
166
+ } = propsActive,
167
+ size = propsActive.size || (propsActive.unstyled ? void 0 : "$true"),
168
+ color = propsActive.color,
169
+ iconSize = (typeof size == "number" ? size * 0.5 : getFontSize(size, {
170
+ font: fontFamily?.[0] === "$" ? fontFamily : void 0
171
+ })) * scaleIcon,
172
+ getThemedIcon = useGetThemedIcon({
173
+ size: iconSize,
174
+ color
175
+ }),
176
+ [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon),
177
+ spaceSize = space ?? getVariableValue(iconSize) * scaleSpace,
178
+ contents = noTextWrap ? [propsIn.children] : wrapChildrenInText(Text, {
179
+ children: propsIn.children,
180
+ fontFamily,
181
+ fontSize,
182
+ textProps,
183
+ fontWeight,
184
+ fontStyle,
185
+ letterSpacing,
186
+ ellipse,
187
+ maxFontSizeMultiplier
188
+ }, Text === ButtonText && propsActive.unstyled !== !0 ? {
189
+ unstyled: process.env.TAMAGUI_HEADLESS === "1",
190
+ size
191
+ } : void 0),
192
+ inner = spacedChildren({
193
+ // a bit arbitrary but scaling to font size is necessary so long as button does
194
+ space: spaceSize,
195
+ spaceFlex,
196
+ separator,
197
+ direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
198
+ children: [themedIcon, ...contents, themedIconAfter]
199
+ }),
200
+ props = {
201
+ size,
202
+ ...(propsIn.disabled && {
203
+ // in rnw - false still has keyboard tabIndex, undefined = not actually focusable
204
+ focusable: void 0,
205
+ // even with tabIndex unset, it will keep focusStyle on web so disable it here
206
+ focusStyle: {
207
+ borderColor: "$background"
208
+ }
209
+ }),
210
+ // fixes SSR issue + DOM nesting issue of not allowing button in button
211
+ tag: tag ?? (isNested ? "span" :
212
+ // defaults to <a /> when accessibilityRole = link
213
+ // see https://github.com/tamagui/tamagui/issues/505
214
+ propsActive.accessibilityRole === "link" || propsActive.role === "link" ? "a" : "button"),
215
+ ...restProps,
216
+ children: /* @__PURE__ */jsx(ButtonNestingContext.Provider, {
217
+ value: !0,
218
+ children: inner
219
+ }),
220
+ // forces it to be a runtime pressStyle so it passes through context text colors
221
+ disableClassName: !0
222
+ };
223
+ return {
224
+ spaceSize,
225
+ isNested,
226
+ props
227
+ };
228
+ }
229
+ export { Button2 as Button, ButtonContext, ButtonFrame, ButtonIcon, ButtonText, buttonStaticConfig, useButton };
@@ -0,0 +1,9 @@
1
+ import { getDefaultTamaguiConfig } from "@tamagui/config-default";
2
+ import { createTamagui } from "@tamagui/core";
3
+ import { describe, expect, test } from "vitest";
4
+ const conf = createTamagui(getDefaultTamaguiConfig());
5
+ describe("Button", () => {
6
+ test("123", () => {
7
+ expect(!0).toBeTruthy();
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "./Button.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/button",
3
- "version": "1.88.13",
3
+ "version": "1.89.0-1706308641099",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -32,19 +32,19 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@tamagui/font-size": "1.88.13",
36
- "@tamagui/get-button-sized": "1.88.13",
37
- "@tamagui/helpers": "1.88.13",
38
- "@tamagui/helpers-tamagui": "1.88.13",
39
- "@tamagui/stacks": "1.88.13",
40
- "@tamagui/text": "1.88.13",
41
- "@tamagui/web": "1.88.13"
35
+ "@tamagui/font-size": "1.89.0-1706308641099",
36
+ "@tamagui/get-button-sized": "1.89.0-1706308641099",
37
+ "@tamagui/helpers": "1.89.0-1706308641099",
38
+ "@tamagui/helpers-tamagui": "1.89.0-1706308641099",
39
+ "@tamagui/stacks": "1.89.0-1706308641099",
40
+ "@tamagui/text": "1.89.0-1706308641099",
41
+ "@tamagui/web": "1.89.0-1706308641099"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "*"
45
45
  },
46
46
  "devDependencies": {
47
- "@tamagui/build": "1.88.13",
47
+ "@tamagui/build": "1.89.0-1706308641099",
48
48
  "react": "^18.2.0",
49
49
  "vitest": "^0.34.3"
50
50
  },