@s_mart/form 0.0.0-font-awesome-20240308181754
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/dist/index.d.ts +602 -0
- package/dist/index.mjs +68 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FieldValues, UseFormReturn, FormProviderProps, UseFormProps, ControllerProps, UseControllerProps } from 'react-hook-form';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
+
import { TextFieldProps as TextFieldProps$1, SelectProps as SelectProps$1, AutocompleteProps as AutocompleteProps$1, CheckboxProps as CheckboxProps$1, SwitchProps as SwitchProps$1, RadioProps as RadioProps$1, RadioGroupProps as RadioGroupProps$1, SliderProps as SliderProps$1 } from '@mui/material';
|
|
7
|
+
import { DatePickerProps as DatePickerProps$1, TimePickerProps as TimePickerProps$1 } from '@mui/x-date-pickers';
|
|
8
|
+
|
|
9
|
+
interface IFormProps<T extends FieldValues> extends IUseFormProps<T> {
|
|
10
|
+
children: ((methods: UseFormReturn<T> & {
|
|
11
|
+
onSubmit: (e?: React.FormEvent | undefined) => Promise<void>;
|
|
12
|
+
}) => React.ReactNode) | React.ReactNode;
|
|
13
|
+
style?: React.HTMLAttributes<HTMLFormElement>['style'];
|
|
14
|
+
}
|
|
15
|
+
interface IFormProviderProps<TFieldValues extends FieldValues> extends FormProviderProps<TFieldValues> {
|
|
16
|
+
style?: React.HTMLAttributes<HTMLFormElement>['style'];
|
|
17
|
+
onSubmit: (e?: React.BaseSyntheticEvent) => void;
|
|
18
|
+
}
|
|
19
|
+
interface IUseFormProps<TValues extends FieldValues> extends Omit<UseFormProps<TValues>, 'resolver'> {
|
|
20
|
+
onSubmit: (data: TValues, methods: UseFormReturn<TValues>) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Prop que faz com que o formulário não atualize ao mudar o defaultValue
|
|
23
|
+
*/
|
|
24
|
+
disableDefaultValuesUpdate?: boolean;
|
|
25
|
+
schema?: z.ZodObject<any> | z.ZodEffects<z.ZodObject<any>>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Utilizado overloading para poder passar uma tipagem para o Componente
|
|
30
|
+
* @example
|
|
31
|
+
* // Não passar uma tipagem, todas as props terão o funcionamento normal, sem tipagem
|
|
32
|
+
* <Form onSubmit={({email}) => {}}>
|
|
33
|
+
* ...
|
|
34
|
+
* </Form>
|
|
35
|
+
* @example
|
|
36
|
+
* // Passar uma tipagem, todas as props derivadas do react-hook-form terão a tipagem passada no generic
|
|
37
|
+
* type Cadastro = {
|
|
38
|
+
* email: string;
|
|
39
|
+
* }
|
|
40
|
+
* <Form<Cadastro> onSubmit={({email}) => {}}>
|
|
41
|
+
* ...
|
|
42
|
+
* </Form>
|
|
43
|
+
*/
|
|
44
|
+
declare function Form(props: IFormProps<any>): JSX.Element;
|
|
45
|
+
declare function Form<T extends FieldValues>(props: IFormProps<T>): JSX.Element;
|
|
46
|
+
|
|
47
|
+
declare const useForm: <TValues extends FieldValues>({ disableDefaultValuesUpdate, onSubmit, ...rest }: IUseFormProps<TValues>) => {
|
|
48
|
+
onSubmit: (e?: react.BaseSyntheticEvent<object, any, any> | undefined) => Promise<void>;
|
|
49
|
+
watch: react_hook_form.UseFormWatch<TValues>;
|
|
50
|
+
getValues: react_hook_form.UseFormGetValues<TValues>;
|
|
51
|
+
getFieldState: react_hook_form.UseFormGetFieldState<TValues>;
|
|
52
|
+
setError: react_hook_form.UseFormSetError<TValues>;
|
|
53
|
+
clearErrors: react_hook_form.UseFormClearErrors<TValues>;
|
|
54
|
+
setValue: react_hook_form.UseFormSetValue<TValues>;
|
|
55
|
+
trigger: react_hook_form.UseFormTrigger<TValues>;
|
|
56
|
+
formState: react_hook_form.FormState<TValues>;
|
|
57
|
+
resetField: react_hook_form.UseFormResetField<TValues>;
|
|
58
|
+
reset: react_hook_form.UseFormReset<TValues>;
|
|
59
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<TValues, undefined>;
|
|
60
|
+
unregister: react_hook_form.UseFormUnregister<TValues>;
|
|
61
|
+
control: react_hook_form.Control<TValues, any>;
|
|
62
|
+
register: react_hook_form.UseFormRegister<TValues>;
|
|
63
|
+
setFocus: react_hook_form.UseFormSetFocus<TValues>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
declare function FormProvider<TFieldValues extends FieldValues>({ children, style, onSubmit, ...methods }: IFormProviderProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
67
|
+
|
|
68
|
+
type ControllerTextField = Omit<ControllerProps, 'render' | 'control'>;
|
|
69
|
+
type Masks = 'cpf' | 'cnpj' | 'cpfCnpj' | 'cep' | 'telefone' | 'decimal' | 'decimal3' | 'decimal4' | 'decimal5' | 'porcentagem' | 'porcentagem0' | 'nome' | 'numero' | 'numeroPontuacao' | 'placa' | 'valor';
|
|
70
|
+
type TextFieldProps = TextFieldProps$1 & ControllerTextField & {
|
|
71
|
+
mask?: Masks;
|
|
72
|
+
/**
|
|
73
|
+
* @description Função que será executada quando o valor do input for alterado
|
|
74
|
+
* @param value valor atual do Field
|
|
75
|
+
* @param values valores atuais do Form
|
|
76
|
+
*
|
|
77
|
+
* @example onInputChange={(values,values) => console.log({value, values})}
|
|
78
|
+
*/
|
|
79
|
+
onInputChange?: (value: string, values: FieldValues) => void;
|
|
80
|
+
/**
|
|
81
|
+
* @param value Valor do input
|
|
82
|
+
* @returns Valor formatado para o input
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* <TextField mask="cpf" parse={(value) => value.replace(/\D/g, '')} />
|
|
86
|
+
*/
|
|
87
|
+
parse?: (value: string) => string;
|
|
88
|
+
/**
|
|
89
|
+
* @param value Valor do input formatado
|
|
90
|
+
* @returns Valor sem formatação para o input
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* <TextField mask="cpf" format={(value) => value.replace(/\D/g, '')} />
|
|
94
|
+
*/
|
|
95
|
+
format?: (value: string) => string;
|
|
96
|
+
/**
|
|
97
|
+
* É o conteúdo passado para a tooltip que renderizará ao lado da label do campo,
|
|
98
|
+
* montada à tela como um ícone de informação.
|
|
99
|
+
*/
|
|
100
|
+
info?: React.ReactNode;
|
|
101
|
+
/**
|
|
102
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
103
|
+
* @default false
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* <TextField disableIconError />
|
|
107
|
+
*/
|
|
108
|
+
disableIconError?: boolean;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
declare const _default$6: react.MemoExoticComponent<({ name, rules, defaultValue, shouldUnregister, label, required, mask, variant, info, parse, inputMode, format, onInputChange, disableIconError, ...rest }: TextFieldProps) => react_jsx_runtime.JSX.Element>;
|
|
112
|
+
|
|
113
|
+
declare const _default$5: react.MemoExoticComponent<({ name, rules, defaultValue, shouldUnregister, label, required, options, placeholder, clearable, disableOnChangeForm, multiple, info, footer, onChange: onChangeProp, disableIconError, variant, ...rest }: SelectProps) => react_jsx_runtime.JSX.Element>;
|
|
114
|
+
|
|
115
|
+
type ControllerSelect = Omit<ControllerProps, 'render' | 'control'>;
|
|
116
|
+
type SelectOption = {
|
|
117
|
+
label: string;
|
|
118
|
+
value: string | number | readonly string[] | undefined;
|
|
119
|
+
afterLabel?: string | React.ReactNode;
|
|
120
|
+
};
|
|
121
|
+
type FooterProps = {
|
|
122
|
+
closeSelect: () => void;
|
|
123
|
+
};
|
|
124
|
+
type SelectProps = Omit<SelectProps$1, 'onChange'> & ControllerSelect & {
|
|
125
|
+
/**
|
|
126
|
+
* As opções que serão renderizadas no select
|
|
127
|
+
*
|
|
128
|
+
* @type {SelectOption[]}
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* options: [
|
|
132
|
+
* { label: 'Option 1', value: 'option1' },
|
|
133
|
+
* { label: 'Option 2', value: 'option2' },
|
|
134
|
+
* ]
|
|
135
|
+
*/
|
|
136
|
+
options: SelectOption[];
|
|
137
|
+
onChange?: (value: any, values: FieldValues) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Desabilita o onChange do select, para que o onChange do form não seja disparado
|
|
140
|
+
*
|
|
141
|
+
* @type {boolean}
|
|
142
|
+
* @default false
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* <Select name="select" options={options} disableOnChangeForm />
|
|
146
|
+
*/
|
|
147
|
+
disableOnChangeForm?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Função que renderiza o footer do select (opcional) - recebe como parâmetro a função closeSelect que fecha o select
|
|
150
|
+
* @param {FooterProps} props
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* footer: ({ closeSelect }) => (
|
|
154
|
+
* <Button onClick={closeSelect}>Fechar</Button>
|
|
155
|
+
* )
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
footer?: (props: FooterProps) => React.ReactNode;
|
|
159
|
+
/**
|
|
160
|
+
* É o conteúdo passado para a tooltip que renderizará ao lado da label do campo,
|
|
161
|
+
* montada à tela como um ícone de informação.
|
|
162
|
+
*/
|
|
163
|
+
info?: React.ReactNode;
|
|
164
|
+
/**
|
|
165
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
166
|
+
* @default false
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* <Select disableIconError />
|
|
170
|
+
*/
|
|
171
|
+
disableIconError?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Habilita ícone no endAdornment para limpar o valor do campo.
|
|
174
|
+
* @default false
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* <Select clearable />
|
|
178
|
+
*/
|
|
179
|
+
clearable?: boolean;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
type ControllerSearchable = Omit<ControllerProps, 'render' | 'control'>;
|
|
183
|
+
type SearchableOption = {
|
|
184
|
+
key?: string | number;
|
|
185
|
+
label: string;
|
|
186
|
+
value: string | number | readonly string[] | undefined;
|
|
187
|
+
afterLabel?: string | React.ReactNode;
|
|
188
|
+
} | string;
|
|
189
|
+
type SearchableProps = Omit<AutocompleteProps$1<SearchableOption, true, true, true>, 'renderInput' | 'size' | 'onInputChange' | 'onChange'> & ControllerSearchable & {
|
|
190
|
+
/**
|
|
191
|
+
* Opções do autocomplete
|
|
192
|
+
* @default []
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* [
|
|
196
|
+
* { label: 'Opção 1', value: '1' },
|
|
197
|
+
* ]
|
|
198
|
+
*
|
|
199
|
+
* @type {SearchableOption[]}
|
|
200
|
+
* @memberof SearchableProps
|
|
201
|
+
*/
|
|
202
|
+
options: SearchableOption[];
|
|
203
|
+
/**
|
|
204
|
+
* Props do textField que é renderizado dentro do autocomplete
|
|
205
|
+
* @default {}
|
|
206
|
+
* @type {TextFieldProps}
|
|
207
|
+
* @memberof SearchableProps
|
|
208
|
+
*/
|
|
209
|
+
textFieldProps?: TextFieldProps$1;
|
|
210
|
+
label?: React.ReactNode;
|
|
211
|
+
required?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Texto que será exibido quando não houver opções para serem exibidas
|
|
214
|
+
* @default 'Nenhuma opção encontrada'
|
|
215
|
+
*/
|
|
216
|
+
noOptionsText?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Componente que renderiza no footer do searchable (opcional)
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* footer: (
|
|
222
|
+
* <Button onClick={handleClick}>Mostrar mais...</Button>
|
|
223
|
+
* )
|
|
224
|
+
*
|
|
225
|
+
*
|
|
226
|
+
*/
|
|
227
|
+
footer?: React.ReactNode;
|
|
228
|
+
/**
|
|
229
|
+
* É o conteúdo passado para a tooltip que renderizará ao lado da label do campo,
|
|
230
|
+
* montada à tela como um ícone de informação.
|
|
231
|
+
*/
|
|
232
|
+
info?: React.ReactNode;
|
|
233
|
+
onInputChange?: (value: string, values: FieldValues) => void;
|
|
234
|
+
onChange?: (value: any, values: FieldValues) => void;
|
|
235
|
+
/**
|
|
236
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
237
|
+
* @default false
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* <TextField disableIconError />
|
|
241
|
+
*/
|
|
242
|
+
disableIconError?: boolean;
|
|
243
|
+
placeholder?: string;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
declare const _default$4: react.MemoExoticComponent<({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, noOptionsText, footer, multiple, info, placeholder, onChange: onChangeProp, onInputChange, disableIconError, ...rest }: SearchableProps) => react_jsx_runtime.JSX.Element>;
|
|
247
|
+
|
|
248
|
+
type ControllerCreatable = Omit<ControllerProps, 'render' | 'control'>;
|
|
249
|
+
type CreatableOption = {
|
|
250
|
+
key?: string | number;
|
|
251
|
+
label: string;
|
|
252
|
+
value?: string | number | readonly string[] | undefined;
|
|
253
|
+
afterLabel?: string | React.ReactNode;
|
|
254
|
+
} | string;
|
|
255
|
+
type CreatableProps = Omit<AutocompleteProps$1<CreatableOption, true, true, true>, 'renderInput' | 'size' | 'onInputChange' | 'onChange'> & ControllerCreatable & {
|
|
256
|
+
/**
|
|
257
|
+
* Opções do autocomplete
|
|
258
|
+
* @default []
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* [
|
|
262
|
+
* { label: 'Opção 1', value: '1' },
|
|
263
|
+
* ]
|
|
264
|
+
*
|
|
265
|
+
* @type {CreatableOption[]}
|
|
266
|
+
* @memberof CreatableProps
|
|
267
|
+
*/
|
|
268
|
+
options: CreatableOption[];
|
|
269
|
+
/**
|
|
270
|
+
* Props do textField que é renderizado dentro do autocomplete
|
|
271
|
+
* @default {}
|
|
272
|
+
* @type {TextFieldProps}
|
|
273
|
+
* @memberof CreatableProps
|
|
274
|
+
*/
|
|
275
|
+
textFieldProps?: TextFieldProps$1;
|
|
276
|
+
/**
|
|
277
|
+
* Label do autocomplete
|
|
278
|
+
* @default ''
|
|
279
|
+
* @type {string}
|
|
280
|
+
* @memberof CreatableProps
|
|
281
|
+
*/
|
|
282
|
+
label?: React.ReactNode;
|
|
283
|
+
/**
|
|
284
|
+
* Adiciona um * ao label do autocomplete para indicar que o campo é obrigatório
|
|
285
|
+
* @default false
|
|
286
|
+
* @type {boolean}
|
|
287
|
+
* @memberof CreatableProps
|
|
288
|
+
*/
|
|
289
|
+
required?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Função que será executada quando o usuário clicar no botão de criar uma nova opção
|
|
292
|
+
* @default () => {}
|
|
293
|
+
* @type {(value: string) => void}
|
|
294
|
+
* @memberof CreatableProps
|
|
295
|
+
*/
|
|
296
|
+
onCreateOption?: (value: string | Record<string, unknown>) => void;
|
|
297
|
+
/**
|
|
298
|
+
* Quando true, o botão de criar uma nova opção externo não será renderizado
|
|
299
|
+
* @default false
|
|
300
|
+
* @type {boolean}
|
|
301
|
+
* @memberof CreatableProps
|
|
302
|
+
*/
|
|
303
|
+
hideAddButton?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
*
|
|
306
|
+
* @default false
|
|
307
|
+
* @type {boolean}
|
|
308
|
+
* @memberof CreatableProps
|
|
309
|
+
*/
|
|
310
|
+
editable?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Função que será executada quando o usuário clicar no botão de editar uma opção
|
|
313
|
+
* @default () => {}
|
|
314
|
+
* @type {(value) => void}
|
|
315
|
+
* @memberof CreatableProps
|
|
316
|
+
*/
|
|
317
|
+
onEditOption?: (value: any) => void;
|
|
318
|
+
/**
|
|
319
|
+
* Componente que renderiza no footer do creatable (opcional)
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* footer: (
|
|
323
|
+
* <Button onClick={handleClick}>Mostrar mais...</Button>
|
|
324
|
+
* )
|
|
325
|
+
*
|
|
326
|
+
*
|
|
327
|
+
*/
|
|
328
|
+
footer?: React.ReactNode;
|
|
329
|
+
/**
|
|
330
|
+
* É o conteúdo passado para a tooltip que renderizará ao lado da label do campo,
|
|
331
|
+
* montada à tela como um ícone de informação.
|
|
332
|
+
*/
|
|
333
|
+
info?: React.ReactNode;
|
|
334
|
+
onInputChange?: (value: string, values: FieldValues) => void;
|
|
335
|
+
onChange?: (value: any, values: FieldValues) => void;
|
|
336
|
+
/**
|
|
337
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
338
|
+
* @default false
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* <TextField disableIconError />
|
|
342
|
+
*/
|
|
343
|
+
disableIconError?: boolean;
|
|
344
|
+
placeholder?: string;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
declare const _default$3: react.MemoExoticComponent<({ name, rules, defaultValue, shouldUnregister, label, required, options, editable, footer, onEditOption, onCreateOption, textFieldProps, hideAddButton, multiple, info, onChange: onChangeProp, onInputChange, placeholder, disableIconError, ...rest }: CreatableProps) => react_jsx_runtime.JSX.Element>;
|
|
348
|
+
|
|
349
|
+
type ControllerCheckbox = Omit<ControllerProps, 'render' | 'control'>;
|
|
350
|
+
type CheckboxProps = CheckboxProps$1 & ControllerCheckbox & {
|
|
351
|
+
/**
|
|
352
|
+
* O nome do checkbox que será renderizado na tela
|
|
353
|
+
* @default ''
|
|
354
|
+
* @example 'Nome do checkbox'
|
|
355
|
+
* @type string
|
|
356
|
+
* @memberof CheckboxProps
|
|
357
|
+
*/
|
|
358
|
+
label?: React.ReactNode;
|
|
359
|
+
/**
|
|
360
|
+
* Posição do label em relação ao checkbox
|
|
361
|
+
* @default 'end'
|
|
362
|
+
* @type 'start' | 'end' | 'top' | 'bottom'
|
|
363
|
+
* @example
|
|
364
|
+
* <Checkbox label="Checkbox" labelPlacement="start" />
|
|
365
|
+
*/
|
|
366
|
+
labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
|
|
367
|
+
/**
|
|
368
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
369
|
+
* @default false
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* <TextField disableIconError />
|
|
373
|
+
*/
|
|
374
|
+
disableIconError?: boolean;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
declare const Checkbox: ({ name, rules, defaultValue, shouldUnregister, label, labelPlacement, required, disableIconError, onChange: onChangeProp, ...rest }: CheckboxProps) => react_jsx_runtime.JSX.Element;
|
|
378
|
+
|
|
379
|
+
type ControllerSwitch = Omit<ControllerProps, 'render' | 'control'>;
|
|
380
|
+
type SwitchProps = SwitchProps$1 & ControllerSwitch & {
|
|
381
|
+
/**
|
|
382
|
+
* O nome do switch que será renderizado na tela
|
|
383
|
+
* @default ''
|
|
384
|
+
* @example 'Nome do switch'
|
|
385
|
+
* @type React.ReactNode
|
|
386
|
+
* @memberof SwitchProps
|
|
387
|
+
*/
|
|
388
|
+
label?: React.ReactNode;
|
|
389
|
+
/**
|
|
390
|
+
* Posição do label em relação ao switch
|
|
391
|
+
* @default 'end'
|
|
392
|
+
* @type 'start' | 'end' | 'top' | 'bottom'
|
|
393
|
+
* @example
|
|
394
|
+
* <Switch label="Switch" labelPlacement="start" />
|
|
395
|
+
*/
|
|
396
|
+
labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
|
|
397
|
+
/**
|
|
398
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
399
|
+
* @default false
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* <TextField disableIconError />
|
|
403
|
+
*/
|
|
404
|
+
disableIconError?: boolean;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
declare const Switch: ({ name, rules, defaultValue, shouldUnregister, label, labelPlacement, disableIconError, onChange: onChangeProp, ...rest }: SwitchProps) => react_jsx_runtime.JSX.Element;
|
|
408
|
+
|
|
409
|
+
type RadioProps = RadioProps$1 & {
|
|
410
|
+
/**
|
|
411
|
+
* O nome do checkbox que será renderizado na tela
|
|
412
|
+
* @default ''
|
|
413
|
+
* @example 'Nome do checkbox'
|
|
414
|
+
* @type React.ReactNode
|
|
415
|
+
* @memberof RadioProps
|
|
416
|
+
*/
|
|
417
|
+
label?: React.ReactNode;
|
|
418
|
+
/**
|
|
419
|
+
* Posição do label em relação ao checkbox
|
|
420
|
+
* @default 'end'
|
|
421
|
+
* @type 'start' | 'end' | 'top' | 'bottom'
|
|
422
|
+
* @example
|
|
423
|
+
* <Radio label="Radio" labelPlacement="start" />
|
|
424
|
+
*/
|
|
425
|
+
labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
declare const RadioButton: ({ label, labelPlacement, ...rest }: RadioProps) => react_jsx_runtime.JSX.Element;
|
|
429
|
+
|
|
430
|
+
type ControllerRadioGroup = Omit<ControllerProps, 'render' | 'control'>;
|
|
431
|
+
type RadioGroupProps = RadioGroupProps$1 & ControllerRadioGroup & {
|
|
432
|
+
/**
|
|
433
|
+
* O nome do checkbox que será renderizado na tela
|
|
434
|
+
* @default ''
|
|
435
|
+
* @example 'Nome do checkbox'
|
|
436
|
+
* @type React.ReactNode
|
|
437
|
+
* @memberof RadioGroupProps
|
|
438
|
+
*/
|
|
439
|
+
label?: React.ReactNode;
|
|
440
|
+
/**
|
|
441
|
+
* Adiciona um asterisco ao label do radioGroup
|
|
442
|
+
* @default false
|
|
443
|
+
* @type boolean
|
|
444
|
+
* @memberof RadioGroupProps
|
|
445
|
+
*/
|
|
446
|
+
required?: boolean;
|
|
447
|
+
/**
|
|
448
|
+
* Parte interna do componente para renderizar os RadiosButtons
|
|
449
|
+
* @default []
|
|
450
|
+
* @type ReactNode
|
|
451
|
+
* @memberof RadioGroupProps
|
|
452
|
+
* @example
|
|
453
|
+
* <Radio value="1" label="Radio 1" />
|
|
454
|
+
* <Radio value="2" label="Radio 2" />
|
|
455
|
+
*/
|
|
456
|
+
children: React.ReactNode;
|
|
457
|
+
/**
|
|
458
|
+
* Define a orientação dos radios buttons dentro do radioGroup
|
|
459
|
+
* @default 'row'
|
|
460
|
+
* @type 'row' | 'column'
|
|
461
|
+
* @memberof RadioGroupProps
|
|
462
|
+
*/
|
|
463
|
+
orientation?: 'row' | 'column';
|
|
464
|
+
/**
|
|
465
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
466
|
+
* @default false
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* <TextField disableIconError />
|
|
470
|
+
*/
|
|
471
|
+
disableIconError?: boolean;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
declare const RadioGroup: ({ name, rules, defaultValue, shouldUnregister, label, required, children, orientation, disableIconError, ...rest }: RadioGroupProps) => react_jsx_runtime.JSX.Element;
|
|
475
|
+
|
|
476
|
+
type ControllerSlider = Omit<ControllerProps, 'render' | 'control'>;
|
|
477
|
+
type SliderProps = SliderProps$1 & ControllerSlider & {
|
|
478
|
+
/**
|
|
479
|
+
* O nome do switch que será renderizado na tela
|
|
480
|
+
* @default ''
|
|
481
|
+
* @example 'Nome do switch'
|
|
482
|
+
* @type string
|
|
483
|
+
* @memberof SliderProps
|
|
484
|
+
*/
|
|
485
|
+
label?: string;
|
|
486
|
+
/**
|
|
487
|
+
* Posição do label em relação ao switch
|
|
488
|
+
* @default 'end'
|
|
489
|
+
* @type 'start' | 'end' | 'top' | 'bottom'
|
|
490
|
+
* @example
|
|
491
|
+
* <Slider label="Slider" labelPlacement="start" />
|
|
492
|
+
*/
|
|
493
|
+
labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
declare const Slider: ({ name, rules, defaultValue, shouldUnregister, ...rest }: SliderProps) => react_jsx_runtime.JSX.Element;
|
|
497
|
+
|
|
498
|
+
type DatePickerProps = Omit<UseControllerProps, 'control'> & Pick<TextFieldProps$1, 'label' | 'error' | 'helperText' | 'size' | 'fullWidth' | 'variant' | 'autoFocus' | 'placeholder'> & {
|
|
499
|
+
datePickerProps?: Partial<DatePickerProps$1<any>>;
|
|
500
|
+
/**
|
|
501
|
+
* Se `true` irá adicionar um asterisco ao label do campo
|
|
502
|
+
*
|
|
503
|
+
* @default false
|
|
504
|
+
*/
|
|
505
|
+
required?: boolean;
|
|
506
|
+
/**
|
|
507
|
+
* Se `true` irá desabilitar o campo e não será possível interagir com ele
|
|
508
|
+
*
|
|
509
|
+
* @default false
|
|
510
|
+
*/
|
|
511
|
+
disabled?: boolean;
|
|
512
|
+
/**
|
|
513
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
514
|
+
* @default false
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* <TextField disableIconError />
|
|
518
|
+
*/
|
|
519
|
+
disableIconError?: boolean;
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
declare const _default$2: react.MemoExoticComponent<({ rules, name, defaultValue, shouldUnregister, datePickerProps, label, required, placeholder, disabled, disableIconError, ...rest }: DatePickerProps) => react_jsx_runtime.JSX.Element>;
|
|
523
|
+
|
|
524
|
+
type TimePickerProps = Omit<UseControllerProps, 'control'> & Pick<TextFieldProps$1, 'label' | 'error' | 'helperText' | 'size' | 'fullWidth' | 'variant' | 'autoFocus' | 'placeholder'> & {
|
|
525
|
+
timePickerProps?: Partial<TimePickerProps$1<any>>;
|
|
526
|
+
/**
|
|
527
|
+
* Se `true` irá adicionar um asterisco ao label do campo
|
|
528
|
+
*
|
|
529
|
+
* @default false
|
|
530
|
+
*/
|
|
531
|
+
required?: boolean;
|
|
532
|
+
/**
|
|
533
|
+
* Se `true` irá desabilitar o campo e não será possível interagir com ele
|
|
534
|
+
*
|
|
535
|
+
* @default false
|
|
536
|
+
*/
|
|
537
|
+
disabled?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
540
|
+
* @default false
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* <TextField disableIconError />
|
|
544
|
+
*/
|
|
545
|
+
disableIconError?: boolean;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
declare const _default$1: react.MemoExoticComponent<({ rules, defaultValue, shouldUnregister, name, required, label, timePickerProps, placeholder, disabled, disableIconError, ...rest }: TimePickerProps) => react_jsx_runtime.JSX.Element>;
|
|
549
|
+
|
|
550
|
+
type AutoCompleteOption = {
|
|
551
|
+
key?: string | number;
|
|
552
|
+
label: string;
|
|
553
|
+
value: string | number | readonly string[] | undefined;
|
|
554
|
+
afterLabel?: string | React.ReactNode;
|
|
555
|
+
};
|
|
556
|
+
type AutocompleteProps<T = any> = Omit<UseControllerProps, 'control'> & Omit<AutocompleteProps$1<T, any, any, any>, 'renderInput' | 'size' | 'onInputChange' | 'onChange' | 'options'> & {
|
|
557
|
+
/**
|
|
558
|
+
* Opções do autocomplete
|
|
559
|
+
* @default []
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* [
|
|
563
|
+
* { label: 'Opção 1', value: '1' },
|
|
564
|
+
* ]
|
|
565
|
+
*
|
|
566
|
+
* @type {AutoCompleteOption[]}
|
|
567
|
+
* @memberof AutocompleteProps
|
|
568
|
+
*/
|
|
569
|
+
options: AutoCompleteOption[];
|
|
570
|
+
/**
|
|
571
|
+
* Props do textField que é renderizado dentro do autocomplete
|
|
572
|
+
* @default {}
|
|
573
|
+
* @type {TextFieldProps}
|
|
574
|
+
* @memberof AutocompleteProps
|
|
575
|
+
*/
|
|
576
|
+
textFieldProps?: TextFieldProps$1;
|
|
577
|
+
label?: React.ReactNode;
|
|
578
|
+
required?: boolean;
|
|
579
|
+
onInputChange?: (value: string, values: FieldValues) => void;
|
|
580
|
+
onChange?: (value: any, values: FieldValues) => void;
|
|
581
|
+
/**
|
|
582
|
+
* Desabilita o ícone de erro da validação do campo.
|
|
583
|
+
* @default false
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* <TextField disableIconError />
|
|
587
|
+
*/
|
|
588
|
+
disableIconError?: boolean;
|
|
589
|
+
placeholder?: string;
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
declare const _default: react.MemoExoticComponent<({ name, defaultValue, rules, shouldUnregister, label, required, noOptionsText, placeholder, onInputChange, onChange, disableIconError, ...rest }: AutocompleteProps) => react_jsx_runtime.JSX.Element>;
|
|
593
|
+
|
|
594
|
+
type FieldLabelProps = {
|
|
595
|
+
label: React.ReactNode;
|
|
596
|
+
required?: boolean;
|
|
597
|
+
regular?: boolean;
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
declare const FieldLabel: ({ label, required, regular }: FieldLabelProps) => react_jsx_runtime.JSX.Element;
|
|
601
|
+
|
|
602
|
+
export { _default as Autocomplete, AutocompleteProps, Checkbox, CheckboxProps, _default$3 as Creatable, CreatableOption, CreatableProps, _default$2 as DatePicker, DatePickerProps, FieldLabel, FieldLabelProps, FooterProps, Form, FormProvider, IFormProps, IFormProviderProps, IUseFormProps, RadioButton, RadioGroup, RadioGroupProps, RadioProps, _default$4 as Searchable, SearchableOption, SearchableProps, _default$5 as Select, SelectOption, SelectProps, Slider, SliderProps, Switch, SwitchProps, _default$6 as TextField, TextFieldProps, _default$1 as TimePicker, TimePickerProps, useForm };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import{FormProvider as Ve}from"react-hook-form";import{jsx as de}from"react/jsx-runtime";function Re({children:e,style:r,onSubmit:i,...t}){return de(Ve,{...t,children:de("form",{onSubmit:n=>{n.preventDefault(),n.stopPropagation(),i(n)},style:r,children:e})})}var ie=Re;import{useEffect as Ee}from"react";import{useForm as Be}from"react-hook-form";import{zodResolver as Ae}from"@hookform/resolvers/zod";var De=({disableDefaultValuesUpdate:e,onSubmit:r,...i})=>{let t=Be({...i,resolver:i.schema&&Ae(i.schema)});return Ee(()=>{e||t.reset(i.defaultValues)},[i.defaultValues,t.reset]),{...t,onSubmit:t.handleSubmit(n=>r(n,t))}},le=De;import{jsx as ze}from"react/jsx-runtime";function $e({children:e,style:r,...i}){let t=le(i);return ze(ie,{...t,style:r,children:typeof e=="function"?e(t):e})}var Me=$e;import{memo as He,useState as We}from"react";import{Controller as Ye,useFormContext as Je}from"react-hook-form";import{Grid as ne,InputAdornment as Ke,TextField as Xe}from"@mui/material";import{lineEye as Qe,lineEyeSlash as Ze,lineInfoCircle as eo}from"@s_mart/solid-icons";import*as ue from"@s_mart/masks";import{Typography as pe}from"@mui/material";import{toRem as qe}from"@s_mart/utils";import{jsx as me,jsxs as Oe}from"react/jsx-runtime";var _e=({label:e,required:r,regular:i})=>Oe("span",{style:{display:"flex",alignItems:"center",gap:qe(2)},children:[me(pe,{variant:"caption",fontWeight:i?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&me(pe,{variant:"caption",fontWeight:900,color:"error",children:"*"})]}),v=_e;import{useFormContext as Ue}from"react-hook-form";import{Indicator as je}from"@s_mart/core";var V=(e,r)=>r.replace(/[[\]]/g,"").split(".").reduce((t,n)=>t?.[n],e);import{jsx as Ne}from"react/jsx-runtime";var T=({name:e,disableIcon:r})=>{let i=Ue(),t=V(i?.formState?.errors,e);return t?Ne(je,{severity:"error",icon:r?!1:void 0,children:t?.message}):null};import{LIcon as fe,Tooltip as oo}from"@s_mart/core";import{jsx as B,jsxs as ce}from"react/jsx-runtime";var ro=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,required:b,mask:m,variant:g="outlined",info:I,parse:c,inputMode:u,format:a,onInputChange:F,disableIconError:d,...x})=>{let P=Je();if(!P)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[s,C]=We(!1),p=l=>{let o=l;return a&&(o=a(l)),m?ue?.[m]?.format(o):o},f=l=>{let o=l;return c&&(o=c(l)),m?ue?.[m]?.parse(o):o},R=l=>{if(!l||m!=="porcentagem"&&m!=="porcentagem0")return;l?.stopPropagation();let o=(l?.target).value;if(o){let E=String(o);if(E.length>0){let w=E.indexOf("%");w>-1&&(l.currentTarget.selectionEnd=w)}}},z=V(P.formState.errors,e);return B(Ye,{control:P.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:l,onChange:o,ref:E}})=>ce(ne,{display:"flex",flexDirection:"column",children:[ce("div",{style:{display:"flex"},children:[n&&B(ne,{item:!0,children:B(v,{label:n,required:b})}),I&&B(ne,{item:!0,children:B(oo,{title:I,placement:"top",children:B("div",{style:{width:"fit-content"},children:B(fe,{icon:eo,color:"#757575"})})})})]}),B(Xe,{variant:g,defaultValue:i,value:p(l||(l!=0?"":l)),onChange:w=>{let N=f(w?.target?.value);o(N),F?.(N,P.getValues())},error:!!z,...x,type:x.type==="password"?s?"text":"password":x.type,autoComplete:x.autoComplete||"off",inputProps:{inputMode:u,...x.inputProps},InputProps:{onKeyDown:R,inputRef:E,endAdornment:x.type==="password"&&B(Ke,{position:"start",onClick:()=>C(!s),style:{cursor:"pointer"},children:B(fe,{icon:s?Qe:Ze,size:"24px",removeMargin:!0})}),...x.InputProps}},e),B(T,{name:e,disableIcon:d})]})})},to=He(ro);import{memo as io,useState as lo}from"react";import{Controller as no,useFormContext as ao}from"react-hook-form";import{Divider as so,IconButton as po,LIcon as xe,Tooltip as mo}from"@s_mart/core";import{lineTimes as uo}from"@s_mart/regular-icons";import{lineInfoCircle as fo}from"@s_mart/solid-icons";import{colorPalette as co}from"@s_mart/tokens";import{Grid as _,Select as xo,MenuItem as yo,useTheme as Fo}from"@mui/material";import{Fragment as ho,jsx as L,jsxs as W}from"react/jsx-runtime";var Po=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,required:b,options:m,placeholder:g,clearable:I,disableOnChangeForm:c=!1,multiple:u,info:a,footer:F,onChange:d,disableIconError:x,variant:P="outlined",...s})=>{let C=ao(),{palette:p}=Fo(),[f,R]=lo(!1);if(!C)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let z=V(C.formState.errors,e);return console.warn=()=>{},L(no,{control:C.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:l,onChange:o,ref:E}})=>W(_,{display:"flex",flexDirection:"column",children:[W("div",{style:{display:"flex"},children:[n&&L(_,{item:!0,children:L(v,{label:n,required:b})}),a&&L(_,{item:!0,children:L(mo,{title:a,placement:"top",children:L("div",{style:{width:"fit-content"},children:L(xe,{icon:fo,color:"#757575"})})})})]}),W(xo,{open:f,onOpen:()=>R(!0),onClose:()=>R(!1),displayEmpty:!!g,variant:P,autoComplete:"off",value:l?l||"":u?[]:"",renderValue:w=>{if(w.label)return w.label;if(g)return L("p",{style:{color:p.grey[400]},children:g})},multiple:u,onChange:w=>{!c&&o(w.target.value),d&&d(w.target.value,C.getValues())},error:!!z,size:s.size||"medium",inputRef:E,...s,endAdornment:W(ho,{children:[s.endAdornment,!!(I&&l)&&L(po,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Clear",title:"Clear",onClick:()=>{!c&&o(null),d&&d(null,C.getValues())},children:L(xe,{icon:uo,color:co.neutral[100],size:"25px",removeMargin:!0})})]}),children:[m?.map((w,N)=>L(yo,{value:w,children:W(_,{container:!0,direction:"column",children:[L(_,{item:!0,children:w.label}),w.afterLabel&&L(_,{item:!0,children:w.afterLabel})]})},N)),F&&[L(_,{px:2,py:1,children:L(so,{})},"footer-divider"),L("div",{children:F({closeSelect:()=>R(!1)})},"footer-content")]]},e),L(T,{name:e,disableIcon:x})]})})},bo=io(Po);import{forwardRef as go,memo as Co}from"react";import{Controller as vo,useFormContext as Io}from"react-hook-form";import{Grid as M,Autocomplete as To,TextField as ko}from"@mui/material";import{Divider as ye,LIcon as wo,Tooltip as So}from"@s_mart/core";import{lineInfoCircle as Go}from"@s_mart/solid-icons";import{colorPalette as Lo}from"@s_mart/tokens";import{Fragment as X,jsx as G,jsxs as O}from"react/jsx-runtime";import{createElement as Fe}from"react";var Vo=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,required:b,options:m,textFieldProps:g,noOptionsText:I,footer:c,multiple:u,info:a,placeholder:F,onChange:d,onInputChange:x,disableIconError:P,...s})=>{let C=Io();if(!C)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let p=V(C.formState.errors,e);return console.warn=()=>{},G(vo,{control:C.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{onChange:f,value:R,ref:z}})=>O(M,{display:"flex",flexDirection:"column",children:[O("div",{style:{display:"flex"},children:[n&&G(M,{item:!0,children:G(v,{label:n,required:b})}),a&&G(M,{item:!0,children:G(So,{title:a,placement:"top",children:G("div",{style:{width:"fit-content"},children:G(wo,{icon:Go,color:"#757575"})})})})]}),G(To,{onChange:(l,o)=>{f(o),d?.(o,C.getValues())},onInputChange:(l,o,E)=>{E==="input"&&setTimeout(()=>{x?.(o,C.getValues())},0)},slotProps:{...s.slotProps||{},paper:{...(s.slotProps||{}).paper||{},sx:{border:`1px solid ${Lo.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(s.slotProps||{}).paper?.sx||{}}}},value:R||(u?[]:null),options:m,multiple:u,readOnly:s.disabled,noOptionsText:O(X,{children:[I||"Nenhum resultado encontrado",c?O(X,{children:[G(M,{py:1,children:G(ye,{})}),c]}):null]}),isOptionEqualToValue:(l,o)=>typeof l=="string"&&typeof o=="string"?l===o:typeof l=="object"&&typeof o=="object"?typeof l.value=="object"&&typeof o.value=="object"&&l.key!==void 0&&o.key!==void 0?l.key===o.key:l.value===o.value:!1,renderOption:(l,o)=>typeof o=="object"?Fe("li",{...l,key:o.key||o.value},O(M,{container:!0,direction:"column",children:[G(M,{item:!0,children:o.label}),o.afterLabel&&G(M,{item:!0,children:o.afterLabel})]})):Fe("li",{...l,key:o},o),ListboxComponent:go(function(o,E){return O(X,{children:[G("ul",{...o,ref:E}),!!c&&G("div",{...o,children:O(X,{children:[G(M,{px:2,py:1,children:G(ye,{})}),c]})},"searchable-footer")]})}),...s,renderInput:l=>G(ko,{error:!!p,placeholder:F,...l,...g,inputRef:z})},e),G(T,{name:e,disableIcon:P})]})})},Ro=Co(Vo);import{forwardRef as Ao,memo as Do}from"react";import{Controller as $o,useFormContext as Mo}from"react-hook-form";import{isObject as zo,isEmpty as qo}from"lodash-es";import{Grid as U,Autocomplete as _o,TextField as Oo}from"@mui/material";import{LIcon as Z,Tooltip as Uo,Button as jo,Divider as No}from"@s_mart/core";import{colorPalette as Ho}from"@s_mart/tokens";import{linePlus as ge,linePen as Wo,lineInfoCircle as Yo}from"@s_mart/solid-icons";import{toRem as Ce}from"@s_mart/utils";import{toRem as Q}from"@s_mart/utils";import Eo from"@emotion/styled";import{css as Pe}from"@emotion/react";var be=Pe`
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
`,Bo=e=>Pe`
|
|
6
|
+
.creatable,
|
|
7
|
+
.editable {
|
|
8
|
+
${be}
|
|
9
|
+
|
|
10
|
+
.divider {
|
|
11
|
+
width: 1px;
|
|
12
|
+
height: ${Q(20)};
|
|
13
|
+
background-color: ${e.palette.grey[400]};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.button {
|
|
17
|
+
display: flex;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
align-items: center;
|
|
20
|
+
color: ${e.palette.grey[600]};
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
|
|
23
|
+
margin: 0 ${Q(6)};
|
|
24
|
+
width: ${Q(28)};
|
|
25
|
+
height: ${Q(28)};
|
|
26
|
+
|
|
27
|
+
&:hover {
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
background-color: ${e.palette.grey[100]};
|
|
30
|
+
transition: background-color 0.2s ease-in-out;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`,he=Eo.div`
|
|
35
|
+
display: flex;
|
|
36
|
+
|
|
37
|
+
div.endAdornments {
|
|
38
|
+
position: absolute;
|
|
39
|
+
right: 0;
|
|
40
|
+
|
|
41
|
+
${be}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.MuiAutocomplete-endAdornment {
|
|
45
|
+
position: relative;
|
|
46
|
+
right: 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
${({hideAddButton:e,theme:r})=>!e&&Bo(r)}
|
|
50
|
+
`;import{Fragment as ae,jsx as h,jsxs as A}from"react/jsx-runtime";import{createElement as ve}from"react";var Jo=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,required:b,options:m,editable:g,footer:I,onEditOption:c,onCreateOption:u,textFieldProps:a,hideAddButton:F,multiple:d,info:x,onChange:P,onInputChange:s,placeholder:C,disableIconError:p,...f})=>{let R=Mo();if(!R)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let z=V(R.formState.errors,e),l=F||f.disabled,o=k=>{let q=0;return a?.InputProps||(q+=2.5),l||(q+=2.56,E(k)&&(q+=2.56)),!f.disableClearable&&!f.disabled&&(q+=1.3),q+"rem"},E=k=>f.disabled?!1:g&&zo(k)&&!qo(k);console.warn=()=>{};let w=k=>{u?u(k):console.error("onCreateOption n\xE3o foi definido")},N=k=>{c?c(k):console.error("onEditOption n\xE3o foi definido")};return h($o,{control:R.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:k,onChange:q,ref:Le}})=>{let se=k?.label||k?.value||k;return A(U,{display:"flex",flexDirection:"column",children:[A("div",{style:{display:"flex"},children:[n&&h(U,{item:!0,children:h(v,{label:n,required:b})}),x&&h(U,{item:!0,children:h(Uo,{title:x,placement:"top",children:h("div",{style:{width:"fit-content"},children:h(Z,{icon:Yo,color:"#757575"})})})})]}),h(he,{hideAddButton:l,children:h(_o,{fullWidth:!0,onChange:(S,y)=>{q(y),P?.(y,R.getValues())},onInputChange:(S,y,te)=>{te==="input"&&setTimeout(()=>{s?.(y,R.getValues())},0)},slotProps:{...f.slotProps||{},paper:{...(f.slotProps||{}).paper||{},sx:{border:`1px solid ${Ho.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(f.slotProps||{}).paper?.sx||{}}}},options:m,value:k||(d?[]:null),multiple:d,readOnly:f.disabled,noOptionsText:l?void 0:A(jo,{sx:{justifyContent:"flex-start",padding:`${Ce(6)} ${Ce(-16)}`,margin:0},fullWidth:!0,onClick:()=>w(k),variant:"text",startIcon:h(Z,{icon:ge}),children:["Adicionar ",se&&`"${se}"`]}),isOptionEqualToValue:(S,y)=>y?typeof S=="string"&&typeof y=="string"?S===y:typeof S=="object"&&typeof y=="object"?typeof S.value=="object"&&typeof y.value=="object"&&S.key!==void 0&&y.key!==void 0?S.key===y.key:S.value===y.value:typeof S=="object"&&typeof y=="string":!1,renderOption:(S,y)=>typeof y=="object"?ve("li",{...S,key:y.key||y.value},A(U,{container:!0,direction:"column",children:[h(U,{item:!0,children:y.label}),y.afterLabel&&h(U,{item:!0,children:y.afterLabel})]})):ve("li",{...S,key:y},y),ListboxComponent:Ao(function(y,te){return A(ae,{children:[h("ul",{...y,ref:te}),!!I&&h("div",{...y,children:A(ae,{children:[h(U,{px:2,py:1,children:h(No,{})}),I]})},"creatable-footer")]})}),...f,sx:{"& div.MuiInputBase-root":{paddingRight:`${o(k)} !important`},...f.sx},renderInput:S=>h(Oo,{placeholder:C,...S,error:!!z,InputProps:{...S.InputProps,inputRef:Le,endAdornment:A("div",{className:"endAdornments",children:[S.InputProps.endAdornment,!l&&A(ae,{children:[E(k)?A("div",{className:"editable",children:[h("div",{className:"divider"}),h("div",{className:"button",onClick:()=>N(k),children:h(Z,{icon:Wo,size:"24px",removeMargin:!0})})]}):null,A("div",{className:"creatable",children:[h("div",{className:"divider"}),h("div",{className:"button",onClick:()=>w(k),children:h(Z,{icon:ge,size:"24px",removeMargin:!0})})]})]})]})},...a})},e)}),h(T,{name:e,disableIcon:p})]})}})},Ko=Do(Jo);import{Controller as Xo,useFormContext as Qo}from"react-hook-form";import{Grid as Zo,Checkbox as er,FormControlLabel as or}from"@mui/material";import{jsx as Y,jsxs as ir}from"react/jsx-runtime";var rr=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,labelPlacement:b,required:m,disableIconError:g,onChange:I,...c})=>{let u=Qo();if(!u)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Y(Xo,{control:u.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:a,onChange:F}})=>ir(Zo,{display:"flex",flexDirection:"column",children:[Y(or,{control:Y(er,{checked:!!a,value:a??"",defaultValue:a,onChange:(d,x)=>{F(d,x),I?.(d,x)},...c},e),label:Y(v,{label:n,required:m,regular:!0}),labelPlacement:b||"end"}),Y(T,{name:e,disableIcon:g})]})})},tr=rr;import{Controller as lr,useFormContext as nr}from"react-hook-form";import{Grid as ar,Switch as sr,FormControlLabel as dr}from"@mui/material";import{jsx as J,jsxs as ur}from"react/jsx-runtime";var pr=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,labelPlacement:b,disableIconError:m,onChange:g,...I})=>{let c=nr();if(!c)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return J(lr,{control:c.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:u,onChange:a}})=>ur(ar,{display:"flex",flexDirection:"column",children:[J(dr,{control:J(sr,{value:u??"",checked:u??!1,defaultValue:u,onChange:(F,d)=>{a(F,d),g?.(F,d)},...I},e),label:J(v,{label:n}),labelPlacement:b||"end"}),J(T,{name:e,disableIcon:m})]})})},mr=pr;import{Grid as fr,Radio as cr,FormControlLabel as xr}from"@mui/material";import{jsx as ee}from"react/jsx-runtime";var yr=({label:e,labelPlacement:r,...i})=>ee(fr,{display:"flex",flexDirection:"column",children:ee(xr,{control:ee(cr,{...i}),label:ee(v,{label:e}),labelPlacement:r||"end"})}),Fr=yr;import{Controller as Pr,useFormContext as br}from"react-hook-form";import{Grid as hr,RadioGroup as gr}from"@mui/material";import{jsx as oe,jsxs as Ir}from"react/jsx-runtime";var Cr=({name:e,rules:r,defaultValue:i,shouldUnregister:t,label:n,required:b,children:m,orientation:g="row",disableIconError:I,...c})=>{let u=br();if(!u)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return oe(Pr,{control:u.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:a,onChange:F}})=>Ir(hr,{display:"flex",flexDirection:"column",children:[n&&oe(v,{label:n,required:b}),oe(gr,{value:a||"",name:e,...c,onChange:d=>{c?.onChange?.(d,d.target?.value),F(d)},style:{display:"flex",flexDirection:g},children:m},e),oe(T,{name:e,disableIcon:I})]})})},vr=Cr;import{Controller as Tr,useFormContext as kr}from"react-hook-form";import{Slider as wr}from"@mui/material";import{jsx as Ie}from"react/jsx-runtime";var Sr=({name:e,rules:r,defaultValue:i,shouldUnregister:t,...n})=>{let b=kr();if(!b)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Ie(Tr,{control:b.control,name:e,rules:r,defaultValue:i,shouldUnregister:t,render:({field:{value:m,onChange:g}})=>Ie(wr,{value:m||n?.min||0,onChange:g,valueLabelDisplay:"auto",...n},e)})},Gr=Sr;import{memo as Br}from"react";import{Controller as Ar,useFormContext as Dr}from"react-hook-form";import{Grid as $r}from"@s_mart/core";import{composeValidators as Mr,date as ke}from"@s_mart/rules";import{TextField as zr}from"@mui/material";import{DatePicker as qr}from"@mui/x-date-pickers/DatePicker";import{AdapterDayjs as _r}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as Or}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as Ur}from"@mui/x-date-pickers/locales/ptBR";import jr from"dayjs/locale/pt-br";import Lr from"@emotion/styled";import{IconButton as Vr}from"@mui/material";import{toRem as D}from"@s_mart/utils";var Rr=e=>{switch(e){case"small":return D(16);default:case"medium":return D(20);case"large":return D(24)}},Er=e=>{switch(e){case"small":return`${D(2)} ${D(8)}`;default:case"medium":return`${D(6)} ${D(8)}`;case"large":return`${D(10)}`}},Te=Lr(Vr)`
|
|
51
|
+
margin: 0px;
|
|
52
|
+
|
|
53
|
+
padding: ${({size:e})=>Er(e)};
|
|
54
|
+
border-radius: 0 ${D(4)} ${D(4)} 0;
|
|
55
|
+
|
|
56
|
+
svg {
|
|
57
|
+
width: ${({size:e})=>Rr(e)} !important;
|
|
58
|
+
}
|
|
59
|
+
`;import{jsx as K,jsxs as Yr}from"react/jsx-runtime";import{createElement as Wr}from"react";var Nr=({rules:e,name:r,defaultValue:i,shouldUnregister:t,datePickerProps:n,label:b,required:m,placeholder:g,disabled:I,disableIconError:c,...u})=>{let a=Dr();if(!a)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let F=V(a.formState.errors,r),d=n?.format||"DD/MM/YYYY",x=e?Mr([ke(d),e]):ke(d);return K(Or,{dateAdapter:_r,adapterLocale:jr,localeText:Ur.components.MuiLocalizationProvider.defaultProps.localeText,children:K(Ar,{control:a.control,name:r,rules:x,defaultValue:i,shouldUnregister:t,render:({field:{value:P,onChange:s,ref:C}})=>Yr($r,{display:"flex",flexDirection:"column",children:[b&&K(v,{label:b,required:m}),Wr(qr,{...n,key:r,value:P??null,format:d,onChange:(p,f)=>{s(p,f),n?.onChange?.(p,f)},disabled:I,slots:{textField:zr,openPickerButton:p=>K(Te,{...p,size:u.size})},slotProps:{textField:p=>({variant:"outlined",...p,error:!!F,...u,inputProps:{...p.inputProps,placeholder:g||p.inputProps?.placeholder},InputProps:{...p.InputProps,inputRef(f){C(f),typeof p.inputRef=="function"&&p.inputRef(f)}}})}}),K(T,{name:r,disableIcon:c})]})})})},Hr=Br(Nr);import{memo as Zr}from"react";import{Controller as et,useFormContext as ot}from"react-hook-form";import{Grid as rt}from"@s_mart/core";import{composeValidators as tt,time as Se}from"@s_mart/rules";import{TextField as it}from"@mui/material";import{TimePicker as lt}from"@mui/x-date-pickers/TimePicker";import{AdapterDayjs as nt}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as at}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as st}from"@mui/x-date-pickers/locales/ptBR";import dt from"dayjs/locale/pt-br";import Jr from"@emotion/styled";import{IconButton as Kr}from"@mui/material";import{toRem as $}from"@s_mart/utils";var Xr=e=>{switch(e){case"small":return $(16);default:case"medium":return $(20);case"large":return $(24)}},Qr=e=>{switch(e){case"small":return`${$(2)} ${$(8)}`;default:case"medium":return`${$(6)} ${$(8)}`;case"large":return`${$(10)}`}},we=Jr(Kr)`
|
|
60
|
+
margin: 0px;
|
|
61
|
+
|
|
62
|
+
padding: ${({size:e})=>Qr(e)};
|
|
63
|
+
border-radius: 0 ${$(4)} ${$(4)} 0;
|
|
64
|
+
|
|
65
|
+
svg {
|
|
66
|
+
width: ${({size:e})=>Xr(e)} !important;
|
|
67
|
+
}
|
|
68
|
+
`;import{jsx as H,jsxs as ut}from"react/jsx-runtime";var pt=({rules:e,defaultValue:r,shouldUnregister:i,name:t,required:n,label:b,timePickerProps:m,placeholder:g,disabled:I,disableIconError:c,...u})=>{let a=ot();if(!a)throw new Error("Para usar o <TimePicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let F=V(a.formState.errors,t),d=m?.format||"HH:mm",x=e?tt([Se(d),e]):Se(d);return H(at,{dateAdapter:nt,adapterLocale:dt,localeText:st.components.MuiLocalizationProvider.defaultProps.localeText,children:H(et,{control:a.control,name:t,rules:x,defaultValue:r,shouldUnregister:i,render:({field:{value:P,onChange:s,ref:C}})=>ut(rt,{display:"flex",flexDirection:"column",children:[b&&H(v,{label:b,required:n}),H(lt,{ampm:!1,format:d,value:P??null,disabled:I,...m,onChange:(p,f)=>{s(p,f),m?.onChange?.(p,f)},slots:{textField:it,openPickerButton:p=>H(we,{...p,size:u.size})},slotProps:{textField:p=>({variant:"outlined",...p,error:!!F,...u,inputProps:{...p.inputProps,placeholder:g||p.inputProps?.placeholder},InputProps:{...p.InputProps,inputRef(f){C(f),typeof p.inputRef=="function"&&p.inputRef(f)}}})}},t),H(T,{name:t,disableIcon:c})]})})})},mt=Zr(pt);import{memo as ft}from"react";import{Controller as ct,useFormContext as xt}from"react-hook-form";import{Autocomplete as yt,TextField as Ft}from"@mui/material";import{Grid as re}from"@s_mart/core";import{colorPalette as Pt}from"@s_mart/tokens";import{jsx as j,jsxs as Ge}from"react/jsx-runtime";import{createElement as gt}from"react";var bt=({name:e,defaultValue:r,rules:i,shouldUnregister:t,label:n,required:b,noOptionsText:m,placeholder:g,onInputChange:I,onChange:c,disableIconError:u,...a})=>{let F=xt();if(!F)throw new Error("Para usar o <Autocomplete /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let d=V(F.formState.errors,e);return console.warn=()=>{},j(ct,{name:e,control:F.control,defaultValue:r,rules:i,shouldUnregister:t,render:({field:x})=>Ge(re,{display:"flex",flexDirection:"column",children:[n&&j(v,{label:n,required:b}),j(yt,{onChange:(P,s)=>{x.onChange(s),c?.(s,F.getValues())},onInputChange:(P,s,C)=>{C==="input"&&(x.onChange(s),setTimeout(()=>{I?.(s,F.getValues())},0))},slotProps:{...a.slotProps||{},paper:{...(a.slotProps||{}).paper||{},sx:{border:`1px solid ${Pt.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(a.slotProps||{}).paper?.sx||{}}}},isOptionEqualToValue:(P,s)=>P.value===s.value,renderOption:(P,s)=>gt("li",{...P,key:s.key||s.value,onClick:C=>{P.onClick?.(C),x.onChange(s)}},Ge(re,{container:!0,direction:"column",children:[j(re,{item:!0,children:s.label}),s.afterLabel&&j(re,{item:!0,children:s.afterLabel})]})),value:x.value||null,readOnly:a.disabled,noOptionsText:m||"Nenhuma op\xE7\xE3o encontrada",...a,renderInput:P=>j(Ft,{placeholder:g,...P,...a.textFieldProps,error:!!d,InputProps:{...P.InputProps,...a.textFieldProps?.InputProps,inputRef:x.ref,inputProps:{...P.inputProps,...a.textFieldProps?.InputProps?.inputProps}}})},e),j(T,{name:e,disableIcon:u})]})})},ht=ft(bt);export{ht as Autocomplete,tr as Checkbox,Ko as Creatable,Hr as DatePicker,v as FieldLabel,Me as Form,ie as FormProvider,Fr as RadioButton,vr as RadioGroup,Ro as Searchable,bo as Select,Gr as Slider,mr as Switch,to as TextField,mt as TimePicker,le as useForm};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@s_mart/form",
|
|
3
|
+
"version": "0.0.0-font-awesome-20240308181754",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@hookform/resolvers": "^3.1.0",
|
|
14
|
+
"dayjs": "^1.11.10",
|
|
15
|
+
"@types/react": "^18.2.21",
|
|
16
|
+
"@types/react-dom": "^18.2.7",
|
|
17
|
+
"@types/lodash-es": ">=4.17.12",
|
|
18
|
+
"lodash-es": "^4.17.21",
|
|
19
|
+
"tsup": "^6.7.0",
|
|
20
|
+
"typescript": "^5.2.2",
|
|
21
|
+
"@s_mart/core": "0.0.0-font-awesome-20240308181754",
|
|
22
|
+
"@s_mart/masks": "0.0.0-font-awesome-20240308181754",
|
|
23
|
+
"eslint-config-smarten": "4.0.1",
|
|
24
|
+
"@s_mart/rules": "0.0.0-font-awesome-20240308181754",
|
|
25
|
+
"@s_mart/solid-icons": "0.0.0-font-awesome-20240308181754",
|
|
26
|
+
"@s_mart/regular-icons": "0.0.0-font-awesome-20240308181754",
|
|
27
|
+
"@s_mart/tokens": "0.0.0-font-awesome-20240308181754",
|
|
28
|
+
"@s_mart/typed": "0.0.0-font-awesome-20240308181754",
|
|
29
|
+
"@s_mart/tsconfig": "0.0.0-font-awesome-20240308181754",
|
|
30
|
+
"@s_mart/utils": "0.0.0-font-awesome-20240308181754"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@emotion/react": ">=11.10.8",
|
|
34
|
+
"@emotion/styled": ">=11.10.8",
|
|
35
|
+
"@mui/material": ">=5.14.6",
|
|
36
|
+
"@mui/x-date-pickers": ">=6.3.0",
|
|
37
|
+
"@types/react": ">=18.2.5",
|
|
38
|
+
"@types/react-dom": ">=18.2.7",
|
|
39
|
+
"@types/lodash-es": ">=4.17.12",
|
|
40
|
+
"dayjs": "^1.11.10",
|
|
41
|
+
"react": ">=18.2.0",
|
|
42
|
+
"react-dom": ">=18.2.0",
|
|
43
|
+
"react-hook-form": ">=7.36.1",
|
|
44
|
+
"typescript": ">=5.2.2",
|
|
45
|
+
"zod": ">=3.21.4",
|
|
46
|
+
"@s_mart/core": "0.0.0-font-awesome-20240308181754",
|
|
47
|
+
"@s_mart/masks": "0.0.0-font-awesome-20240308181754",
|
|
48
|
+
"@s_mart/rules": "0.0.0-font-awesome-20240308181754",
|
|
49
|
+
"@s_mart/tokens": "0.0.0-font-awesome-20240308181754",
|
|
50
|
+
"@s_mart/typed": "0.0.0-font-awesome-20240308181754",
|
|
51
|
+
"@s_mart/utils": "0.0.0-font-awesome-20240308181754"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"eslint": "^8.47.0"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup src/index.tsx --minify --format esm --dts --external react",
|
|
58
|
+
"dev": "tsup src/index.tsx --format esm --watch --dts --external react",
|
|
59
|
+
"lint": "eslint src/**/*.ts* --fix"
|
|
60
|
+
}
|
|
61
|
+
}
|