@liguelead/design-system 0.0.8 → 0.0.10
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 -62
- package/components/Button/Button.sizes.ts +41 -41
- package/components/Button/Button.styles.ts +50 -50
- package/components/Button/Button.tsx +76 -76
- package/components/Button/Button.types.ts +23 -23
- package/components/Button/index.ts +1 -1
- package/components/Checkbox/Checkbox.styles.ts +66 -66
- package/components/Checkbox/Checkbox.tsx +40 -40
- package/components/Checkbox/Checkbox.types.ts +11 -11
- package/components/Checkbox/index.tsx +2 -2
- package/components/DatePicker/DatePicker.styles.ts +66 -66
- package/components/DatePicker/DatePicker.tsx +135 -135
- package/components/DatePicker/DatePicker.types.ts +29 -29
- package/components/DatePicker/index.ts +1 -1
- package/components/IconButton/IconButton.sizes.ts +41 -41
- package/components/IconButton/IconButton.tsx +70 -70
- package/components/IconButton/index.ts +1 -1
- package/components/PageWrapper/PageWrapper.tsx +31 -31
- package/components/PageWrapper/index.ts +1 -1
- package/components/SegmentedButton/SegmentedButton.styles.ts +29 -29
- package/components/SegmentedButton/SegmentedButton.tsx +49 -49
- package/components/SegmentedButton/SegmentedButton.types.ts +20 -20
- package/components/SegmentedButton/index.ts +1 -1
- package/components/Select/Select.sizes.ts +56 -56
- package/components/Select/Select.states.tsx +69 -69
- package/components/Select/Select.styles.ts +148 -148
- package/components/Select/Select.tsx +145 -144
- package/components/Select/Select.types.ts +36 -36
- package/components/Select/index.ts +1 -1
- package/components/Text/Text.styles.ts +43 -43
- package/components/Text/Text.tsx +27 -27
- package/components/Text/Text.types.ts +42 -42
- package/components/Text/index.ts +1 -1
- package/components/TextField/TextField.sizes.ts +58 -58
- package/components/TextField/TextField.states.tsx +53 -76
- package/components/TextField/TextField.styles.ts +81 -98
- package/components/TextField/TextField.tsx +105 -108
- package/components/TextField/TextField.types.ts +22 -21
- package/components/TextField/index.ts +2 -2
- package/components/TextField/utils/getState.ts +7 -0
- package/components/ThemeProvider/ThemeProvider.tsx +21 -21
- package/components/ThemeProvider/index.ts +1 -1
- package/components/ThemeProvider/style.ts +969 -969
- package/components/Wizard/StepContent.tsx +28 -28
- package/components/Wizard/StepMenuItem.tsx +33 -33
- package/components/Wizard/Wizard.context.tsx +76 -76
- package/components/Wizard/Wizard.styles.ts +126 -126
- package/components/Wizard/Wizard.tsx +55 -55
- package/components/Wizard/index.ts +1 -1
- package/components/index.ts +11 -11
- package/package.json +41 -39
- package/scripts/createTypes.js +70 -70
- package/utils/colorDarken.ts +10 -10
- package/utils/colorLighten.ts +10 -10
- package/utils/darkenOrLighen.ts +19 -19
- package/utils/getTextColor.ts +12 -12
- package/utils/index.ts +5 -5
- package/utils/parseColor.ts +7 -7
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { fontSize, lineHeight, spacing } from '@liguelead/foundation'
|
|
2
|
-
|
|
3
|
-
export type TextFieldSize = 'sm' | 'md' | 'lg'
|
|
4
|
-
|
|
5
|
-
export type TextFieldSizeType = {
|
|
6
|
-
input: string
|
|
7
|
-
label: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const textFieldSizes = (size: TextFieldSize, leftIcon: boolean, rightIcon: boolean) => {
|
|
11
|
-
const withIconMargin = Number(spacing.spacing8) + 20
|
|
12
|
-
const withIconPadding = {
|
|
13
|
-
sm: Number(spacing.spacing12) + Number(withIconMargin),
|
|
14
|
-
md: Number(spacing.spacing16) + Number(withIconMargin),
|
|
15
|
-
lg: Number(spacing.spacing16) + Number(withIconMargin)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const sizes = {
|
|
19
|
-
sm: {
|
|
20
|
-
input: `
|
|
21
|
-
font-size: ${fontSize.fontSize14}px;
|
|
22
|
-
line-height: ${lineHeight.lineHeight22}px;
|
|
23
|
-
padding: ${spacing.spacing8}px ${spacing.spacing12}px;
|
|
24
|
-
padding-left: ${leftIcon ? withIconPadding.sm : spacing.spacing12}px;
|
|
25
|
-
padding-right: ${rightIcon ? withIconPadding.sm : spacing.spacing12}px;
|
|
26
|
-
`,
|
|
27
|
-
label: `font-size: ${fontSize.fontSize14}px;
|
|
28
|
-
margin-left: ${leftIcon ? withIconMargin : 0}px;
|
|
29
|
-
margin-right: ${rightIcon ? withIconMargin : 0}px;`
|
|
30
|
-
},
|
|
31
|
-
md: {
|
|
32
|
-
input: `
|
|
33
|
-
font-size: ${fontSize.fontSize14}px;
|
|
34
|
-
line-height: ${lineHeight.lineHeight20}px;
|
|
35
|
-
padding: ${spacing.spacing12}px ${spacing.spacing16}px;
|
|
36
|
-
padding-left: ${leftIcon ? withIconPadding.md : spacing.spacing16}px;
|
|
37
|
-
padding-right: ${rightIcon ? withIconPadding.md : spacing.spacing16}px;
|
|
38
|
-
`,
|
|
39
|
-
label: `font-size: ${fontSize.fontSize14}px;
|
|
40
|
-
margin-left: ${leftIcon ? withIconMargin : 0}px;
|
|
41
|
-
margin-right: ${rightIcon ? withIconMargin : 0}px;`
|
|
42
|
-
},
|
|
43
|
-
lg: {
|
|
44
|
-
input: `
|
|
45
|
-
font-size: ${fontSize.fontSize16}px;
|
|
46
|
-
line-height: ${lineHeight.lineHeight24}px;
|
|
47
|
-
padding: ${spacing.spacing12}px ${spacing.spacing16}px;
|
|
48
|
-
padding-left: ${leftIcon ? withIconPadding.lg : spacing.spacing16}px;
|
|
49
|
-
padding-right: ${rightIcon ? withIconPadding.lg : spacing.spacing16}px;
|
|
50
|
-
`,
|
|
51
|
-
label: `font-size: ${fontSize.fontSize16}px;
|
|
52
|
-
margin-left: ${leftIcon ? withIconMargin : 0}px;
|
|
53
|
-
margin-right: ${rightIcon ? withIconMargin : 0}px;`
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return sizes[size]
|
|
58
|
-
}
|
|
1
|
+
import { fontSize, lineHeight, spacing } from '@liguelead/foundation'
|
|
2
|
+
|
|
3
|
+
export type TextFieldSize = 'sm' | 'md' | 'lg'
|
|
4
|
+
|
|
5
|
+
export type TextFieldSizeType = {
|
|
6
|
+
input: string
|
|
7
|
+
label: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const textFieldSizes = (size: TextFieldSize, leftIcon: boolean, rightIcon: boolean) => {
|
|
11
|
+
const withIconMargin = Number(spacing.spacing8) + 20
|
|
12
|
+
const withIconPadding = {
|
|
13
|
+
sm: Number(spacing.spacing12) + Number(withIconMargin),
|
|
14
|
+
md: Number(spacing.spacing16) + Number(withIconMargin),
|
|
15
|
+
lg: Number(spacing.spacing16) + Number(withIconMargin)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const sizes = {
|
|
19
|
+
sm: {
|
|
20
|
+
input: `
|
|
21
|
+
font-size: ${fontSize.fontSize14}px;
|
|
22
|
+
line-height: ${lineHeight.lineHeight22}px;
|
|
23
|
+
padding: ${spacing.spacing8}px ${spacing.spacing12}px;
|
|
24
|
+
padding-left: ${leftIcon ? withIconPadding.sm : spacing.spacing12}px;
|
|
25
|
+
padding-right: ${rightIcon ? withIconPadding.sm : spacing.spacing12}px;
|
|
26
|
+
`,
|
|
27
|
+
label: `font-size: ${fontSize.fontSize14}px;
|
|
28
|
+
margin-left: ${leftIcon ? withIconMargin : 0}px;
|
|
29
|
+
margin-right: ${rightIcon ? withIconMargin : 0}px;`
|
|
30
|
+
},
|
|
31
|
+
md: {
|
|
32
|
+
input: `
|
|
33
|
+
font-size: ${fontSize.fontSize14}px;
|
|
34
|
+
line-height: ${lineHeight.lineHeight20}px;
|
|
35
|
+
padding: ${spacing.spacing12}px ${spacing.spacing16}px;
|
|
36
|
+
padding-left: ${leftIcon ? withIconPadding.md : spacing.spacing16}px;
|
|
37
|
+
padding-right: ${rightIcon ? withIconPadding.md : spacing.spacing16}px;
|
|
38
|
+
`,
|
|
39
|
+
label: `font-size: ${fontSize.fontSize14}px;
|
|
40
|
+
margin-left: ${leftIcon ? withIconMargin : 0}px;
|
|
41
|
+
margin-right: ${rightIcon ? withIconMargin : 0}px;`
|
|
42
|
+
},
|
|
43
|
+
lg: {
|
|
44
|
+
input: `
|
|
45
|
+
font-size: ${fontSize.fontSize16}px;
|
|
46
|
+
line-height: ${lineHeight.lineHeight24}px;
|
|
47
|
+
padding: ${spacing.spacing12}px ${spacing.spacing16}px;
|
|
48
|
+
padding-left: ${leftIcon ? withIconPadding.lg : spacing.spacing16}px;
|
|
49
|
+
padding-right: ${rightIcon ? withIconPadding.lg : spacing.spacing16}px;
|
|
50
|
+
`,
|
|
51
|
+
label: `font-size: ${fontSize.fontSize16}px;
|
|
52
|
+
margin-left: ${leftIcon ? withIconMargin : 0}px;
|
|
53
|
+
margin-right: ${rightIcon ? withIconMargin : 0}px;`
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return sizes[size]
|
|
58
|
+
}
|
|
@@ -1,76 +1,53 @@
|
|
|
1
|
-
import {parseColor} from '../../utils'
|
|
2
|
-
import {useTheme} from 'styled-components'
|
|
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
|
-
&:focus
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
color: ${parseColor(theme.colors.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
label: `color: ${parseColor(theme.colors.neutral800)};`,
|
|
55
|
-
helperText: `color: ${parseColor(theme.colors.neutral700)};`,
|
|
56
|
-
animation: `
|
|
57
|
-
&:focus + label,
|
|
58
|
-
&:not(:placeholder-shown) + label {
|
|
59
|
-
top: 0px;
|
|
60
|
-
left: 12px;
|
|
61
|
-
font-size: ${fontSize.fontSize12}px;
|
|
62
|
-
}`
|
|
63
|
-
},
|
|
64
|
-
disabled: {
|
|
65
|
-
input: `
|
|
66
|
-
border: 1px solid ${parseColor(theme.colors.neutral500)};
|
|
67
|
-
color: ${parseColor(theme.colors.neutral600)};
|
|
68
|
-
`,
|
|
69
|
-
label: `color: ${parseColor(theme.colors.neutral500)};
|
|
70
|
-
background: transparent;`,
|
|
71
|
-
helperText: `color: ${parseColor(theme.colors.neutral500)};`,
|
|
72
|
-
animation: ``
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return states[state]
|
|
76
|
-
}
|
|
1
|
+
import {parseColor} from '../../utils'
|
|
2
|
+
import {useTheme} from 'styled-components'
|
|
3
|
+
|
|
4
|
+
export interface StateInterface {
|
|
5
|
+
input: string
|
|
6
|
+
label?: string
|
|
7
|
+
helperText: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface TextFieldStates {
|
|
11
|
+
error: StateInterface
|
|
12
|
+
default: StateInterface
|
|
13
|
+
disabled: StateInterface
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const TextFieldStates = (state: keyof TextFieldStates) => {
|
|
17
|
+
const theme = useTheme()
|
|
18
|
+
const states: TextFieldStates = {
|
|
19
|
+
error: {
|
|
20
|
+
input: `
|
|
21
|
+
border: 1px solid ${parseColor(theme.colors.danger200)};
|
|
22
|
+
color: ${parseColor(theme.colors.neutral1000)};
|
|
23
|
+
&:focus {
|
|
24
|
+
border-color: ${parseColor(theme.colors.danger200)};
|
|
25
|
+
box-shadow: 0 0 0 3px #DC262633;
|
|
26
|
+
}
|
|
27
|
+
`,
|
|
28
|
+
label: `color: ${parseColor(theme.colors.danger100)};`,
|
|
29
|
+
helperText: `color: ${parseColor(theme.colors.danger100)};`,
|
|
30
|
+
},
|
|
31
|
+
default: {
|
|
32
|
+
input: `
|
|
33
|
+
border: 1px solid #CFCFD1;
|
|
34
|
+
color: ${parseColor(theme.colors.neutral1000)};
|
|
35
|
+
&:focus {
|
|
36
|
+
border-color: ${parseColor(theme.colors.neutral700)};
|
|
37
|
+
box-shadow: 0 0 0 3px #A3A3A380;
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
label: `color: ${parseColor(theme.colors.neutral1100)};`,
|
|
41
|
+
helperText: `color: ${parseColor(theme.colors.neutral800)};`,
|
|
42
|
+
},
|
|
43
|
+
disabled: {
|
|
44
|
+
input: `
|
|
45
|
+
color: ${parseColor(theme.colors.neutral1100)};
|
|
46
|
+
box-shadow: 0 1px 2px 0 #0000000D;
|
|
47
|
+
opacity: 0.5;
|
|
48
|
+
`,
|
|
49
|
+
helperText: `color: ${parseColor(theme.colors.neutral500)};`,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return states[state]
|
|
53
|
+
}
|
|
@@ -1,98 +1,81 @@
|
|
|
1
|
-
import styled from 'styled-components'
|
|
2
|
-
import {TextFieldSizeType} from './TextField.sizes'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const
|
|
18
|
-
position:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
export const HelperText = styled.span<{error?: boolean}>`
|
|
30
|
-
font-size: ${fontSize.fontSize12}px;
|
|
31
|
-
line-height: ${lineHeight.
|
|
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
|
-
transition: border-color 0.2s ease;
|
|
61
|
-
background: transparent;
|
|
62
|
-
`
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
`
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import { TextFieldSizeType } from './TextField.sizes'
|
|
3
|
+
import {
|
|
4
|
+
fontSize,
|
|
5
|
+
fontWeight,
|
|
6
|
+
lineHeight,
|
|
7
|
+
spacing
|
|
8
|
+
} from '@liguelead/foundation'
|
|
9
|
+
import { StateInterface } from './TextField.states'
|
|
10
|
+
import { parseColor } from '../../utils'
|
|
11
|
+
|
|
12
|
+
interface StyledInputProps {
|
|
13
|
+
size: TextFieldSizeType
|
|
14
|
+
$themefication: StateInterface
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const InputWrapper = styled.div`
|
|
18
|
+
position: relative;
|
|
19
|
+
width: 100%;
|
|
20
|
+
`
|
|
21
|
+
|
|
22
|
+
export const Label = styled.label`
|
|
23
|
+
display: block;
|
|
24
|
+
font-weight: ${fontWeight.fontWeight600};
|
|
25
|
+
margin-bottom: ${spacing.spacing4}px;
|
|
26
|
+
font-size: ${fontSize.fontSize14}px;
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
export const HelperText = styled.span<{ error?: boolean }>`
|
|
30
|
+
font-size: ${fontSize.fontSize12}px;
|
|
31
|
+
line-height: ${lineHeight.lineHeight16}px;
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
export const IconWrapper = styled.div<{ $right?: boolean }>`
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
justify-content: space-between;
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: 0px;
|
|
40
|
+
height: 100%;
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
${({ $right }) => ($right ? 'right: 0px;' : 'left: 0px;')}
|
|
43
|
+
padding: 0px ${spacing.spacing16}px;
|
|
44
|
+
|
|
45
|
+
& svg {
|
|
46
|
+
width: 20px;
|
|
47
|
+
height: 20px;
|
|
48
|
+
fill: ${({ theme }) => parseColor(theme.colors.neutral700)};
|
|
49
|
+
transition: fill 0.2s ease;
|
|
50
|
+
}
|
|
51
|
+
`
|
|
52
|
+
|
|
53
|
+
export const StyledInput = styled.input.withConfig({
|
|
54
|
+
shouldForwardProp: prop => !['control', 'errors', 'rules'].includes(prop)
|
|
55
|
+
})`
|
|
56
|
+
width: 100%;
|
|
57
|
+
border-radius: 4px;
|
|
58
|
+
outline: none;
|
|
59
|
+
border: 1px solid #CFCFD1;
|
|
60
|
+
transition: border-color 0.2s ease;
|
|
61
|
+
background: transparent;
|
|
62
|
+
`
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export const Wrapper = styled.div<StyledInputProps>`
|
|
66
|
+
position: relative;
|
|
67
|
+
width: 100%;
|
|
68
|
+
${({ $themefication, size }) => `
|
|
69
|
+
${StyledInput} {
|
|
70
|
+
${$themefication.input}
|
|
71
|
+
${size.input}
|
|
72
|
+
}
|
|
73
|
+
${Label} {
|
|
74
|
+
${$themefication.label}
|
|
75
|
+
${size.label}
|
|
76
|
+
}
|
|
77
|
+
${HelperText} {
|
|
78
|
+
${$themefication.label}
|
|
79
|
+
}
|
|
80
|
+
`}
|
|
81
|
+
`
|
|
@@ -1,108 +1,105 @@
|
|
|
1
|
-
import React, { forwardRef, useState } from 'react'
|
|
2
|
-
import { TextFieldProps } from './TextField.types'
|
|
3
|
-
import { StateInterface, TextFieldStates } from './TextField.states'
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
TextField.displayName = 'TextField'
|
|
107
|
-
|
|
108
|
-
export default TextField
|
|
1
|
+
import React, { forwardRef, useState } from 'react'
|
|
2
|
+
import { TextFieldProps } from './TextField.types'
|
|
3
|
+
import { StateInterface, TextFieldStates } from './TextField.states'
|
|
4
|
+
import {
|
|
5
|
+
Label,
|
|
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
|
+
import getState from './utils/getState'
|
|
15
|
+
|
|
16
|
+
const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
|
17
|
+
(
|
|
18
|
+
{
|
|
19
|
+
className,
|
|
20
|
+
disabled = false,
|
|
21
|
+
error,
|
|
22
|
+
handleLeftIcon,
|
|
23
|
+
handleRightIcon,
|
|
24
|
+
helperText,
|
|
25
|
+
label,
|
|
26
|
+
leftIcon,
|
|
27
|
+
onChange,
|
|
28
|
+
rightIcon,
|
|
29
|
+
size = 'md',
|
|
30
|
+
type = 'text',
|
|
31
|
+
value,
|
|
32
|
+
register,
|
|
33
|
+
placeholder,
|
|
34
|
+
...props
|
|
35
|
+
},
|
|
36
|
+
ref
|
|
37
|
+
) => {
|
|
38
|
+
const [passwordVisible, setPasswordVisible] = useState(
|
|
39
|
+
type !== 'password'
|
|
40
|
+
)
|
|
41
|
+
const state = getState(disabled, !!error)
|
|
42
|
+
const textFieldState: StateInterface = TextFieldStates(state)
|
|
43
|
+
const textFieldSize = textFieldSizes(size, !!leftIcon, !!rightIcon)
|
|
44
|
+
|
|
45
|
+
const togglePasswordVisibility = () => {
|
|
46
|
+
setPasswordVisible(!passwordVisible)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const transformRightIcon = (
|
|
50
|
+
type: string,
|
|
51
|
+
rightIcon: React.ReactNode
|
|
52
|
+
) => {
|
|
53
|
+
if (type === 'password') {
|
|
54
|
+
return (
|
|
55
|
+
<IconWrapper onClick={togglePasswordVisibility} $right>
|
|
56
|
+
{passwordVisible ? <Eye /> : <EyeClosed />}
|
|
57
|
+
</IconWrapper>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
<IconWrapper onClick={handleRightIcon} $right>
|
|
62
|
+
{rightIcon}
|
|
63
|
+
</IconWrapper>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Wrapper
|
|
69
|
+
className={className}
|
|
70
|
+
size={textFieldSize}
|
|
71
|
+
$themefication={textFieldState}
|
|
72
|
+
>
|
|
73
|
+
<Label>{label}</Label>
|
|
74
|
+
<InputWrapper>
|
|
75
|
+
{leftIcon && (
|
|
76
|
+
<IconWrapper onClick={handleLeftIcon}>
|
|
77
|
+
{leftIcon}
|
|
78
|
+
</IconWrapper>
|
|
79
|
+
)}
|
|
80
|
+
{transformRightIcon(type, rightIcon)}
|
|
81
|
+
<StyledInput
|
|
82
|
+
ref={ref}
|
|
83
|
+
type={passwordVisible ? 'text' : 'password'}
|
|
84
|
+
value={value}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
placeholder={placeholder}
|
|
87
|
+
{...props}
|
|
88
|
+
{...register}
|
|
89
|
+
onChange={e => {
|
|
90
|
+
register?.onChange(e)
|
|
91
|
+
onChange?.(e)
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
</InputWrapper>
|
|
95
|
+
{(helperText || error) && (
|
|
96
|
+
<HelperText>{error?.message || helperText}</HelperText>
|
|
97
|
+
)}
|
|
98
|
+
</Wrapper>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
TextField.displayName = 'TextField'
|
|
104
|
+
|
|
105
|
+
export default TextField
|