Skip to content

Commit ed97058

Browse files
author
Jon Bellah
committed
Update Button API to make more sense
1 parent 5863d19 commit ed97058

3 files changed

Lines changed: 194 additions & 105 deletions

File tree

src/Button/index.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import React from 'react';
55
interface Props {
66
/** text to display in the button */
77
children: React.ReactChild;
8-
/** button type */
9-
type?:
8+
/** button variant */
9+
variant?:
1010
| 'primary'
1111
| 'primaryOutline'
1212
| 'warning'
1313
| 'success'
1414
| 'info'
1515
| 'danger'
1616
| 'black';
17+
/** button type */
18+
type?: 'button' | 'submit' | 'reset';
1719
/** onChange handler */
1820
onClick?: () => void;
1921
/** onFocus handler */
@@ -60,41 +62,41 @@ const styledButton = css`
6062
outline: 0;
6163
}
6264
63-
&[data-type='primary'] {
65+
&[data-variant='primary'] {
6466
background-color: #4e4e4e;
6567
}
6668
67-
&[data-type='primaryOutline'] {
69+
&[data-variant='primaryOutline'] {
6870
background-color: #fff;
6971
background-image: none;
7072
border-color: #111;
7173
color: #111;
7274
}
7375
74-
&[data-type='success'] {
76+
&[data-variant='success'] {
7577
background-color: #61b563;
7678
}
7779
78-
&[data-type='info'] {
80+
&[data-variant='info'] {
7981
background-color: #71c1d9;
8082
}
8183
82-
&[data-type='warning'] {
84+
&[data-variant='warning'] {
8385
background-color: #eaa04a;
8486
}
8587
86-
&[data-type='danger'] {
88+
&[data-variant='danger'] {
8789
background-color: #e12e28;
8890
}
8991
90-
&[data-type='black'] {
92+
&[data-variant='black'] {
9193
background-image: none;
9294
background-color: #111;
9395
color: #fff;
9496
text-shadow: none;
9597
}
9698
97-
&[data-type='default'] {
99+
&[data-variant='default'] {
98100
border-color: #d7d7d7;
99101
color: #444;
100102
font-weight: 700;
@@ -103,6 +105,7 @@ const styledButton = css`
103105
`;
104106

105107
const Button = ({
108+
variant,
106109
type,
107110
onClick,
108111
onFocus,
@@ -112,13 +115,13 @@ const Button = ({
112115
}: Props) => (
113116
<button
114117
css={styledButton}
115-
type="button"
116-
onClick={onClick}
118+
data-testid="button"
119+
data-variant={variant || 'default'}
120+
disabled={disabled}
117121
onBlur={onBlur}
122+
onClick={onClick}
118123
onFocus={onFocus}
119-
disabled={disabled}
120-
data-testid="button"
121-
data-type={type || 'default'}
124+
type={type || 'button'}
122125
>
123126
{children}
124127
</button>

src/Button/story.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,50 @@ storiesOf('Button', module)
2323
'Primary',
2424
withInfo(`
2525
Provides extra visual weight and identifies the primary action in a set of buttons.
26-
`)(() => <Button type="primary">Primary</Button>),
26+
`)(() => <Button variant="primary">Primary</Button>),
2727
)
2828
.add(
2929
'Primary (Outline)',
3030
withInfo(`
3131
Provides extra visual weight and identifies the primary action in a set of buttons.
32-
`)(() => <Button type="primaryOutline">Primary Outline</Button>),
32+
`)(() => <Button variant="primaryOutline">Primary Outline</Button>),
3333
)
3434
.add(
3535
'Success',
3636
withInfo(`
3737
Indicates a successful or positive action.
38-
`)(() => <Button type="success">Success</Button>),
38+
`)(() => <Button variant="success">Success</Button>),
3939
)
4040
.add(
4141
'Info',
4242
withInfo(`
4343
Contextual button for informational alert messages.
44-
`)(() => <Button type="info">Info</Button>),
44+
`)(() => <Button variant="info">Info</Button>),
4545
)
4646
.add(
4747
'Warning',
4848
withInfo(`
4949
Indicates caution should be taken with this action.
50-
`)(() => <Button type="warning">Warning</Button>),
50+
`)(() => <Button variant="warning">Warning</Button>),
5151
)
5252
.add(
5353
'Danger',
5454
withInfo(`
5555
Indicates a dangerous or potentially negative action.
56-
`)(() => <Button type="danger">Danger</Button>),
56+
`)(() => <Button variant="danger">Danger</Button>),
5757
)
5858
.add(
5959
'Black',
6060
withInfo(`
6161
Basic flat button.
62-
`)(() => <Button type="black">Danger</Button>),
62+
`)(() => <Button variant="black">Danger</Button>),
6363
)
6464
.add(
6565
'Disabled',
6666
withInfo(`
6767
Indicates a disabled button.
6868
`)(() => (
69-
<Button type="danger" disabled>
69+
<Button variant="danger" disabled>
7070
Danger
7171
</Button>
7272
)),

0 commit comments

Comments
 (0)