11import React from 'react' ;
2- import styled from 'styled-components' ;
2+ import styled , { css } from 'styled-components' ;
33import { Link } from 'gatsby' ;
4- import theme from '../styles/theme' ;
4+ import theme from '../../ styles/theme' ;
55import { ButtonProps } from './Button.types' ;
66
7- const ButtonBase : React . FC < ButtonProps > = ( {
7+ const { size, height, spacing, font, weight, color } = theme . typography . button ;
8+
9+ const buttonStyle = css < { disabled ?: boolean } > `
10+ display: inline-block;
11+ background: transparent;
12+ padding: 0.66em 2em;
13+ border-color: ${ theme . colors . tertiary } ;
14+ border-style: solid;
15+ border-width: 0.15rem;
16+ border-radius: 10rem;
17+ transition: all 0.2s ease;
18+ font-size: ${ size } ;
19+ line-height: ${ height } ;
20+ letter-spacing: ${ spacing } ;
21+ font-family: ${ font } ;
22+ font-weight: ${ weight } ;
23+ color: ${ color } ;
24+ text-decoration: none;
25+ &:hover {
26+ color: ${ ( props ) =>
27+ props . disabled ? theme . colors . tertiary : theme . colors . white } ;
28+ background: ${ ( props ) =>
29+ props . disabled ? 'transparant' : theme . colors . primary } ;
30+ border-color: ${ ( props ) =>
31+ props . disabled ? theme . colors . tertiary : theme . colors . primary } ;
32+ cursor: pointer;
33+ }
34+ ` ;
35+
36+ const StyledGatsbyButton = styled ( Link ) < { disabled ?: boolean } > `
37+ ${ buttonStyle }
38+ ` ;
39+ const StyledButton = styled . button < { disabled ?: boolean } > `
40+ ${ buttonStyle }
41+ ` ;
42+ const StyledAnchor = styled . a < { disabled ?: boolean } > `
43+ ${ buttonStyle }
44+ ` ;
45+
46+ const Button : React . FC < ButtonProps > = ( {
847 href,
948 useGatsbyLink = false ,
10- className = '' ,
1149 rel,
1250 submit,
1351 target,
@@ -18,63 +56,29 @@ const ButtonBase: React.FC<ButtonProps> = ({
1856 if ( useGatsbyLink ) {
1957 if ( href ) {
2058 return (
21- < Link
59+ < StyledGatsbyButton
2260 to = { href }
23- className = { `button ${ className } ` }
2461 rel = { rel }
2562 target = { target }
2663 onClick = { onClick }
2764 >
2865 { children }
29- </ Link >
66+ </ StyledGatsbyButton >
3067 ) ;
3168 }
3269 }
3370 if ( submit ) {
3471 return (
35- < button
36- type = "button"
37- className = { `button ${ className } ` }
38- onClick = { onClick }
39- disabled = { disabled }
40- >
72+ < StyledButton type = "button" onClick = { onClick } disabled = { disabled } >
4173 { children }
42- </ button >
74+ </ StyledButton >
4375 ) ;
4476 }
4577 return (
46- < a
47- href = { href }
48- className = { `button ${ className } ` }
49- rel = { rel }
50- target = { target }
51- onClick = { onClick }
52- >
78+ < StyledAnchor href = { href } rel = { rel } target = { target } onClick = { onClick } >
5379 { children }
54- </ a >
80+ </ StyledAnchor >
5581 ) ;
5682} ;
57- const Button =
58- styled ( ButtonBase ) <
59- ButtonProps >
60- `
61- display: inline-block;
62- background: transparent;
63- padding: 0.66em 2em;
64- border-color: ${ theme . colors . tertiary } ;
65- border-style: solid;
66- border-width: 0.15rem;
67- border-radius: 10rem;
68- transition: all 0.2s ease;
69- &:hover {
70- color: ${ ( props ) =>
71- props . disabled ? theme . colors . tertiary : theme . colors . white } ;
72- background: ${ ( props ) =>
73- props . disabled ? 'transparant' : theme . colors . primary } ;
74- border-color: ${ ( props ) =>
75- props . disabled ? theme . colors . tertiary : theme . colors . primary } ;
76- cursor: pointer;
77- }
78- ` ;
7983
8084export default Button ;
0 commit comments