1
1
import React from 'react' ;
2
- import PropTypes from 'prop-types' ;
3
2
import styled from 'styled-components' ;
4
3
import { Link , LinkProps } from 'react-router-dom' ;
5
4
import { remSize , prop } from '../theme' ;
@@ -24,6 +23,71 @@ type StyledButtonProps = {
24
23
display : Display
25
24
}
26
25
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
+
27
91
// The '&&&' will increase the specificity of the
28
92
// component's CSS so that it overrides the more
29
93
// general global styles
@@ -117,73 +181,19 @@ const StyledInlineButton = styled.button`
117
181
}
118
182
` ;
119
183
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
-
174
184
/**
175
185
* A Button performs an primary action
176
186
*/
177
187
const Button = ( {
178
188
children = null ,
179
189
display = displays . block ,
180
- href = null ,
190
+ href,
181
191
kind = kinds . primary ,
182
192
iconBefore = null ,
183
193
iconAfter = null ,
184
194
iconOnly = false ,
185
- 'aria-label' : ariaLabel = null ,
186
- to = null ,
195
+ 'aria-label' : ariaLabel ,
196
+ to,
187
197
type = buttonTypes . button ,
188
198
...props
189
199
} : ButtonProps ) => {
0 commit comments