Skip to content

Commit 2644657

Browse files
authored
fix(button): adding some polish (#67)
* fix: add transitions test * chore(website): add space between buttons * fix(button): less transition time on focus * fix(button): link variant font-size should behave like anchro * fix(website): pass Box into scope * fix(button): remove outline transition * fix(button): many improvements - fix thrown error message typo - pick the correct default 'size=icon' prop if there's only 1 icon child - make size prop optionable - add a displayName * feat(icon): add displayName to all icons * fix(website): button preview spacing * fix(website): remove extra semicolon on button page * fix(button): also set size for destructive_link variant
1 parent 05f38ae commit 2644657

File tree

118 files changed

+358
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+358
-114
lines changed

packages/paste-core/components/button/src/index.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const handlePropValidation = (props: ButtonProps): void => {
1818
throw new Error(`[Paste: Button] This should be a link. Use the [Paste: Anchor] component.`);
1919
}
2020
if (variant === 'reset' && size !== 'reset') {
21-
throw new Error('[Paste: Button] The "RESET" variant can only be used with the "NONE" size.');
21+
throw new Error('[Paste: Button] The "RESET" variant can only be used with the "RESET" size.');
2222
}
2323
if (size === 'icon' && fullWidth) {
2424
throw new Error('[Paste: Button] Icon buttons should not be fullWidth.');
@@ -46,6 +46,28 @@ const Button: React.FC<ButtonProps> = props => {
4646
const showLoading = buttonState === 'loading';
4747
const disabled = buttonState !== 'default';
4848

49+
// If size isn't passed, come up with a smart default:
50+
// - 'reset' for variant 'link'
51+
// - 'icon' if there's 1 child that's an icon
52+
// - 'default' otherwise
53+
let defaultSize = props.size;
54+
if (defaultSize == null) {
55+
defaultSize = 'default';
56+
57+
if (props.variant === 'link' || props.variant === 'destructive_link') {
58+
defaultSize = 'reset';
59+
} else if (React.Children.count(props.children) === 1) {
60+
React.Children.forEach(props.children, child => {
61+
if (React.isValidElement(child)) {
62+
// @ts-ignore
63+
if (typeof child.type.displayName === 'string' && child.type.displayName.includes('Icon')) {
64+
defaultSize = 'icon';
65+
}
66+
}
67+
});
68+
}
69+
}
70+
4971
handlePropValidation(props);
5072

5173
return (
@@ -59,10 +81,10 @@ const Button: React.FC<ButtonProps> = props => {
5981
onBlur={props.onBlur}
6082
onClick={props.onClick}
6183
onFocus={props.onFocus}
62-
size={props.size}
84+
variant={props.variant}
85+
size={defaultSize}
6386
tabIndex={props.tabIndex}
6487
type={props.type}
65-
variant={props.variant}
6688
>
6789
<ButtonChildren buttonState={buttonState}>{props.children}</ButtonChildren>
6890
{showLoading ? (
@@ -78,10 +100,11 @@ Button.defaultProps = {
78100
as: 'button',
79101
type: 'button',
80102
variant: 'primary',
81-
size: 'default',
82103
disabled: false,
83104
loading: false,
84105
fullWidth: false,
85106
};
86107

108+
Button.displayName = 'Button';
109+
87110
export {Button};

packages/paste-core/components/button/src/styles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const baseButtonWrapper = css`
4141
display: inline-block;
4242
outline: none;
4343
background: none;
44+
font-size: 100%;
45+
transition: background-color 100ms ease-in;
4446
4547
/* Remove extra black dotted border FF adds */
4648
&::-moz-focus-inner {

packages/paste-core/components/button/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ButtonProps {
1414
tabIndex?: ButtonTabIndexes;
1515

1616
variant: ButtonVariants;
17-
size: ButtonSizes;
17+
size?: ButtonSizes;
1818
fullWidth?: boolean;
1919

2020
children: React.ReactNode;

packages/paste-icons/src/react/AccountProfileIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ AccountProfileIcon.defaultProps = {
3838
decorative: true,
3939
};
4040

41+
AccountProfileIcon.displayName = 'AccountProfileIcon';
42+
4143
export {AccountProfileIcon};

packages/paste-icons/src/react/AddOnsIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ AddOnsIcon.defaultProps = {
3838
decorative: true,
3939
};
4040

41+
AddOnsIcon.displayName = 'AddOnsIcon';
42+
4143
export {AddOnsIcon};

packages/paste-icons/src/react/AlertTriggersIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ AlertTriggersIcon.defaultProps = {
3838
decorative: true,
3939
};
4040

41+
AlertTriggersIcon.displayName = 'AlertTriggersIcon';
42+
4143
export {AlertTriggersIcon};

packages/paste-icons/src/react/ApiExplorerIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ ApiExplorerIcon.defaultProps = {
3838
decorative: true,
3939
};
4040

41+
ApiExplorerIcon.displayName = 'ApiExplorerIcon';
42+
4143
export {ApiExplorerIcon};

packages/paste-icons/src/react/ApiKeysIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ ApiKeysIcon.defaultProps = {
3838
decorative: true,
3939
};
4040

41+
ApiKeysIcon.displayName = 'ApiKeysIcon';
42+
4143
export {ApiKeysIcon};

packages/paste-icons/src/react/ArrowRightIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ ArrowRightIcon.defaultProps = {
3838
decorative: true,
3939
};
4040

41+
ArrowRightIcon.displayName = 'ArrowRightIcon';
42+
4143
export {ArrowRightIcon};

packages/paste-icons/src/react/ArrowShaftDownIcon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ ArrowShaftDownIcon.defaultProps = {
3232
decorative: true,
3333
};
3434

35+
ArrowShaftDownIcon.displayName = 'ArrowShaftDownIcon';
36+
3537
export {ArrowShaftDownIcon};

0 commit comments

Comments
 (0)