@liguelead/design-system 0.0.1 → 0.0.2
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.
|
@@ -2,86 +2,102 @@ import React, { forwardRef, useState } from 'react'
|
|
|
2
2
|
import { TextFieldProps } from './TextField.types'
|
|
3
3
|
import { StateInterface, TextFieldStates } from './TextField.states'
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
FloatingLabel,
|
|
6
|
+
HelperText,
|
|
7
|
+
IconWrapper,
|
|
8
|
+
InputWrapper,
|
|
9
|
+
StyledInput,
|
|
10
|
+
Wrapper
|
|
11
11
|
} from './TextField.styles'
|
|
12
|
-
import { textFieldSizes } from './TextField.sizes'
|
|
12
|
+
import { textFieldSizes } from './TextField.sizes'
|
|
13
13
|
import { Eye, EyeClosed } from '@phosphor-icons/react'
|
|
14
14
|
|
|
15
15
|
const getState = (disabled: boolean, error: boolean) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
if (disabled) return 'disabled'
|
|
17
|
+
if (error) return 'error'
|
|
18
|
+
return 'default'
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
(
|
|
23
|
+
{
|
|
24
|
+
className,
|
|
25
|
+
disabled = false,
|
|
26
|
+
error,
|
|
27
|
+
handleLeftIcon,
|
|
28
|
+
handleRightIcon,
|
|
29
|
+
helperText,
|
|
30
|
+
label,
|
|
31
|
+
leftIcon,
|
|
32
|
+
onChange,
|
|
33
|
+
rightIcon,
|
|
34
|
+
size = 'md',
|
|
35
|
+
type = 'text',
|
|
36
|
+
value,
|
|
37
|
+
...props
|
|
38
|
+
},
|
|
39
|
+
ref // A ref passada pelo componente pai
|
|
40
|
+
) => {
|
|
41
|
+
const [passwordVisible, setPasswordVisible] = useState(
|
|
42
|
+
type !== 'password'
|
|
43
|
+
)
|
|
44
|
+
const state = getState(disabled, !!error)
|
|
45
|
+
const textFieldState: StateInterface = TextFieldStates(state)
|
|
46
|
+
const textFieldSize = textFieldSizes(size, !!leftIcon, !!rightIcon)
|
|
47
|
+
|
|
48
|
+
const togglePasswordVisibility = () => {
|
|
49
|
+
setPasswordVisible(!passwordVisible)
|
|
50
|
+
}
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const transformRightIcon = (
|
|
53
|
+
type: string,
|
|
54
|
+
rightIcon: React.ReactNode
|
|
55
|
+
) => {
|
|
56
|
+
if (type === 'password') {
|
|
57
|
+
return (
|
|
58
|
+
<IconWrapper onClick={togglePasswordVisibility} $right>
|
|
59
|
+
{passwordVisible ? <Eye /> : <EyeClosed />}
|
|
60
|
+
</IconWrapper>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
return (
|
|
64
|
+
<IconWrapper onClick={handleRightIcon} $right>
|
|
65
|
+
{rightIcon}
|
|
66
|
+
</IconWrapper>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
50
69
|
|
|
51
|
-
const transformRightIcon = (type: string, rightIcon: React.ReactNode) => {
|
|
52
|
-
if (type === 'password') {
|
|
53
70
|
return (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
<Wrapper
|
|
72
|
+
className={className}
|
|
73
|
+
size={textFieldSize}
|
|
74
|
+
$themefication={textFieldState}>
|
|
75
|
+
<InputWrapper>
|
|
76
|
+
{leftIcon && (
|
|
77
|
+
<IconWrapper onClick={handleLeftIcon}>
|
|
78
|
+
{leftIcon}
|
|
79
|
+
</IconWrapper>
|
|
80
|
+
)}
|
|
81
|
+
{transformRightIcon(type, rightIcon)}
|
|
82
|
+
<StyledInput
|
|
83
|
+
ref={ref}
|
|
84
|
+
type={passwordVisible ? 'text' : 'password'}
|
|
85
|
+
value={value}
|
|
86
|
+
onChange={onChange}
|
|
87
|
+
placeholder=" "
|
|
88
|
+
disabled={disabled}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
<FloatingLabel>{label}</FloatingLabel>
|
|
92
|
+
</InputWrapper>
|
|
93
|
+
{(helperText || error) && (
|
|
94
|
+
<HelperText>{error?.message || helperText}</HelperText>
|
|
95
|
+
)}
|
|
96
|
+
</Wrapper>
|
|
57
97
|
)
|
|
58
|
-
}
|
|
59
|
-
return <IconWrapper onClick={handleRightIcon} $right>{rightIcon}</IconWrapper>
|
|
60
98
|
}
|
|
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
99
|
)
|
|
84
100
|
|
|
85
|
-
TextField.displayName = 'TextField'
|
|
101
|
+
TextField.displayName = 'TextField'
|
|
86
102
|
|
|
87
103
|
export default TextField
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldValues } from 'react-hook-form'
|
|
2
2
|
import { TextFieldSize } from './TextField.sizes'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
|
|
5
5
|
export interface TextFieldProps<TFieldValues extends FieldValues = FieldValues>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type?: 'text' | 'password' | 'email' | 'number'
|
|
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
|
+
error?: TFieldValues
|
|
19
|
+
type?: 'text' | 'password' | 'email' | 'number'
|
|
21
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liguelead/design-system",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "components/index.ts",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"@phosphor-icons/react": "^2.1.7"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"lint": "eslint ."
|
|
14
|
+
"lint": "eslint .",
|
|
15
|
+
"ll-create-types": "node ./scripts/createTypes.js"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"components/",
|