Skip to content

Commit dc7665d

Browse files
committed
Button: clean up type definition to interface and add basic html element attributes
1 parent 9515291 commit dc7665d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

client/common/Button.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import styled from 'styled-components';
3-
import { Link, LinkProps } from 'react-router-dom';
3+
import { Link } from 'react-router-dom';
44
import { remSize, prop } from '../theme';
55

66
enum Kinds {
@@ -18,13 +18,7 @@ enum ButtonTypes {
1818
submit = 'submit'
1919
}
2020

21-
type StyledButtonProps = {
22-
kind: ButtonTypes;
23-
display: Displays;
24-
type?: ButtonTypes;
25-
} & React.ButtonHTMLAttributes<HTMLButtonElement>;
26-
27-
interface SharedButtonProps {
21+
export interface ButtonProps extends React.HTMLAttributes<HTMLElement> {
2822
/**
2923
* The visible part of the button, telling the user what
3024
* the action is
@@ -66,6 +60,10 @@ interface SharedButtonProps {
6660
* Specifying a to URL will use a react-router Link
6761
*/
6862
to?: string;
63+
/**
64+
* If using a native button, specifies on an onClick action
65+
*/
66+
onClick?: () => void;
6967
/**
7068
* If using a button, then type is defines the type of button
7169
*/
@@ -77,10 +75,10 @@ interface SharedButtonProps {
7775
focusable?: boolean | 'true' | 'false';
7876
}
7977

80-
export type ButtonProps = SharedButtonProps &
81-
React.ButtonHTMLAttributes<HTMLButtonElement> &
82-
React.AnchorHTMLAttributes<HTMLAnchorElement> &
83-
Partial<LinkProps>;
78+
interface StyledButtonProps extends ButtonProps {
79+
kind: Kinds;
80+
display: Displays;
81+
}
8482

8583
// The '&&&' will increase the specificity of the
8684
// component's CSS so that it overrides the more
@@ -203,6 +201,7 @@ export const Button = ({
203201
? StyledInlineButton
204202
: StyledButton;
205203

204+
// Anchor Link
206205
if (href) {
207206
return (
208207
<StyledComponent
@@ -218,6 +217,7 @@ export const Button = ({
218217
);
219218
}
220219

220+
// Internal React Router Link
221221
if (to) {
222222
return (
223223
<StyledComponent
@@ -233,6 +233,7 @@ export const Button = ({
233233
);
234234
}
235235

236+
// Native Button
236237
return (
237238
<StyledComponent
238239
kind={kind}

client/common/IconButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const ButtonWrapper = styled(Button)`
1414
export interface IconButtonProps
1515
extends Omit<ButtonProps, 'iconBefore' | 'display' | 'focusable'> {
1616
icon?: ComponentType<{ 'aria-label'?: string }>;
17+
href?: string;
18+
to?: string;
19+
onClick?: () => void;
1720
}
1821

1922
export const IconButton = ({ icon: Icon, ...otherProps }: IconButtonProps) => (

0 commit comments

Comments
 (0)