@tamagui/button 1.27.2 → 1.27.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/button",
3
- "version": "1.27.2",
3
+ "version": "1.27.3",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -29,17 +29,17 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@tamagui/font-size": "1.27.2",
33
- "@tamagui/get-button-sized": "1.27.2",
34
- "@tamagui/helpers-tamagui": "1.27.2",
35
- "@tamagui/text": "1.27.2",
36
- "@tamagui/web": "1.27.2"
32
+ "@tamagui/font-size": "1.27.3",
33
+ "@tamagui/get-button-sized": "1.27.3",
34
+ "@tamagui/helpers-tamagui": "1.27.3",
35
+ "@tamagui/text": "1.27.3",
36
+ "@tamagui/web": "1.27.3"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "react": "*"
40
40
  },
41
41
  "devDependencies": {
42
- "@tamagui/build": "1.27.2",
42
+ "@tamagui/build": "1.27.3",
43
43
  "react": "^18.2.0",
44
44
  "vitest": "^0.26.3"
45
45
  },
@@ -1,237 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { createContextScope } from "@tamagui/create-context";
3
- import { getFontSize } from "@tamagui/font-size";
4
- import { getButtonSized } from "@tamagui/get-button-sized";
5
- import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
6
- import { ThemeableStack } from "@tamagui/stacks";
7
- import { SizableText, wrapChildrenInText } from "@tamagui/text";
8
- import {
9
- ButtonNestingContext,
10
- getVariableValue,
11
- isRSC,
12
- spacedChildren,
13
- styled,
14
- useProps,
15
- withStaticProperties
16
- } from "@tamagui/web";
17
- import {
18
- forwardRef,
19
- useCallback,
20
- useContext,
21
- useEffect,
22
- useState
23
- } from "react";
24
- const BUTTON_NAME = "Button";
25
- const ButtonFrame = styled(ThemeableStack, {
26
- name: BUTTON_NAME,
27
- tag: "button",
28
- focusable: true,
29
- variants: {
30
- unstyled: {
31
- false: {
32
- size: "$true",
33
- justifyContent: "center",
34
- alignItems: "center",
35
- flexWrap: "nowrap",
36
- flexDirection: "row",
37
- cursor: "pointer",
38
- hoverTheme: true,
39
- pressTheme: true,
40
- backgrounded: true,
41
- borderWidth: 1,
42
- borderColor: "transparent",
43
- pressStyle: {
44
- borderColor: "transparent"
45
- },
46
- hoverStyle: {
47
- borderColor: "transparent"
48
- },
49
- focusStyle: {
50
- borderColor: "$borderColorFocus",
51
- outlineColor: "$borderColorFocus",
52
- outlineStyle: "solid",
53
- outlineWidth: 2
54
- }
55
- }
56
- },
57
- size: {
58
- "...size": getButtonSized
59
- },
60
- active: {
61
- true: {
62
- hoverStyle: {
63
- backgroundColor: "$background"
64
- }
65
- }
66
- },
67
- disabled: {
68
- true: {
69
- pointerEvents: "none"
70
- }
71
- }
72
- },
73
- defaultVariants: {
74
- unstyled: false
75
- }
76
- });
77
- const BUTTON_TEXT_NAME = "ButtonText";
78
- const ButtonTextFrame = styled(SizableText, {
79
- name: BUTTON_TEXT_NAME,
80
- variants: {
81
- unstyled: {
82
- false: {
83
- userSelect: "none",
84
- cursor: "pointer",
85
- // flexGrow 1 leads to inconsistent native style where text pushes to start of view
86
- flexGrow: 0,
87
- flexShrink: 1,
88
- ellipse: true,
89
- color: "$color"
90
- }
91
- }
92
- },
93
- defaultVariants: {
94
- unstyled: false
95
- }
96
- });
97
- const [createButtonContext, createButtonScope] = createContextScope("Button");
98
- const [ButtonProvider, useButtonContext] = createButtonContext("Button");
99
- const ButtonTextComponent = ButtonTextFrame.extractable(
100
- forwardRef(
101
- (props, ref) => {
102
- const context = useButtonContext(BUTTON_TEXT_NAME, props.__scopeButton);
103
- useEffect(() => {
104
- const unregister = context.registerButtonText();
105
- return () => unregister();
106
- }, [context.registerButtonText]);
107
- return /* @__PURE__ */ jsx(ButtonTextFrame, { size: props.size ?? context.size, ...props, ref });
108
- }
109
- )
110
- );
111
- const BUTTON_ICON_NAME = "ButtonIcon";
112
- const ButtonIcon = (props) => {
113
- const { children, scaleIcon = 1 } = props;
114
- const context = useButtonContext(BUTTON_ICON_NAME, props.__scopeButton);
115
- const size = context.size;
116
- const color = context.color;
117
- const iconSize = (typeof size === "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
118
- const getThemedIcon = useGetThemedIcon({ size: iconSize, color });
119
- return getThemedIcon(children);
120
- };
121
- const ButtonComponent = ButtonFrame.styleable(function Button(props, ref) {
122
- const { props: buttonProps } = useButton(props);
123
- const [buttonTextCount, setButtonTextCount] = useState(0);
124
- const registerButtonText = useCallback(() => {
125
- setButtonTextCount((prev) => prev + 1);
126
- return () => setButtonTextCount((prev) => prev - 1);
127
- }, [setButtonTextCount]);
128
- const hasTextComponent = buttonTextCount > 0;
129
- return /* @__PURE__ */ jsx(
130
- ButtonProvider,
131
- {
132
- scope: props.__scopeButton,
133
- color: props.color,
134
- hasTextComponent,
135
- size: props.size ?? "$true",
136
- registerButtonText,
137
- children: /* @__PURE__ */ jsx(ButtonFrame, { ...hasTextComponent ? props : buttonProps, ref })
138
- }
139
- );
140
- });
141
- const buttonStaticConfig = {
142
- inlineProps: /* @__PURE__ */ new Set([
143
- // text props go here (can't really optimize them, but we never fully extract button anyway)
144
- // may be able to remove this entirely, as the compiler / runtime have gotten better
145
- "color",
146
- "fontWeight",
147
- "fontSize",
148
- "fontFamily",
149
- "fontStyle",
150
- "letterSpacing",
151
- "textAlign",
152
- "unstyled"
153
- ])
154
- };
155
- const Button2 = withStaticProperties(ButtonComponent, {
156
- Text: ButtonTextComponent,
157
- Icon: ButtonIcon
158
- });
159
- function useButton(propsIn, { Text = ButtonTextFrame } = { Text: ButtonTextFrame }) {
160
- const {
161
- children,
162
- icon,
163
- iconAfter,
164
- noTextWrap,
165
- theme: themeName,
166
- space,
167
- spaceFlex,
168
- scaleIcon = 1,
169
- scaleSpace = 0.66,
170
- separator,
171
- // text props
172
- color,
173
- fontWeight,
174
- letterSpacing,
175
- fontSize,
176
- fontFamily,
177
- fontStyle,
178
- textAlign,
179
- textProps,
180
- ...rest
181
- } = propsIn;
182
- const hasUnstyled = typeof propsIn.unstyled !== "undefined";
183
- const isNested = isRSC ? false : useContext(ButtonNestingContext);
184
- const propsActive = useProps(propsIn);
185
- const size = propsActive.size || "$true";
186
- const iconSize = (typeof size === "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
187
- const getThemedIcon = useGetThemedIcon({ size: iconSize, color });
188
- const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon);
189
- const spaceSize = propsActive.space ?? getVariableValue(iconSize) * scaleSpace;
190
- const contents = wrapChildrenInText(
191
- Text,
192
- propsActive,
193
- Text === ButtonTextFrame && hasUnstyled ? {
194
- unstyled: propsIn.unstyled
195
- } : void 0
196
- );
197
- const inner = spacedChildren({
198
- // a bit arbitrary but scaling to font size is necessary so long as button does
199
- space: spaceSize,
200
- spaceFlex,
201
- separator,
202
- direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
203
- children: [themedIcon, ...contents, themedIconAfter]
204
- });
205
- const tag = isNested ? "span" : (
206
- // defaults to <a /> when accessibilityRole = link
207
- // see https://github.com/tamagui/tamagui/issues/505
208
- propsIn.accessibilityRole === "link" ? "a" : void 0
209
- );
210
- const props = {
211
- ...propsActive.disabled && {
212
- // in rnw - false still has keyboard tabIndex, undefined = not actually focusable
213
- focusable: void 0,
214
- // even with tabIndex unset, it will keep focusStyle on web so disable it here
215
- focusStyle: {
216
- borderColor: "$background"
217
- }
218
- },
219
- tag,
220
- ...rest,
221
- children: isRSC ? inner : /* @__PURE__ */ jsx(ButtonNestingContext.Provider, { value: true, children: inner })
222
- };
223
- return {
224
- spaceSize,
225
- isNested,
226
- props
227
- };
228
- }
229
- export {
230
- Button2 as Button,
231
- ButtonFrame,
232
- ButtonTextFrame as ButtonText,
233
- buttonStaticConfig,
234
- createButtonScope,
235
- useButton
236
- };
237
- //# sourceMappingURL=Button.mjs.map
@@ -1,11 +0,0 @@
1
- process.env.TAMAGUI_TARGET = "web";
2
- import { getDefaultTamaguiConfig } from "@tamagui/config-default";
3
- import { createTamagui } from "@tamagui/core";
4
- import { describe, expect, test } from "vitest";
5
- const conf = createTamagui(getDefaultTamaguiConfig());
6
- describe("Button", () => {
7
- test(`123`, () => {
8
- expect(true).toBeTruthy();
9
- });
10
- });
11
- //# sourceMappingURL=Button.test.mjs.map
@@ -1,2 +0,0 @@
1
- export * from "./Button";
2
- //# sourceMappingURL=index.mjs.map
package/dist/jsx/base.mjs DELETED
@@ -1,5 +0,0 @@
1
- import { Button } from "./Button";
2
- export {
3
- Button
4
- };
5
- //# sourceMappingURL=base.mjs.map
@@ -1,232 +0,0 @@
1
- import { createContextScope } from "@tamagui/create-context";
2
- import { getFontSize } from "@tamagui/font-size";
3
- import { getButtonSized } from "@tamagui/get-button-sized";
4
- import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
5
- import { wrapChildrenInText } from "@tamagui/text";
6
- import {
7
- ButtonNestingContext,
8
- getConfig,
9
- getVariableValue,
10
- isRSC,
11
- spacedChildren,
12
- styled,
13
- useMediaPropsActive,
14
- withStaticProperties
15
- } from "@tamagui/web";
16
- import { useCallback, useContext, useEffect, useState } from "react";
17
- import {
18
- BUTTON_ICON_NAME,
19
- BUTTON_NAME,
20
- BUTTON_TEXT_NAME,
21
- Button as BaseButton
22
- } from "./Button";
23
- const ButtonFrame = styled(BaseButton, {
24
- name: BUTTON_NAME,
25
- variants: {
26
- unstyled: {
27
- false: {
28
- size: "$true",
29
- justifyContent: "center",
30
- alignItems: "center",
31
- flexWrap: "nowrap",
32
- flexDirection: "row",
33
- cursor: "pointer",
34
- hoverTheme: true,
35
- pressTheme: true,
36
- backgrounded: true,
37
- borderWidth: 1,
38
- borderColor: "$borderColor",
39
- pressStyle: {
40
- borderColor: "$borderColorPress"
41
- },
42
- focusStyle: {
43
- outlineColor: "$borderColorFocus",
44
- outlineStyle: "solid",
45
- outlineWidth: 2
46
- }
47
- }
48
- },
49
- size: {
50
- "...size": getButtonSized
51
- },
52
- active: {
53
- true: {
54
- hoverStyle: {
55
- backgroundColor: "$background"
56
- }
57
- }
58
- },
59
- disabled: {
60
- true: {
61
- pointerEvents: "none"
62
- }
63
- }
64
- },
65
- defaultVariants: {
66
- unstyled: false
67
- }
68
- });
69
- const [createButtonContext, createButtonScope] = createContextScope(BUTTON_NAME);
70
- const [ButtonProvider, useButtonContext] = createButtonContext("Button");
71
- const ButtonTextFrame = styled(BaseButton.Text, {
72
- name: BUTTON_TEXT_NAME,
73
- variants: {
74
- unstyled: {
75
- false: {
76
- userSelect: "none",
77
- cursor: "pointer",
78
- // flexGrow 1 leads to inconsistent native style where text pushes to start of view
79
- flexGrow: 0,
80
- flexShrink: 1,
81
- ellipse: true,
82
- color: "$color"
83
- }
84
- }
85
- },
86
- defaultVariants: {
87
- unstyled: false
88
- }
89
- });
90
- const ButtonText = ButtonTextFrame.styleable(
91
- (props, ref) => {
92
- const context = useButtonContext(BUTTON_TEXT_NAME, props.__scopeButton);
93
- useEffect(() => {
94
- const unregister = context.registerButtonText();
95
- return () => unregister();
96
- }, [context.registerButtonText]);
97
- return <ButtonTextFrame ref={ref} color={context.color} size={context.size} {...props}>{props.children}</ButtonTextFrame>;
98
- }
99
- );
100
- const ButtonIcon = (props) => {
101
- const { children, scaleIcon = 1 } = props;
102
- const context = useButtonContext(BUTTON_ICON_NAME, props.__scopeButton);
103
- const size = context.size;
104
- const color = context.color;
105
- const iconSize = (typeof size === "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
106
- const getThemedIcon = useGetThemedIcon({ size: iconSize, color });
107
- return getThemedIcon(children);
108
- };
109
- const ButtonComponent = ButtonFrame.styleable(
110
- (props, ref) => {
111
- const buttonApi = props.forceButtonApi ?? getConfig().buttonApi ?? "mixed";
112
- const { props: buttonProps } = useButton(props);
113
- const [buttonTextCount, setButtonTextCount] = useState(0);
114
- const registerButtonText = useCallback(() => {
115
- if (buttonApi === "simple") {
116
- console.warn(
117
- "You are using Button.Text with simple button API. Either remove Button.Text or use either `buttonApi: composable` or `mixed` in your tamagui config."
118
- );
119
- }
120
- if (buttonApi === "composable")
121
- return () => {
122
- };
123
- setButtonTextCount((prev) => prev + 1);
124
- return () => setButtonTextCount((prev) => prev - 1);
125
- }, [setButtonTextCount]);
126
- const usesComposableApi = buttonApi === "composable" || buttonApi === "mixed" && buttonTextCount > 0;
127
- return <ButtonProvider
128
- scope={props.__scopeButton}
129
- size={props.size ?? "$true"}
130
- color={props.color}
131
- usesComposableApi={usesComposableApi}
132
- registerButtonText={registerButtonText}
133
- ><ButtonFrame unstyled={props.unstyled ?? false} ref={ref} {...buttonProps} /></ButtonProvider>;
134
- }
135
- );
136
- const Button = withStaticProperties(ButtonComponent, {
137
- Text: ButtonText,
138
- Icon: ButtonIcon
139
- });
140
- function useButton(propsIn, { Text = ButtonTextFrame } = { Text: ButtonTextFrame }) {
141
- const {
142
- children,
143
- icon,
144
- iconAfter,
145
- noTextWrap,
146
- theme: themeName,
147
- space,
148
- spaceFlex,
149
- scaleIcon = 1,
150
- scaleSpace = 0.66,
151
- separator,
152
- // text props
153
- color,
154
- fontWeight,
155
- letterSpacing,
156
- fontSize,
157
- fontFamily,
158
- fontStyle,
159
- textAlign,
160
- unstyled = false,
161
- textProps,
162
- ...rest
163
- } = propsIn;
164
- const isNested = isRSC ? false : useContext(ButtonNestingContext);
165
- const propsActive = useMediaPropsActive(propsIn);
166
- const size = propsActive.size || "$true";
167
- const iconSize = (typeof size === "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
168
- const getThemedIcon = useGetThemedIcon({ size: iconSize, color });
169
- const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon);
170
- const spaceSize = propsActive.space ?? getVariableValue(iconSize) * scaleSpace;
171
- const contents = wrapChildrenInText(
172
- Text,
173
- propsActive,
174
- Text === ButtonTextFrame ? {
175
- unstyled
176
- } : void 0
177
- );
178
- const inner = spacedChildren({
179
- // a bit arbitrary but scaling to font size is necessary so long as button does
180
- space: spaceSize,
181
- spaceFlex,
182
- separator,
183
- direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
184
- children: [themedIcon, ...contents, themedIconAfter]
185
- });
186
- const tag = isNested ? "span" : (
187
- // defaults to <a /> when accessibilityRole = link
188
- // see https://github.com/tamagui/tamagui/issues/505
189
- propsIn.accessibilityRole === "link" ? "a" : void 0
190
- );
191
- const props = {
192
- ...propsActive.disabled && {
193
- // in rnw - false still has keyboard tabIndex, undefined = not actually focusable
194
- focusable: void 0,
195
- // even with tabIndex unset, it will keep focusStyle on web so disable it here
196
- focusStyle: {
197
- borderColor: "$background"
198
- }
199
- },
200
- tag,
201
- ...rest,
202
- children: isRSC ? inner : <ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>
203
- };
204
- return {
205
- spaceSize,
206
- isNested,
207
- props
208
- };
209
- }
210
- const buttonStaticConfig = {
211
- inlineProps: /* @__PURE__ */ new Set([
212
- // text props go here (can't really optimize them, but we never fully extract button anyway)
213
- // may be able to remove this entirely, as the compiler / runtime have gotten better
214
- "color",
215
- "fontWeight",
216
- "fontSize",
217
- "fontFamily",
218
- "fontStyle",
219
- "letterSpacing",
220
- "textAlign",
221
- "unstyled"
222
- ])
223
- };
224
- export {
225
- Button,
226
- ButtonFrame,
227
- ButtonTextFrame as ButtonText,
228
- buttonStaticConfig,
229
- createButtonScope,
230
- useButton
231
- };
232
- //# sourceMappingURL=themed.mjs.map