Skip to content

Commit b1c90a6

Browse files
committed
Button.tsx: clean up integration with IconButton
1 parent 07eb2b1 commit b1c90a6

File tree

1 file changed

+68
-58
lines changed

1 file changed

+68
-58
lines changed

client/common/Button.tsx

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import styled from 'styled-components';
43
import { Link, LinkProps } from 'react-router-dom';
54
import { remSize, prop } from '../theme';
@@ -24,6 +23,71 @@ type StyledButtonProps = {
2423
display: Display
2524
}
2625

26+
const buttonTypes = {
27+
button: 'button',
28+
submit: 'submit'
29+
} as const;
30+
31+
type ButtonType = keyof typeof buttonTypes
32+
33+
type SharedButtonProps = {
34+
/**
35+
* The visible part of the button, telling the user what
36+
* the action is
37+
*/
38+
children?: React.ReactNode,
39+
/**
40+
If the button can be activated or not
41+
*/
42+
disabled?: boolean,
43+
/**
44+
* The display type of the button—inline or block
45+
*/
46+
display?: Display,
47+
/**
48+
* SVG icon to place after child content
49+
*/
50+
iconAfter?: React.ReactNode,
51+
/**
52+
* SVG icon to place before child content
53+
*/
54+
iconBefore?: React.ReactNode,
55+
/**
56+
* If the button content is only an SVG icon
57+
*/
58+
iconOnly?: boolean,
59+
/**
60+
* The kind of button - determines how it appears visually
61+
*/
62+
kind?: Kind,
63+
/**
64+
* Specifying an href will use an <a> to link to the URL
65+
*/
66+
href?: string | null,
67+
/**
68+
* An ARIA Label used for accessibility
69+
*/
70+
'aria-label'?: string | null,
71+
/**
72+
* Specifying a to URL will use a react-router Link
73+
*/
74+
to?: string | null,
75+
/**
76+
* If using a button, then type is defines the type of button
77+
*/
78+
type?: ButtonType,
79+
/**
80+
* Allows for IconButton to pass `focusable="false"` as a prop for SVGs.
81+
* See @types/react > interface SVGAttributes<T> extends AriaAttributes, DOMAttributes<T>
82+
*/
83+
focusable?: boolean | 'true' | 'false'
84+
}
85+
86+
export type ButtonProps = SharedButtonProps &
87+
React.ButtonHTMLAttributes<HTMLButtonElement> &
88+
React.AnchorHTMLAttributes<HTMLAnchorElement> &
89+
Partial<LinkProps>;
90+
2791
// The '&&&' will increase the specificity of the
2892
// component's CSS so that it overrides the more
2993
// general global styles
@@ -117,73 +181,19 @@ const StyledInlineButton = styled.button`
117181
}
118182
`;
119183

120-
const buttonTypes = {
121-
button: 'button',
122-
submit: 'submit'
123-
} as const;
124-
125-
type ButtonType = keyof typeof buttonTypes
126-
export type ButtonProps = {
127-
/**
128-
* The visible part of the button, telling the user what
129-
* the action is
130-
*/
131-
children?: React.ReactNode,
132-
/**
133-
If the button can be activated or not
134-
*/
135-
disabled?: boolean,
136-
/**
137-
* The display type of the button—inline or block
138-
*/
139-
display?: Display,
140-
/**
141-
* SVG icon to place after child content
142-
*/
143-
iconAfter?: React.ReactNode,
144-
/**
145-
* SVG icon to place before child content
146-
*/
147-
iconBefore?: React.ReactNode,
148-
/**
149-
* If the button content is only an SVG icon
150-
*/
151-
iconOnly?: boolean,
152-
/**
153-
* The kind of button - determines how it appears visually
154-
*/
155-
kind?: Kind,
156-
/**
157-
* Specifying an href will use an <a> to link to the URL
158-
*/
159-
href?: string | null,
160-
/**
161-
* An ARIA Label used for accessibility
162-
*/
163-
'aria-label'?: string | null,
164-
/**
165-
* Specifying a to URL will use a react-router Link
166-
*/
167-
to?: string | null,
168-
/**
169-
* If using a button, then type is defines the type of button
170-
*/
171-
type?: ButtonType,
172-
}
173-
174184
/**
175185
* A Button performs an primary action
176186
*/
177187
const Button = ({
178188
children = null,
179189
display = displays.block,
180-
href = null,
190+
href,
181191
kind = kinds.primary,
182192
iconBefore = null,
183193
iconAfter = null,
184194
iconOnly = false,
185-
'aria-label': ariaLabel = null,
186-
to = null,
195+
'aria-label': ariaLabel,
196+
to,
187197
type = buttonTypes.button,
188198
...props
189199
}: ButtonProps) => {

0 commit comments

Comments
 (0)