-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathButton.tsx
81 lines (67 loc) · 2.94 KB
/
Button.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import styled from 'styled-components';
import { ButtonStyleProps, ResponsiveValue, variant } from 'styled-system';
import { theme } from '../../essentials/theme';
import { getSemanticValue } from '../../utils/cssVariables';
import { BaseButton, BaseButtonProps } from './BaseButton';
import { ComponentSemanticTokens } from '../../essentials/Colors/types';
type Variant = 'primary' | 'secondary' | 'danger';
interface ButtonProps extends BaseButtonProps, ButtonStyleProps {
/**
* Define style of the button component, defaults to primary
*/
variant?: ResponsiveValue<Variant>;
}
const variantStyles = variant<ComponentSemanticTokens, Variant>({
variants: {
primary: {
color: getSemanticValue('foreground-on-background-primary'),
fill: getSemanticValue('foreground-on-background-primary'),
background: getSemanticValue('background-element-primary-default'),
'&:hover': {
color: getSemanticValue('foreground-on-background-accent'),
background: getSemanticValue('background-element-primary-emphasized')
},
'&:disabled': {
color: getSemanticValue('foreground-on-background-disabled'),
background: getSemanticValue('background-element-disabled-default')
}
},
secondary: {
color: getSemanticValue('foreground-primary'),
fill: getSemanticValue('foreground-primary'),
background: getSemanticValue('background-page-default'),
borderColor: getSemanticValue('border-neutral-default'),
'&:hover': {
color: getSemanticValue('foreground-on-background-neutral'),
background: getSemanticValue('background-element-neutral-emphasized')
},
'&:disabled': {
color: getSemanticValue('foreground-disabled'),
fill: getSemanticValue('foreground-disabled'),
background: getSemanticValue('transparent'),
borderColor: getSemanticValue('border-disabled')
}
},
danger: {
color: getSemanticValue('foreground-on-background-danger'),
fill: getSemanticValue('foreground-on-background-danger'),
background: getSemanticValue('background-element-danger-default'),
'&:hover': {
background: getSemanticValue('background-element-danger-emphasized')
},
'&:disabled': {
background: getSemanticValue('background-element-disabled-default'),
borderColor: getSemanticValue('border-disabled')
}
}
}
});
const Button = styled(BaseButton).attrs({ theme })<ButtonProps>`
transition: background ease 200ms, border-color ease 200ms, color ease 200ms, fill ease 200ms;
${variantStyles};
`;
Button.defaultProps = {
size: 'medium',
variant: 'primary'
};
export { Button, ButtonProps };