Skip to content

Commit e532037

Browse files
authored
Icon button (codesandbox#3596)
* add 32x32 svgs * confused about icons * separate viewboxes * remove 32by32 icons * add comments, fix story * I AM A TYPESCRIPT GOD * remove unrelated change * simplify disabled state * add icon button * remove unrelated change
1 parent f5d8612 commit e532037

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

packages/components/src/components/Button/index.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const variantStyles = {
77
primary: {
88
backgroundColor: 'button.background',
99
color: 'button.foreground',
10-
':hover': {
10+
':hover:not(:disabled)': {
1111
// hoverBackground is polyfilled and uses a gradient
1212
// so we use background and not backgroundColor
1313

@@ -16,57 +16,44 @@ const variantStyles = {
1616
// TODO @sid: extend our system to make background work as well
1717
background: theme => theme.colors.button.hoverBackground,
1818
},
19-
':focus': {
19+
':focus:not(:disabled)': {
2020
// we use the same colors for hover and focus
2121
// but we add an active state to give
2222
background: theme => theme.colors.button.hoverBackground,
2323
},
24-
':disabled:hover': {
25-
background: 'transparent', // override hover
26-
backgroundColor: 'button.background',
27-
},
2824
},
2925
secondary: {
3026
backgroundColor: 'secondaryButton.background',
3127
color: 'secondaryButton.foreground',
3228
// same technique as primary
33-
':hover': {
29+
':hover:not(:disabled)': {
3430
background: theme => theme.colors.secondaryButton.hoverBackground,
3531
},
36-
':focus': {
32+
':focus:not(:disabled)': {
3733
background: theme => theme.colors.secondaryButton.hoverBackground,
3834
},
39-
':disabled:hover': {
40-
background: 'transparent', // override hover
41-
backgroundColor: 'secondaryButton.background',
42-
},
4335
},
4436
link: {
4537
backgroundColor: 'transparent',
4638
color: 'mutedForeground',
4739
// same technique as primary
48-
':hover': {
40+
':hover:not(:disabled)': {
4941
color: 'foreground',
5042
},
51-
':focus': {
43+
':focus:not(:disabled)': {
5244
color: 'foreground',
5345
},
5446
},
5547
danger: {
5648
backgroundColor: 'dangerButton.background',
5749
color: 'dangerButton.foreground',
5850
// same technique as primary
59-
':hover': {
51+
':hover:not(:disabled)': {
6052
background: theme => theme.colors.dangerButton.hoverBackground,
6153
},
62-
':focus': {
54+
':focus:not(:disabled)': {
6355
background: theme => theme.colors.dangerButton.hoverBackground,
6456
},
65-
66-
':disabled:hover': {
67-
background: 'transparent', // override hover
68-
backgroundColor: 'dangerButton.background',
69-
},
7057
},
7158
};
7259

@@ -107,7 +94,7 @@ export const Button = styled(Element).attrs({ as: 'button' })<IButtonProps>(
10794
':focus': {
10895
outline: 'none',
10996
},
110-
':active': {
97+
':active:not(:disabled)': {
11198
transform: 'scale(0.98)',
11299
},
113100
':disabled': {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { IconButton } from '.';
3+
4+
export default {
5+
title: 'components/IconButton',
6+
component: IconButton,
7+
};
8+
9+
export const Basic = () => <IconButton name="filter" />;
10+
11+
export const Disabled = () => <IconButton disabled name="filter" />;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { Button } from '../Button';
3+
import { Icon } from '../Icon';
4+
5+
export const IconButton = ({ name, ...props }) => (
6+
<Button
7+
variant="link"
8+
css={{
9+
width: '26px', // same width as (height of the button)
10+
padding: 0,
11+
borderRadius: '50%',
12+
':hover:not(:disabled)': {
13+
backgroundColor: 'secondaryButton.background',
14+
},
15+
':focus:not(:disabled)': {
16+
outline: 'none',
17+
backgroundColor: 'secondaryButton.background',
18+
},
19+
}}
20+
{...props}
21+
>
22+
<Icon name={name} />
23+
</Button>
24+
);

0 commit comments

Comments
 (0)