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