Skip to content

Commit a080593

Browse files
authored
Add disable button (#19)
1 parent e307046 commit a080593

6 files changed

Lines changed: 81 additions & 16 deletions

File tree

src/Button/__snapshots__/index.test.jsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Button renders with button style 1`] = `
44
<div>
55
<button
6-
class="button-0-2-1 button-d4-0-2-7"
6+
class="button-0-2-1 button-d6-0-2-10 common-0-2-2 common-d7-0-2-11"
77
type="button"
88
>
99
Press Me
@@ -14,7 +14,7 @@ exports[`Button renders with button style 1`] = `
1414
exports[`Button renders with link style 1`] = `
1515
<div>
1616
<button
17-
class="link-0-2-2 link-d3-0-2-6"
17+
class="button-0-2-1 button-d3-0-2-7 common-0-2-2 common-d4-0-2-8"
1818
type="button"
1919
>
2020
Click Me
@@ -25,7 +25,7 @@ exports[`Button renders with link style 1`] = `
2525
exports[`Button renders with no style 1`] = `
2626
<div>
2727
<button
28-
class="button-0-2-1 button-d0-0-2-3"
28+
class="button-0-2-1 button-d0-0-2-4 common-0-2-2 common-d1-0-2-5"
2929
type="button"
3030
>
3131
Press Me

src/Button/index.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,85 @@ import { createUseStyles, useTheme } from "react-jss";
55
type ButtonProps = {
66
onClick?: () => void,
77
name: string,
8-
style?: string,
8+
disabled?: boolean,
9+
type?: string,
910
};
1011

1112
export type ButtonStyleProps = {
1213
color?: string,
14+
margin?: string,
15+
marginRight?: string,
16+
marginLeft?: string,
17+
marginTop?: string,
18+
marginBottom?: string,
1319
};
1420
export function Button({
1521
onClick,
1622
name,
23+
disabled,
1724
color,
18-
style,
25+
margin,
26+
marginBottom,
27+
marginLeft,
28+
marginRight,
29+
marginTop,
30+
type,
1931
}: ButtonProps & ButtonStyleProps): React.Node {
2032
const theme = useTheme();
21-
const classes = useButtonStyles({ color });
33+
const classes = useButtonStyles({
34+
color,
35+
disabled,
36+
margin,
37+
marginTop,
38+
marginBottom,
39+
marginLeft,
40+
marginRight,
41+
});
2242

2343
return (
24-
<button type="button" onClick={onClick} className={style && classes[style]}>
44+
<button
45+
type="button"
46+
onClick={onClick}
47+
className={[type && classes[type], classes.common].join(" ")}
48+
disabled={disabled}
49+
>
2550
{name}
2651
</button>
2752
);
2853
}
2954

3055
Button.defaultProps = {
31-
style: "button",
56+
type: "button",
3257
};
3358

3459
export const useButtonStyles: (ButtonStyleProps) => {
3560
button: string,
61+
common: string,
3662
link: string,
3763
} = createUseStyles((theme) => {
3864
return {
3965
button: {
4066
background: theme.button.primary,
41-
borderRadius: "10px",
67+
borderRadius: "0.75rem",
4268
borderStyle: "none",
4369
color: ({ color }) => color || theme.button.color,
70+
opacity: ({ disabled }) => (disabled ? 0.5 : 1),
71+
},
72+
common: {
73+
fontSize: "1rem",
74+
margin: ({ margin }) => margin,
75+
marginLeft: ({ marginLeft }) => marginLeft,
76+
marginRight: ({ marginRight }) => marginRight,
77+
marginTop: ({ marginTop }) => marginTop,
78+
marginBottom: ({ marginBottom }) => marginBottom,
4479
},
4580
link: {
4681
border: 0,
4782
background: "inherit",
4883
textDecoration: "underline",
4984
color: ({ color }) => color || theme.button.primary,
85+
opacity: ({ disabled }) => (disabled ? 0.5 : 1),
86+
padding: 0,
5087
},
5188
};
5289
});

src/Form/index.jsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type InputLayoutProps = {
3939

4040
type SubmitProps = {
4141
name: string,
42+
disabled?: boolean,
4243
testID?: string,
4344
};
4445

@@ -191,17 +192,32 @@ export function SelectInput({
191192

192193
export function SubmitInput({
193194
name,
195+
disabled,
194196
color,
197+
margin,
198+
marginRight,
199+
marginLeft,
200+
marginTop,
201+
marginBottom,
195202
testID,
196203
}: SubmitProps & ButtonStyleProps): React.Node {
197-
const classes = useButtonStyles({ color });
204+
const classes = useButtonStyles({
205+
color,
206+
disabled,
207+
margin,
208+
marginRight,
209+
marginLeft,
210+
marginTop,
211+
marginBottom,
212+
});
198213

199214
return (
200215
<input
201216
type="submit"
202217
value={name}
203-
className={classes.button}
218+
className={[classes.button, classes.common].join(" ")}
204219
data-testid={testID}
220+
disabled={disabled}
205221
/>
206222
);
207223
}

src/Layout/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ export type LayoutProps = {
1111

1212
type RowType = {
1313
justifyContent: FlexAlignType,
14+
alignItems: FlexAlignType,
1415
backgroundColor?: string,
1516
children?: React.Node,
1617
className?: string,
1718
};
1819

1920
export function Row({
21+
alignItems,
2022
justifyContent,
2123
backgroundColor,
2224
children,
2325
className,
2426
height,
2527
width,
2628
}: RowType & LayoutProps): React.Node {
27-
const classes = useRowStyles({ backgroundColor, justifyContent });
29+
const classes = useRowStyles({ alignItems, backgroundColor, justifyContent });
2830
const layoutClasses = useLayoutStyles({ height, width });
2931

3032
return (
@@ -39,13 +41,15 @@ export function Row({
3941
}
4042

4143
Row.defaultProps = {
44+
alignItems: "start",
4245
justifyContent: "space-between",
4346
};
4447

4548
const useRowStyles = createUseStyles({
4649
row: {
4750
display: "flex",
48-
padding: "5px 0",
51+
padding: "0.375rem 0",
52+
alignItems: ({ alignItems }: { alignItems: FlexAlignType }) => alignItems,
4953
justifyContent: ({ justifyContent }: { justifyContent: FlexAlignType }) =>
5054
justifyContent,
5155
backgroundColor: ({ backgroundColor }: { backgroundColor: string }) =>

stories/Button/Button.stories.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ and more traditional web link.
2020

2121
export const Template = (args) => (
2222
<div>
23-
<Row justifyContent="start">
23+
<Row justifyContent="start" alignItems="center">
2424
This is a normal button <Button {...args} />
2525
</Row>
2626
<Row justifyContent="start">
27-
This a link button <Button {...args} style="link" />
27+
This a link button{" "}
28+
<Button
29+
{...args}
30+
type="link"
31+
marginLeft="0.5rem"
32+
marginRight="0"
33+
marginTop="0"
34+
marginBottom="0"
35+
/>
2836
</Row>
2937
</div>
3038
);

stories/Form/Form.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const Template = (args) => (
3838
/>
3939
</Row>
4040
<Row>
41-
<SubmitInput name="Submit" />
41+
<SubmitInput name="Submit" disabled={true} />
4242
</Row>
4343
</Form>
4444
);

0 commit comments

Comments
 (0)