@tamagui/button 1.27.2 → 1.28.0
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 +24 -45
- package/dist/cjs/Button.js.map +1 -1
- package/dist/cjs/Button.test.js.map +1 -1
- package/dist/esm/Button.js +28 -52
- package/dist/esm/Button.js.map +1 -1
- package/dist/esm/Button.test.js.map +1 -1
- package/dist/jsx/Button.js +28 -48
- package/dist/jsx/Button.js.map +1 -1
- package/dist/jsx/Button.mjs +28 -48
- package/dist/jsx/Button.mjs.map +1 -1
- package/dist/jsx/Button.test.js.map +1 -1
- package/dist/jsx/Button.test.mjs.map +1 -1
- package/package.json +7 -7
- package/src/Button.test.tsx +1 -4
- package/src/Button.tsx +47 -91
- package/types/Button.d.ts +117 -107
- package/types/Button.d.ts.map +1 -1
- package/dist/esm/Button.mjs +0 -237
- package/dist/esm/Button.test.mjs +0 -11
- package/dist/esm/index.mjs +0 -2
- package/dist/jsx/base.mjs +0 -5
- package/dist/jsx/themed.mjs +0 -232
package/dist/jsx/Button.mjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Button.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAA4B,kBAAkB;AAEvC,MAAM,gBAAgB,oBAI3B;AAAA,EACA,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,eAAe;AAAA,E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AAwB,CAAC;AAEpD,SAAS,UAAU,MAAM;AACvB,OAAK,OAAO,MAAM;AAChB,WAAO,IAAI,EAAE,WAAW;AAAA,EAC1B,CAAC;AAWH,CAAC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Button.test.tsx"],
|
|
4
|
-
"mappings": "AAAA,QAAQ,IAAI,iBAAiB;AAE7B,SAAS,+BAA+B;AACxC,
|
|
4
|
+
"mappings": "AAAA,QAAQ,IAAI,iBAAiB;AAE7B,SAAS,+BAA+B;AACxC,SAAS,qBAAqB;AAC9B,SAAS,UAAU,QAAQ,YAAY;AAEvC,MAAM,OAAO,cAAc,wBAAwB,CAAC;AAEpD,SAAS,UAAU,MAAM;AACvB,OAAK,OAAO,MAAM;AAChB,WAAO,IAAI,EAAE,WAAW;AAAA,EAC1B,CAAC;AAWH,CAAC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/button",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tamagui/font-size": "1.
|
|
33
|
-
"@tamagui/get-button-sized": "1.
|
|
34
|
-
"@tamagui/helpers-tamagui": "1.
|
|
35
|
-
"@tamagui/text": "1.
|
|
36
|
-
"@tamagui/web": "1.
|
|
32
|
+
"@tamagui/font-size": "1.28.0",
|
|
33
|
+
"@tamagui/get-button-sized": "1.28.0",
|
|
34
|
+
"@tamagui/helpers-tamagui": "1.28.0",
|
|
35
|
+
"@tamagui/text": "1.28.0",
|
|
36
|
+
"@tamagui/web": "1.28.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.
|
|
42
|
+
"@tamagui/build": "1.28.0",
|
|
43
43
|
"react": "^18.2.0",
|
|
44
44
|
"vitest": "^0.26.3"
|
|
45
45
|
},
|
package/src/Button.test.tsx
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
process.env.TAMAGUI_TARGET = 'web'
|
|
2
2
|
|
|
3
3
|
import { getDefaultTamaguiConfig } from '@tamagui/config-default'
|
|
4
|
-
import {
|
|
5
|
-
import { render } from '@testing-library/react'
|
|
4
|
+
import { createTamagui } from '@tamagui/core'
|
|
6
5
|
import { describe, expect, test } from 'vitest'
|
|
7
6
|
|
|
8
|
-
import { Button } from '.'
|
|
9
|
-
|
|
10
7
|
const conf = createTamagui(getDefaultTamaguiConfig())
|
|
11
8
|
|
|
12
9
|
describe('Button', () => {
|
package/src/Button.tsx
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import type { Scope } from '@tamagui/create-context'
|
|
2
|
-
import { createContextScope } from '@tamagui/create-context'
|
|
3
1
|
import { getFontSize } from '@tamagui/font-size'
|
|
4
2
|
import { getButtonSized } from '@tamagui/get-button-sized'
|
|
5
|
-
import {
|
|
3
|
+
import { useGetThemedIcon } from '@tamagui/helpers-tamagui'
|
|
6
4
|
import { ThemeableStack } from '@tamagui/stacks'
|
|
7
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
SizableText,
|
|
7
|
+
TextContextStyles,
|
|
8
|
+
TextParentStyles,
|
|
9
|
+
wrapChildrenInText,
|
|
10
|
+
} from '@tamagui/text'
|
|
8
11
|
import {
|
|
9
12
|
ButtonNestingContext,
|
|
13
|
+
ColorStyleProp,
|
|
10
14
|
GetProps,
|
|
11
15
|
SizeTokens,
|
|
12
|
-
TamaguiElement,
|
|
13
16
|
ThemeableProps,
|
|
17
|
+
createStyledContext,
|
|
14
18
|
getVariableValue,
|
|
15
19
|
isRSC,
|
|
16
20
|
spacedChildren,
|
|
@@ -18,14 +22,22 @@ import {
|
|
|
18
22
|
useProps,
|
|
19
23
|
withStaticProperties,
|
|
20
24
|
} from '@tamagui/web'
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
import { FunctionComponent, useContext } from 'react'
|
|
26
|
+
|
|
27
|
+
export const ButtonContext = createStyledContext<
|
|
28
|
+
TextContextStyles & {
|
|
29
|
+
size: SizeTokens
|
|
30
|
+
}
|
|
31
|
+
>({
|
|
32
|
+
size: '$true',
|
|
33
|
+
color: undefined,
|
|
34
|
+
fontFamily: undefined,
|
|
35
|
+
fontSize: undefined,
|
|
36
|
+
fontStyle: undefined,
|
|
37
|
+
fontWeight: undefined,
|
|
38
|
+
letterSpacing: undefined,
|
|
39
|
+
textAlign: undefined,
|
|
40
|
+
})
|
|
29
41
|
|
|
30
42
|
type ButtonIconProps = { color?: string; size?: number }
|
|
31
43
|
type IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null
|
|
@@ -66,6 +78,7 @@ const BUTTON_NAME = 'Button'
|
|
|
66
78
|
const ButtonFrame = styled(ThemeableStack, {
|
|
67
79
|
name: BUTTON_NAME,
|
|
68
80
|
tag: 'button',
|
|
81
|
+
context: ButtonContext,
|
|
69
82
|
focusable: true,
|
|
70
83
|
|
|
71
84
|
variants: {
|
|
@@ -119,9 +132,9 @@ const ButtonFrame = styled(ThemeableStack, {
|
|
|
119
132
|
},
|
|
120
133
|
})
|
|
121
134
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
135
|
+
const ButtonText = styled(SizableText, {
|
|
136
|
+
name: 'ButtonText',
|
|
137
|
+
context: ButtonContext,
|
|
125
138
|
|
|
126
139
|
variants: {
|
|
127
140
|
unstyled: {
|
|
@@ -142,82 +155,22 @@ const ButtonTextFrame = styled(SizableText, {
|
|
|
142
155
|
},
|
|
143
156
|
})
|
|
144
157
|
|
|
145
|
-
|
|
146
|
-
const [createButtonContext, createButtonScope] = createContextScope('Button')
|
|
147
|
-
|
|
148
|
-
type ButtonContextValue = {
|
|
149
|
-
size: SizeTokens
|
|
150
|
-
color: ColorProp
|
|
151
|
-
|
|
152
|
-
// used to keep backward compat with the new Button.Text api
|
|
153
|
-
hasTextComponent: boolean
|
|
154
|
-
registerButtonText: () => () => void
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const [ButtonProvider, useButtonContext] =
|
|
158
|
-
createButtonContext<ButtonContextValue>('Button')
|
|
159
|
-
|
|
160
|
-
const ButtonTextComponent = ButtonTextFrame.extractable(
|
|
161
|
-
forwardRef<TamaguiElement, ScopedProps<GetProps<typeof ButtonTextFrame>>>(
|
|
162
|
-
(props, ref) => {
|
|
163
|
-
const context = useButtonContext(BUTTON_TEXT_NAME, props.__scopeButton)
|
|
164
|
-
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
const unregister = context.registerButtonText()
|
|
167
|
-
return () => unregister()
|
|
168
|
-
}, [context.registerButtonText])
|
|
169
|
-
|
|
170
|
-
return <ButtonTextFrame size={props.size ?? context.size} {...props} ref={ref} />
|
|
171
|
-
}
|
|
172
|
-
)
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
const BUTTON_ICON_NAME = 'ButtonIcon'
|
|
176
|
-
|
|
177
|
-
const ButtonIcon = (
|
|
178
|
-
props: ScopedProps<{
|
|
179
|
-
children: React.ReactNode
|
|
180
|
-
scaleIcon?: number
|
|
181
|
-
}>
|
|
182
|
-
) => {
|
|
158
|
+
const ButtonIcon = (props: { children: React.ReactNode; scaleIcon?: number }) => {
|
|
183
159
|
const { children, scaleIcon = 1 } = props
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const size = context.size
|
|
187
|
-
const color = context.color
|
|
188
|
-
|
|
160
|
+
const { size, color } = useContext(ButtonContext)
|
|
189
161
|
const iconSize = (typeof size === 'number' ? size * 0.5 : getFontSize(size)) * scaleIcon
|
|
190
162
|
const getThemedIcon = useGetThemedIcon({ size: iconSize, color })
|
|
191
163
|
return getThemedIcon(children)
|
|
192
164
|
}
|
|
193
165
|
|
|
194
|
-
const ButtonComponent = ButtonFrame.styleable<
|
|
195
|
-
props,
|
|
196
|
-
ref
|
|
197
|
-
) {
|
|
166
|
+
const ButtonComponent = ButtonFrame.styleable<ButtonProps>(function Button(props, ref) {
|
|
198
167
|
const { props: buttonProps } = useButton(props)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const registerButtonText = useCallback(() => {
|
|
202
|
-
setButtonTextCount((prev) => prev + 1)
|
|
203
|
-
return () => setButtonTextCount((prev) => prev - 1)
|
|
204
|
-
}, [setButtonTextCount])
|
|
205
|
-
|
|
206
|
-
const hasTextComponent = buttonTextCount > 0
|
|
207
|
-
|
|
208
|
-
return (
|
|
209
|
-
<ButtonProvider
|
|
210
|
-
scope={props.__scopeButton}
|
|
211
|
-
color={props.color}
|
|
212
|
-
hasTextComponent={hasTextComponent}
|
|
213
|
-
size={props.size ?? '$true'}
|
|
214
|
-
registerButtonText={registerButtonText}
|
|
215
|
-
>
|
|
216
|
-
<ButtonFrame {...(hasTextComponent ? props : buttonProps)} ref={ref} />
|
|
217
|
-
</ButtonProvider>
|
|
218
|
-
)
|
|
168
|
+
return <ButtonFrame {...buttonProps} ref={ref} />
|
|
219
169
|
})
|
|
220
170
|
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Instead of useButton, see the Button docs for the newer and much improved Advanced customization pattern: https://tamagui.dev/docs/components/button
|
|
173
|
+
*/
|
|
221
174
|
const buttonStaticConfig = {
|
|
222
175
|
inlineProps: new Set([
|
|
223
176
|
// text props go here (can't really optimize them, but we never fully extract button anyway)
|
|
@@ -234,13 +187,16 @@ const buttonStaticConfig = {
|
|
|
234
187
|
}
|
|
235
188
|
|
|
236
189
|
const Button = withStaticProperties(ButtonComponent, {
|
|
237
|
-
Text:
|
|
190
|
+
Text: ButtonText,
|
|
238
191
|
Icon: ButtonIcon,
|
|
239
192
|
})
|
|
240
193
|
|
|
194
|
+
/**
|
|
195
|
+
* @deprecated Instead of useButton, see the Button docs for the newer and much improved Advanced customization pattern: https://tamagui.dev/docs/components/button
|
|
196
|
+
*/
|
|
241
197
|
function useButton(
|
|
242
198
|
propsIn: ButtonProps,
|
|
243
|
-
{ Text =
|
|
199
|
+
{ Text = Button.Text }: { Text: any } = { Text: Button.Text }
|
|
244
200
|
) {
|
|
245
201
|
// careful not to desctructure and re-order props, order is important
|
|
246
202
|
const {
|
|
@@ -279,12 +235,13 @@ function useButton(
|
|
|
279
235
|
const contents = wrapChildrenInText(
|
|
280
236
|
Text,
|
|
281
237
|
propsActive,
|
|
282
|
-
Text ===
|
|
238
|
+
Text === ButtonText && hasUnstyled
|
|
283
239
|
? {
|
|
284
240
|
unstyled: propsIn.unstyled,
|
|
285
241
|
}
|
|
286
242
|
: undefined
|
|
287
243
|
)
|
|
244
|
+
|
|
288
245
|
const inner = spacedChildren({
|
|
289
246
|
// a bit arbitrary but scaling to font size is necessary so long as button does
|
|
290
247
|
space: spaceSize,
|
|
@@ -333,14 +290,13 @@ function useButton(
|
|
|
333
290
|
}
|
|
334
291
|
|
|
335
292
|
export {
|
|
336
|
-
createButtonScope,
|
|
337
293
|
Button,
|
|
294
|
+
ButtonFrame,
|
|
295
|
+
ButtonText,
|
|
296
|
+
ButtonIcon,
|
|
338
297
|
|
|
339
|
-
// legacy
|
|
298
|
+
// legacy
|
|
340
299
|
useButton,
|
|
341
300
|
buttonStaticConfig,
|
|
342
|
-
ButtonFrame,
|
|
343
|
-
ButtonTextFrame as ButtonText,
|
|
344
301
|
}
|
|
345
|
-
|
|
346
302
|
export type { ButtonProps }
|