@tamagui/button 1.2.3 → 1.2.5
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/dist/cjs/Button.js +58 -39
- package/dist/cjs/Button.js.map +2 -2
- package/dist/esm/Button.js +58 -39
- package/dist/esm/Button.js.map +2 -2
- package/dist/jsx/Button.js +58 -39
- package/dist/jsx/Button.js.map +2 -2
- package/package.json +6 -6
- package/src/Button.tsx +74 -53
- package/types/Button.d.ts +200 -192
- package/types/Button.d.ts.map +1 -1
package/src/Button.tsx
CHANGED
|
@@ -33,9 +33,8 @@ export type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &
|
|
|
33
33
|
iconAfter?: IconProp
|
|
34
34
|
/**
|
|
35
35
|
* adjust icon relative to size
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* default: -1
|
|
36
|
+
*
|
|
37
|
+
* @default 1
|
|
39
38
|
*/
|
|
40
39
|
scaleIcon?: number
|
|
41
40
|
/**
|
|
@@ -46,6 +45,10 @@ export type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &
|
|
|
46
45
|
* adjust internal space relative to icon size
|
|
47
46
|
*/
|
|
48
47
|
scaleSpace?: number
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
unstyled?: boolean
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
const NAME = 'Button'
|
|
@@ -53,33 +56,36 @@ const NAME = 'Button'
|
|
|
53
56
|
export const ButtonFrame = styled(ThemeableStack, {
|
|
54
57
|
name: NAME,
|
|
55
58
|
tag: 'button',
|
|
56
|
-
focusable: true,
|
|
57
|
-
hoverTheme: true,
|
|
58
|
-
pressTheme: true,
|
|
59
|
-
backgrounded: true,
|
|
60
|
-
borderWidth: 1,
|
|
61
|
-
borderColor: 'transparent',
|
|
62
59
|
justifyContent: 'center',
|
|
63
60
|
alignItems: 'center',
|
|
64
61
|
flexWrap: 'nowrap',
|
|
65
62
|
flexDirection: 'row',
|
|
66
|
-
|
|
67
|
-
// if we wanted this only when pressable = true, we'd need to merge variants?
|
|
68
63
|
cursor: 'pointer',
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
variants: {
|
|
66
|
+
defaultStyle: {
|
|
67
|
+
true: {
|
|
68
|
+
focusable: true,
|
|
69
|
+
hoverTheme: true,
|
|
70
|
+
pressTheme: true,
|
|
71
|
+
backgrounded: true,
|
|
72
|
+
borderWidth: 1,
|
|
73
|
+
borderColor: 'transparent',
|
|
74
|
+
|
|
75
|
+
pressStyle: {
|
|
76
|
+
borderColor: 'transparent',
|
|
77
|
+
},
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
hoverStyle: {
|
|
80
|
+
borderColor: 'transparent',
|
|
81
|
+
},
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
focusStyle: {
|
|
84
|
+
borderColor: '$borderColorFocus',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
81
88
|
|
|
82
|
-
variants: {
|
|
83
89
|
size: {
|
|
84
90
|
'...size': getButtonSized,
|
|
85
91
|
},
|
|
@@ -104,20 +110,53 @@ export const ButtonFrame = styled(ThemeableStack, {
|
|
|
104
110
|
},
|
|
105
111
|
})
|
|
106
112
|
|
|
107
|
-
// see TODO breaking types
|
|
108
|
-
// type x = GetProps<typeof ButtonFrame>
|
|
109
|
-
// type y = x['size']
|
|
110
|
-
|
|
111
113
|
export const ButtonText = styled(SizableText, {
|
|
112
|
-
|
|
114
|
+
name: 'ButtonText',
|
|
113
115
|
userSelect: 'none',
|
|
114
116
|
cursor: 'pointer',
|
|
115
117
|
// flexGrow 1 leads to inconsistent native style where text pushes to start of view
|
|
116
118
|
flexGrow: 0,
|
|
117
119
|
flexShrink: 1,
|
|
118
120
|
ellipse: true,
|
|
121
|
+
|
|
122
|
+
variants: {
|
|
123
|
+
defaultStyle: {
|
|
124
|
+
true: {
|
|
125
|
+
color: '$color',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const ButtonComponent = forwardRef<TamaguiElement, ButtonProps>(function Button(
|
|
132
|
+
props,
|
|
133
|
+
ref
|
|
134
|
+
) {
|
|
135
|
+
const {
|
|
136
|
+
props: { unstyled, ...buttonProps },
|
|
137
|
+
} = useButton(props)
|
|
138
|
+
return <ButtonFrame defaultStyle={!unstyled} {...buttonProps} ref={ref} />
|
|
119
139
|
})
|
|
120
140
|
|
|
141
|
+
export const buttonStaticConfig = {
|
|
142
|
+
inlineProps: 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
|
+
'letterSpacing',
|
|
150
|
+
'textAlign',
|
|
151
|
+
'unstyled',
|
|
152
|
+
]),
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const Button = ButtonFrame.extractable(
|
|
156
|
+
themeable(ButtonComponent, ButtonFrame.staticConfig),
|
|
157
|
+
buttonStaticConfig
|
|
158
|
+
)
|
|
159
|
+
|
|
121
160
|
export function useButton(
|
|
122
161
|
propsIn: ButtonProps,
|
|
123
162
|
{ Text = ButtonText }: { Text: any } = { Text: ButtonText }
|
|
@@ -153,7 +192,15 @@ export function useButton(
|
|
|
153
192
|
const getThemedIcon = useGetThemedIcon({ size: iconSize, color })
|
|
154
193
|
const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon)
|
|
155
194
|
const spaceSize = propsActive.space ?? getVariableValue(iconSize) * scaleSpace
|
|
156
|
-
const contents = wrapChildrenInText(
|
|
195
|
+
const contents = wrapChildrenInText(
|
|
196
|
+
Text,
|
|
197
|
+
propsActive,
|
|
198
|
+
Text === ButtonText
|
|
199
|
+
? {
|
|
200
|
+
defaultStyle: !propsIn.unstyled,
|
|
201
|
+
}
|
|
202
|
+
: undefined
|
|
203
|
+
)
|
|
157
204
|
const inner = spacedChildren({
|
|
158
205
|
// a bit arbitrary but scaling to font size is necessary so long as button does
|
|
159
206
|
space: spaceSize,
|
|
@@ -200,29 +247,3 @@ export function useButton(
|
|
|
200
247
|
props,
|
|
201
248
|
}
|
|
202
249
|
}
|
|
203
|
-
|
|
204
|
-
const ButtonComponent = forwardRef<TamaguiElement, ButtonProps>(function Button(
|
|
205
|
-
props,
|
|
206
|
-
ref
|
|
207
|
-
) {
|
|
208
|
-
const { props: buttonProps } = useButton(props)
|
|
209
|
-
return <ButtonFrame {...buttonProps} ref={ref} />
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
export const buttonStaticConfig = {
|
|
213
|
-
inlineProps: new Set([
|
|
214
|
-
// text props go here (can't really optimize them, but we never fully extract button anyway)
|
|
215
|
-
// may be able to remove this entirely, as the compiler / runtime have gotten better
|
|
216
|
-
'color',
|
|
217
|
-
'fontWeight',
|
|
218
|
-
'fontSize',
|
|
219
|
-
'fontFamily',
|
|
220
|
-
'letterSpacing',
|
|
221
|
-
'textAlign',
|
|
222
|
-
]),
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export const Button = ButtonFrame.extractable(
|
|
226
|
-
themeable(ButtonComponent, ButtonFrame.staticConfig),
|
|
227
|
-
buttonStaticConfig
|
|
228
|
-
)
|