/
PrimaryButton-box.tsx
79 lines (73 loc) · 2.08 KB
/
PrimaryButton-box.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
import React from 'react';
import merge from 'deepmerge';
import { Box } from '../../../primitives/Box/src/index';
import type { StyleProps } from '../../../styles/style-props.css';
import {
baseStyles,
defaultStyles,
disabledStyles,
loadingStyles,
resetStyles,
} from './styles-box';
import type { DirectButtonPropsWithBox } from './types';
const disabledPrimaryStyles = merge(disabledStyles, {
backgroundColor: {
base: '$colorBackgroundWeak',
hover: '$colorBackgroundWeak',
active: '$colorBackgroundWeak',
},
boxShadow: {
base: '$shadowBorderWeak',
hover: '$shadowBorderWeak',
active: '$shadowBorderWeak',
},
} satisfies StyleProps);
const loadingPrimaryStyles = merge(loadingStyles, {
backgroundColor: {
// eslint-disable-next-line sonarjs/no-duplicate-string
base: '$colorBackgroundPrimaryStrong',
hover: '$colorBackgroundPrimaryStrong',
active: '$colorBackgroundPrimaryStrong',
},
boxShadow: {
// eslint-disable-next-line sonarjs/no-duplicate-string
base: '$shadowBorderPrimaryStrong',
hover: '$shadowBorderPrimaryStrong',
active: '$shadowBorderPrimaryStrong',
},
} satisfies StyleProps);
const ButtonStyleMapping = {
default: defaultStyles,
loading: loadingPrimaryStyles,
disabled: disabledPrimaryStyles,
};
const PrimaryButton = React.forwardRef<
HTMLButtonElement,
DirectButtonPropsWithBox
>(({ buttonState, children, fullWidth, ...props }, ref): JSX.Element => {
return (
<Box
{...props}
{...resetStyles}
{...baseStyles}
backgroundColor={{
base: '$colorBackgroundPrimary',
hover: '$colorBackgroundPrimaryStrong',
active: '$colorBackgroundPrimaryStrong',
}}
boxShadow={{
base: '$shadowBorderPrimary',
hover: '$shadowBorderPrimaryStrong',
active: '$shadowBorderPrimaryStrong',
}}
color="$colorTextInverse"
width={fullWidth ? '100%' : 'auto'}
ref={ref}
{...ButtonStyleMapping[buttonState]}
>
{children}
</Box>
);
});
PrimaryButton.displayName = 'PrimaryButton';
export { PrimaryButton };