@ttoss/forms 0.18.21 → 0.20.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
@@ -235,9 +235,109 @@ var FormFieldCheckbox = ({
235
235
  });
236
236
  };
237
237
 
238
- // src/FormFieldInput.tsx
238
+ // src/FormFieldPatternFormat.tsx
239
239
  import { Input } from "@ttoss/ui";
240
+ import { PatternFormat } from "react-number-format";
240
241
  import { jsx as jsx5 } from "react/jsx-runtime";
242
+ var FormFieldPatternFormat = ({
243
+ label,
244
+ name,
245
+ ...patternFormatProps
246
+ }) => {
247
+ return /* @__PURE__ */jsx5(FormField, {
248
+ name,
249
+ label,
250
+ render: ({
251
+ field,
252
+ fieldState
253
+ }) => {
254
+ return /* @__PURE__ */jsx5(PatternFormat, {
255
+ name: field.name,
256
+ value: field.value,
257
+ onBlur: field.onBlur,
258
+ onValueChange: values => {
259
+ field.onChange(values.value);
260
+ },
261
+ customInput: Input,
262
+ "aria-invalid": Boolean(fieldState.error).valueOf(),
263
+ ...patternFormatProps
264
+ });
265
+ }
266
+ });
267
+ };
268
+
269
+ // src/FormFieldCreditCardNumber.tsx
270
+ import { jsx as jsx6 } from "react/jsx-runtime";
271
+ var FormFieldCreditCardNumber = ({
272
+ label,
273
+ name,
274
+ ...formFieldPatternFormatProps
275
+ }) => {
276
+ return /* @__PURE__ */jsx6(FormFieldPatternFormat, {
277
+ name,
278
+ label,
279
+ format: "#### #### #### ####",
280
+ placeholder: "1234 1234 1234 1234",
281
+ ...formFieldPatternFormatProps
282
+ });
283
+ };
284
+
285
+ // src/FormFieldNumericFormat.tsx
286
+ import { Input as Input2 } from "@ttoss/ui";
287
+ import { NumericFormat } from "react-number-format";
288
+ import { jsx as jsx7 } from "react/jsx-runtime";
289
+ var FormFieldNumericFormat = ({
290
+ label,
291
+ name,
292
+ ...numericFormatProps
293
+ }) => {
294
+ return /* @__PURE__ */jsx7(FormField, {
295
+ label,
296
+ name,
297
+ render: ({
298
+ field
299
+ }) => {
300
+ return /* @__PURE__ */jsx7(NumericFormat, {
301
+ name: field.name,
302
+ value: field.value,
303
+ onBlur: field.onBlur,
304
+ onValueChange: values => {
305
+ field.onChange(values.floatValue);
306
+ },
307
+ customInput: Input2,
308
+ ...numericFormatProps
309
+ });
310
+ }
311
+ });
312
+ };
313
+
314
+ // src/FormFieldCurrencyInput.tsx
315
+ import { jsx as jsx8 } from "react/jsx-runtime";
316
+ var FormFieldCurrencyInput = ({
317
+ label,
318
+ name,
319
+ prefix,
320
+ decimalSeparator,
321
+ thousandSeparator,
322
+ ...formFieldNumericFormatProps
323
+ }) => {
324
+ return /* @__PURE__ */jsx8(FormFieldNumericFormat, {
325
+ name,
326
+ label,
327
+ fixedDecimalScale: true,
328
+ decimalScale: 2,
329
+ prefix,
330
+ decimalSeparator,
331
+ thousandSeparator,
332
+ placeholder: `${prefix} 0${decimalSeparator}00`,
333
+ allowNegative: false,
334
+ ...formFieldNumericFormatProps
335
+ });
336
+ };
337
+
338
+ // src/FormFieldInput.tsx
339
+ import { Input as Input3 } from "@ttoss/ui";
340
+ import { jsx as jsx9 } from "react/jsx-runtime";
241
341
  var FormFieldInput = ({
242
342
  label,
243
343
  name,
@@ -247,7 +347,7 @@ var FormFieldInput = ({
247
347
  defaultValue = "",
248
348
  ...inputProps
249
349
  }) => {
250
- return /* @__PURE__ */jsx5(FormField, {
350
+ return /* @__PURE__ */jsx9(FormField, {
251
351
  name,
252
352
  label,
253
353
  disabled: inputProps.disabled,
@@ -259,7 +359,7 @@ var FormFieldInput = ({
259
359
  field,
260
360
  fieldState
261
361
  }) => {
262
- return /* @__PURE__ */jsx5(Input, {
362
+ return /* @__PURE__ */jsx9(Input3, {
263
363
  ...inputProps,
264
364
  ...field,
265
365
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -270,7 +370,7 @@ var FormFieldInput = ({
270
370
 
271
371
  // src/FormFieldPassword.tsx
272
372
  import { InputPassword } from "@ttoss/ui";
273
- import { jsx as jsx6 } from "react/jsx-runtime";
373
+ import { jsx as jsx10 } from "react/jsx-runtime";
274
374
  var FormFieldPassword = ({
275
375
  label,
276
376
  name,
@@ -280,7 +380,7 @@ var FormFieldPassword = ({
280
380
  defaultValue = "",
281
381
  ...inputProps
282
382
  }) => {
283
- return /* @__PURE__ */jsx6(FormField, {
383
+ return /* @__PURE__ */jsx10(FormField, {
284
384
  name,
285
385
  label,
286
386
  disabled: inputProps.disabled,
@@ -292,7 +392,7 @@ var FormFieldPassword = ({
292
392
  field,
293
393
  fieldState
294
394
  }) => {
295
- return /* @__PURE__ */jsx6(InputPassword, {
395
+ return /* @__PURE__ */jsx10(InputPassword, {
296
396
  ...inputProps,
297
397
  ...field,
298
398
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -304,7 +404,7 @@ var FormFieldPassword = ({
304
404
  // src/FormFieldRadio.tsx
305
405
  import { Box as Box2, Flex as Flex3, Label as Label3, Radio } from "@ttoss/ui";
306
406
  import { useController as useController3 } from "react-hook-form";
307
- import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
407
+ import { jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
308
408
  var FormFieldRadio = ({
309
409
  label,
310
410
  name,
@@ -329,17 +429,17 @@ var FormFieldRadio = ({
329
429
  width: "100%",
330
430
  ...sx
331
431
  },
332
- children: [label && /* @__PURE__ */jsx7(Label3, {
432
+ children: [label && /* @__PURE__ */jsx11(Label3, {
333
433
  sx: {
334
434
  marginBottom: "md"
335
435
  },
336
436
  children: label
337
- }), /* @__PURE__ */jsx7(Box2, {
437
+ }), /* @__PURE__ */jsx11(Box2, {
338
438
  children: options.map(option => {
339
439
  const id = `form-field-radio-${name}-${option.value}`;
340
440
  return /* @__PURE__ */jsxs3(Label3, {
341
441
  htmlFor: id,
342
- children: [/* @__PURE__ */jsx7(Radio, {
442
+ children: [/* @__PURE__ */jsx11(Radio, {
343
443
  ref,
344
444
  onChange,
345
445
  onBlur,
@@ -351,7 +451,7 @@ var FormFieldRadio = ({
351
451
  }), option.label]
352
452
  }, id);
353
453
  })
354
- }), /* @__PURE__ */jsx7(ErrorMessage, {
454
+ }), /* @__PURE__ */jsx11(ErrorMessage, {
355
455
  name
356
456
  })]
357
457
  });
@@ -359,7 +459,7 @@ var FormFieldRadio = ({
359
459
 
360
460
  // src/FormFieldSelect.tsx
361
461
  import { Select } from "@ttoss/ui";
362
- import { jsx as jsx8 } from "react/jsx-runtime";
462
+ import { jsx as jsx12 } from "react/jsx-runtime";
363
463
  var checkDefaultValue = ({
364
464
  options,
365
465
  defaultValue,
@@ -402,7 +502,7 @@ var FormFieldSelect = ({
402
502
  defaultValue,
403
503
  placeholder
404
504
  });
405
- return /* @__PURE__ */jsx8(FormField, {
505
+ return /* @__PURE__ */jsx12(FormField, {
406
506
  name,
407
507
  label,
408
508
  disabled: selectProps.disabled,
@@ -414,7 +514,7 @@ var FormFieldSelect = ({
414
514
  field,
415
515
  fieldState
416
516
  }) => {
417
- return /* @__PURE__ */jsx8(Select, {
517
+ return /* @__PURE__ */jsx12(Select, {
418
518
  ...selectProps,
419
519
  ...field,
420
520
  ...{
@@ -423,7 +523,7 @@ var FormFieldSelect = ({
423
523
  },
424
524
  "aria-invalid": fieldState.error ? "true" : void 0,
425
525
  children: options.map(option => {
426
- return /* @__PURE__ */jsx8("option", {
526
+ return /* @__PURE__ */jsx12("option", {
427
527
  value: option.value,
428
528
  children: option.label
429
529
  }, option.label);
@@ -435,7 +535,7 @@ var FormFieldSelect = ({
435
535
 
436
536
  // src/FormFieldTextarea.tsx
437
537
  import { Textarea } from "@ttoss/ui";
438
- import { jsx as jsx9 } from "react/jsx-runtime";
538
+ import { jsx as jsx13 } from "react/jsx-runtime";
439
539
  var FormFieldTextarea = ({
440
540
  label,
441
541
  name,
@@ -443,7 +543,7 @@ var FormFieldTextarea = ({
443
543
  ...textareaProps
444
544
  }) => {
445
545
  const id = `form-field-textarea-${name}`;
446
- return /* @__PURE__ */jsx9(FormField, {
546
+ return /* @__PURE__ */jsx13(FormField, {
447
547
  label,
448
548
  name,
449
549
  id,
@@ -452,7 +552,7 @@ var FormFieldTextarea = ({
452
552
  field,
453
553
  fieldState
454
554
  }) => {
455
- return /* @__PURE__ */jsx9(Textarea, {
555
+ return /* @__PURE__ */jsx13(Textarea, {
456
556
  ...field,
457
557
  ...textareaProps,
458
558
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -464,7 +564,7 @@ var FormFieldTextarea = ({
464
564
  // src/FormGroup.tsx
465
565
  import * as React3 from "react";
466
566
  import { Box as Box3, Flex as Flex4, Text } from "@ttoss/ui";
467
- import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
567
+ import { jsx as jsx14, jsxs as jsxs4 } from "react/jsx-runtime";
468
568
  var FormGroupLevelsManagerContext = /*#__PURE__*/React3.createContext({
469
569
  levelsLength: 1,
470
570
  registerChild: () => {
@@ -480,7 +580,7 @@ var FormGroupLevelsManager = ({
480
580
  setLevelsLength(level + 1);
481
581
  }
482
582
  }, [levelsLength]);
483
- return /* @__PURE__ */jsx10(FormGroupLevelsManagerContext.Provider, {
583
+ return /* @__PURE__ */jsx14(FormGroupLevelsManagerContext.Provider, {
484
584
  value: {
485
585
  levelsLength,
486
586
  registerChild
@@ -531,18 +631,18 @@ var FormGroupWrapper = ({
531
631
  marginBottom: "lg",
532
632
  ...boxProps.sx
533
633
  },
534
- children: [title && /* @__PURE__ */jsx10(Box3, {
634
+ children: [title && /* @__PURE__ */jsx14(Box3, {
535
635
  sx: {
536
636
  marginBottom: "md"
537
637
  },
538
- children: /* @__PURE__ */jsx10(Text, {
638
+ children: /* @__PURE__ */jsx14(Text, {
539
639
  sx: {
540
640
  fontSize: "2xl",
541
641
  fontWeight: "bold"
542
642
  },
543
643
  children: title
544
644
  })
545
- }), /* @__PURE__ */jsx10(Flex4, {
645
+ }), /* @__PURE__ */jsx14(Flex4, {
546
646
  sx: childrenContainerSx,
547
647
  children
548
648
  })]
@@ -553,17 +653,17 @@ var FormGroup = props => {
553
653
  level
554
654
  } = useFormGroup();
555
655
  const currentLevel = level === void 0 ? 0 : level + 1;
556
- return /* @__PURE__ */jsx10(FormGroupContext.Provider, {
656
+ return /* @__PURE__ */jsx14(FormGroupContext.Provider, {
557
657
  value: {
558
658
  parentLevel: currentLevel
559
659
  },
560
- children: currentLevel === 0 ? /* @__PURE__ */jsx10(FormGroupLevelsManager, {
561
- children: /* @__PURE__ */jsx10(FormGroupWrapper, {
660
+ children: currentLevel === 0 ? /* @__PURE__ */jsx14(FormGroupLevelsManager, {
661
+ children: /* @__PURE__ */jsx14(FormGroupWrapper, {
562
662
  ...props
563
663
  })
564
- }) : /* @__PURE__ */jsx10(FormGroupWrapper, {
664
+ }) : /* @__PURE__ */jsx14(FormGroupWrapper, {
565
665
  ...props
566
666
  })
567
667
  });
568
668
  };
569
- export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup, yup, yupResolver };
669
+ export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup, yup, yupResolver };
package/dist/index.d.mts CHANGED
@@ -7,6 +7,7 @@ export { yup };
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import * as React from 'react';
9
9
  import { BoxProps, FlexProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
+ import { PatternFormatProps, NumericFormatProps } from 'react-number-format';
10
11
 
11
12
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
12
13
  children?: React.ReactNode;
@@ -36,6 +37,33 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
36
37
  name: FieldPath<TFieldValues>;
37
38
  } & CheckboxProps) => react_jsx_runtime.JSX.Element;
38
39
 
40
+ type FormFieldPatternFormatProps = {
41
+ label?: string;
42
+ name: string;
43
+ } & PatternFormatProps;
44
+ declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
45
+
46
+ type FormFieldCreditCardNumberProps = {
47
+ label: string;
48
+ name: string;
49
+ } & Partial<FormFieldPatternFormatProps>;
50
+ declare const FormFieldCreditCardNumber: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCreditCardNumberProps) => react_jsx_runtime.JSX.Element;
51
+
52
+ type FormFieldNumericFormatProps = {
53
+ label?: string;
54
+ name: string;
55
+ } & NumericFormatProps;
56
+ declare const FormFieldNumericFormat: ({ label, name, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
57
+
58
+ type FormFieldCurrencyInputProps = {
59
+ label?: string;
60
+ name: string;
61
+ prefix: string;
62
+ decimalSeparator: string;
63
+ thousandSeparator: string;
64
+ } & FormFieldNumericFormatProps;
65
+ declare const FormFieldCurrencyInput: ({ label, name, prefix, decimalSeparator, thousandSeparator, ...formFieldNumericFormatProps }: FormFieldCurrencyInputProps) => react_jsx_runtime.JSX.Element;
66
+
39
67
  type FormFieldInputProps<TName> = {
40
68
  label?: string;
41
69
  name: TName;
@@ -90,4 +118,4 @@ type FormGroupProps = {
90
118
  } & BoxProps;
91
119
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
92
120
 
93
- export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
121
+ export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { yup };
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import * as React from 'react';
9
9
  import { BoxProps, FlexProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
+ import { PatternFormatProps, NumericFormatProps } from 'react-number-format';
10
11
 
11
12
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
12
13
  children?: React.ReactNode;
@@ -36,6 +37,33 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
36
37
  name: FieldPath<TFieldValues>;
37
38
  } & CheckboxProps) => react_jsx_runtime.JSX.Element;
38
39
 
40
+ type FormFieldPatternFormatProps = {
41
+ label?: string;
42
+ name: string;
43
+ } & PatternFormatProps;
44
+ declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
45
+
46
+ type FormFieldCreditCardNumberProps = {
47
+ label: string;
48
+ name: string;
49
+ } & Partial<FormFieldPatternFormatProps>;
50
+ declare const FormFieldCreditCardNumber: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCreditCardNumberProps) => react_jsx_runtime.JSX.Element;
51
+
52
+ type FormFieldNumericFormatProps = {
53
+ label?: string;
54
+ name: string;
55
+ } & NumericFormatProps;
56
+ declare const FormFieldNumericFormat: ({ label, name, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
57
+
58
+ type FormFieldCurrencyInputProps = {
59
+ label?: string;
60
+ name: string;
61
+ prefix: string;
62
+ decimalSeparator: string;
63
+ thousandSeparator: string;
64
+ } & FormFieldNumericFormatProps;
65
+ declare const FormFieldCurrencyInput: ({ label, name, prefix, decimalSeparator, thousandSeparator, ...formFieldNumericFormatProps }: FormFieldCurrencyInputProps) => react_jsx_runtime.JSX.Element;
66
+
39
67
  type FormFieldInputProps<TName> = {
40
68
  label?: string;
41
69
  name: TName;
@@ -90,4 +118,4 @@ type FormGroupProps = {
90
118
  } & BoxProps;
91
119
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
92
120
 
93
- export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
121
+ export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.js CHANGED
@@ -42,8 +42,12 @@ __export(src_exports, {
42
42
  Form: () => Form,
43
43
  FormField: () => FormField,
44
44
  FormFieldCheckbox: () => FormFieldCheckbox,
45
+ FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
46
+ FormFieldCurrencyInput: () => FormFieldCurrencyInput,
45
47
  FormFieldInput: () => FormFieldInput,
48
+ FormFieldNumericFormat: () => FormFieldNumericFormat,
46
49
  FormFieldPassword: () => FormFieldPassword,
50
+ FormFieldPatternFormat: () => FormFieldPatternFormat,
47
51
  FormFieldRadio: () => FormFieldRadio,
48
52
  FormFieldSelect: () => FormFieldSelect,
49
53
  FormFieldTextarea: () => FormFieldTextarea,
@@ -271,9 +275,109 @@ var FormFieldCheckbox = ({
271
275
  });
272
276
  };
273
277
 
274
- // src/FormFieldInput.tsx
278
+ // src/FormFieldPatternFormat.tsx
275
279
  var import_ui5 = require("@ttoss/ui");
280
+ var import_react_number_format = require("react-number-format");
276
281
  var import_jsx_runtime5 = require("react/jsx-runtime");
282
+ var FormFieldPatternFormat = ({
283
+ label,
284
+ name,
285
+ ...patternFormatProps
286
+ }) => {
287
+ return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormField, {
288
+ name,
289
+ label,
290
+ render: ({
291
+ field,
292
+ fieldState
293
+ }) => {
294
+ return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_react_number_format.PatternFormat, {
295
+ name: field.name,
296
+ value: field.value,
297
+ onBlur: field.onBlur,
298
+ onValueChange: values => {
299
+ field.onChange(values.value);
300
+ },
301
+ customInput: import_ui5.Input,
302
+ "aria-invalid": Boolean(fieldState.error).valueOf(),
303
+ ...patternFormatProps
304
+ });
305
+ }
306
+ });
307
+ };
308
+
309
+ // src/FormFieldCreditCardNumber.tsx
310
+ var import_jsx_runtime6 = require("react/jsx-runtime");
311
+ var FormFieldCreditCardNumber = ({
312
+ label,
313
+ name,
314
+ ...formFieldPatternFormatProps
315
+ }) => {
316
+ return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormFieldPatternFormat, {
317
+ name,
318
+ label,
319
+ format: "#### #### #### ####",
320
+ placeholder: "1234 1234 1234 1234",
321
+ ...formFieldPatternFormatProps
322
+ });
323
+ };
324
+
325
+ // src/FormFieldNumericFormat.tsx
326
+ var import_ui6 = require("@ttoss/ui");
327
+ var import_react_number_format2 = require("react-number-format");
328
+ var import_jsx_runtime7 = require("react/jsx-runtime");
329
+ var FormFieldNumericFormat = ({
330
+ label,
331
+ name,
332
+ ...numericFormatProps
333
+ }) => {
334
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(FormField, {
335
+ label,
336
+ name,
337
+ render: ({
338
+ field
339
+ }) => {
340
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_react_number_format2.NumericFormat, {
341
+ name: field.name,
342
+ value: field.value,
343
+ onBlur: field.onBlur,
344
+ onValueChange: values => {
345
+ field.onChange(values.floatValue);
346
+ },
347
+ customInput: import_ui6.Input,
348
+ ...numericFormatProps
349
+ });
350
+ }
351
+ });
352
+ };
353
+
354
+ // src/FormFieldCurrencyInput.tsx
355
+ var import_jsx_runtime8 = require("react/jsx-runtime");
356
+ var FormFieldCurrencyInput = ({
357
+ label,
358
+ name,
359
+ prefix,
360
+ decimalSeparator,
361
+ thousandSeparator,
362
+ ...formFieldNumericFormatProps
363
+ }) => {
364
+ return /* @__PURE__ */(0, import_jsx_runtime8.jsx)(FormFieldNumericFormat, {
365
+ name,
366
+ label,
367
+ fixedDecimalScale: true,
368
+ decimalScale: 2,
369
+ prefix,
370
+ decimalSeparator,
371
+ thousandSeparator,
372
+ placeholder: `${prefix} 0${decimalSeparator}00`,
373
+ allowNegative: false,
374
+ ...formFieldNumericFormatProps
375
+ });
376
+ };
377
+
378
+ // src/FormFieldInput.tsx
379
+ var import_ui7 = require("@ttoss/ui");
380
+ var import_jsx_runtime9 = require("react/jsx-runtime");
277
381
  var FormFieldInput = ({
278
382
  label,
279
383
  name,
@@ -283,7 +387,7 @@ var FormFieldInput = ({
283
387
  defaultValue = "",
284
388
  ...inputProps
285
389
  }) => {
286
- return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormField, {
390
+ return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormField, {
287
391
  name,
288
392
  label,
289
393
  disabled: inputProps.disabled,
@@ -295,7 +399,7 @@ var FormFieldInput = ({
295
399
  field,
296
400
  fieldState
297
401
  }) => {
298
- return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Input, {
402
+ return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui7.Input, {
299
403
  ...inputProps,
300
404
  ...field,
301
405
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -305,8 +409,8 @@ var FormFieldInput = ({
305
409
  };
306
410
 
307
411
  // src/FormFieldPassword.tsx
308
- var import_ui6 = require("@ttoss/ui");
309
- var import_jsx_runtime6 = require("react/jsx-runtime");
412
+ var import_ui8 = require("@ttoss/ui");
413
+ var import_jsx_runtime10 = require("react/jsx-runtime");
310
414
  var FormFieldPassword = ({
311
415
  label,
312
416
  name,
@@ -316,7 +420,7 @@ var FormFieldPassword = ({
316
420
  defaultValue = "",
317
421
  ...inputProps
318
422
  }) => {
319
- return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormField, {
423
+ return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormField, {
320
424
  name,
321
425
  label,
322
426
  disabled: inputProps.disabled,
@@ -328,7 +432,7 @@ var FormFieldPassword = ({
328
432
  field,
329
433
  fieldState
330
434
  }) => {
331
- return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_ui6.InputPassword, {
435
+ return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(import_ui8.InputPassword, {
332
436
  ...inputProps,
333
437
  ...field,
334
438
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -338,9 +442,9 @@ var FormFieldPassword = ({
338
442
  };
339
443
 
340
444
  // src/FormFieldRadio.tsx
341
- var import_ui7 = require("@ttoss/ui");
445
+ var import_ui9 = require("@ttoss/ui");
342
446
  var import_react_hook_form5 = require("react-hook-form");
343
- var import_jsx_runtime7 = require("react/jsx-runtime");
447
+ var import_jsx_runtime11 = require("react/jsx-runtime");
344
448
  var FormFieldRadio = ({
345
449
  label,
346
450
  name,
@@ -359,23 +463,23 @@ var FormFieldRadio = ({
359
463
  name,
360
464
  defaultValue: ""
361
465
  });
362
- return /* @__PURE__ */(0, import_jsx_runtime7.jsxs)(import_ui7.Flex, {
466
+ return /* @__PURE__ */(0, import_jsx_runtime11.jsxs)(import_ui9.Flex, {
363
467
  sx: {
364
468
  flexDirection: "column",
365
469
  width: "100%",
366
470
  ...sx
367
471
  },
368
- children: [label && /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_ui7.Label, {
472
+ children: [label && /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Label, {
369
473
  sx: {
370
474
  marginBottom: "md"
371
475
  },
372
476
  children: label
373
- }), /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_ui7.Box, {
477
+ }), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Box, {
374
478
  children: options.map(option => {
375
479
  const id = `form-field-radio-${name}-${option.value}`;
376
- return /* @__PURE__ */(0, import_jsx_runtime7.jsxs)(import_ui7.Label, {
480
+ return /* @__PURE__ */(0, import_jsx_runtime11.jsxs)(import_ui9.Label, {
377
481
  htmlFor: id,
378
- children: [/* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_ui7.Radio, {
482
+ children: [/* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Radio, {
379
483
  ref,
380
484
  onChange,
381
485
  onBlur,
@@ -387,15 +491,15 @@ var FormFieldRadio = ({
387
491
  }), option.label]
388
492
  }, id);
389
493
  })
390
- }), /* @__PURE__ */(0, import_jsx_runtime7.jsx)(ErrorMessage, {
494
+ }), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(ErrorMessage, {
391
495
  name
392
496
  })]
393
497
  });
394
498
  };
395
499
 
396
500
  // src/FormFieldSelect.tsx
397
- var import_ui8 = require("@ttoss/ui");
398
- var import_jsx_runtime8 = require("react/jsx-runtime");
501
+ var import_ui10 = require("@ttoss/ui");
502
+ var import_jsx_runtime12 = require("react/jsx-runtime");
399
503
  var checkDefaultValue = ({
400
504
  options,
401
505
  defaultValue,
@@ -438,7 +542,7 @@ var FormFieldSelect = ({
438
542
  defaultValue,
439
543
  placeholder
440
544
  });
441
- return /* @__PURE__ */(0, import_jsx_runtime8.jsx)(FormField, {
545
+ return /* @__PURE__ */(0, import_jsx_runtime12.jsx)(FormField, {
442
546
  name,
443
547
  label,
444
548
  disabled: selectProps.disabled,
@@ -450,7 +554,7 @@ var FormFieldSelect = ({
450
554
  field,
451
555
  fieldState
452
556
  }) => {
453
- return /* @__PURE__ */(0, import_jsx_runtime8.jsx)(import_ui8.Select, {
557
+ return /* @__PURE__ */(0, import_jsx_runtime12.jsx)(import_ui10.Select, {
454
558
  ...selectProps,
455
559
  ...field,
456
560
  ...{
@@ -459,7 +563,7 @@ var FormFieldSelect = ({
459
563
  },
460
564
  "aria-invalid": fieldState.error ? "true" : void 0,
461
565
  children: options.map(option => {
462
- return /* @__PURE__ */(0, import_jsx_runtime8.jsx)("option", {
566
+ return /* @__PURE__ */(0, import_jsx_runtime12.jsx)("option", {
463
567
  value: option.value,
464
568
  children: option.label
465
569
  }, option.label);
@@ -470,8 +574,8 @@ var FormFieldSelect = ({
470
574
  };
471
575
 
472
576
  // src/FormFieldTextarea.tsx
473
- var import_ui9 = require("@ttoss/ui");
474
- var import_jsx_runtime9 = require("react/jsx-runtime");
577
+ var import_ui11 = require("@ttoss/ui");
578
+ var import_jsx_runtime13 = require("react/jsx-runtime");
475
579
  var FormFieldTextarea = ({
476
580
  label,
477
581
  name,
@@ -479,7 +583,7 @@ var FormFieldTextarea = ({
479
583
  ...textareaProps
480
584
  }) => {
481
585
  const id = `form-field-textarea-${name}`;
482
- return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormField, {
586
+ return /* @__PURE__ */(0, import_jsx_runtime13.jsx)(FormField, {
483
587
  label,
484
588
  name,
485
589
  id,
@@ -488,7 +592,7 @@ var FormFieldTextarea = ({
488
592
  field,
489
593
  fieldState
490
594
  }) => {
491
- return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Textarea, {
595
+ return /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_ui11.Textarea, {
492
596
  ...field,
493
597
  ...textareaProps,
494
598
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -499,8 +603,8 @@ var FormFieldTextarea = ({
499
603
 
500
604
  // src/FormGroup.tsx
501
605
  var React3 = __toESM(require("react"));
502
- var import_ui10 = require("@ttoss/ui");
503
- var import_jsx_runtime10 = require("react/jsx-runtime");
606
+ var import_ui12 = require("@ttoss/ui");
607
+ var import_jsx_runtime14 = require("react/jsx-runtime");
504
608
  var FormGroupLevelsManagerContext = React3.createContext({
505
609
  levelsLength: 1,
506
610
  registerChild: () => {
@@ -516,7 +620,7 @@ var FormGroupLevelsManager = ({
516
620
  setLevelsLength(level + 1);
517
621
  }
518
622
  }, [levelsLength]);
519
- return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormGroupLevelsManagerContext.Provider, {
623
+ return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupLevelsManagerContext.Provider, {
520
624
  value: {
521
625
  levelsLength,
522
626
  registerChild
@@ -559,7 +663,7 @@ var FormGroupWrapper = ({
559
663
  gap: "md",
560
664
  width: "100%"
561
665
  };
562
- return /* @__PURE__ */(0, import_jsx_runtime10.jsxs)(import_ui10.Box, {
666
+ return /* @__PURE__ */(0, import_jsx_runtime14.jsxs)(import_ui12.Box, {
563
667
  "aria-level": level,
564
668
  ...boxProps,
565
669
  sx: {
@@ -567,18 +671,18 @@ var FormGroupWrapper = ({
567
671
  marginBottom: "lg",
568
672
  ...boxProps.sx
569
673
  },
570
- children: [title && /* @__PURE__ */(0, import_jsx_runtime10.jsx)(import_ui10.Box, {
674
+ children: [title && /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Box, {
571
675
  sx: {
572
676
  marginBottom: "md"
573
677
  },
574
- children: /* @__PURE__ */(0, import_jsx_runtime10.jsx)(import_ui10.Text, {
678
+ children: /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Text, {
575
679
  sx: {
576
680
  fontSize: "2xl",
577
681
  fontWeight: "bold"
578
682
  },
579
683
  children: title
580
684
  })
581
- }), /* @__PURE__ */(0, import_jsx_runtime10.jsx)(import_ui10.Flex, {
685
+ }), /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Flex, {
582
686
  sx: childrenContainerSx,
583
687
  children
584
688
  })]
@@ -589,15 +693,15 @@ var FormGroup = props => {
589
693
  level
590
694
  } = useFormGroup();
591
695
  const currentLevel = level === void 0 ? 0 : level + 1;
592
- return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormGroupContext.Provider, {
696
+ return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupContext.Provider, {
593
697
  value: {
594
698
  parentLevel: currentLevel
595
699
  },
596
- children: currentLevel === 0 ? /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormGroupLevelsManager, {
597
- children: /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormGroupWrapper, {
700
+ children: currentLevel === 0 ? /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupLevelsManager, {
701
+ children: /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupWrapper, {
598
702
  ...props
599
703
  })
600
- }) : /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormGroupWrapper, {
704
+ }) : /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupWrapper, {
601
705
  ...props
602
706
  })
603
707
  });
@@ -607,8 +711,12 @@ var FormGroup = props => {
607
711
  Form,
608
712
  FormField,
609
713
  FormFieldCheckbox,
714
+ FormFieldCreditCardNumber,
715
+ FormFieldCurrencyInput,
610
716
  FormFieldInput,
717
+ FormFieldNumericFormat,
611
718
  FormFieldPassword,
719
+ FormFieldPatternFormat,
612
720
  FormFieldRadio,
613
721
  FormFieldSelect,
614
722
  FormFieldTextarea,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.18.21",
3
+ "version": "0.20.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -23,6 +23,7 @@
23
23
  "@hookform/error-message": "^2.0.1",
24
24
  "@hookform/resolvers": "^3.1.0",
25
25
  "react-hook-form": "^7.44.3",
26
+ "react-number-format": "^5.3.1",
26
27
  "yup": "^1.2.0"
27
28
  },
28
29
  "peerDependencies": {
@@ -0,0 +1,25 @@
1
+ import {
2
+ FormFieldPatternFormat,
3
+ FormFieldPatternFormatProps,
4
+ } from './FormFieldPatternFormat';
5
+
6
+ export type FormFieldCreditCardNumberProps = {
7
+ label: string;
8
+ name: string;
9
+ } & Partial<FormFieldPatternFormatProps>;
10
+
11
+ export const FormFieldCreditCardNumber = ({
12
+ label,
13
+ name,
14
+ ...formFieldPatternFormatProps
15
+ }: FormFieldCreditCardNumberProps) => {
16
+ return (
17
+ <FormFieldPatternFormat
18
+ name={name}
19
+ label={label}
20
+ format="#### #### #### ####"
21
+ placeholder="1234 1234 1234 1234"
22
+ {...formFieldPatternFormatProps}
23
+ />
24
+ );
25
+ };
@@ -0,0 +1,36 @@
1
+ import {
2
+ FormFieldNumericFormat,
3
+ FormFieldNumericFormatProps,
4
+ } from './FormFieldNumericFormat';
5
+
6
+ export type FormFieldCurrencyInputProps = {
7
+ label?: string;
8
+ name: string;
9
+ prefix: string;
10
+ decimalSeparator: string;
11
+ thousandSeparator: string;
12
+ } & FormFieldNumericFormatProps;
13
+
14
+ export const FormFieldCurrencyInput = ({
15
+ label,
16
+ name,
17
+ prefix,
18
+ decimalSeparator,
19
+ thousandSeparator,
20
+ ...formFieldNumericFormatProps
21
+ }: FormFieldCurrencyInputProps) => {
22
+ return (
23
+ <FormFieldNumericFormat
24
+ name={name}
25
+ label={label}
26
+ fixedDecimalScale
27
+ decimalScale={2}
28
+ prefix={prefix}
29
+ decimalSeparator={decimalSeparator}
30
+ thousandSeparator={thousandSeparator}
31
+ placeholder={`${prefix} 0${decimalSeparator}00`}
32
+ allowNegative={false}
33
+ {...formFieldNumericFormatProps}
34
+ />
35
+ );
36
+ };
@@ -10,7 +10,7 @@ export type FormFieldInputProps<TName> = {
10
10
 
11
11
  export const FormFieldInput = <
12
12
  TFieldValues extends FieldValues = FieldValues,
13
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
13
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
14
14
  >({
15
15
  label,
16
16
  name,
@@ -0,0 +1,35 @@
1
+ import { FormField } from './FormField';
2
+ import { Input } from '@ttoss/ui';
3
+ import { NumericFormat, NumericFormatProps } from 'react-number-format';
4
+
5
+ export type FormFieldNumericFormatProps = {
6
+ label?: string;
7
+ name: string;
8
+ } & NumericFormatProps;
9
+
10
+ export const FormFieldNumericFormat = ({
11
+ label,
12
+ name,
13
+ ...numericFormatProps
14
+ }: FormFieldNumericFormatProps) => {
15
+ return (
16
+ <FormField
17
+ label={label}
18
+ name={name}
19
+ render={({ field }) => {
20
+ return (
21
+ <NumericFormat
22
+ name={field.name}
23
+ value={field.value}
24
+ onBlur={field.onBlur}
25
+ onValueChange={(values) => {
26
+ field.onChange(values.floatValue);
27
+ }}
28
+ customInput={Input}
29
+ {...numericFormatProps}
30
+ />
31
+ );
32
+ }}
33
+ />
34
+ );
35
+ };
@@ -10,7 +10,7 @@ export type FormFieldPasswordProps<TName> = {
10
10
 
11
11
  export const FormFieldPassword = <
12
12
  TFieldValues extends FieldValues = FieldValues,
13
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
13
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
14
14
  >({
15
15
  label,
16
16
  name,
@@ -0,0 +1,36 @@
1
+ import { FormField } from './FormField';
2
+ import { Input } from '@ttoss/ui';
3
+ import { PatternFormat, PatternFormatProps } from 'react-number-format';
4
+
5
+ export type FormFieldPatternFormatProps = {
6
+ label?: string;
7
+ name: string;
8
+ } & PatternFormatProps;
9
+
10
+ export const FormFieldPatternFormat = ({
11
+ label,
12
+ name,
13
+ ...patternFormatProps
14
+ }: FormFieldPatternFormatProps) => {
15
+ return (
16
+ <FormField
17
+ name={name}
18
+ label={label}
19
+ render={({ field, fieldState }) => {
20
+ return (
21
+ <PatternFormat
22
+ name={field.name}
23
+ value={field.value}
24
+ onBlur={field.onBlur}
25
+ onValueChange={(values) => {
26
+ field.onChange(values.value);
27
+ }}
28
+ customInput={Input}
29
+ aria-invalid={Boolean(fieldState.error).valueOf()}
30
+ {...patternFormatProps}
31
+ />
32
+ );
33
+ }}
34
+ />
35
+ );
36
+ };
package/src/index.ts CHANGED
@@ -7,6 +7,10 @@ export * as yup from 'yup';
7
7
  export { Form } from './Form';
8
8
  export { FormField } from './FormField';
9
9
  export { FormFieldCheckbox } from './FormFieldCheckbox';
10
+ export { FormFieldCreditCardNumber } from './FormFieldCreditCardNumber';
11
+ export { FormFieldNumericFormat } from './FormFieldNumericFormat';
12
+ export { FormFieldPatternFormat } from './FormFieldPatternFormat';
13
+ export { FormFieldCurrencyInput } from './FormFieldCurrencyInput';
10
14
  export { FormFieldInput } from './FormFieldInput';
11
15
  export { FormFieldPassword } from './FormFieldPassword';
12
16
  export { FormFieldRadio } from './FormFieldRadio';