@ttoss/forms 0.19.0 → 0.21.0

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/esm/index.js CHANGED
@@ -141,9 +141,12 @@ var FormField = ({
141
141
  id: idProp,
142
142
  name,
143
143
  defaultValue,
144
+ disabled,
145
+ tooltip,
146
+ onTooltipClick,
144
147
  sx,
145
- render,
146
- ...formFieldProps
148
+ css,
149
+ render
147
150
  }) => {
148
151
  const controllerReturn = useController({
149
152
  name,
@@ -154,10 +157,10 @@ var FormField = ({
154
157
  return React2.Children.map(render(controllerReturn), child => {
155
158
  return /* @__PURE__ */jsxs(Fragment, {
156
159
  children: [label && /* @__PURE__ */jsx3(Label, {
157
- "aria-disabled": formFieldProps.disabled,
160
+ "aria-disabled": disabled,
158
161
  htmlFor: id,
159
- tooltip: formFieldProps.tooltip,
160
- onTooltipClick: formFieldProps.onTooltipClick,
162
+ tooltip,
163
+ onTooltipClick,
161
164
  children: label
162
165
  }), /*#__PURE__*/React2.createElement(child.type, {
163
166
  id,
@@ -165,7 +168,7 @@ var FormField = ({
165
168
  })]
166
169
  });
167
170
  });
168
- }, [controllerReturn, formFieldProps.disabled, formFieldProps.onTooltipClick, formFieldProps.tooltip, id, label, render]);
171
+ }, [controllerReturn, disabled, onTooltipClick, tooltip, id, label, render]);
169
172
  return /* @__PURE__ */jsxs(Flex, {
170
173
  sx: {
171
174
  flexDirection: "column",
@@ -173,6 +176,7 @@ var FormField = ({
173
176
  gap: "md",
174
177
  ...sx
175
178
  },
179
+ css,
176
180
  children: [memoizedRender, /* @__PURE__ */jsx3(ErrorMessage, {
177
181
  name
178
182
  })]
@@ -235,38 +239,109 @@ var FormFieldCheckbox = ({
235
239
  });
236
240
  };
237
241
 
238
- // src/FormFieldNumericFormat.tsx
242
+ // src/FormFieldPatternFormat.tsx
239
243
  import { Input } from "@ttoss/ui";
240
- import { NumericFormat } from "react-number-format";
244
+ import { PatternFormat } from "react-number-format";
241
245
  import { jsx as jsx5 } from "react/jsx-runtime";
246
+ var FormFieldPatternFormat = ({
247
+ label,
248
+ name,
249
+ ...patternFormatProps
250
+ }) => {
251
+ return /* @__PURE__ */jsx5(FormField, {
252
+ name,
253
+ label,
254
+ render: ({
255
+ field,
256
+ fieldState
257
+ }) => {
258
+ return /* @__PURE__ */jsx5(PatternFormat, {
259
+ name: field.name,
260
+ value: field.value,
261
+ onBlur: field.onBlur,
262
+ onValueChange: values => {
263
+ field.onChange(values.value);
264
+ },
265
+ customInput: Input,
266
+ "aria-invalid": Boolean(fieldState.error).valueOf(),
267
+ ...patternFormatProps
268
+ });
269
+ }
270
+ });
271
+ };
272
+
273
+ // src/FormFieldCreditCardNumber.tsx
274
+ import { jsx as jsx6 } from "react/jsx-runtime";
275
+ var FormFieldCreditCardNumber = ({
276
+ label,
277
+ name,
278
+ ...formFieldPatternFormatProps
279
+ }) => {
280
+ return /* @__PURE__ */jsx6(FormFieldPatternFormat, {
281
+ name,
282
+ label,
283
+ format: "#### #### #### ####",
284
+ placeholder: "1234 1234 1234 1234",
285
+ ...formFieldPatternFormatProps
286
+ });
287
+ };
288
+
289
+ // src/FormFieldNumericFormat.tsx
290
+ import { Input as Input2 } from "@ttoss/ui";
291
+ import { NumericFormat } from "react-number-format";
292
+ import { jsx as jsx7 } from "react/jsx-runtime";
242
293
  var FormFieldNumericFormat = ({
243
294
  label,
244
295
  name,
245
296
  ...numericFormatProps
246
297
  }) => {
247
- return /* @__PURE__ */jsx5(FormField, {
298
+ return /* @__PURE__ */jsx7(FormField, {
248
299
  label,
249
300
  name,
250
301
  render: ({
251
302
  field
252
303
  }) => {
253
- return /* @__PURE__ */jsx5(NumericFormat, {
304
+ return /* @__PURE__ */jsx7(NumericFormat, {
254
305
  name: field.name,
255
306
  value: field.value,
256
307
  onBlur: field.onBlur,
257
308
  onValueChange: values => {
258
309
  field.onChange(values.floatValue);
259
310
  },
260
- customInput: Input,
311
+ customInput: Input2,
261
312
  ...numericFormatProps
262
313
  });
263
314
  }
264
315
  });
265
316
  };
266
317
 
318
+ // src/FormFieldCurrencyInput.tsx
319
+ import { jsx as jsx8 } from "react/jsx-runtime";
320
+ var FormFieldCurrencyInput = ({
321
+ label,
322
+ name,
323
+ prefix,
324
+ decimalSeparator,
325
+ thousandSeparator,
326
+ ...formFieldNumericFormatProps
327
+ }) => {
328
+ return /* @__PURE__ */jsx8(FormFieldNumericFormat, {
329
+ name,
330
+ label,
331
+ fixedDecimalScale: true,
332
+ decimalScale: 2,
333
+ prefix,
334
+ decimalSeparator,
335
+ thousandSeparator,
336
+ placeholder: `${prefix} 0${decimalSeparator}00`,
337
+ allowNegative: false,
338
+ ...formFieldNumericFormatProps
339
+ });
340
+ };
341
+
267
342
  // src/FormFieldInput.tsx
268
- import { Input as Input2 } from "@ttoss/ui";
269
- import { jsx as jsx6 } from "react/jsx-runtime";
343
+ import { Input as Input3 } from "@ttoss/ui";
344
+ import { jsx as jsx9 } from "react/jsx-runtime";
270
345
  var FormFieldInput = ({
271
346
  label,
272
347
  name,
@@ -276,7 +351,7 @@ var FormFieldInput = ({
276
351
  defaultValue = "",
277
352
  ...inputProps
278
353
  }) => {
279
- return /* @__PURE__ */jsx6(FormField, {
354
+ return /* @__PURE__ */jsx9(FormField, {
280
355
  name,
281
356
  label,
282
357
  disabled: inputProps.disabled,
@@ -288,7 +363,7 @@ var FormFieldInput = ({
288
363
  field,
289
364
  fieldState
290
365
  }) => {
291
- return /* @__PURE__ */jsx6(Input2, {
366
+ return /* @__PURE__ */jsx9(Input3, {
292
367
  ...inputProps,
293
368
  ...field,
294
369
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -299,7 +374,7 @@ var FormFieldInput = ({
299
374
 
300
375
  // src/FormFieldPassword.tsx
301
376
  import { InputPassword } from "@ttoss/ui";
302
- import { jsx as jsx7 } from "react/jsx-runtime";
377
+ import { jsx as jsx10 } from "react/jsx-runtime";
303
378
  var FormFieldPassword = ({
304
379
  label,
305
380
  name,
@@ -309,7 +384,7 @@ var FormFieldPassword = ({
309
384
  defaultValue = "",
310
385
  ...inputProps
311
386
  }) => {
312
- return /* @__PURE__ */jsx7(FormField, {
387
+ return /* @__PURE__ */jsx10(FormField, {
313
388
  name,
314
389
  label,
315
390
  disabled: inputProps.disabled,
@@ -321,7 +396,7 @@ var FormFieldPassword = ({
321
396
  field,
322
397
  fieldState
323
398
  }) => {
324
- return /* @__PURE__ */jsx7(InputPassword, {
399
+ return /* @__PURE__ */jsx10(InputPassword, {
325
400
  ...inputProps,
326
401
  ...field,
327
402
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -333,7 +408,7 @@ var FormFieldPassword = ({
333
408
  // src/FormFieldRadio.tsx
334
409
  import { Box as Box2, Flex as Flex3, Label as Label3, Radio } from "@ttoss/ui";
335
410
  import { useController as useController3 } from "react-hook-form";
336
- import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
411
+ import { jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
337
412
  var FormFieldRadio = ({
338
413
  label,
339
414
  name,
@@ -358,17 +433,17 @@ var FormFieldRadio = ({
358
433
  width: "100%",
359
434
  ...sx
360
435
  },
361
- children: [label && /* @__PURE__ */jsx8(Label3, {
436
+ children: [label && /* @__PURE__ */jsx11(Label3, {
362
437
  sx: {
363
438
  marginBottom: "md"
364
439
  },
365
440
  children: label
366
- }), /* @__PURE__ */jsx8(Box2, {
441
+ }), /* @__PURE__ */jsx11(Box2, {
367
442
  children: options.map(option => {
368
443
  const id = `form-field-radio-${name}-${option.value}`;
369
444
  return /* @__PURE__ */jsxs3(Label3, {
370
445
  htmlFor: id,
371
- children: [/* @__PURE__ */jsx8(Radio, {
446
+ children: [/* @__PURE__ */jsx11(Radio, {
372
447
  ref,
373
448
  onChange,
374
449
  onBlur,
@@ -380,7 +455,7 @@ var FormFieldRadio = ({
380
455
  }), option.label]
381
456
  }, id);
382
457
  })
383
- }), /* @__PURE__ */jsx8(ErrorMessage, {
458
+ }), /* @__PURE__ */jsx11(ErrorMessage, {
384
459
  name
385
460
  })]
386
461
  });
@@ -388,75 +463,48 @@ var FormFieldRadio = ({
388
463
 
389
464
  // src/FormFieldSelect.tsx
390
465
  import { Select } from "@ttoss/ui";
391
- import { jsx as jsx9 } from "react/jsx-runtime";
392
- var checkDefaultValue = ({
393
- options,
394
- defaultValue,
395
- placeholder
396
- }) => {
397
- if (defaultValue) {
398
- return defaultValue;
399
- }
400
- const hasEmptyValue = options.some(opt => {
401
- return opt.value === "" || opt.value === 0;
402
- });
403
- const EMPTY_VALUE = "";
404
- if (placeholder && hasEmptyValue) {
405
- return EMPTY_VALUE;
406
- }
407
- if (placeholder && !hasEmptyValue) {
408
- options.unshift({
409
- label: placeholder,
410
- value: ""
411
- });
412
- return EMPTY_VALUE;
413
- }
414
- if (!placeholder && defaultValue) return EMPTY_VALUE;
415
- if (options.length === 0) return EMPTY_VALUE;
416
- return options?.[0]?.value;
417
- };
466
+ import { jsx as jsx12 } from "react/jsx-runtime";
418
467
  var FormFieldSelect = ({
419
468
  label,
420
469
  name,
421
- options,
470
+ id,
471
+ defaultValue,
422
472
  sx,
473
+ css,
474
+ disabled,
475
+ tooltip,
476
+ onTooltipClick,
423
477
  ...selectProps
424
478
  }) => {
425
- const {
426
- defaultValue,
427
- placeholder
428
- } = selectProps;
429
- const checkedDefaultValue = checkDefaultValue({
430
- options,
431
- defaultValue,
432
- placeholder
433
- });
434
- return /* @__PURE__ */jsx9(FormField, {
479
+ return /* @__PURE__ */jsx12(FormField, {
435
480
  name,
436
481
  label,
437
- disabled: selectProps.disabled,
438
- tooltip: selectProps.tooltip,
439
- onTooltipClick: selectProps.onTooltipClick,
482
+ id,
483
+ defaultValue,
484
+ disabled,
485
+ tooltip,
486
+ onTooltipClick,
440
487
  sx,
441
- defaultValue: checkedDefaultValue,
488
+ css,
442
489
  render: ({
443
490
  field,
444
491
  fieldState
445
492
  }) => {
446
- return /* @__PURE__ */jsx9(Select, {
493
+ const value = selectProps.options?.find(option => {
494
+ if ("value" in option) {
495
+ return option.value === field.value;
496
+ }
497
+ return false;
498
+ });
499
+ return /* @__PURE__ */jsx12(Select, {
447
500
  ...selectProps,
448
501
  ...field,
449
- ...{
450
- ...selectProps,
451
- defaultValue: void 0
502
+ defaultValue: value,
503
+ value,
504
+ onChange: value2 => {
505
+ field.onChange(value2?.value);
452
506
  },
453
- "aria-invalid": fieldState.error ? "true" : void 0,
454
- children: options.map(option => {
455
- return /* @__PURE__ */jsx9("option", {
456
- value: option.value,
457
- children: option.label
458
- }, option.label);
459
- })
507
+ "aria-invalid": fieldState.error ? "true" : void 0
460
508
  });
461
509
  }
462
510
  });
@@ -464,7 +512,7 @@ var FormFieldSelect = ({
464
512
 
465
513
  // src/FormFieldTextarea.tsx
466
514
  import { Textarea } from "@ttoss/ui";
467
- import { jsx as jsx10 } from "react/jsx-runtime";
515
+ import { jsx as jsx13 } from "react/jsx-runtime";
468
516
  var FormFieldTextarea = ({
469
517
  label,
470
518
  name,
@@ -472,7 +520,7 @@ var FormFieldTextarea = ({
472
520
  ...textareaProps
473
521
  }) => {
474
522
  const id = `form-field-textarea-${name}`;
475
- return /* @__PURE__ */jsx10(FormField, {
523
+ return /* @__PURE__ */jsx13(FormField, {
476
524
  label,
477
525
  name,
478
526
  id,
@@ -481,7 +529,7 @@ var FormFieldTextarea = ({
481
529
  field,
482
530
  fieldState
483
531
  }) => {
484
- return /* @__PURE__ */jsx10(Textarea, {
532
+ return /* @__PURE__ */jsx13(Textarea, {
485
533
  ...field,
486
534
  ...textareaProps,
487
535
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -493,7 +541,7 @@ var FormFieldTextarea = ({
493
541
  // src/FormGroup.tsx
494
542
  import * as React3 from "react";
495
543
  import { Box as Box3, Flex as Flex4, Text } from "@ttoss/ui";
496
- import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
544
+ import { jsx as jsx14, jsxs as jsxs4 } from "react/jsx-runtime";
497
545
  var FormGroupLevelsManagerContext = /*#__PURE__*/React3.createContext({
498
546
  levelsLength: 1,
499
547
  registerChild: () => {
@@ -509,7 +557,7 @@ var FormGroupLevelsManager = ({
509
557
  setLevelsLength(level + 1);
510
558
  }
511
559
  }, [levelsLength]);
512
- return /* @__PURE__ */jsx11(FormGroupLevelsManagerContext.Provider, {
560
+ return /* @__PURE__ */jsx14(FormGroupLevelsManagerContext.Provider, {
513
561
  value: {
514
562
  levelsLength,
515
563
  registerChild
@@ -560,18 +608,18 @@ var FormGroupWrapper = ({
560
608
  marginBottom: "lg",
561
609
  ...boxProps.sx
562
610
  },
563
- children: [title && /* @__PURE__ */jsx11(Box3, {
611
+ children: [title && /* @__PURE__ */jsx14(Box3, {
564
612
  sx: {
565
613
  marginBottom: "md"
566
614
  },
567
- children: /* @__PURE__ */jsx11(Text, {
615
+ children: /* @__PURE__ */jsx14(Text, {
568
616
  sx: {
569
617
  fontSize: "2xl",
570
618
  fontWeight: "bold"
571
619
  },
572
620
  children: title
573
621
  })
574
- }), /* @__PURE__ */jsx11(Flex4, {
622
+ }), /* @__PURE__ */jsx14(Flex4, {
575
623
  sx: childrenContainerSx,
576
624
  children
577
625
  })]
@@ -582,17 +630,17 @@ var FormGroup = props => {
582
630
  level
583
631
  } = useFormGroup();
584
632
  const currentLevel = level === void 0 ? 0 : level + 1;
585
- return /* @__PURE__ */jsx11(FormGroupContext.Provider, {
633
+ return /* @__PURE__ */jsx14(FormGroupContext.Provider, {
586
634
  value: {
587
635
  parentLevel: currentLevel
588
636
  },
589
- children: currentLevel === 0 ? /* @__PURE__ */jsx11(FormGroupLevelsManager, {
590
- children: /* @__PURE__ */jsx11(FormGroupWrapper, {
637
+ children: currentLevel === 0 ? /* @__PURE__ */jsx14(FormGroupLevelsManager, {
638
+ children: /* @__PURE__ */jsx14(FormGroupWrapper, {
591
639
  ...props
592
640
  })
593
- }) : /* @__PURE__ */jsx11(FormGroupWrapper, {
641
+ }) : /* @__PURE__ */jsx14(FormGroupWrapper, {
594
642
  ...props
595
643
  })
596
644
  });
597
645
  };
598
- export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup, yup, yupResolver };
646
+ export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup, yup, yupResolver };
package/dist/index.d.mts CHANGED
@@ -1,13 +1,13 @@
1
1
  export { yupResolver } from '@hookform/resolvers/yup';
2
2
  import * as react_hook_form from 'react-hook-form';
3
- import { FieldValues, FieldPath, FieldPathValue, UseControllerReturn } from 'react-hook-form';
3
+ import { FieldValues, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
4
4
  export * from 'react-hook-form';
5
5
  import * as yup from 'yup';
6
6
  export { yup };
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import * as React from 'react';
9
- import { BoxProps, FlexProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
- import { NumericFormatProps } from 'react-number-format';
9
+ import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
+ import { PatternFormatProps, NumericFormatProps } from 'react-number-format';
11
11
 
12
12
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
13
13
  children?: React.ReactNode;
@@ -17,32 +17,52 @@ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children,
17
17
  children: React.ReactNode | React.ReactNode[];
18
18
  } & react_hook_form.UseFormReturn<TFieldValues, any, undefined>) => react_jsx_runtime.JSX.Element;
19
19
 
20
- type FormFieldProps = {
21
- sx?: FlexProps['sx'];
22
- disabled?: boolean;
23
- tooltip?: boolean;
24
- onTooltipClick?: () => void;
25
- };
26
- type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
20
+ type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
27
21
  label?: string;
28
22
  id?: string;
29
23
  name: TName;
30
24
  defaultValue?: FieldPathValue<TFieldValues, TName>;
25
+ disabled?: boolean;
26
+ tooltip?: boolean;
27
+ onTooltipClick?: () => void;
28
+ } & SxProp;
29
+ type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
31
30
  render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
32
- } & FormFieldProps;
33
- declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, sx, render, ...formFieldProps }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
31
+ } & FormFieldProps<TFieldValues, TName>;
32
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, onTooltipClick, sx, css, render, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
34
33
 
35
34
  declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues>({ label, name, sx, ...checkboxProps }: {
36
35
  label?: string | undefined;
37
36
  name: FieldPath<TFieldValues>;
38
37
  } & CheckboxProps) => react_jsx_runtime.JSX.Element;
39
38
 
39
+ type FormFieldPatternFormatProps = {
40
+ label?: string;
41
+ name: string;
42
+ } & PatternFormatProps;
43
+ declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
44
+
45
+ type FormFieldCreditCardNumberProps = {
46
+ label: string;
47
+ name: string;
48
+ } & Partial<FormFieldPatternFormatProps>;
49
+ declare const FormFieldCreditCardNumber: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCreditCardNumberProps) => react_jsx_runtime.JSX.Element;
50
+
40
51
  type FormFieldNumericFormatProps = {
41
52
  label?: string;
42
53
  name: string;
43
54
  } & NumericFormatProps;
44
55
  declare const FormFieldNumericFormat: ({ label, name, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
45
56
 
57
+ type FormFieldCurrencyInputProps = {
58
+ label?: string;
59
+ name: string;
60
+ prefix: string;
61
+ decimalSeparator: string;
62
+ thousandSeparator: string;
63
+ } & FormFieldNumericFormatProps;
64
+ declare const FormFieldCurrencyInput: ({ label, name, prefix, decimalSeparator, thousandSeparator, ...formFieldNumericFormatProps }: FormFieldCurrencyInputProps) => react_jsx_runtime.JSX.Element;
65
+
46
66
  type FormFieldInputProps<TName> = {
47
67
  label?: string;
48
68
  name: TName;
@@ -55,32 +75,18 @@ type FormFieldPasswordProps<TName> = {
55
75
  } & InputPasswordProps & FormFieldProps;
56
76
  declare const FormFieldPassword: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, tooltip, onTooltipClick, sx, defaultValue, ...inputProps }: FormFieldPasswordProps<TName>) => react_jsx_runtime.JSX.Element;
57
77
 
58
- type FormRadioOption$1 = {
78
+ type FormRadioOption = {
59
79
  value: string | number;
60
80
  label: string;
61
81
  };
62
82
  declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, sx, ...radioProps }: {
63
83
  label?: string | undefined;
64
84
  name: FieldPath<TFieldValues>;
65
- options: FormRadioOption$1[];
85
+ options: FormRadioOption[];
66
86
  } & RadioProps) => react_jsx_runtime.JSX.Element;
67
87
 
68
- type FormRadioOption = {
69
- value: string | number;
70
- label: string;
71
- };
72
- type SelectSwitchProps = (SelectProps & {
73
- placeholder?: never;
74
- }) | (SelectProps & {
75
- defaultValue?: never;
76
- });
77
- type FormFieldSelectProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = SelectSwitchProps & FormFieldProps & {
78
- label?: string;
79
- name: FieldPath<TFieldValues>;
80
- options: FormRadioOption[];
81
- defaultValue?: FieldPathValue<TFieldValues, TName>;
82
- };
83
- declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, options, sx, ...selectProps }: FormFieldSelectProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
88
+ type FormFieldSelectProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<SelectProps, 'defaultValue'> & FormFieldProps<TFieldValues, TName>;
89
+ declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>({ label, name, id, defaultValue, sx, css, disabled, tooltip, onTooltipClick, ...selectProps }: FormFieldSelectProps<TFieldValues, react_hook_form.Path<TFieldValues>>) => react_jsx_runtime.JSX.Element;
84
90
 
85
91
  declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, ...textareaProps }: {
86
92
  label?: string | undefined;
@@ -97,4 +103,4 @@ type FormGroupProps = {
97
103
  } & BoxProps;
98
104
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
99
105
 
100
- export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
106
+ export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  export { yupResolver } from '@hookform/resolvers/yup';
2
2
  import * as react_hook_form from 'react-hook-form';
3
- import { FieldValues, FieldPath, FieldPathValue, UseControllerReturn } from 'react-hook-form';
3
+ import { FieldValues, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
4
4
  export * from 'react-hook-form';
5
5
  import * as yup from 'yup';
6
6
  export { yup };
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import * as React from 'react';
9
- import { BoxProps, FlexProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
- import { NumericFormatProps } from 'react-number-format';
9
+ import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
+ import { PatternFormatProps, NumericFormatProps } from 'react-number-format';
11
11
 
12
12
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
13
13
  children?: React.ReactNode;
@@ -17,32 +17,52 @@ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children,
17
17
  children: React.ReactNode | React.ReactNode[];
18
18
  } & react_hook_form.UseFormReturn<TFieldValues, any, undefined>) => react_jsx_runtime.JSX.Element;
19
19
 
20
- type FormFieldProps = {
21
- sx?: FlexProps['sx'];
22
- disabled?: boolean;
23
- tooltip?: boolean;
24
- onTooltipClick?: () => void;
25
- };
26
- type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
20
+ type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
27
21
  label?: string;
28
22
  id?: string;
29
23
  name: TName;
30
24
  defaultValue?: FieldPathValue<TFieldValues, TName>;
25
+ disabled?: boolean;
26
+ tooltip?: boolean;
27
+ onTooltipClick?: () => void;
28
+ } & SxProp;
29
+ type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
31
30
  render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
32
- } & FormFieldProps;
33
- declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, sx, render, ...formFieldProps }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
31
+ } & FormFieldProps<TFieldValues, TName>;
32
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, onTooltipClick, sx, css, render, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
34
33
 
35
34
  declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues>({ label, name, sx, ...checkboxProps }: {
36
35
  label?: string | undefined;
37
36
  name: FieldPath<TFieldValues>;
38
37
  } & CheckboxProps) => react_jsx_runtime.JSX.Element;
39
38
 
39
+ type FormFieldPatternFormatProps = {
40
+ label?: string;
41
+ name: string;
42
+ } & PatternFormatProps;
43
+ declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
44
+
45
+ type FormFieldCreditCardNumberProps = {
46
+ label: string;
47
+ name: string;
48
+ } & Partial<FormFieldPatternFormatProps>;
49
+ declare const FormFieldCreditCardNumber: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCreditCardNumberProps) => react_jsx_runtime.JSX.Element;
50
+
40
51
  type FormFieldNumericFormatProps = {
41
52
  label?: string;
42
53
  name: string;
43
54
  } & NumericFormatProps;
44
55
  declare const FormFieldNumericFormat: ({ label, name, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
45
56
 
57
+ type FormFieldCurrencyInputProps = {
58
+ label?: string;
59
+ name: string;
60
+ prefix: string;
61
+ decimalSeparator: string;
62
+ thousandSeparator: string;
63
+ } & FormFieldNumericFormatProps;
64
+ declare const FormFieldCurrencyInput: ({ label, name, prefix, decimalSeparator, thousandSeparator, ...formFieldNumericFormatProps }: FormFieldCurrencyInputProps) => react_jsx_runtime.JSX.Element;
65
+
46
66
  type FormFieldInputProps<TName> = {
47
67
  label?: string;
48
68
  name: TName;
@@ -55,32 +75,18 @@ type FormFieldPasswordProps<TName> = {
55
75
  } & InputPasswordProps & FormFieldProps;
56
76
  declare const FormFieldPassword: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, tooltip, onTooltipClick, sx, defaultValue, ...inputProps }: FormFieldPasswordProps<TName>) => react_jsx_runtime.JSX.Element;
57
77
 
58
- type FormRadioOption$1 = {
78
+ type FormRadioOption = {
59
79
  value: string | number;
60
80
  label: string;
61
81
  };
62
82
  declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, sx, ...radioProps }: {
63
83
  label?: string | undefined;
64
84
  name: FieldPath<TFieldValues>;
65
- options: FormRadioOption$1[];
85
+ options: FormRadioOption[];
66
86
  } & RadioProps) => react_jsx_runtime.JSX.Element;
67
87
 
68
- type FormRadioOption = {
69
- value: string | number;
70
- label: string;
71
- };
72
- type SelectSwitchProps = (SelectProps & {
73
- placeholder?: never;
74
- }) | (SelectProps & {
75
- defaultValue?: never;
76
- });
77
- type FormFieldSelectProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = SelectSwitchProps & FormFieldProps & {
78
- label?: string;
79
- name: FieldPath<TFieldValues>;
80
- options: FormRadioOption[];
81
- defaultValue?: FieldPathValue<TFieldValues, TName>;
82
- };
83
- declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, options, sx, ...selectProps }: FormFieldSelectProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
88
+ type FormFieldSelectProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<SelectProps, 'defaultValue'> & FormFieldProps<TFieldValues, TName>;
89
+ declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>({ label, name, id, defaultValue, sx, css, disabled, tooltip, onTooltipClick, ...selectProps }: FormFieldSelectProps<TFieldValues, react_hook_form.Path<TFieldValues>>) => react_jsx_runtime.JSX.Element;
84
90
 
85
91
  declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, ...textareaProps }: {
86
92
  label?: string | undefined;
@@ -97,4 +103,4 @@ type FormGroupProps = {
97
103
  } & BoxProps;
98
104
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
99
105
 
100
- export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
106
+ export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };