@liguelead/design-system 0.0.1 → 0.0.3

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
- FloatingLabel,
6
- HelperText,
7
- IconWrapper,
8
- InputWrapper,
9
- StyledInput,
10
- Wrapper
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
- if (disabled) return 'disabled';
17
- if (error) return 'error';
18
- return 'default';
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
- 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)
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
- const togglePasswordVisibility = () => {
48
- setPasswordVisible(!passwordVisible);
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
- <IconWrapper onClick={togglePasswordVisibility} $right>
55
- {passwordVisible ? <Eye /> : <EyeClosed />}
56
- </IconWrapper>
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 { Control, FieldValues } from 'react-hook-form'
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
- 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'
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.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "components/index.ts",
6
6
  "publishConfig": {
@@ -11,11 +11,13 @@
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/",
18
- "utils/"
19
+ "utils/",
20
+ "scripts/"
19
21
  ],
20
22
  "devDependencies": {
21
23
  "@eslint/js": "^9.13.0",
@@ -0,0 +1,42 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ // Diretório e arquivos que queremos criar
5
+ const srcDir = path.resolve(process.cwd(), 'src')
6
+ const typesDir = path.join(srcDir, 'types')
7
+ const indexFile = path.join(typesDir, 'index.ts')
8
+ const typesFile = path.join(typesDir, 'types.ts')
9
+
10
+ // Função para criar pasta e arquivos
11
+ const createOrUpdateTypes = () => {
12
+ // Verifica se a pasta src existe
13
+ if (!fs.existsSync(srcDir)) {
14
+ console.error(
15
+ 'A pasta "src" não foi encontrada. Certifique-se de que ela existe.'
16
+ )
17
+ process.exit(1)
18
+ }
19
+
20
+ // Cria a pasta types se não existir
21
+ if (!fs.existsSync(typesDir)) {
22
+ fs.mkdirSync(typesDir, { recursive: true })
23
+ console.log(`Pasta criada: ${typesDir}`)
24
+ } else {
25
+ console.log(`A pasta já existe: ${typesDir}`)
26
+ }
27
+
28
+ // Verifica se o arquivo index.ts existe e cria se necessário
29
+ if (!fs.existsSync(indexFile)) {
30
+ fs.writeFileSync(indexFile, '// Arquivo de exportação\n', 'utf8')
31
+ console.log(`Arquivo criado: ${indexFile}`)
32
+ } else {
33
+ console.log(`O arquivo já existe e não será modificado: ${indexFile}`)
34
+ }
35
+
36
+ // Sobrescreve o arquivo types.ts com novo conteúdo
37
+ fs.writeFileSync(typesFile, '// Definições de tipos atualizadas\n', 'utf8')
38
+ console.log(`Arquivo sobrescrito: ${typesFile}`)
39
+ }
40
+
41
+ // Executa a função
42
+ createOrUpdateTypes()