@liguelead/design-system 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,28 +1,40 @@
|
|
|
1
|
-
import { ButtonVariantTypes} from './Button.types'
|
|
1
|
+
import { ButtonVariantTypes } from './Button.types'
|
|
2
2
|
import { colorType } from '../../types'
|
|
3
3
|
import { useTheme } from 'styled-components'
|
|
4
|
-
import {darkenOrLighten, getTextColor, parseColor} from '../../utils'
|
|
4
|
+
import { darkenOrLighten, getTextColor, parseColor, getHoverColor } from '../../utils'
|
|
5
|
+
|
|
5
6
|
|
|
6
7
|
export const ButtonVariant = (
|
|
7
8
|
color: colorType,
|
|
8
9
|
variant: ButtonVariantTypes
|
|
9
10
|
) => {
|
|
10
|
-
const theme = useTheme()
|
|
11
|
-
|
|
11
|
+
const theme = useTheme();
|
|
12
|
+
|
|
13
|
+
const colorValue = theme.colors[color];
|
|
14
|
+
|
|
15
|
+
if (!colorValue) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
12
18
|
|
|
13
|
-
const
|
|
19
|
+
const parsedColor = parseColor(colorValue);
|
|
14
20
|
|
|
15
|
-
const
|
|
21
|
+
const hoverBackground = getHoverColor(color, parsedColor, theme);
|
|
16
22
|
|
|
17
|
-
const
|
|
23
|
+
const solidtextColor = parseColor(theme.colors[getTextColor(parsedColor)]);
|
|
24
|
+
|
|
25
|
+
const colorHover = darkenOrLighten(0.2, parsedColor);
|
|
26
|
+
|
|
27
|
+
const variants: Record<ButtonVariantTypes, string> = {
|
|
18
28
|
solid: `
|
|
19
29
|
background-color: ${parsedColor};
|
|
20
30
|
color: ${solidtextColor};
|
|
21
31
|
border: 1px solid ${parsedColor};
|
|
32
|
+
|
|
22
33
|
&:hover {
|
|
23
|
-
background-color: ${
|
|
34
|
+
background-color: ${hoverBackground};
|
|
24
35
|
border-color: ${colorHover};
|
|
25
36
|
}
|
|
37
|
+
|
|
26
38
|
&:disabled {
|
|
27
39
|
background-color: ${parsedColor}80;
|
|
28
40
|
color: ${solidtextColor}cc;
|
|
@@ -59,8 +71,44 @@ export const ButtonVariant = (
|
|
|
59
71
|
color: ${parseColor(theme.colors.neutral1100)}80;
|
|
60
72
|
cursor: not-allowed;
|
|
61
73
|
}
|
|
74
|
+
`,
|
|
75
|
+
neutralOutline: `
|
|
76
|
+
background-color: transparent;
|
|
77
|
+
color: ${parseColor(theme.colors.textDark)};
|
|
78
|
+
border: 1px solid ${parseColor(theme.colors.neutral900)};
|
|
79
|
+
|
|
80
|
+
&:hover {
|
|
81
|
+
background-color: ${parseColor(theme.colors.primaryDarker)};
|
|
82
|
+
color: ${parseColor(theme.colors.textLight)};
|
|
83
|
+
border-color: ${parseColor(theme.colors.neutral400)};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&:disabled {
|
|
87
|
+
background-color: transparent;
|
|
88
|
+
color: ${parseColor(theme.colors.textDark)}80;
|
|
89
|
+
border-color: ${parseColor(theme.colors.neutral400)}80;
|
|
90
|
+
cursor: not-allowed;
|
|
91
|
+
}
|
|
92
|
+
`,
|
|
93
|
+
neutralGhost: `
|
|
94
|
+
background-color: transparent;
|
|
95
|
+
color: ${parseColor(theme.colors.textDark)};
|
|
96
|
+
border: 1px solid transparent;
|
|
97
|
+
&:hover {
|
|
98
|
+
background-color: ${parseColor(theme.colors.neutral1000)};
|
|
99
|
+
color: ${parseColor(theme.colors.textLight)};
|
|
100
|
+
}
|
|
101
|
+
&:disabled {
|
|
102
|
+
background-color: transparent;
|
|
103
|
+
color: ${parseColor(theme.colors.textDark)}80;
|
|
104
|
+
cursor: not-allowed;
|
|
105
|
+
}
|
|
62
106
|
`
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (!variants[variant]) {
|
|
110
|
+
return '';
|
|
63
111
|
}
|
|
64
112
|
|
|
65
|
-
return variants[variant]
|
|
113
|
+
return variants[variant];
|
|
66
114
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { colorType } from '../../types'
|
|
2
2
|
|
|
3
3
|
export type ButtonSizeTypes = 'sm' | 'md' | 'lg'
|
|
4
|
-
export type ButtonVariantTypes = 'solid' | 'outline' | 'ghost'
|
|
4
|
+
export type ButtonVariantTypes = 'solid' | 'outline' | 'ghost' | 'neutralOutline' | 'neutralGhost'
|
|
5
5
|
|
|
6
6
|
export interface ButtonProps {
|
|
7
7
|
variant?: ButtonVariantTypes
|
|
@@ -3,6 +3,8 @@ import styled from 'styled-components';
|
|
|
3
3
|
import { spacing, shadow, fontSize } from '@liguelead/foundation';
|
|
4
4
|
import { parseColor } from '../../utils';
|
|
5
5
|
|
|
6
|
+
type variant = 'default' | 'danger'
|
|
7
|
+
|
|
6
8
|
export const Overlay = styled(DialogPrimitive.Overlay)`
|
|
7
9
|
background: rgba(0, 0, 0, 0.3);
|
|
8
10
|
position: fixed;
|
|
@@ -19,13 +21,22 @@ export const Content = styled(DialogPrimitive.Content)<{$centerContent?: boolean
|
|
|
19
21
|
flex-direction: column;
|
|
20
22
|
align-items: ${({ $centerContent }) => ($centerContent ? 'center' : 'flex-start')};
|
|
21
23
|
|
|
22
|
-
min-width:
|
|
23
|
-
max-width:
|
|
24
|
+
min-width: 448px;
|
|
25
|
+
max-width: 688px;
|
|
24
26
|
position: fixed;
|
|
25
27
|
top: 8vh;
|
|
26
28
|
left: 50%;
|
|
27
29
|
transform: translateX(-50%);
|
|
28
30
|
`
|
|
31
|
+
|
|
32
|
+
export const TitleDescriptionContainer = styled.div<{$centerContent?: boolean, $variant?: variant}>`
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
align-items: ${({ $centerContent }) => ($centerContent ? 'center' : 'flex-start')};
|
|
36
|
+
gap: ${({$variant}) => ($variant === 'danger' ? `${spacing.spacing8}px` : `${spacing.spacing4}px`)};
|
|
37
|
+
width: 100%;
|
|
38
|
+
`
|
|
39
|
+
|
|
29
40
|
export const CloseDialogIconButton = styled.button`
|
|
30
41
|
position: absolute;
|
|
31
42
|
top: 10px;
|
|
@@ -47,6 +58,7 @@ export const CloseDialogIconButton = styled.button`
|
|
|
47
58
|
box-shadow: ${shadow.focusShadow};
|
|
48
59
|
}
|
|
49
60
|
`
|
|
61
|
+
|
|
50
62
|
export const ChildrenContainer = styled.div`
|
|
51
63
|
margin-top: ${spacing.spacing24}px;
|
|
52
64
|
width: 100%;
|
|
@@ -57,12 +69,15 @@ export const ButtonContainer = styled.div<{$centerContent?: boolean}>`
|
|
|
57
69
|
display: flex;
|
|
58
70
|
justify-content: ${({ $centerContent }) => ($centerContent ? 'center' : 'flex-end')};
|
|
59
71
|
flex-direction: ${({ $centerContent }) => ($centerContent ? 'column-reverse' : 'row')};
|
|
60
|
-
gap: ${spacing.
|
|
72
|
+
gap: ${({ $centerContent }) => ($centerContent ? `${spacing.spacing8}px` : `${spacing.spacing16}px`)};
|
|
61
73
|
margin-top: ${spacing.spacing24}px;
|
|
62
74
|
`;
|
|
63
75
|
|
|
64
|
-
export const DialogDescription = styled(DialogPrimitive.Description)
|
|
65
|
-
color: ${({ theme }) =>
|
|
76
|
+
export const DialogDescription = styled(DialogPrimitive.Description)<{$variant?: variant}>`
|
|
77
|
+
color: ${({ theme, $variant }) => $variant === 'danger'
|
|
78
|
+
? parseColor(theme.colors.textDark)
|
|
79
|
+
: parseColor(theme.colors.textMedium)};
|
|
80
|
+
|
|
66
81
|
font-size: ${fontSize.fontSize14}px;
|
|
67
82
|
font-weight: 400;
|
|
68
83
|
white-space: pre-line;
|
|
@@ -8,8 +8,10 @@ import {
|
|
|
8
8
|
Content,
|
|
9
9
|
DialogDescription,
|
|
10
10
|
DialogTitle,
|
|
11
|
-
Overlay
|
|
11
|
+
Overlay,
|
|
12
|
+
TitleDescriptionContainer
|
|
12
13
|
} from "./Dialog.style"
|
|
14
|
+
|
|
13
15
|
import { TDialogProps } from "./Dialog.types"
|
|
14
16
|
|
|
15
17
|
import Button from "../Button"
|
|
@@ -49,6 +51,7 @@ export const Dialog: React.FC<TDialogProps> = ({
|
|
|
49
51
|
|
|
50
52
|
<Content
|
|
51
53
|
{...rest}
|
|
54
|
+
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
52
55
|
className={className}
|
|
53
56
|
$centerContent={centerContent}
|
|
54
57
|
onInteractOutside={(event) => {
|
|
@@ -58,27 +61,34 @@ export const Dialog: React.FC<TDialogProps> = ({
|
|
|
58
61
|
if (variant === 'danger') event.preventDefault()
|
|
59
62
|
}}
|
|
60
63
|
>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
<TitleDescriptionContainer
|
|
65
|
+
$centerContent={centerContent}
|
|
66
|
+
$variant={variant}
|
|
67
|
+
>
|
|
68
|
+
{title && (
|
|
69
|
+
<DialogTitle>
|
|
70
|
+
{title}
|
|
71
|
+
</DialogTitle>
|
|
72
|
+
)}
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
{description && (
|
|
75
|
+
<DialogDescription $variant={variant}>
|
|
76
|
+
{description}
|
|
77
|
+
</DialogDescription>
|
|
78
|
+
)}
|
|
79
|
+
</TitleDescriptionContainer>
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
{variant === 'danger' ? null : (
|
|
82
|
+
<ChildrenContainer>
|
|
74
83
|
{children}
|
|
75
|
-
|
|
84
|
+
</ChildrenContainer>
|
|
85
|
+
)}
|
|
76
86
|
|
|
77
87
|
<ButtonContainer $centerContent={centerContent}>
|
|
78
88
|
<DialogPrimitive.Close asChild>
|
|
79
89
|
{cancelButton && (
|
|
80
90
|
<Button
|
|
81
|
-
|
|
91
|
+
variant="neutralOutline"
|
|
82
92
|
>
|
|
83
93
|
{cancelLabel}
|
|
84
94
|
</Button>
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { colorType } from '../types'
|
|
2
|
+
import darkenOrLighten from './darkenOrLighen';
|
|
3
|
+
import parseColor from './parseColor';
|
|
4
|
+
import { DefaultTheme } from 'styled-components';
|
|
5
|
+
|
|
6
|
+
const getHoverColor = (color: colorType, parsedColor: string, theme: DefaultTheme) => {
|
|
7
|
+
|
|
8
|
+
switch (color) {
|
|
9
|
+
case 'primary':
|
|
10
|
+
return parseColor(theme.colors.primaryDarker);
|
|
11
|
+
|
|
12
|
+
case 'secondary':
|
|
13
|
+
return parseColor(theme.colors.secondaryDarker);
|
|
14
|
+
|
|
15
|
+
case 'danger200':
|
|
16
|
+
return parseColor(theme.colors.danger300);
|
|
17
|
+
|
|
18
|
+
default:
|
|
19
|
+
return darkenOrLighten(0.2, parsedColor);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default getHoverColor;
|
package/utils/index.ts
CHANGED
|
@@ -3,3 +3,4 @@ export {default as getTextColor} from './getTextColor'
|
|
|
3
3
|
export {default as darken} from './colorDarken'
|
|
4
4
|
export {default as lighten} from './colorLighten'
|
|
5
5
|
export {default as darkenOrLighten} from './darkenOrLighen'
|
|
6
|
+
export {default as getHoverColor} from './getHolverColor'
|