@liguelead/design-system 0.0.1
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.
- package/components/Button/Button.appearance.ts +62 -0
- package/components/Button/Button.sizes.ts +41 -0
- package/components/Button/Button.styles.ts +50 -0
- package/components/Button/Button.tsx +70 -0
- package/components/Button/Button.types.ts +22 -0
- package/components/Button/index.ts +1 -0
- package/components/IconButton/IconButton.sizes.ts +41 -0
- package/components/IconButton/IconButton.tsx +67 -0
- package/components/IconButton/index.ts +1 -0
- package/components/PageWrapper/PageWrapper.tsx +31 -0
- package/components/PageWrapper/index.ts +1 -0
- package/components/Text/Text.styles.ts +43 -0
- package/components/Text/Text.tsx +65 -0
- package/components/Text/index.ts +1 -0
- package/components/TextField/TextField.sizes.ts +58 -0
- package/components/TextField/TextField.states.tsx +76 -0
- package/components/TextField/TextField.styles.ts +98 -0
- package/components/TextField/TextField.tsx +87 -0
- package/components/TextField/TextField.types.ts +21 -0
- package/components/TextField/index.ts +2 -0
- package/components/ThemeProvider/ThemeProvider.tsx +30 -0
- package/components/ThemeProvider/index.ts +1 -0
- package/components/ThemeProvider/style.ts +200 -0
- package/components/Wizard/StepContent.tsx +28 -0
- package/components/Wizard/StepMenuItem.tsx +33 -0
- package/components/Wizard/Wizard.context.tsx +76 -0
- package/components/Wizard/Wizard.styles.ts +126 -0
- package/components/Wizard/Wizard.tsx +55 -0
- package/components/Wizard/index.ts +1 -0
- package/components/index.ts +7 -0
- package/package.json +32 -0
- package/utils/colorDarken.ts +10 -0
- package/utils/colorLighten.ts +10 -0
- package/utils/darkenOrLighen.ts +19 -0
- package/utils/getTextColor.ts +12 -0
- package/utils/index.ts +5 -0
- package/utils/parseColor.ts +7 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import {TextFieldSizeType} from './TextField.sizes'
|
|
3
|
+
import {fontSize, fontWeight, lineHeight, spacing} from '@liguelead/foundation'
|
|
4
|
+
import {StateInterface} from './TextField.states'
|
|
5
|
+
import {parseColor} from '../../utils'
|
|
6
|
+
|
|
7
|
+
interface StyledInputProps {
|
|
8
|
+
size: TextFieldSizeType
|
|
9
|
+
$themefication: StateInterface
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const InputWrapper = styled.div`
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 100%;
|
|
15
|
+
`
|
|
16
|
+
|
|
17
|
+
export const FloatingLabel = styled.label`
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 50%;
|
|
20
|
+
left: 12px;
|
|
21
|
+
transform: translateY(-50%);
|
|
22
|
+
font-weight: ${fontWeight.fontWeight600};
|
|
23
|
+
transition: all 0.2s ease;
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
background-color: white;
|
|
26
|
+
padding: 0 4px;
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
export const HelperText = styled.span<{error?: boolean}>`
|
|
30
|
+
font-size: ${fontSize.fontSize12}px;
|
|
31
|
+
line-height: ${lineHeight.lineHeight12}px;
|
|
32
|
+
padding-left: ${spacing.spacing16}px;
|
|
33
|
+
`
|
|
34
|
+
|
|
35
|
+
export const IconWrapper = styled.div<{$right?: boolean}>`
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: space-between;
|
|
39
|
+
position: absolute;
|
|
40
|
+
top: 0px;
|
|
41
|
+
height: 100%;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
${({$right}) => ($right ? 'right: 0px;' : 'left: 0px;')}
|
|
44
|
+
padding: 0px ${spacing.spacing16}px;
|
|
45
|
+
|
|
46
|
+
& svg {
|
|
47
|
+
width: 20px;
|
|
48
|
+
height: 20px;
|
|
49
|
+
fill: ${({theme}) => parseColor(theme.colors.neutral700)};
|
|
50
|
+
transition: fill 0.2s ease;
|
|
51
|
+
}
|
|
52
|
+
`
|
|
53
|
+
|
|
54
|
+
export const StyledInput = styled.input.withConfig({
|
|
55
|
+
shouldForwardProp: prop => !['control', 'errors', 'rules'].includes(prop)
|
|
56
|
+
})`
|
|
57
|
+
width: 100%;
|
|
58
|
+
border-radius: 4px;
|
|
59
|
+
outline: none;
|
|
60
|
+
transition: border-color 0.2s ease;
|
|
61
|
+
background: transparent;
|
|
62
|
+
`
|
|
63
|
+
|
|
64
|
+
export const BorderWrapper = styled.div`
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: 0;
|
|
67
|
+
left: 0;
|
|
68
|
+
right: 0;
|
|
69
|
+
bottom: 0;
|
|
70
|
+
pointer-events: none;
|
|
71
|
+
border: 2px solid #ccc;
|
|
72
|
+
border-radius: 4px;
|
|
73
|
+
background-color: transparent;
|
|
74
|
+
z-index: -1;
|
|
75
|
+
|
|
76
|
+
${StyledInput}:focus ~ & {
|
|
77
|
+
border-color: ${({theme}) => theme.colors.primary};
|
|
78
|
+
}
|
|
79
|
+
`
|
|
80
|
+
|
|
81
|
+
export const Wrapper = styled.div<StyledInputProps>`
|
|
82
|
+
position: relative;
|
|
83
|
+
width: 100%;
|
|
84
|
+
${({$themefication, size}) => `
|
|
85
|
+
${StyledInput} {
|
|
86
|
+
${$themefication.animation}
|
|
87
|
+
${$themefication.input}
|
|
88
|
+
${size.input}
|
|
89
|
+
}
|
|
90
|
+
${FloatingLabel} {
|
|
91
|
+
${$themefication.label}
|
|
92
|
+
${size.label}
|
|
93
|
+
}
|
|
94
|
+
${HelperText} {
|
|
95
|
+
${$themefication.label}
|
|
96
|
+
}
|
|
97
|
+
`}
|
|
98
|
+
`
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React, { forwardRef, useState } from 'react'
|
|
2
|
+
import { TextFieldProps } from './TextField.types'
|
|
3
|
+
import { StateInterface, TextFieldStates } from './TextField.states'
|
|
4
|
+
import {
|
|
5
|
+
FloatingLabel,
|
|
6
|
+
HelperText,
|
|
7
|
+
IconWrapper,
|
|
8
|
+
InputWrapper,
|
|
9
|
+
StyledInput,
|
|
10
|
+
Wrapper
|
|
11
|
+
} from './TextField.styles'
|
|
12
|
+
import { textFieldSizes } from './TextField.sizes';
|
|
13
|
+
import { Eye, EyeClosed } from '@phosphor-icons/react'
|
|
14
|
+
|
|
15
|
+
const getState = (disabled: boolean, error: boolean) => {
|
|
16
|
+
if (disabled) return 'disabled';
|
|
17
|
+
if (error) return 'error';
|
|
18
|
+
return 'default';
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
|
22
|
+
(
|
|
23
|
+
{
|
|
24
|
+
className,
|
|
25
|
+
control,
|
|
26
|
+
disabled = false,
|
|
27
|
+
error,
|
|
28
|
+
handleLeftIcon,
|
|
29
|
+
handleRightIcon,
|
|
30
|
+
helperText,
|
|
31
|
+
label,
|
|
32
|
+
leftIcon,
|
|
33
|
+
onChange,
|
|
34
|
+
rightIcon,
|
|
35
|
+
size = 'md',
|
|
36
|
+
type = 'text',
|
|
37
|
+
value,
|
|
38
|
+
...props
|
|
39
|
+
},
|
|
40
|
+
ref // A ref passada pelo componente pai
|
|
41
|
+
) => {
|
|
42
|
+
const [passwordVisible, setPasswordVisible] = useState(type !== 'password');
|
|
43
|
+
const state = getState(disabled, !!error);
|
|
44
|
+
const textFieldState: StateInterface = TextFieldStates(state)
|
|
45
|
+
const textFieldSize = textFieldSizes(size, !!leftIcon, !!rightIcon)
|
|
46
|
+
|
|
47
|
+
const togglePasswordVisibility = () => {
|
|
48
|
+
setPasswordVisible(!passwordVisible);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const transformRightIcon = (type: string, rightIcon: React.ReactNode) => {
|
|
52
|
+
if (type === 'password') {
|
|
53
|
+
return (
|
|
54
|
+
<IconWrapper onClick={togglePasswordVisibility} $right>
|
|
55
|
+
{passwordVisible ? <Eye /> : <EyeClosed />}
|
|
56
|
+
</IconWrapper>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
return <IconWrapper onClick={handleRightIcon} $right>{rightIcon}</IconWrapper>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Wrapper className={className} size={textFieldSize} $themefication={textFieldState}>
|
|
64
|
+
|
|
65
|
+
<InputWrapper>
|
|
66
|
+
{leftIcon && <IconWrapper onClick={handleLeftIcon}>{leftIcon}</IconWrapper>}
|
|
67
|
+
{transformRightIcon(type, rightIcon)}
|
|
68
|
+
<StyledInput
|
|
69
|
+
ref={ref}
|
|
70
|
+
type={passwordVisible ? 'text' : 'password'}
|
|
71
|
+
value={value}
|
|
72
|
+
onChange={onChange}
|
|
73
|
+
placeholder=" "
|
|
74
|
+
disabled={disabled}
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
<FloatingLabel>{label}</FloatingLabel>
|
|
78
|
+
</InputWrapper>
|
|
79
|
+
{(helperText || error) && (<HelperText>{error?.message || helperText}</HelperText>)}
|
|
80
|
+
</Wrapper>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
TextField.displayName = 'TextField';
|
|
86
|
+
|
|
87
|
+
export default TextField
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Control, FieldValues } from 'react-hook-form'
|
|
2
|
+
import { TextFieldSize } from './TextField.sizes'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
export interface TextFieldProps<TFieldValues extends FieldValues = FieldValues>
|
|
6
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
|
|
7
|
+
label: string
|
|
8
|
+
value?: string
|
|
9
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
|
|
10
|
+
handleLeftIcon?: () => void
|
|
11
|
+
handleRightIcon?: () => void
|
|
12
|
+
helperText?: string
|
|
13
|
+
size?: TextFieldSize
|
|
14
|
+
className?: string
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
leftIcon?: React.ReactNode
|
|
17
|
+
rightIcon?: React.ReactNode
|
|
18
|
+
control?: Control<{ [key: string]: unknown }>
|
|
19
|
+
error?: TFieldValues
|
|
20
|
+
type?: 'text' | 'password' | 'email' | 'number'
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ThemeProvider as StyledTheme } from 'styled-components'
|
|
2
|
+
import { themes} from '@liguelead/foundation'
|
|
3
|
+
import { SpaThemeTypes } from '@liguelead/foundation/src/themes/spa'
|
|
4
|
+
import { globalStyle as Reset } from './style'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
interface ThemeProviderProps {
|
|
8
|
+
children: React.ReactNode
|
|
9
|
+
theme?: 'spa'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type SpaTheme = SpaThemeTypes
|
|
13
|
+
|
|
14
|
+
declare module 'styled-components' {
|
|
15
|
+
export interface DefaultTheme extends SpaTheme{}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const ThemeProvider = ({ children, theme }: ThemeProviderProps) => {
|
|
19
|
+
const appliedTheme = theme ? themes[theme] : themes['spa']
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<StyledTheme theme={appliedTheme}>
|
|
24
|
+
<Reset />
|
|
25
|
+
{children}
|
|
26
|
+
</StyledTheme>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default ThemeProvider
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ThemeProvider'
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { spacing, SpacingInterface } from '@liguelead/foundation'
|
|
2
|
+
import { createGlobalStyle } from 'styled-components'
|
|
3
|
+
|
|
4
|
+
// Função para gerar estilos de margem
|
|
5
|
+
export const marginStyles = (): string => {
|
|
6
|
+
let result = ''
|
|
7
|
+
|
|
8
|
+
Object.keys(spacing).forEach((item) => {
|
|
9
|
+
if (item !== 'none') {
|
|
10
|
+
const key = item as keyof SpacingInterface
|
|
11
|
+
const value = spacing[key] === 'auto' ? 'auto' : `${spacing[key]}px`
|
|
12
|
+
const name = item.replace('spacing', '')
|
|
13
|
+
result += `
|
|
14
|
+
.mb-${name} {
|
|
15
|
+
margin-bottom: ${value};
|
|
16
|
+
}
|
|
17
|
+
.mt-${name} {
|
|
18
|
+
margin-top: ${value};
|
|
19
|
+
}
|
|
20
|
+
.my-${name} {
|
|
21
|
+
margin-top: ${value};
|
|
22
|
+
margin-bottom: ${value};
|
|
23
|
+
}
|
|
24
|
+
.ml-${name} {
|
|
25
|
+
margin-left: ${value};
|
|
26
|
+
}
|
|
27
|
+
.mr-${name} {
|
|
28
|
+
margin-right: ${value};
|
|
29
|
+
}
|
|
30
|
+
.mx-${name} {
|
|
31
|
+
margin-left: ${value};
|
|
32
|
+
margin-right: ${value};
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Estilos globais utilizando `createGlobalStyle`
|
|
42
|
+
export const globalStyle = createGlobalStyle`
|
|
43
|
+
*, *::before, *::after {
|
|
44
|
+
box-sizing: border-box;
|
|
45
|
+
outline: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
body {
|
|
49
|
+
margin: 0;
|
|
50
|
+
font-size: 1rem;
|
|
51
|
+
font-weight: 400;
|
|
52
|
+
font-family: Manrope, sans-serif;
|
|
53
|
+
line-height: 1.5;
|
|
54
|
+
-webkit-text-size-adjust: 100%;
|
|
55
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
56
|
+
-webkit-font-smoothing: antialiased;
|
|
57
|
+
-moz-osx-font-smoothing: grayscale;
|
|
58
|
+
text-rendering: optimizeLegibility;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
input:-webkit-autofill {
|
|
63
|
+
background-color: transparent !important; /* Cor de fundo personalizada */
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
input:-webkit-autofill:hover,
|
|
67
|
+
input:-webkit-autofill:focus,
|
|
68
|
+
input:-webkit-autofill:active {
|
|
69
|
+
background-color: transparent
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
[tabindex="-1"]:focus:not(:focus-visible) {
|
|
73
|
+
outline: 0 !important;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
hr {
|
|
77
|
+
margin: 1rem 0;
|
|
78
|
+
color: inherit;
|
|
79
|
+
border: 0;
|
|
80
|
+
opacity: 0.25;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
hr:not([size]) {
|
|
84
|
+
height: 1px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
h1, h2, h3, h4, h5, h6 {
|
|
88
|
+
margin-top: 0;
|
|
89
|
+
margin-bottom: 0;
|
|
90
|
+
font-weight: 500;
|
|
91
|
+
line-height: 1.2;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
p {
|
|
95
|
+
margin: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
abbr[title], abbr[data-original-title] {
|
|
99
|
+
text-decoration: underline;
|
|
100
|
+
-webkit-text-decoration: underline dotted;
|
|
101
|
+
text-decoration: underline dotted;
|
|
102
|
+
cursor: help;
|
|
103
|
+
-webkit-text-decoration-skip-ink: none;
|
|
104
|
+
text-decoration-skip-ink: none;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
address {
|
|
108
|
+
margin: 0;
|
|
109
|
+
font-style: normal;
|
|
110
|
+
line-height: inherit;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
ol, ul {
|
|
114
|
+
padding: 0;
|
|
115
|
+
margin: 0;
|
|
116
|
+
list-style: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
figure {
|
|
120
|
+
margin: 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
img {
|
|
124
|
+
vertical-align: middle;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
svg {
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
vertical-align: middle;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
table {
|
|
133
|
+
border-collapse: collapse;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
caption {
|
|
137
|
+
padding-top: 0.5rem;
|
|
138
|
+
padding-bottom: 0.5rem;
|
|
139
|
+
text-align: left;
|
|
140
|
+
caption-side: bottom;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
th {
|
|
144
|
+
text-align: inherit;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
input, button, select, optgroup, textarea {
|
|
148
|
+
margin: 0;
|
|
149
|
+
font-family: inherit;
|
|
150
|
+
font-size: inherit;
|
|
151
|
+
line-height: inherit;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
button, input {
|
|
155
|
+
overflow: visible;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
button, select {
|
|
159
|
+
text-transform: none;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
[list]::-webkit-calendar-picker-indicator {
|
|
163
|
+
display: none;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
button, [type="button"], [type="reset"], [type="submit"] {
|
|
167
|
+
-webkit-appearance: button;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
button:not(:disabled), [type="button"]:not(:disabled), [type="reset"]:not(:disabled), [type="submit"]:not(:disabled) {
|
|
171
|
+
cursor: pointer;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
::-moz-focus-inner {
|
|
175
|
+
padding: 0;
|
|
176
|
+
border-style: none;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
textarea {
|
|
180
|
+
overflow: auto;
|
|
181
|
+
resize: none;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
fieldset {
|
|
185
|
+
min-width: 0;
|
|
186
|
+
padding: 0;
|
|
187
|
+
margin: 0;
|
|
188
|
+
border: 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
main {
|
|
192
|
+
display: block;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
[hidden] {
|
|
196
|
+
display: none !important;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
${marginStyles()}
|
|
200
|
+
`
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useWizard } from './Wizard.context'
|
|
4
|
+
|
|
5
|
+
interface IChildrenFunctionParams {
|
|
6
|
+
nextStep: () => void
|
|
7
|
+
prevStep: () => void
|
|
8
|
+
}
|
|
9
|
+
interface StepContentProps {
|
|
10
|
+
children: ((params: IChildrenFunctionParams) => ReactNode) | ReactNode
|
|
11
|
+
stepNumber?: number
|
|
12
|
+
label?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function StepContent({ children, stepNumber }: StepContentProps) {
|
|
16
|
+
const { state, nextStep, prevStep } = useWizard()
|
|
17
|
+
const notActive = stepNumber !== state.currentStep
|
|
18
|
+
|
|
19
|
+
if (notActive) return null
|
|
20
|
+
|
|
21
|
+
if (typeof children === 'function') {
|
|
22
|
+
return <div>{children({ nextStep, prevStep })}</div>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return <>{children}</>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default StepContent
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useWizard } from './Wizard.context'
|
|
2
|
+
import { WizardMenuItem, StepNumber, StepLabel } from './Wizard.styles'
|
|
3
|
+
|
|
4
|
+
interface StepMenuItemProps {
|
|
5
|
+
stepNumber: number
|
|
6
|
+
label?: string
|
|
7
|
+
menuNavigation?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function StepMenuItem({ stepNumber, label, menuNavigation }: StepMenuItemProps) {
|
|
11
|
+
const { setState, state } = useWizard()
|
|
12
|
+
|
|
13
|
+
const active = stepNumber === state.currentStep
|
|
14
|
+
const completed = state.currentStep > stepNumber
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<WizardMenuItem
|
|
18
|
+
$active={active}
|
|
19
|
+
$completed={completed}
|
|
20
|
+
$menuNavigation={menuNavigation}
|
|
21
|
+
onClick={() => {
|
|
22
|
+
if (menuNavigation) {
|
|
23
|
+
setState((curr) => ({ ...curr, currentStep: stepNumber }))
|
|
24
|
+
}
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<StepNumber>{completed ? <span>C</span> : stepNumber}</StepNumber>
|
|
28
|
+
<StepLabel>{label}</StepLabel>
|
|
29
|
+
</WizardMenuItem>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default StepMenuItem
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { createContext, ReactNode, useContext, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
interface IWizardState {
|
|
4
|
+
currentStep: number
|
|
5
|
+
totalSteps: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface IWizardContext {
|
|
9
|
+
state: IWizardState
|
|
10
|
+
setState: React.Dispatch<React.SetStateAction<IWizardState>>
|
|
11
|
+
nextStep: () => void
|
|
12
|
+
prevStep: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface IWizardContextProvider {
|
|
16
|
+
children: ReactNode
|
|
17
|
+
totalSteps: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const INITIAL_VALUE = {
|
|
21
|
+
state: {
|
|
22
|
+
currentStep: 0,
|
|
23
|
+
totalSteps: 0
|
|
24
|
+
},
|
|
25
|
+
setState: () => {},
|
|
26
|
+
nextStep: () => {},
|
|
27
|
+
prevStep: () => {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const WizardContext = createContext<IWizardContext>(INITIAL_VALUE)
|
|
31
|
+
|
|
32
|
+
function WizardContextProvider({ children, totalSteps }: IWizardContextProvider) {
|
|
33
|
+
const [state, setState] = useState({
|
|
34
|
+
currentStep: 1,
|
|
35
|
+
totalSteps
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
function nextStep() {
|
|
39
|
+
const nextStep = state.currentStep + 1
|
|
40
|
+
|
|
41
|
+
if (nextStep > state.totalSteps) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setState((curr) => ({
|
|
46
|
+
...curr,
|
|
47
|
+
currentStep: nextStep
|
|
48
|
+
}))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function prevStep() {
|
|
52
|
+
const prevStep = state.currentStep - 1
|
|
53
|
+
|
|
54
|
+
if (prevStep === 0) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setState((curr) => ({
|
|
59
|
+
...curr,
|
|
60
|
+
currentStep: prevStep
|
|
61
|
+
}))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const value = { state, setState, nextStep, prevStep }
|
|
65
|
+
return <WizardContext.Provider value={value}>{children}</WizardContext.Provider>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function useWizard() {
|
|
69
|
+
const context = useContext(WizardContext)
|
|
70
|
+
if (context === undefined) {
|
|
71
|
+
throw new Error('useWizard must be used within a WizardContextProvider')
|
|
72
|
+
}
|
|
73
|
+
return context
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { WizardContextProvider, useWizard }
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {parseColor} from '../../utils'
|
|
2
|
+
import styled, {css, DefaultTheme} from 'styled-components'
|
|
3
|
+
import Text from '../Text'
|
|
4
|
+
|
|
5
|
+
interface WizardMenuItemProps {
|
|
6
|
+
$active?: boolean
|
|
7
|
+
$completed?: boolean
|
|
8
|
+
$menuNavigation?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const WizardWrapper = styled.div`
|
|
12
|
+
display: flex;
|
|
13
|
+
width: 100%;
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
const WizardMenu = styled.div`
|
|
17
|
+
flex: 1;
|
|
18
|
+
padding: 32px 24px;
|
|
19
|
+
border-radius: 4px 0 0 4px;
|
|
20
|
+
border: 1px solid #ddd;
|
|
21
|
+
border-right: 0;
|
|
22
|
+
background-color: #efefef;
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
const WizardContent = styled.div`
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
flex: 3;
|
|
29
|
+
padding: 32px 24px;
|
|
30
|
+
border-radius: 0 4px 4px 0;
|
|
31
|
+
border: 1px solid #ddd;
|
|
32
|
+
border-left: 0;
|
|
33
|
+
background-color: ${({theme}) => parseColor(theme.colors.white)};
|
|
34
|
+
|
|
35
|
+
& > div {
|
|
36
|
+
height: 100%;
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
const itemActive = (theme: DefaultTheme) => {
|
|
41
|
+
return css`
|
|
42
|
+
.step-number {
|
|
43
|
+
background-color: ${parseColor(theme.colors.primary)};
|
|
44
|
+
border-color: ${parseColor(theme.colors.primary)};
|
|
45
|
+
color: ${parseColor(theme.colors.neutral100)};
|
|
46
|
+
}
|
|
47
|
+
.step-number::after {
|
|
48
|
+
border-left: 1px dashed ${parseColor(theme.colors.primary)};
|
|
49
|
+
}
|
|
50
|
+
`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const itemCompleted = (theme: DefaultTheme) => {
|
|
54
|
+
return css`
|
|
55
|
+
.step-number {
|
|
56
|
+
background-color: ${parseColor(theme.colors.primary)};
|
|
57
|
+
border-color: ${parseColor(theme.colors.primary)};
|
|
58
|
+
color: ${parseColor(theme.colors.neutral200)};
|
|
59
|
+
}
|
|
60
|
+
.step-number::after {
|
|
61
|
+
background-color: ${parseColor(theme.colors.primary)};
|
|
62
|
+
border-left: 1px solid ${parseColor(theme.colors.primary)};
|
|
63
|
+
}
|
|
64
|
+
`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const WizardMenuList = styled.ul``
|
|
68
|
+
const WizardMenuItem = styled.li<WizardMenuItemProps>`
|
|
69
|
+
cursor: ${({$menuNavigation}) => ($menuNavigation ? 'pointer' : 'default')};
|
|
70
|
+
display: flex;
|
|
71
|
+
gap: 16px;
|
|
72
|
+
align-items: center;
|
|
73
|
+
& + li {
|
|
74
|
+
margin-top: 30px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
${({theme, $active}) => $active && itemActive(theme)}
|
|
78
|
+
${({theme, $completed}) => $completed && itemCompleted(theme)}
|
|
79
|
+
`
|
|
80
|
+
|
|
81
|
+
const StepNumber = styled(Text).attrs({
|
|
82
|
+
tag: 'span',
|
|
83
|
+
size: 'body01',
|
|
84
|
+
className: 'step-number'
|
|
85
|
+
})`
|
|
86
|
+
position: relative;
|
|
87
|
+
display: flex;
|
|
88
|
+
justify-content: center;
|
|
89
|
+
align-items: center;
|
|
90
|
+
width: 32px;
|
|
91
|
+
height: 32px;
|
|
92
|
+
border-radius: 50%;
|
|
93
|
+
background-color: ${({theme}) => parseColor(theme.colors.neutral300)};
|
|
94
|
+
border: 1px dashed ${({theme}) => parseColor(theme.colors.primary)};
|
|
95
|
+
color: ${({theme}) => parseColor(theme.colors.primary)};
|
|
96
|
+
|
|
97
|
+
&::after {
|
|
98
|
+
content: '';
|
|
99
|
+
position: absolute;
|
|
100
|
+
top: 31px;
|
|
101
|
+
height: 32px;
|
|
102
|
+
width: 1px;
|
|
103
|
+
border-left: 1px dashed ${({theme}) => parseColor(theme.colors.primary)};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
${WizardMenuItem}:last-child &::after {
|
|
107
|
+
display: none;
|
|
108
|
+
}
|
|
109
|
+
`
|
|
110
|
+
const StepLabel = styled(Text).attrs({
|
|
111
|
+
tag: 'p',
|
|
112
|
+
size: 'body01',
|
|
113
|
+
className: 'step-label'
|
|
114
|
+
})`
|
|
115
|
+
color: ${({theme}) => parseColor(theme.colors.neutral900)};
|
|
116
|
+
`
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
WizardWrapper,
|
|
120
|
+
WizardMenu,
|
|
121
|
+
WizardContent,
|
|
122
|
+
WizardMenuList,
|
|
123
|
+
WizardMenuItem,
|
|
124
|
+
StepNumber,
|
|
125
|
+
StepLabel
|
|
126
|
+
}
|