Skip to content

Commit

Permalink
fix(button): adding some polish (#67)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TheSisb committed Aug 26, 2019
1 parent 05f38ae commit 2644657
Show file tree
Hide file tree
Showing 118 changed files with 358 additions and 114 deletions.
31 changes: 27 additions & 4 deletions packages/paste-core/components/button/src/index.tsx
Expand Up @@ -18,7 +18,7 @@ const handlePropValidation = (props: ButtonProps): void => {
throw new Error(`[Paste: Button] This should be a link. Use the [Paste: Anchor] component.`); throw new Error(`[Paste: Button] This should be a link. Use the [Paste: Anchor] component.`);
} }
if (variant === 'reset' && size !== 'reset') { if (variant === 'reset' && size !== 'reset') {
throw new Error('[Paste: Button] The "RESET" variant can only be used with the "NONE" size.'); throw new Error('[Paste: Button] The "RESET" variant can only be used with the "RESET" size.');
} }
if (size === 'icon' && fullWidth) { if (size === 'icon' && fullWidth) {
throw new Error('[Paste: Button] Icon buttons should not be fullWidth.'); throw new Error('[Paste: Button] Icon buttons should not be fullWidth.');
Expand Down Expand Up @@ -46,6 +46,28 @@ const Button: React.FC<ButtonProps> = props => {
const showLoading = buttonState === 'loading'; const showLoading = buttonState === 'loading';
const disabled = buttonState !== 'default'; const disabled = buttonState !== 'default';


// If size isn't passed, come up with a smart default:
// - 'reset' for variant 'link'
// - 'icon' if there's 1 child that's an icon
// - 'default' otherwise
let defaultSize = props.size;
if (defaultSize == null) {
defaultSize = 'default';

if (props.variant === 'link' || props.variant === 'destructive_link') {
defaultSize = 'reset';
} else if (React.Children.count(props.children) === 1) {
React.Children.forEach(props.children, child => {
if (React.isValidElement(child)) {
// @ts-ignore
if (typeof child.type.displayName === 'string' && child.type.displayName.includes('Icon')) {
defaultSize = 'icon';
}
}
});
}
}

handlePropValidation(props); handlePropValidation(props);


return ( return (
Expand All @@ -59,10 +81,10 @@ const Button: React.FC<ButtonProps> = props => {
onBlur={props.onBlur} onBlur={props.onBlur}
onClick={props.onClick} onClick={props.onClick}
onFocus={props.onFocus} onFocus={props.onFocus}
size={props.size} variant={props.variant}
size={defaultSize}
tabIndex={props.tabIndex} tabIndex={props.tabIndex}
type={props.type} type={props.type}
variant={props.variant}
> >
<ButtonChildren buttonState={buttonState}>{props.children}</ButtonChildren> <ButtonChildren buttonState={buttonState}>{props.children}</ButtonChildren>
{showLoading ? ( {showLoading ? (
Expand All @@ -78,10 +100,11 @@ Button.defaultProps = {
as: 'button', as: 'button',
type: 'button', type: 'button',
variant: 'primary', variant: 'primary',
size: 'default',
disabled: false, disabled: false,
loading: false, loading: false,
fullWidth: false, fullWidth: false,
}; };


Button.displayName = 'Button';

export {Button}; export {Button};
2 changes: 2 additions & 0 deletions packages/paste-core/components/button/src/styles.ts
Expand Up @@ -41,6 +41,8 @@ const baseButtonWrapper = css`
display: inline-block; display: inline-block;
outline: none; outline: none;
background: none; background: none;
font-size: 100%;
transition: background-color 100ms ease-in;
/* Remove extra black dotted border FF adds */ /* Remove extra black dotted border FF adds */
&::-moz-focus-inner { &::-moz-focus-inner {
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/button/src/types.ts
Expand Up @@ -14,7 +14,7 @@ export interface ButtonProps {
tabIndex?: ButtonTabIndexes; tabIndex?: ButtonTabIndexes;


variant: ButtonVariants; variant: ButtonVariants;
size: ButtonSizes; size?: ButtonSizes;
fullWidth?: boolean; fullWidth?: boolean;


children: React.ReactNode; children: React.ReactNode;
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AccountProfileIcon.tsx
Expand Up @@ -38,4 +38,6 @@ AccountProfileIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AccountProfileIcon.displayName = 'AccountProfileIcon';

export {AccountProfileIcon}; export {AccountProfileIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AddOnsIcon.tsx
Expand Up @@ -38,4 +38,6 @@ AddOnsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AddOnsIcon.displayName = 'AddOnsIcon';

export {AddOnsIcon}; export {AddOnsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AlertTriggersIcon.tsx
Expand Up @@ -38,4 +38,6 @@ AlertTriggersIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AlertTriggersIcon.displayName = 'AlertTriggersIcon';

export {AlertTriggersIcon}; export {AlertTriggersIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ApiExplorerIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ApiExplorerIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ApiExplorerIcon.displayName = 'ApiExplorerIcon';

export {ApiExplorerIcon}; export {ApiExplorerIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ApiKeysIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ApiKeysIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ApiKeysIcon.displayName = 'ApiKeysIcon';

export {ApiKeysIcon}; export {ApiKeysIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ArrowRightIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ArrowRightIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ArrowRightIcon.displayName = 'ArrowRightIcon';

export {ArrowRightIcon}; export {ArrowRightIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ArrowShaftDownIcon.tsx
Expand Up @@ -32,4 +32,6 @@ ArrowShaftDownIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ArrowShaftDownIcon.displayName = 'ArrowShaftDownIcon';

export {ArrowShaftDownIcon}; export {ArrowShaftDownIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ArrowShaftLeftIcon.tsx
Expand Up @@ -32,4 +32,6 @@ ArrowShaftLeftIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ArrowShaftLeftIcon.displayName = 'ArrowShaftLeftIcon';

export {ArrowShaftLeftIcon}; export {ArrowShaftLeftIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ArrowShaftRightIcon.tsx
Expand Up @@ -32,4 +32,6 @@ ArrowShaftRightIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ArrowShaftRightIcon.displayName = 'ArrowShaftRightIcon';

export {ArrowShaftRightIcon}; export {ArrowShaftRightIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ArrowShaftUpIcon.tsx
Expand Up @@ -32,4 +32,6 @@ ArrowShaftUpIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ArrowShaftUpIcon.displayName = 'ArrowShaftUpIcon';

export {ArrowShaftUpIcon}; export {ArrowShaftUpIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AssetsIcon.tsx
Expand Up @@ -35,4 +35,6 @@ AssetsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AssetsIcon.displayName = 'AssetsIcon';

export {AssetsIcon}; export {AssetsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AuditEventsIcon.tsx
Expand Up @@ -38,4 +38,6 @@ AuditEventsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AuditEventsIcon.displayName = 'AuditEventsIcon';

export {AuditEventsIcon}; export {AuditEventsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AuthyIcon.tsx
Expand Up @@ -38,4 +38,6 @@ AuthyIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AuthyIcon.displayName = 'AuthyIcon';

export {AuthyIcon}; export {AuthyIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/AutopilotIcon.tsx
Expand Up @@ -38,4 +38,6 @@ AutopilotIcon.defaultProps = {
decorative: true, decorative: true,
}; };


AutopilotIcon.displayName = 'AutopilotIcon';

export {AutopilotIcon}; export {AutopilotIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/BackIcon.tsx
Expand Up @@ -38,4 +38,6 @@ BackIcon.defaultProps = {
decorative: true, decorative: true,
}; };


BackIcon.displayName = 'BackIcon';

export {BackIcon}; export {BackIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/BarChartIcon.tsx
Expand Up @@ -32,4 +32,6 @@ BarChartIcon.defaultProps = {
decorative: true, decorative: true,
}; };


BarChartIcon.displayName = 'BarChartIcon';

export {BarChartIcon}; export {BarChartIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/BillingIcon.tsx
Expand Up @@ -38,4 +38,6 @@ BillingIcon.defaultProps = {
decorative: true, decorative: true,
}; };


BillingIcon.displayName = 'BillingIcon';

export {BillingIcon}; export {BillingIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/BuildIcon.tsx
Expand Up @@ -32,4 +32,6 @@ BuildIcon.defaultProps = {
decorative: true, decorative: true,
}; };


BuildIcon.displayName = 'BuildIcon';

export {BuildIcon}; export {BuildIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ChannelsIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ChannelsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ChannelsIcon.displayName = 'ChannelsIcon';

export {ChannelsIcon}; export {ChannelsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CheckboxCheckedIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CheckboxCheckedIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CheckboxCheckedIcon.displayName = 'CheckboxCheckedIcon';

export {CheckboxCheckedIcon}; export {CheckboxCheckedIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CheckboxMultiIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CheckboxMultiIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CheckboxMultiIcon.displayName = 'CheckboxMultiIcon';

export {CheckboxMultiIcon}; export {CheckboxMultiIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CheckboxUncheckedIcon.tsx
Expand Up @@ -35,4 +35,6 @@ CheckboxUncheckedIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CheckboxUncheckedIcon.displayName = 'CheckboxUncheckedIcon';

export {CheckboxUncheckedIcon}; export {CheckboxUncheckedIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ClockRegularIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ClockRegularIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ClockRegularIcon.displayName = 'ClockRegularIcon';

export {ClockRegularIcon}; export {ClockRegularIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CloseIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CloseIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CloseIcon.displayName = 'CloseIcon';

export {CloseIcon}; export {CloseIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CollapseIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CollapseIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CollapseIcon.displayName = 'CollapseIcon';

export {CollapseIcon}; export {CollapseIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CollapseMenuIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CollapseMenuIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CollapseMenuIcon.displayName = 'CollapseMenuIcon';

export {CollapseMenuIcon}; export {CollapseMenuIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CollapsedIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CollapsedIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CollapsedIcon.displayName = 'CollapsedIcon';

export {CollapsedIcon}; export {CollapsedIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CommunityIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CommunityIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CommunityIcon.displayName = 'CommunityIcon';

export {CommunityIcon}; export {CommunityIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ConnectAppsIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ConnectAppsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ConnectAppsIcon.displayName = 'ConnectAppsIcon';

export {ConnectAppsIcon}; export {ConnectAppsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ConnectedDevicesIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ConnectedDevicesIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ConnectedDevicesIcon.displayName = 'ConnectedDevicesIcon';

export {ConnectedDevicesIcon}; export {ConnectedDevicesIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ConsoleDashIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ConsoleDashIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ConsoleDashIcon.displayName = 'ConsoleDashIcon';

export {ConsoleDashIcon}; export {ConsoleDashIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/CopyIcon.tsx
Expand Up @@ -38,4 +38,6 @@ CopyIcon.defaultProps = {
decorative: true, decorative: true,
}; };


CopyIcon.displayName = 'CopyIcon';

export {CopyIcon}; export {CopyIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DebuggerIcon.tsx
Expand Up @@ -38,4 +38,6 @@ DebuggerIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DebuggerIcon.displayName = 'DebuggerIcon';

export {DebuggerIcon}; export {DebuggerIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DebuggerOldIcon.tsx
Expand Up @@ -38,4 +38,6 @@ DebuggerOldIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DebuggerOldIcon.displayName = 'DebuggerOldIcon';

export {DebuggerOldIcon}; export {DebuggerOldIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DevToolsIcon.tsx
Expand Up @@ -38,4 +38,6 @@ DevToolsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DevToolsIcon.displayName = 'DevToolsIcon';

export {DevToolsIcon}; export {DevToolsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DoNotIcon.tsx
Expand Up @@ -32,4 +32,6 @@ DoNotIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DoNotIcon.displayName = 'DoNotIcon';

export {DoNotIcon}; export {DoNotIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DocsIcon.tsx
Expand Up @@ -38,4 +38,6 @@ DocsIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DocsIcon.displayName = 'DocsIcon';

export {DocsIcon}; export {DocsIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DownloadIcon.tsx
Expand Up @@ -38,4 +38,6 @@ DownloadIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DownloadIcon.displayName = 'DownloadIcon';

export {DownloadIcon}; export {DownloadIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/DropdownIcon.tsx
Expand Up @@ -38,4 +38,6 @@ DropdownIcon.defaultProps = {
decorative: true, decorative: true,
}; };


DropdownIcon.displayName = 'DropdownIcon';

export {DropdownIcon}; export {DropdownIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/EmailIcon.tsx
Expand Up @@ -38,4 +38,6 @@ EmailIcon.defaultProps = {
decorative: true, decorative: true,
}; };


EmailIcon.displayName = 'EmailIcon';

export {EmailIcon}; export {EmailIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ExclamationCircleIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ExclamationCircleIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ExclamationCircleIcon.displayName = 'ExclamationCircleIcon';

export {ExclamationCircleIcon}; export {ExclamationCircleIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ExpandIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ExpandIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ExpandIcon.displayName = 'ExpandIcon';

export {ExpandIcon}; export {ExpandIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ExpandMenuIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ExpandMenuIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ExpandMenuIcon.displayName = 'ExpandMenuIcon';

export {ExpandMenuIcon}; export {ExpandMenuIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/ExternalLinkIcon.tsx
Expand Up @@ -38,4 +38,6 @@ ExternalLinkIcon.defaultProps = {
decorative: true, decorative: true,
}; };


ExternalLinkIcon.displayName = 'ExternalLinkIcon';

export {ExternalLinkIcon}; export {ExternalLinkIcon};
2 changes: 2 additions & 0 deletions packages/paste-icons/src/react/FaxEnabledIcon.tsx
Expand Up @@ -38,4 +38,6 @@ FaxEnabledIcon.defaultProps = {
decorative: true, decorative: true,
}; };


FaxEnabledIcon.displayName = 'FaxEnabledIcon';

export {FaxEnabledIcon}; export {FaxEnabledIcon};

1 comment on commit 2644657

@vercel
Copy link

@vercel vercel bot commented on 2644657 Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.