@tamagui/button 1.0.1-rc.4.1 → 1.0.1-rc.5.1
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 +21 -22
- package/dist/cjs/Button.js.map +2 -2
- package/dist/esm/Button.js +21 -22
- package/dist/esm/Button.js.map +2 -2
- package/dist/jsx/Button.js +18 -19
- package/dist/jsx/Button.js.map +2 -2
- package/package.json +6 -6
- package/src/Button.tsx +26 -28
- package/types/Button.d.ts +17 -3
package/dist/cjs/Button.js
CHANGED
|
@@ -86,7 +86,7 @@ const ButtonText = (0, import_core.styled)(import_text.SizableText, {
|
|
|
86
86
|
flexShrink: 1,
|
|
87
87
|
ellipse: true
|
|
88
88
|
});
|
|
89
|
-
function useButton(
|
|
89
|
+
function useButton(propsIn, { Text = ButtonText } = { Text: ButtonText }) {
|
|
90
90
|
const {
|
|
91
91
|
children,
|
|
92
92
|
icon,
|
|
@@ -106,41 +106,40 @@ function useButton(props, { Text = ButtonText } = { Text: ButtonText }) {
|
|
|
106
106
|
textAlign,
|
|
107
107
|
textProps,
|
|
108
108
|
...rest
|
|
109
|
-
} =
|
|
109
|
+
} = propsIn;
|
|
110
110
|
const isNested = import_core.isRSC ? false : (0, import_react.useContext)(import_core.ButtonNestingContext);
|
|
111
|
-
const
|
|
112
|
-
const size =
|
|
111
|
+
const propsActive = (0, import_core.useMediaPropsActive)(propsIn);
|
|
112
|
+
const size = propsActive.size || "$4";
|
|
113
113
|
const iconSize = (typeof size === "number" ? size * 0.5 : (0, import_font_size.getFontSize)(size)) * scaleIcon;
|
|
114
114
|
const getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({ size: iconSize, color });
|
|
115
115
|
const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon);
|
|
116
116
|
const spaceSize = (0, import_core.getVariableValue)(iconSize) * scaleSpace;
|
|
117
|
-
const contents = (0, import_text.wrapChildrenInText)(Text,
|
|
117
|
+
const contents = (0, import_text.wrapChildrenInText)(Text, propsActive);
|
|
118
118
|
const inner = themedIcon || themedIconAfter ? (0, import_core.spacedChildren)({
|
|
119
119
|
space: spaceSize,
|
|
120
120
|
spaceFlex,
|
|
121
121
|
separator,
|
|
122
|
-
direction:
|
|
122
|
+
direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
|
|
123
123
|
children: [themedIcon, contents, themedIconAfter]
|
|
124
124
|
}) : contents;
|
|
125
|
+
const props = {
|
|
126
|
+
...propsActive.disabled && {
|
|
127
|
+
focusable: void 0,
|
|
128
|
+
focusStyle: {
|
|
129
|
+
borderColor: "$background"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
tag: isNested ? "span" : void 0,
|
|
133
|
+
...rest,
|
|
134
|
+
children: import_core.isRSC ? inner : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ButtonNestingContext.Provider, {
|
|
135
|
+
value: true,
|
|
136
|
+
children: inner
|
|
137
|
+
})
|
|
138
|
+
};
|
|
125
139
|
return {
|
|
126
140
|
spaceSize,
|
|
127
141
|
isNested,
|
|
128
|
-
props
|
|
129
|
-
...props.disabled && {
|
|
130
|
-
focusable: void 0,
|
|
131
|
-
focusStyle: {
|
|
132
|
-
borderColor: "$background"
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
...isNested ? {
|
|
136
|
-
tag: "span"
|
|
137
|
-
} : {},
|
|
138
|
-
...rest,
|
|
139
|
-
children: import_core.isRSC ? inner : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ButtonNestingContext.Provider, {
|
|
140
|
-
value: true,
|
|
141
|
-
children: inner
|
|
142
|
-
})
|
|
143
|
-
}
|
|
142
|
+
props
|
|
144
143
|
};
|
|
145
144
|
}
|
|
146
145
|
const ButtonComponent = (0, import_react.forwardRef)(function Button(props, ref) {
|
package/dist/cjs/Button.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Button.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n ButtonNestingContext,\n GetProps,\n TamaguiElement,\n ThemeableProps,\n getVariableValue,\n isRSC,\n spacedChildren,\n styled,\n themeable,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText, TextParentStyles, wrapChildrenInText } from '@tamagui/text'\nimport { FunctionComponent, forwardRef, useContext } from 'react'\n\ntype ButtonIconProps = { color?: string; size?: number }\ntype IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null\n\nexport type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &\n GetProps<typeof ButtonFrame> &\n ThemeableProps & {\n /**\n * add icon before, passes color and size automatically if Component\n */\n icon?: IconProp\n /**\n * add icon after, passes color and size automatically if Component\n */\n iconAfter?: IconProp\n /**\n * adjust icon relative to size\n */\n /**\n * default: -1\n */\n scaleIcon?: number\n /**\n * make the spacing elements flex\n */\n spaceFlex?: number | boolean\n /**\n * adjust internal space relative to icon size\n */\n scaleSpace?: number\n }\n\nconst NAME = 'Button'\n\nexport const ButtonFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n focusable: true,\n hoverTheme: true,\n pressTheme: true,\n backgrounded: true,\n borderWidth: 1,\n borderColor: 'transparent',\n justifyContent: 'center',\n alignItems: 'center',\n flexWrap: 'nowrap',\n flexDirection: 'row',\n\n // if we wanted this only when pressable = true, we'd need to merge variants?\n cursor: 'pointer',\n\n pressStyle: {\n borderColor: 'transparent',\n },\n\n hoverStyle: {\n borderColor: 'transparent',\n },\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': getButtonSized,\n },\n\n active: {\n true: {\n hoverStyle: {\n backgroundColor: '$background',\n },\n },\n },\n\n disabled: {\n true: {\n pointerEvents: 'none',\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\n// see TODO breaking types\n// type x = GetProps<typeof ButtonFrame>\n// type y = x['size']\n\nexport const ButtonText = styled(SizableText, {\n color: '$color',\n userSelect: 'none',\n cursor: 'pointer',\n // flexGrow 1 leads to inconsistent native style where text pushes to start of view\n flexGrow: 0,\n flexShrink: 1,\n ellipse: true,\n})\n\nexport function useButton(\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n ButtonNestingContext,\n GetProps,\n TamaguiElement,\n ThemeableProps,\n getVariableValue,\n isRSC,\n spacedChildren,\n styled,\n themeable,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText, TextParentStyles, wrapChildrenInText } from '@tamagui/text'\nimport { FunctionComponent, forwardRef, useContext } from 'react'\n\ntype ButtonIconProps = { color?: string; size?: number }\ntype IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null\n\nexport type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &\n GetProps<typeof ButtonFrame> &\n ThemeableProps & {\n /**\n * add icon before, passes color and size automatically if Component\n */\n icon?: IconProp\n /**\n * add icon after, passes color and size automatically if Component\n */\n iconAfter?: IconProp\n /**\n * adjust icon relative to size\n */\n /**\n * default: -1\n */\n scaleIcon?: number\n /**\n * make the spacing elements flex\n */\n spaceFlex?: number | boolean\n /**\n * adjust internal space relative to icon size\n */\n scaleSpace?: number\n }\n\nconst NAME = 'Button'\n\nexport const ButtonFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n focusable: true,\n hoverTheme: true,\n pressTheme: true,\n backgrounded: true,\n borderWidth: 1,\n borderColor: 'transparent',\n justifyContent: 'center',\n alignItems: 'center',\n flexWrap: 'nowrap',\n flexDirection: 'row',\n\n // if we wanted this only when pressable = true, we'd need to merge variants?\n cursor: 'pointer',\n\n pressStyle: {\n borderColor: 'transparent',\n },\n\n hoverStyle: {\n borderColor: 'transparent',\n },\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': getButtonSized,\n },\n\n active: {\n true: {\n hoverStyle: {\n backgroundColor: '$background',\n },\n },\n },\n\n disabled: {\n true: {\n pointerEvents: 'none',\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\n// see TODO breaking types\n// type x = GetProps<typeof ButtonFrame>\n// type y = x['size']\n\nexport const ButtonText = styled(SizableText, {\n color: '$color',\n userSelect: 'none',\n cursor: 'pointer',\n // flexGrow 1 leads to inconsistent native style where text pushes to start of view\n flexGrow: 0,\n flexShrink: 1,\n ellipse: true,\n})\n\nexport function useButton(\n propsIn: ButtonProps,\n { Text = ButtonText }: { Text: any } = { Text: ButtonText }\n) {\n // careful not to desctructure and re-order props, order is important\n const {\n children,\n icon,\n iconAfter,\n noTextWrap,\n theme: themeName,\n space,\n spaceFlex,\n scaleIcon = 1,\n scaleSpace = 0.66,\n separator,\n\n // text props\n color,\n fontWeight,\n letterSpacing,\n fontSize,\n fontFamily,\n textAlign,\n textProps,\n ...rest\n } = propsIn\n\n const isNested = isRSC ? false : useContext(ButtonNestingContext)\n const propsActive = useMediaPropsActive(propsIn)\n const size = propsActive.size || '$4'\n const iconSize = (typeof size === 'number' ? size * 0.5 : getFontSize(size)) * scaleIcon\n const getThemedIcon = useGetThemedIcon({ size: iconSize, color })\n const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon)\n const spaceSize = getVariableValue(iconSize) * scaleSpace\n const contents = wrapChildrenInText(Text, propsActive)\n const inner =\n themedIcon || themedIconAfter\n ? spacedChildren({\n // a bit arbitrary but scaling to font size is necessary so long as button does\n space: spaceSize,\n spaceFlex,\n separator,\n direction:\n propsActive.flexDirection === 'column' || propsActive.flexDirection === 'column-reverse'\n ? 'vertical'\n : 'horizontal',\n children: [themedIcon, contents, themedIconAfter],\n })\n : contents\n\n const props = {\n ...(propsActive.disabled && {\n // in rnw - false still has keyboard tabIndex, undefined = not actually focusable\n focusable: undefined,\n // even with tabIndex unset, it will keep focusStyle on web so disable it here\n focusStyle: {\n borderColor: '$background',\n },\n }),\n // fixes SSR issue + DOM nesting issue of not allowing button in button\n tag: isNested ? 'span' : undefined,\n ...rest,\n children: isRSC ? (\n inner\n ) : (\n <ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>\n ),\n }\n\n return {\n spaceSize,\n isNested,\n props,\n }\n}\n\nconst ButtonComponent = forwardRef<TamaguiElement, ButtonProps>(function Button(props, ref) {\n const { props: buttonProps } = useButton(props)\n return <ButtonFrame {...buttonProps} ref={ref} />\n})\n\nexport const buttonStaticConfig = {\n inlineProps: new Set([\n // text props go here (can't really optimize them, but we never fully extract button anyway)\n // may be able to remove this entirely, as the compiler / runtime have gotten better\n 'color',\n 'fontWeight',\n 'fontSize',\n 'fontFamily',\n 'letterSpacing',\n 'textAlign',\n ]),\n}\n\nexport const Button = ButtonFrame.extractable(\n themeable(ButtonComponent, ButtonFrame.staticConfig),\n buttonStaticConfig\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0LM;AA1LN,kBAWO;AACP,uBAA4B;AAC5B,8BAA+B;AAC/B,6BAAiC;AACjC,oBAA+B;AAC/B,kBAAkE;AAClE,mBAA0D;AAiC1D,MAAM,OAAO;AAEN,MAAM,kBAAc,oBAAO,8BAAgB;AAAA,EAChD,MAAM;AAAA,EACN,KAAK;AAAA,EACL,WAAW;AAAA,EACX,YAAY;AAAA,EACZ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/Button.js
CHANGED
|
@@ -67,7 +67,7 @@ const ButtonText = styled(SizableText, {
|
|
|
67
67
|
flexShrink: 1,
|
|
68
68
|
ellipse: true
|
|
69
69
|
});
|
|
70
|
-
function useButton(
|
|
70
|
+
function useButton(propsIn, { Text = ButtonText } = { Text: ButtonText }) {
|
|
71
71
|
const {
|
|
72
72
|
children,
|
|
73
73
|
icon,
|
|
@@ -87,41 +87,40 @@ function useButton(props, { Text = ButtonText } = { Text: ButtonText }) {
|
|
|
87
87
|
textAlign,
|
|
88
88
|
textProps,
|
|
89
89
|
...rest
|
|
90
|
-
} =
|
|
90
|
+
} = propsIn;
|
|
91
91
|
const isNested = isRSC ? false : useContext(ButtonNestingContext);
|
|
92
|
-
const
|
|
93
|
-
const size =
|
|
92
|
+
const propsActive = useMediaPropsActive(propsIn);
|
|
93
|
+
const size = propsActive.size || "$4";
|
|
94
94
|
const iconSize = (typeof size === "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
|
|
95
95
|
const getThemedIcon = useGetThemedIcon({ size: iconSize, color });
|
|
96
96
|
const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon);
|
|
97
97
|
const spaceSize = getVariableValue(iconSize) * scaleSpace;
|
|
98
|
-
const contents = wrapChildrenInText(Text,
|
|
98
|
+
const contents = wrapChildrenInText(Text, propsActive);
|
|
99
99
|
const inner = themedIcon || themedIconAfter ? spacedChildren({
|
|
100
100
|
space: spaceSize,
|
|
101
101
|
spaceFlex,
|
|
102
102
|
separator,
|
|
103
|
-
direction:
|
|
103
|
+
direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
|
|
104
104
|
children: [themedIcon, contents, themedIconAfter]
|
|
105
105
|
}) : contents;
|
|
106
|
+
const props = {
|
|
107
|
+
...propsActive.disabled && {
|
|
108
|
+
focusable: void 0,
|
|
109
|
+
focusStyle: {
|
|
110
|
+
borderColor: "$background"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
tag: isNested ? "span" : void 0,
|
|
114
|
+
...rest,
|
|
115
|
+
children: isRSC ? inner : /* @__PURE__ */ jsx(ButtonNestingContext.Provider, {
|
|
116
|
+
value: true,
|
|
117
|
+
children: inner
|
|
118
|
+
})
|
|
119
|
+
};
|
|
106
120
|
return {
|
|
107
121
|
spaceSize,
|
|
108
122
|
isNested,
|
|
109
|
-
props
|
|
110
|
-
...props.disabled && {
|
|
111
|
-
focusable: void 0,
|
|
112
|
-
focusStyle: {
|
|
113
|
-
borderColor: "$background"
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
...isNested ? {
|
|
117
|
-
tag: "span"
|
|
118
|
-
} : {},
|
|
119
|
-
...rest,
|
|
120
|
-
children: isRSC ? inner : /* @__PURE__ */ jsx(ButtonNestingContext.Provider, {
|
|
121
|
-
value: true,
|
|
122
|
-
children: inner
|
|
123
|
-
})
|
|
124
|
-
}
|
|
123
|
+
props
|
|
125
124
|
};
|
|
126
125
|
}
|
|
127
126
|
const ButtonComponent = forwardRef(function Button(props, ref) {
|
package/dist/esm/Button.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Button.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n ButtonNestingContext,\n GetProps,\n TamaguiElement,\n ThemeableProps,\n getVariableValue,\n isRSC,\n spacedChildren,\n styled,\n themeable,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText, TextParentStyles, wrapChildrenInText } from '@tamagui/text'\nimport { FunctionComponent, forwardRef, useContext } from 'react'\n\ntype ButtonIconProps = { color?: string; size?: number }\ntype IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null\n\nexport type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &\n GetProps<typeof ButtonFrame> &\n ThemeableProps & {\n /**\n * add icon before, passes color and size automatically if Component\n */\n icon?: IconProp\n /**\n * add icon after, passes color and size automatically if Component\n */\n iconAfter?: IconProp\n /**\n * adjust icon relative to size\n */\n /**\n * default: -1\n */\n scaleIcon?: number\n /**\n * make the spacing elements flex\n */\n spaceFlex?: number | boolean\n /**\n * adjust internal space relative to icon size\n */\n scaleSpace?: number\n }\n\nconst NAME = 'Button'\n\nexport const ButtonFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n focusable: true,\n hoverTheme: true,\n pressTheme: true,\n backgrounded: true,\n borderWidth: 1,\n borderColor: 'transparent',\n justifyContent: 'center',\n alignItems: 'center',\n flexWrap: 'nowrap',\n flexDirection: 'row',\n\n // if we wanted this only when pressable = true, we'd need to merge variants?\n cursor: 'pointer',\n\n pressStyle: {\n borderColor: 'transparent',\n },\n\n hoverStyle: {\n borderColor: 'transparent',\n },\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': getButtonSized,\n },\n\n active: {\n true: {\n hoverStyle: {\n backgroundColor: '$background',\n },\n },\n },\n\n disabled: {\n true: {\n pointerEvents: 'none',\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\n// see TODO breaking types\n// type x = GetProps<typeof ButtonFrame>\n// type y = x['size']\n\nexport const ButtonText = styled(SizableText, {\n color: '$color',\n userSelect: 'none',\n cursor: 'pointer',\n // flexGrow 1 leads to inconsistent native style where text pushes to start of view\n flexGrow: 0,\n flexShrink: 1,\n ellipse: true,\n})\n\nexport function useButton(\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import {\n ButtonNestingContext,\n GetProps,\n TamaguiElement,\n ThemeableProps,\n getVariableValue,\n isRSC,\n spacedChildren,\n styled,\n themeable,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText, TextParentStyles, wrapChildrenInText } from '@tamagui/text'\nimport { FunctionComponent, forwardRef, useContext } from 'react'\n\ntype ButtonIconProps = { color?: string; size?: number }\ntype IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null\n\nexport type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &\n GetProps<typeof ButtonFrame> &\n ThemeableProps & {\n /**\n * add icon before, passes color and size automatically if Component\n */\n icon?: IconProp\n /**\n * add icon after, passes color and size automatically if Component\n */\n iconAfter?: IconProp\n /**\n * adjust icon relative to size\n */\n /**\n * default: -1\n */\n scaleIcon?: number\n /**\n * make the spacing elements flex\n */\n spaceFlex?: number | boolean\n /**\n * adjust internal space relative to icon size\n */\n scaleSpace?: number\n }\n\nconst NAME = 'Button'\n\nexport const ButtonFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n focusable: true,\n hoverTheme: true,\n pressTheme: true,\n backgrounded: true,\n borderWidth: 1,\n borderColor: 'transparent',\n justifyContent: 'center',\n alignItems: 'center',\n flexWrap: 'nowrap',\n flexDirection: 'row',\n\n // if we wanted this only when pressable = true, we'd need to merge variants?\n cursor: 'pointer',\n\n pressStyle: {\n borderColor: 'transparent',\n },\n\n hoverStyle: {\n borderColor: 'transparent',\n },\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': getButtonSized,\n },\n\n active: {\n true: {\n hoverStyle: {\n backgroundColor: '$background',\n },\n },\n },\n\n disabled: {\n true: {\n pointerEvents: 'none',\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\n// see TODO breaking types\n// type x = GetProps<typeof ButtonFrame>\n// type y = x['size']\n\nexport const ButtonText = styled(SizableText, {\n color: '$color',\n userSelect: 'none',\n cursor: 'pointer',\n // flexGrow 1 leads to inconsistent native style where text pushes to start of view\n flexGrow: 0,\n flexShrink: 1,\n ellipse: true,\n})\n\nexport function useButton(\n propsIn: ButtonProps,\n { Text = ButtonText }: { Text: any } = { Text: ButtonText }\n) {\n // careful not to desctructure and re-order props, order is important\n const {\n children,\n icon,\n iconAfter,\n noTextWrap,\n theme: themeName,\n space,\n spaceFlex,\n scaleIcon = 1,\n scaleSpace = 0.66,\n separator,\n\n // text props\n color,\n fontWeight,\n letterSpacing,\n fontSize,\n fontFamily,\n textAlign,\n textProps,\n ...rest\n } = propsIn\n\n const isNested = isRSC ? false : useContext(ButtonNestingContext)\n const propsActive = useMediaPropsActive(propsIn)\n const size = propsActive.size || '$4'\n const iconSize = (typeof size === 'number' ? size * 0.5 : getFontSize(size)) * scaleIcon\n const getThemedIcon = useGetThemedIcon({ size: iconSize, color })\n const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon)\n const spaceSize = getVariableValue(iconSize) * scaleSpace\n const contents = wrapChildrenInText(Text, propsActive)\n const inner =\n themedIcon || themedIconAfter\n ? spacedChildren({\n // a bit arbitrary but scaling to font size is necessary so long as button does\n space: spaceSize,\n spaceFlex,\n separator,\n direction:\n propsActive.flexDirection === 'column' || propsActive.flexDirection === 'column-reverse'\n ? 'vertical'\n : 'horizontal',\n children: [themedIcon, contents, themedIconAfter],\n })\n : contents\n\n const props = {\n ...(propsActive.disabled && {\n // in rnw - false still has keyboard tabIndex, undefined = not actually focusable\n focusable: undefined,\n // even with tabIndex unset, it will keep focusStyle on web so disable it here\n focusStyle: {\n borderColor: '$background',\n },\n }),\n // fixes SSR issue + DOM nesting issue of not allowing button in button\n tag: isNested ? 'span' : undefined,\n ...rest,\n children: isRSC ? (\n inner\n ) : (\n <ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>\n ),\n }\n\n return {\n spaceSize,\n isNested,\n props,\n }\n}\n\nconst ButtonComponent = forwardRef<TamaguiElement, ButtonProps>(function Button(props, ref) {\n const { props: buttonProps } = useButton(props)\n return <ButtonFrame {...buttonProps} ref={ref} />\n})\n\nexport const buttonStaticConfig = {\n inlineProps: new Set([\n // text props go here (can't really optimize them, but we never fully extract button anyway)\n // may be able to remove this entirely, as the compiler / runtime have gotten better\n 'color',\n 'fontWeight',\n 'fontSize',\n 'fontFamily',\n 'letterSpacing',\n 'textAlign',\n ]),\n}\n\nexport const Button = ButtonFrame.extractable(\n themeable(ButtonComponent, ButtonFrame.staticConfig),\n buttonStaticConfig\n)\n"],
|
|
5
|
+
"mappings": "AA0LM;AA1LN;AAAA,EACE;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,aAA+B,0BAA0B;AAClE,SAA4B,YAAY,kBAAkB;AAiC1D,MAAM,OAAO;AAEN,MAAM,cAAc,OAAO,gBAAgB;AAAA,EAChD,MAAM;AAAA,EACN,KAAK;AAAA,EACL,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,eAAe;AAAA,EAGf,QAAQ;AAAA,EAER,YAAY;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EAEA,YAAY;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EAEA,YAAY;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EAEA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW;AAAA,IACb;AAAA,IAEA,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,YAAY;AAAA,UACV,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA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AK,WAAW,SAAS;AAAA,IACzB,GAAG;AAAA,IACH,UAAU,QACR,QAEA,oBAAC,qBAAqB,UAArB;AAAA,MAA8B,OAAO;AAAA,MAAO;AAAA,KAAM;AAAA,EAEvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,kBAAkB,WAAwC,SAAS,OAAO,OAAO,KAAK;AAC1F,QAAM,EAAE,OAAO,YAAY,IAAI,UAAU,KAAK;AAC9C,SAAO,oBAAC;AAAA,IAAa,GAAG;AAAA,IAAa;AAAA,GAAU;AACjD,CAAC;AAEM,MAAM,qBAAqB;AAAA,EAChC,aAAa,oBAAI,IAAI;AAAA,IAGnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEO,MAAMA,UAAS,YAAY;AAAA,EAChC,UAAU,iBAAiB,YAAY,YAAY;AAAA,EACnD;AACF;",
|
|
6
6
|
"names": ["Button"]
|
|
7
7
|
}
|
package/dist/jsx/Button.js
CHANGED
|
@@ -66,7 +66,7 @@ const ButtonText = styled(SizableText, {
|
|
|
66
66
|
flexShrink: 1,
|
|
67
67
|
ellipse: true
|
|
68
68
|
});
|
|
69
|
-
function useButton(
|
|
69
|
+
function useButton(propsIn, { Text = ButtonText } = { Text: ButtonText }) {
|
|
70
70
|
const {
|
|
71
71
|
children,
|
|
72
72
|
icon,
|
|
@@ -86,38 +86,37 @@ function useButton(props, { Text = ButtonText } = { Text: ButtonText }) {
|
|
|
86
86
|
textAlign,
|
|
87
87
|
textProps,
|
|
88
88
|
...rest
|
|
89
|
-
} =
|
|
89
|
+
} = propsIn;
|
|
90
90
|
const isNested = isRSC ? false : useContext(ButtonNestingContext);
|
|
91
|
-
const
|
|
92
|
-
const size =
|
|
91
|
+
const propsActive = useMediaPropsActive(propsIn);
|
|
92
|
+
const size = propsActive.size || "$4";
|
|
93
93
|
const iconSize = (typeof size === "number" ? size * 0.5 : getFontSize(size)) * scaleIcon;
|
|
94
94
|
const getThemedIcon = useGetThemedIcon({ size: iconSize, color });
|
|
95
95
|
const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon);
|
|
96
96
|
const spaceSize = getVariableValue(iconSize) * scaleSpace;
|
|
97
|
-
const contents = wrapChildrenInText(Text,
|
|
97
|
+
const contents = wrapChildrenInText(Text, propsActive);
|
|
98
98
|
const inner = themedIcon || themedIconAfter ? spacedChildren({
|
|
99
99
|
space: spaceSize,
|
|
100
100
|
spaceFlex,
|
|
101
101
|
separator,
|
|
102
|
-
direction:
|
|
102
|
+
direction: propsActive.flexDirection === "column" || propsActive.flexDirection === "column-reverse" ? "vertical" : "horizontal",
|
|
103
103
|
children: [themedIcon, contents, themedIconAfter]
|
|
104
104
|
}) : contents;
|
|
105
|
+
const props = {
|
|
106
|
+
...propsActive.disabled && {
|
|
107
|
+
focusable: void 0,
|
|
108
|
+
focusStyle: {
|
|
109
|
+
borderColor: "$background"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
tag: isNested ? "span" : void 0,
|
|
113
|
+
...rest,
|
|
114
|
+
children: isRSC ? inner : <ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>
|
|
115
|
+
};
|
|
105
116
|
return {
|
|
106
117
|
spaceSize,
|
|
107
118
|
isNested,
|
|
108
|
-
props
|
|
109
|
-
...props.disabled && {
|
|
110
|
-
focusable: void 0,
|
|
111
|
-
focusStyle: {
|
|
112
|
-
borderColor: "$background"
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
...isNested ? {
|
|
116
|
-
tag: "span"
|
|
117
|
-
} : {},
|
|
118
|
-
...rest,
|
|
119
|
-
children: isRSC ? inner : <ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>
|
|
120
|
-
}
|
|
119
|
+
props
|
|
121
120
|
};
|
|
122
121
|
}
|
|
123
122
|
const ButtonComponent = forwardRef(function Button(props, ref) {
|
package/dist/jsx/Button.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Button.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n ButtonNestingContext,\n GetProps,\n TamaguiElement,\n ThemeableProps,\n getVariableValue,\n isRSC,\n spacedChildren,\n styled,\n themeable,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText, TextParentStyles, wrapChildrenInText } from '@tamagui/text'\nimport { FunctionComponent, forwardRef, useContext } from 'react'\n\ntype ButtonIconProps = { color?: string; size?: number }\ntype IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null\n\nexport type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &\n GetProps<typeof ButtonFrame> &\n ThemeableProps & {\n /**\n * add icon before, passes color and size automatically if Component\n */\n icon?: IconProp\n /**\n * add icon after, passes color and size automatically if Component\n */\n iconAfter?: IconProp\n /**\n * adjust icon relative to size\n */\n /**\n * default: -1\n */\n scaleIcon?: number\n /**\n * make the spacing elements flex\n */\n spaceFlex?: number | boolean\n /**\n * adjust internal space relative to icon size\n */\n scaleSpace?: number\n }\n\nconst NAME = 'Button'\n\nexport const ButtonFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n focusable: true,\n hoverTheme: true,\n pressTheme: true,\n backgrounded: true,\n borderWidth: 1,\n borderColor: 'transparent',\n justifyContent: 'center',\n alignItems: 'center',\n flexWrap: 'nowrap',\n flexDirection: 'row',\n\n // if we wanted this only when pressable = true, we'd need to merge variants?\n cursor: 'pointer',\n\n pressStyle: {\n borderColor: 'transparent',\n },\n\n hoverStyle: {\n borderColor: 'transparent',\n },\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': getButtonSized,\n },\n\n active: {\n true: {\n hoverStyle: {\n backgroundColor: '$background',\n },\n },\n },\n\n disabled: {\n true: {\n pointerEvents: 'none',\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\n// see TODO breaking types\n// type x = GetProps<typeof ButtonFrame>\n// type y = x['size']\n\nexport const ButtonText = styled(SizableText, {\n color: '$color',\n userSelect: 'none',\n cursor: 'pointer',\n // flexGrow 1 leads to inconsistent native style where text pushes to start of view\n flexGrow: 0,\n flexShrink: 1,\n ellipse: true,\n})\n\nexport function useButton(\n
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,aAA+B,0BAA0B;AAClE,SAA4B,YAAY,kBAAkB;AAiC1D,MAAM,OAAO;AAEN,MAAM,cAAc,OAAO,gBAAgB;AAAA,EAChD,MAAM;AAAA,EACN,KAAK;AAAA,EACL,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,eAAe;AAAA,EAGf,QAAQ;AAAA,EAER,YAAY;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EAEA,YAAY;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EAEA,YAAY;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EAEA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW;AAAA,IACb;AAAA,IAEA,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,YAAY;AAAA,UACV,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,CAAC;AAMM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,QAAQ;AAAA,EAER,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,SAAS;AACX,CAAC;AAEM,SAAS,UACd,
|
|
4
|
+
"sourcesContent": ["import {\n ButtonNestingContext,\n GetProps,\n TamaguiElement,\n ThemeableProps,\n getVariableValue,\n isRSC,\n spacedChildren,\n styled,\n themeable,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport { getFontSize } from '@tamagui/font-size'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { useGetThemedIcon } from '@tamagui/helpers-tamagui'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText, TextParentStyles, wrapChildrenInText } from '@tamagui/text'\nimport { FunctionComponent, forwardRef, useContext } from 'react'\n\ntype ButtonIconProps = { color?: string; size?: number }\ntype IconProp = JSX.Element | FunctionComponent<ButtonIconProps> | null\n\nexport type ButtonProps = Omit<TextParentStyles, 'TextComponent'> &\n GetProps<typeof ButtonFrame> &\n ThemeableProps & {\n /**\n * add icon before, passes color and size automatically if Component\n */\n icon?: IconProp\n /**\n * add icon after, passes color and size automatically if Component\n */\n iconAfter?: IconProp\n /**\n * adjust icon relative to size\n */\n /**\n * default: -1\n */\n scaleIcon?: number\n /**\n * make the spacing elements flex\n */\n spaceFlex?: number | boolean\n /**\n * adjust internal space relative to icon size\n */\n scaleSpace?: number\n }\n\nconst NAME = 'Button'\n\nexport const ButtonFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n focusable: true,\n hoverTheme: true,\n pressTheme: true,\n backgrounded: true,\n borderWidth: 1,\n borderColor: 'transparent',\n justifyContent: 'center',\n alignItems: 'center',\n flexWrap: 'nowrap',\n flexDirection: 'row',\n\n // if we wanted this only when pressable = true, we'd need to merge variants?\n cursor: 'pointer',\n\n pressStyle: {\n borderColor: 'transparent',\n },\n\n hoverStyle: {\n borderColor: 'transparent',\n },\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': getButtonSized,\n },\n\n active: {\n true: {\n hoverStyle: {\n backgroundColor: '$background',\n },\n },\n },\n\n disabled: {\n true: {\n pointerEvents: 'none',\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\n// see TODO breaking types\n// type x = GetProps<typeof ButtonFrame>\n// type y = x['size']\n\nexport const ButtonText = styled(SizableText, {\n color: '$color',\n userSelect: 'none',\n cursor: 'pointer',\n // flexGrow 1 leads to inconsistent native style where text pushes to start of view\n flexGrow: 0,\n flexShrink: 1,\n ellipse: true,\n})\n\nexport function useButton(\n propsIn: ButtonProps,\n { Text = ButtonText }: { Text: any } = { Text: ButtonText }\n) {\n // careful not to desctructure and re-order props, order is important\n const {\n children,\n icon,\n iconAfter,\n noTextWrap,\n theme: themeName,\n space,\n spaceFlex,\n scaleIcon = 1,\n scaleSpace = 0.66,\n separator,\n\n // text props\n color,\n fontWeight,\n letterSpacing,\n fontSize,\n fontFamily,\n textAlign,\n textProps,\n ...rest\n } = propsIn\n\n const isNested = isRSC ? false : useContext(ButtonNestingContext)\n const propsActive = useMediaPropsActive(propsIn)\n const size = propsActive.size || '$4'\n const iconSize = (typeof size === 'number' ? size * 0.5 : getFontSize(size)) * scaleIcon\n const getThemedIcon = useGetThemedIcon({ size: iconSize, color })\n const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon)\n const spaceSize = getVariableValue(iconSize) * scaleSpace\n const contents = wrapChildrenInText(Text, propsActive)\n const inner =\n themedIcon || themedIconAfter\n ? spacedChildren({\n // a bit arbitrary but scaling to font size is necessary so long as button does\n space: spaceSize,\n spaceFlex,\n separator,\n direction:\n propsActive.flexDirection === 'column' || propsActive.flexDirection === 'column-reverse'\n ? 'vertical'\n : 'horizontal',\n children: [themedIcon, contents, themedIconAfter],\n })\n : contents\n\n const props = {\n ...(propsActive.disabled && {\n // in rnw - false still has keyboard tabIndex, undefined = not actually focusable\n focusable: undefined,\n // even with tabIndex unset, it will keep focusStyle on web so disable it here\n focusStyle: {\n borderColor: '$background',\n },\n }),\n // fixes SSR issue + DOM nesting issue of not allowing button in button\n tag: isNested ? 'span' : undefined,\n ...rest,\n children: isRSC ? (\n inner\n ) : (\n <ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>\n ),\n }\n\n return {\n spaceSize,\n isNested,\n props,\n }\n}\n\nconst ButtonComponent = forwardRef<TamaguiElement, ButtonProps>(function Button(props, ref) {\n const { props: buttonProps } = useButton(props)\n return <ButtonFrame {...buttonProps} ref={ref} />\n})\n\nexport const buttonStaticConfig = {\n inlineProps: new Set([\n // text props go here (can't really optimize them, but we never fully extract button anyway)\n // may be able to remove this entirely, as the compiler / runtime have gotten better\n 'color',\n 'fontWeight',\n 'fontSize',\n 'fontFamily',\n 'letterSpacing',\n 'textAlign',\n ]),\n}\n\nexport const Button = ButtonFrame.extractable(\n themeable(ButtonComponent, ButtonFrame.staticConfig),\n buttonStaticConfig\n)\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,aAA+B,0BAA0B;AAClE,SAA4B,YAAY,kBAAkB;AAiC1D,MAAM,OAAO;AAEN,MAAM,cAAc,OAAO,gBAAgB;AAAA,EAChD,MAAM;AAAA,EACN,KAAK;AAAA,EACL,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ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ideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tamagui/core": "^1.0.1-rc.
|
|
32
|
-
"@tamagui/font-size": "^1.0.1-rc.
|
|
33
|
-
"@tamagui/get-button-sized": "^1.0.1-rc.
|
|
34
|
-
"@tamagui/helpers-tamagui": "^1.0.1-rc.
|
|
31
|
+
"@tamagui/core": "^1.0.1-rc.5.1",
|
|
32
|
+
"@tamagui/font-size": "^1.0.1-rc.5.1",
|
|
33
|
+
"@tamagui/get-button-sized": "^1.0.1-rc.5.1",
|
|
34
|
+
"@tamagui/helpers-tamagui": "^1.0.1-rc.5.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "^18.2.0",
|
|
38
38
|
"react-dom": "^18.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "^1.0.1-rc.
|
|
41
|
+
"@tamagui/build": "^1.0.1-rc.5.1",
|
|
42
42
|
"react": "^18.2.0",
|
|
43
43
|
"react-dom": "^18.2.0"
|
|
44
44
|
},
|
package/src/Button.tsx
CHANGED
|
@@ -119,7 +119,7 @@ export const ButtonText = styled(SizableText, {
|
|
|
119
119
|
})
|
|
120
120
|
|
|
121
121
|
export function useButton(
|
|
122
|
-
|
|
122
|
+
propsIn: ButtonProps,
|
|
123
123
|
{ Text = ButtonText }: { Text: any } = { Text: ButtonText }
|
|
124
124
|
) {
|
|
125
125
|
// careful not to desctructure and re-order props, order is important
|
|
@@ -144,16 +144,16 @@ export function useButton(
|
|
|
144
144
|
textAlign,
|
|
145
145
|
textProps,
|
|
146
146
|
...rest
|
|
147
|
-
} =
|
|
147
|
+
} = propsIn
|
|
148
148
|
|
|
149
149
|
const isNested = isRSC ? false : useContext(ButtonNestingContext)
|
|
150
|
-
const
|
|
151
|
-
const size =
|
|
150
|
+
const propsActive = useMediaPropsActive(propsIn)
|
|
151
|
+
const size = propsActive.size || '$4'
|
|
152
152
|
const iconSize = (typeof size === 'number' ? size * 0.5 : getFontSize(size)) * scaleIcon
|
|
153
153
|
const getThemedIcon = useGetThemedIcon({ size: iconSize, color })
|
|
154
154
|
const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon)
|
|
155
155
|
const spaceSize = getVariableValue(iconSize) * scaleSpace
|
|
156
|
-
const contents = wrapChildrenInText(Text,
|
|
156
|
+
const contents = wrapChildrenInText(Text, propsActive)
|
|
157
157
|
const inner =
|
|
158
158
|
themedIcon || themedIconAfter
|
|
159
159
|
? spacedChildren({
|
|
@@ -162,38 +162,36 @@ export function useButton(
|
|
|
162
162
|
spaceFlex,
|
|
163
163
|
separator,
|
|
164
164
|
direction:
|
|
165
|
-
|
|
165
|
+
propsActive.flexDirection === 'column' || propsActive.flexDirection === 'column-reverse'
|
|
166
166
|
? 'vertical'
|
|
167
167
|
: 'horizontal',
|
|
168
168
|
children: [themedIcon, contents, themedIconAfter],
|
|
169
169
|
})
|
|
170
170
|
: contents
|
|
171
171
|
|
|
172
|
+
const props = {
|
|
173
|
+
...(propsActive.disabled && {
|
|
174
|
+
// in rnw - false still has keyboard tabIndex, undefined = not actually focusable
|
|
175
|
+
focusable: undefined,
|
|
176
|
+
// even with tabIndex unset, it will keep focusStyle on web so disable it here
|
|
177
|
+
focusStyle: {
|
|
178
|
+
borderColor: '$background',
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
// fixes SSR issue + DOM nesting issue of not allowing button in button
|
|
182
|
+
tag: isNested ? 'span' : undefined,
|
|
183
|
+
...rest,
|
|
184
|
+
children: isRSC ? (
|
|
185
|
+
inner
|
|
186
|
+
) : (
|
|
187
|
+
<ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>
|
|
188
|
+
),
|
|
189
|
+
}
|
|
190
|
+
|
|
172
191
|
return {
|
|
173
192
|
spaceSize,
|
|
174
193
|
isNested,
|
|
175
|
-
props
|
|
176
|
-
...(props.disabled && {
|
|
177
|
-
// in rnw - false still has keyboard tabIndex, undefined = not actually focusable
|
|
178
|
-
focusable: undefined,
|
|
179
|
-
// even with tabIndex unset, it will keep focusStyle on web so disable it here
|
|
180
|
-
focusStyle: {
|
|
181
|
-
borderColor: '$background',
|
|
182
|
-
},
|
|
183
|
-
}),
|
|
184
|
-
// fixes SSR issue + DOM nesting issue of not allowing button in button
|
|
185
|
-
...(isNested
|
|
186
|
-
? {
|
|
187
|
-
tag: 'span',
|
|
188
|
-
}
|
|
189
|
-
: {}),
|
|
190
|
-
...rest,
|
|
191
|
-
children: isRSC ? (
|
|
192
|
-
inner
|
|
193
|
-
) : (
|
|
194
|
-
<ButtonNestingContext.Provider value={true}>{inner}</ButtonNestingContext.Provider>
|
|
195
|
-
),
|
|
196
|
-
},
|
|
194
|
+
props,
|
|
197
195
|
}
|
|
198
196
|
}
|
|
199
197
|
|
package/types/Button.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export declare const ButtonText: import("@tamagui/core").TamaguiComponent<(Omit<
|
|
|
137
137
|
} & {
|
|
138
138
|
[x: string]: undefined;
|
|
139
139
|
})>;
|
|
140
|
-
export declare function useButton(
|
|
140
|
+
export declare function useButton(propsIn: ButtonProps, { Text }?: {
|
|
141
141
|
Text: any;
|
|
142
142
|
}): {
|
|
143
143
|
spaceSize: number;
|
|
@@ -180,6 +180,18 @@ export declare function useButton(props: ButtonProps, { Text }?: {
|
|
|
180
180
|
onTouchEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
181
181
|
onTouchCancel?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
182
182
|
onTouchEndCapture?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
183
|
+
onPointerEnter?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
184
|
+
onPointerEnterCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
185
|
+
onPointerLeave?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
186
|
+
onPointerLeaveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
187
|
+
onPointerMove?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
188
|
+
onPointerMoveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
189
|
+
onPointerCancel?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
190
|
+
onPointerCancelCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
191
|
+
onPointerDown?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
192
|
+
onPointerDownCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
193
|
+
onPointerUp?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
194
|
+
onPointerUpCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
183
195
|
accessible?: boolean | undefined;
|
|
184
196
|
accessibilityActions?: readonly Readonly<{
|
|
185
197
|
name: string;
|
|
@@ -193,9 +205,11 @@ export declare function useButton(props: ButtonProps, { Text }?: {
|
|
|
193
205
|
accessibilityHint?: string | undefined;
|
|
194
206
|
accessibilityValue?: import("react-native").AccessibilityValue | undefined;
|
|
195
207
|
onAccessibilityAction?: ((event: import("react-native").AccessibilityActionEvent) => void) | undefined;
|
|
208
|
+
accessibilityLabelledBy?: string | string[] | undefined;
|
|
196
209
|
accessibilityLiveRegion?: "none" | "polite" | "assertive" | undefined;
|
|
197
210
|
importantForAccessibility?: "auto" | "yes" | "no" | "no-hide-descendants" | undefined;
|
|
198
211
|
accessibilityElementsHidden?: boolean | undefined;
|
|
212
|
+
accessibilityLanguage?: string | undefined;
|
|
199
213
|
accessibilityViewIsModal?: boolean | undefined;
|
|
200
214
|
onAccessibilityEscape?: (() => void) | undefined;
|
|
201
215
|
onAccessibilityTap?: (() => void) | undefined;
|
|
@@ -238,9 +252,9 @@ export declare function useButton(props: ButtonProps, { Text }?: {
|
|
|
238
252
|
className?: string | undefined;
|
|
239
253
|
themeShallow?: boolean | undefined;
|
|
240
254
|
id?: string | undefined;
|
|
241
|
-
tag
|
|
255
|
+
tag: string | undefined;
|
|
242
256
|
componentName?: string | undefined;
|
|
243
|
-
forceStyle?: "
|
|
257
|
+
forceStyle?: "focus" | "hover" | "press" | undefined;
|
|
244
258
|
onHoverIn?: import("react").MouseEventHandler<HTMLDivElement> | undefined;
|
|
245
259
|
onHoverOut?: import("react").MouseEventHandler<HTMLDivElement> | undefined;
|
|
246
260
|
onPress?: ((event: import("react-native").GestureResponderEvent) => void) | null | undefined;
|