@ttoss/forms 0.18.20 → 0.19.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 +57 -28
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +66 -35
- package/package.json +8 -7
- package/src/FormFieldInput.tsx +1 -1
- package/src/FormFieldNumericFormat.tsx +35 -0
- package/src/FormFieldPassword.tsx +1 -1
- package/src/index.ts +1 -0
package/dist/esm/index.js
CHANGED
|
@@ -235,9 +235,38 @@ var FormFieldCheckbox = ({
|
|
|
235
235
|
});
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
// src/
|
|
238
|
+
// src/FormFieldNumericFormat.tsx
|
|
239
239
|
import { Input } from "@ttoss/ui";
|
|
240
|
+
import { NumericFormat } from "react-number-format";
|
|
240
241
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
242
|
+
var FormFieldNumericFormat = ({
|
|
243
|
+
label,
|
|
244
|
+
name,
|
|
245
|
+
...numericFormatProps
|
|
246
|
+
}) => {
|
|
247
|
+
return /* @__PURE__ */jsx5(FormField, {
|
|
248
|
+
label,
|
|
249
|
+
name,
|
|
250
|
+
render: ({
|
|
251
|
+
field
|
|
252
|
+
}) => {
|
|
253
|
+
return /* @__PURE__ */jsx5(NumericFormat, {
|
|
254
|
+
name: field.name,
|
|
255
|
+
value: field.value,
|
|
256
|
+
onBlur: field.onBlur,
|
|
257
|
+
onValueChange: values => {
|
|
258
|
+
field.onChange(values.floatValue);
|
|
259
|
+
},
|
|
260
|
+
customInput: Input,
|
|
261
|
+
...numericFormatProps
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// src/FormFieldInput.tsx
|
|
268
|
+
import { Input as Input2 } from "@ttoss/ui";
|
|
269
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
241
270
|
var FormFieldInput = ({
|
|
242
271
|
label,
|
|
243
272
|
name,
|
|
@@ -247,7 +276,7 @@ var FormFieldInput = ({
|
|
|
247
276
|
defaultValue = "",
|
|
248
277
|
...inputProps
|
|
249
278
|
}) => {
|
|
250
|
-
return /* @__PURE__ */
|
|
279
|
+
return /* @__PURE__ */jsx6(FormField, {
|
|
251
280
|
name,
|
|
252
281
|
label,
|
|
253
282
|
disabled: inputProps.disabled,
|
|
@@ -259,7 +288,7 @@ var FormFieldInput = ({
|
|
|
259
288
|
field,
|
|
260
289
|
fieldState
|
|
261
290
|
}) => {
|
|
262
|
-
return /* @__PURE__ */
|
|
291
|
+
return /* @__PURE__ */jsx6(Input2, {
|
|
263
292
|
...inputProps,
|
|
264
293
|
...field,
|
|
265
294
|
"aria-invalid": fieldState.error ? "true" : void 0
|
|
@@ -270,7 +299,7 @@ var FormFieldInput = ({
|
|
|
270
299
|
|
|
271
300
|
// src/FormFieldPassword.tsx
|
|
272
301
|
import { InputPassword } from "@ttoss/ui";
|
|
273
|
-
import { jsx as
|
|
302
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
274
303
|
var FormFieldPassword = ({
|
|
275
304
|
label,
|
|
276
305
|
name,
|
|
@@ -280,7 +309,7 @@ var FormFieldPassword = ({
|
|
|
280
309
|
defaultValue = "",
|
|
281
310
|
...inputProps
|
|
282
311
|
}) => {
|
|
283
|
-
return /* @__PURE__ */
|
|
312
|
+
return /* @__PURE__ */jsx7(FormField, {
|
|
284
313
|
name,
|
|
285
314
|
label,
|
|
286
315
|
disabled: inputProps.disabled,
|
|
@@ -292,7 +321,7 @@ var FormFieldPassword = ({
|
|
|
292
321
|
field,
|
|
293
322
|
fieldState
|
|
294
323
|
}) => {
|
|
295
|
-
return /* @__PURE__ */
|
|
324
|
+
return /* @__PURE__ */jsx7(InputPassword, {
|
|
296
325
|
...inputProps,
|
|
297
326
|
...field,
|
|
298
327
|
"aria-invalid": fieldState.error ? "true" : void 0
|
|
@@ -304,7 +333,7 @@ var FormFieldPassword = ({
|
|
|
304
333
|
// src/FormFieldRadio.tsx
|
|
305
334
|
import { Box as Box2, Flex as Flex3, Label as Label3, Radio } from "@ttoss/ui";
|
|
306
335
|
import { useController as useController3 } from "react-hook-form";
|
|
307
|
-
import { jsx as
|
|
336
|
+
import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
308
337
|
var FormFieldRadio = ({
|
|
309
338
|
label,
|
|
310
339
|
name,
|
|
@@ -329,17 +358,17 @@ var FormFieldRadio = ({
|
|
|
329
358
|
width: "100%",
|
|
330
359
|
...sx
|
|
331
360
|
},
|
|
332
|
-
children: [label && /* @__PURE__ */
|
|
361
|
+
children: [label && /* @__PURE__ */jsx8(Label3, {
|
|
333
362
|
sx: {
|
|
334
363
|
marginBottom: "md"
|
|
335
364
|
},
|
|
336
365
|
children: label
|
|
337
|
-
}), /* @__PURE__ */
|
|
366
|
+
}), /* @__PURE__ */jsx8(Box2, {
|
|
338
367
|
children: options.map(option => {
|
|
339
368
|
const id = `form-field-radio-${name}-${option.value}`;
|
|
340
369
|
return /* @__PURE__ */jsxs3(Label3, {
|
|
341
370
|
htmlFor: id,
|
|
342
|
-
children: [/* @__PURE__ */
|
|
371
|
+
children: [/* @__PURE__ */jsx8(Radio, {
|
|
343
372
|
ref,
|
|
344
373
|
onChange,
|
|
345
374
|
onBlur,
|
|
@@ -351,7 +380,7 @@ var FormFieldRadio = ({
|
|
|
351
380
|
}), option.label]
|
|
352
381
|
}, id);
|
|
353
382
|
})
|
|
354
|
-
}), /* @__PURE__ */
|
|
383
|
+
}), /* @__PURE__ */jsx8(ErrorMessage, {
|
|
355
384
|
name
|
|
356
385
|
})]
|
|
357
386
|
});
|
|
@@ -359,7 +388,7 @@ var FormFieldRadio = ({
|
|
|
359
388
|
|
|
360
389
|
// src/FormFieldSelect.tsx
|
|
361
390
|
import { Select } from "@ttoss/ui";
|
|
362
|
-
import { jsx as
|
|
391
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
363
392
|
var checkDefaultValue = ({
|
|
364
393
|
options,
|
|
365
394
|
defaultValue,
|
|
@@ -402,7 +431,7 @@ var FormFieldSelect = ({
|
|
|
402
431
|
defaultValue,
|
|
403
432
|
placeholder
|
|
404
433
|
});
|
|
405
|
-
return /* @__PURE__ */
|
|
434
|
+
return /* @__PURE__ */jsx9(FormField, {
|
|
406
435
|
name,
|
|
407
436
|
label,
|
|
408
437
|
disabled: selectProps.disabled,
|
|
@@ -414,7 +443,7 @@ var FormFieldSelect = ({
|
|
|
414
443
|
field,
|
|
415
444
|
fieldState
|
|
416
445
|
}) => {
|
|
417
|
-
return /* @__PURE__ */
|
|
446
|
+
return /* @__PURE__ */jsx9(Select, {
|
|
418
447
|
...selectProps,
|
|
419
448
|
...field,
|
|
420
449
|
...{
|
|
@@ -423,7 +452,7 @@ var FormFieldSelect = ({
|
|
|
423
452
|
},
|
|
424
453
|
"aria-invalid": fieldState.error ? "true" : void 0,
|
|
425
454
|
children: options.map(option => {
|
|
426
|
-
return /* @__PURE__ */
|
|
455
|
+
return /* @__PURE__ */jsx9("option", {
|
|
427
456
|
value: option.value,
|
|
428
457
|
children: option.label
|
|
429
458
|
}, option.label);
|
|
@@ -435,7 +464,7 @@ var FormFieldSelect = ({
|
|
|
435
464
|
|
|
436
465
|
// src/FormFieldTextarea.tsx
|
|
437
466
|
import { Textarea } from "@ttoss/ui";
|
|
438
|
-
import { jsx as
|
|
467
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
439
468
|
var FormFieldTextarea = ({
|
|
440
469
|
label,
|
|
441
470
|
name,
|
|
@@ -443,7 +472,7 @@ var FormFieldTextarea = ({
|
|
|
443
472
|
...textareaProps
|
|
444
473
|
}) => {
|
|
445
474
|
const id = `form-field-textarea-${name}`;
|
|
446
|
-
return /* @__PURE__ */
|
|
475
|
+
return /* @__PURE__ */jsx10(FormField, {
|
|
447
476
|
label,
|
|
448
477
|
name,
|
|
449
478
|
id,
|
|
@@ -452,7 +481,7 @@ var FormFieldTextarea = ({
|
|
|
452
481
|
field,
|
|
453
482
|
fieldState
|
|
454
483
|
}) => {
|
|
455
|
-
return /* @__PURE__ */
|
|
484
|
+
return /* @__PURE__ */jsx10(Textarea, {
|
|
456
485
|
...field,
|
|
457
486
|
...textareaProps,
|
|
458
487
|
"aria-invalid": fieldState.error ? "true" : void 0
|
|
@@ -464,7 +493,7 @@ var FormFieldTextarea = ({
|
|
|
464
493
|
// src/FormGroup.tsx
|
|
465
494
|
import * as React3 from "react";
|
|
466
495
|
import { Box as Box3, Flex as Flex4, Text } from "@ttoss/ui";
|
|
467
|
-
import { jsx as
|
|
496
|
+
import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
468
497
|
var FormGroupLevelsManagerContext = /*#__PURE__*/React3.createContext({
|
|
469
498
|
levelsLength: 1,
|
|
470
499
|
registerChild: () => {
|
|
@@ -480,7 +509,7 @@ var FormGroupLevelsManager = ({
|
|
|
480
509
|
setLevelsLength(level + 1);
|
|
481
510
|
}
|
|
482
511
|
}, [levelsLength]);
|
|
483
|
-
return /* @__PURE__ */
|
|
512
|
+
return /* @__PURE__ */jsx11(FormGroupLevelsManagerContext.Provider, {
|
|
484
513
|
value: {
|
|
485
514
|
levelsLength,
|
|
486
515
|
registerChild
|
|
@@ -531,18 +560,18 @@ var FormGroupWrapper = ({
|
|
|
531
560
|
marginBottom: "lg",
|
|
532
561
|
...boxProps.sx
|
|
533
562
|
},
|
|
534
|
-
children: [title && /* @__PURE__ */
|
|
563
|
+
children: [title && /* @__PURE__ */jsx11(Box3, {
|
|
535
564
|
sx: {
|
|
536
565
|
marginBottom: "md"
|
|
537
566
|
},
|
|
538
|
-
children: /* @__PURE__ */
|
|
567
|
+
children: /* @__PURE__ */jsx11(Text, {
|
|
539
568
|
sx: {
|
|
540
569
|
fontSize: "2xl",
|
|
541
570
|
fontWeight: "bold"
|
|
542
571
|
},
|
|
543
572
|
children: title
|
|
544
573
|
})
|
|
545
|
-
}), /* @__PURE__ */
|
|
574
|
+
}), /* @__PURE__ */jsx11(Flex4, {
|
|
546
575
|
sx: childrenContainerSx,
|
|
547
576
|
children
|
|
548
577
|
})]
|
|
@@ -553,17 +582,17 @@ var FormGroup = props => {
|
|
|
553
582
|
level
|
|
554
583
|
} = useFormGroup();
|
|
555
584
|
const currentLevel = level === void 0 ? 0 : level + 1;
|
|
556
|
-
return /* @__PURE__ */
|
|
585
|
+
return /* @__PURE__ */jsx11(FormGroupContext.Provider, {
|
|
557
586
|
value: {
|
|
558
587
|
parentLevel: currentLevel
|
|
559
588
|
},
|
|
560
|
-
children: currentLevel === 0 ? /* @__PURE__ */
|
|
561
|
-
children: /* @__PURE__ */
|
|
589
|
+
children: currentLevel === 0 ? /* @__PURE__ */jsx11(FormGroupLevelsManager, {
|
|
590
|
+
children: /* @__PURE__ */jsx11(FormGroupWrapper, {
|
|
562
591
|
...props
|
|
563
592
|
})
|
|
564
|
-
}) : /* @__PURE__ */
|
|
593
|
+
}) : /* @__PURE__ */jsx11(FormGroupWrapper, {
|
|
565
594
|
...props
|
|
566
595
|
})
|
|
567
596
|
});
|
|
568
597
|
};
|
|
569
|
-
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup, yup, yupResolver };
|
|
598
|
+
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, 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 { 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,12 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
|
|
|
36
37
|
name: FieldPath<TFieldValues>;
|
|
37
38
|
} & CheckboxProps) => react_jsx_runtime.JSX.Element;
|
|
38
39
|
|
|
40
|
+
type FormFieldNumericFormatProps = {
|
|
41
|
+
label?: string;
|
|
42
|
+
name: string;
|
|
43
|
+
} & NumericFormatProps;
|
|
44
|
+
declare const FormFieldNumericFormat: ({ label, name, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
|
|
45
|
+
|
|
39
46
|
type FormFieldInputProps<TName> = {
|
|
40
47
|
label?: string;
|
|
41
48
|
name: TName;
|
|
@@ -90,4 +97,4 @@ type FormGroupProps = {
|
|
|
90
97
|
} & BoxProps;
|
|
91
98
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
92
99
|
|
|
93
|
-
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
|
100
|
+
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, 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 { 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,12 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
|
|
|
36
37
|
name: FieldPath<TFieldValues>;
|
|
37
38
|
} & CheckboxProps) => react_jsx_runtime.JSX.Element;
|
|
38
39
|
|
|
40
|
+
type FormFieldNumericFormatProps = {
|
|
41
|
+
label?: string;
|
|
42
|
+
name: string;
|
|
43
|
+
} & NumericFormatProps;
|
|
44
|
+
declare const FormFieldNumericFormat: ({ label, name, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
|
|
45
|
+
|
|
39
46
|
type FormFieldInputProps<TName> = {
|
|
40
47
|
label?: string;
|
|
41
48
|
name: TName;
|
|
@@ -90,4 +97,4 @@ type FormGroupProps = {
|
|
|
90
97
|
} & BoxProps;
|
|
91
98
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
92
99
|
|
|
93
|
-
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
|
100
|
+
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
FormField: () => FormField,
|
|
44
44
|
FormFieldCheckbox: () => FormFieldCheckbox,
|
|
45
45
|
FormFieldInput: () => FormFieldInput,
|
|
46
|
+
FormFieldNumericFormat: () => FormFieldNumericFormat,
|
|
46
47
|
FormFieldPassword: () => FormFieldPassword,
|
|
47
48
|
FormFieldRadio: () => FormFieldRadio,
|
|
48
49
|
FormFieldSelect: () => FormFieldSelect,
|
|
@@ -271,9 +272,38 @@ var FormFieldCheckbox = ({
|
|
|
271
272
|
});
|
|
272
273
|
};
|
|
273
274
|
|
|
274
|
-
// src/
|
|
275
|
+
// src/FormFieldNumericFormat.tsx
|
|
275
276
|
var import_ui5 = require("@ttoss/ui");
|
|
277
|
+
var import_react_number_format = require("react-number-format");
|
|
276
278
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
279
|
+
var FormFieldNumericFormat = ({
|
|
280
|
+
label,
|
|
281
|
+
name,
|
|
282
|
+
...numericFormatProps
|
|
283
|
+
}) => {
|
|
284
|
+
return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormField, {
|
|
285
|
+
label,
|
|
286
|
+
name,
|
|
287
|
+
render: ({
|
|
288
|
+
field
|
|
289
|
+
}) => {
|
|
290
|
+
return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_react_number_format.NumericFormat, {
|
|
291
|
+
name: field.name,
|
|
292
|
+
value: field.value,
|
|
293
|
+
onBlur: field.onBlur,
|
|
294
|
+
onValueChange: values => {
|
|
295
|
+
field.onChange(values.floatValue);
|
|
296
|
+
},
|
|
297
|
+
customInput: import_ui5.Input,
|
|
298
|
+
...numericFormatProps
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/FormFieldInput.tsx
|
|
305
|
+
var import_ui6 = require("@ttoss/ui");
|
|
306
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
277
307
|
var FormFieldInput = ({
|
|
278
308
|
label,
|
|
279
309
|
name,
|
|
@@ -283,7 +313,7 @@ var FormFieldInput = ({
|
|
|
283
313
|
defaultValue = "",
|
|
284
314
|
...inputProps
|
|
285
315
|
}) => {
|
|
286
|
-
return /* @__PURE__ */(0,
|
|
316
|
+
return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormField, {
|
|
287
317
|
name,
|
|
288
318
|
label,
|
|
289
319
|
disabled: inputProps.disabled,
|
|
@@ -295,7 +325,7 @@ var FormFieldInput = ({
|
|
|
295
325
|
field,
|
|
296
326
|
fieldState
|
|
297
327
|
}) => {
|
|
298
|
-
return /* @__PURE__ */(0,
|
|
328
|
+
return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_ui6.Input, {
|
|
299
329
|
...inputProps,
|
|
300
330
|
...field,
|
|
301
331
|
"aria-invalid": fieldState.error ? "true" : void 0
|
|
@@ -305,8 +335,8 @@ var FormFieldInput = ({
|
|
|
305
335
|
};
|
|
306
336
|
|
|
307
337
|
// src/FormFieldPassword.tsx
|
|
308
|
-
var
|
|
309
|
-
var
|
|
338
|
+
var import_ui7 = require("@ttoss/ui");
|
|
339
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
310
340
|
var FormFieldPassword = ({
|
|
311
341
|
label,
|
|
312
342
|
name,
|
|
@@ -316,7 +346,7 @@ var FormFieldPassword = ({
|
|
|
316
346
|
defaultValue = "",
|
|
317
347
|
...inputProps
|
|
318
348
|
}) => {
|
|
319
|
-
return /* @__PURE__ */(0,
|
|
349
|
+
return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(FormField, {
|
|
320
350
|
name,
|
|
321
351
|
label,
|
|
322
352
|
disabled: inputProps.disabled,
|
|
@@ -328,7 +358,7 @@ var FormFieldPassword = ({
|
|
|
328
358
|
field,
|
|
329
359
|
fieldState
|
|
330
360
|
}) => {
|
|
331
|
-
return /* @__PURE__ */(0,
|
|
361
|
+
return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_ui7.InputPassword, {
|
|
332
362
|
...inputProps,
|
|
333
363
|
...field,
|
|
334
364
|
"aria-invalid": fieldState.error ? "true" : void 0
|
|
@@ -338,9 +368,9 @@ var FormFieldPassword = ({
|
|
|
338
368
|
};
|
|
339
369
|
|
|
340
370
|
// src/FormFieldRadio.tsx
|
|
341
|
-
var
|
|
371
|
+
var import_ui8 = require("@ttoss/ui");
|
|
342
372
|
var import_react_hook_form5 = require("react-hook-form");
|
|
343
|
-
var
|
|
373
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
344
374
|
var FormFieldRadio = ({
|
|
345
375
|
label,
|
|
346
376
|
name,
|
|
@@ -359,23 +389,23 @@ var FormFieldRadio = ({
|
|
|
359
389
|
name,
|
|
360
390
|
defaultValue: ""
|
|
361
391
|
});
|
|
362
|
-
return /* @__PURE__ */(0,
|
|
392
|
+
return /* @__PURE__ */(0, import_jsx_runtime8.jsxs)(import_ui8.Flex, {
|
|
363
393
|
sx: {
|
|
364
394
|
flexDirection: "column",
|
|
365
395
|
width: "100%",
|
|
366
396
|
...sx
|
|
367
397
|
},
|
|
368
|
-
children: [label && /* @__PURE__ */(0,
|
|
398
|
+
children: [label && /* @__PURE__ */(0, import_jsx_runtime8.jsx)(import_ui8.Label, {
|
|
369
399
|
sx: {
|
|
370
400
|
marginBottom: "md"
|
|
371
401
|
},
|
|
372
402
|
children: label
|
|
373
|
-
}), /* @__PURE__ */(0,
|
|
403
|
+
}), /* @__PURE__ */(0, import_jsx_runtime8.jsx)(import_ui8.Box, {
|
|
374
404
|
children: options.map(option => {
|
|
375
405
|
const id = `form-field-radio-${name}-${option.value}`;
|
|
376
|
-
return /* @__PURE__ */(0,
|
|
406
|
+
return /* @__PURE__ */(0, import_jsx_runtime8.jsxs)(import_ui8.Label, {
|
|
377
407
|
htmlFor: id,
|
|
378
|
-
children: [/* @__PURE__ */(0,
|
|
408
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime8.jsx)(import_ui8.Radio, {
|
|
379
409
|
ref,
|
|
380
410
|
onChange,
|
|
381
411
|
onBlur,
|
|
@@ -387,15 +417,15 @@ var FormFieldRadio = ({
|
|
|
387
417
|
}), option.label]
|
|
388
418
|
}, id);
|
|
389
419
|
})
|
|
390
|
-
}), /* @__PURE__ */(0,
|
|
420
|
+
}), /* @__PURE__ */(0, import_jsx_runtime8.jsx)(ErrorMessage, {
|
|
391
421
|
name
|
|
392
422
|
})]
|
|
393
423
|
});
|
|
394
424
|
};
|
|
395
425
|
|
|
396
426
|
// src/FormFieldSelect.tsx
|
|
397
|
-
var
|
|
398
|
-
var
|
|
427
|
+
var import_ui9 = require("@ttoss/ui");
|
|
428
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
399
429
|
var checkDefaultValue = ({
|
|
400
430
|
options,
|
|
401
431
|
defaultValue,
|
|
@@ -438,7 +468,7 @@ var FormFieldSelect = ({
|
|
|
438
468
|
defaultValue,
|
|
439
469
|
placeholder
|
|
440
470
|
});
|
|
441
|
-
return /* @__PURE__ */(0,
|
|
471
|
+
return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormField, {
|
|
442
472
|
name,
|
|
443
473
|
label,
|
|
444
474
|
disabled: selectProps.disabled,
|
|
@@ -450,7 +480,7 @@ var FormFieldSelect = ({
|
|
|
450
480
|
field,
|
|
451
481
|
fieldState
|
|
452
482
|
}) => {
|
|
453
|
-
return /* @__PURE__ */(0,
|
|
483
|
+
return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Select, {
|
|
454
484
|
...selectProps,
|
|
455
485
|
...field,
|
|
456
486
|
...{
|
|
@@ -459,7 +489,7 @@ var FormFieldSelect = ({
|
|
|
459
489
|
},
|
|
460
490
|
"aria-invalid": fieldState.error ? "true" : void 0,
|
|
461
491
|
children: options.map(option => {
|
|
462
|
-
return /* @__PURE__ */(0,
|
|
492
|
+
return /* @__PURE__ */(0, import_jsx_runtime9.jsx)("option", {
|
|
463
493
|
value: option.value,
|
|
464
494
|
children: option.label
|
|
465
495
|
}, option.label);
|
|
@@ -470,8 +500,8 @@ var FormFieldSelect = ({
|
|
|
470
500
|
};
|
|
471
501
|
|
|
472
502
|
// src/FormFieldTextarea.tsx
|
|
473
|
-
var
|
|
474
|
-
var
|
|
503
|
+
var import_ui10 = require("@ttoss/ui");
|
|
504
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
475
505
|
var FormFieldTextarea = ({
|
|
476
506
|
label,
|
|
477
507
|
name,
|
|
@@ -479,7 +509,7 @@ var FormFieldTextarea = ({
|
|
|
479
509
|
...textareaProps
|
|
480
510
|
}) => {
|
|
481
511
|
const id = `form-field-textarea-${name}`;
|
|
482
|
-
return /* @__PURE__ */(0,
|
|
512
|
+
return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormField, {
|
|
483
513
|
label,
|
|
484
514
|
name,
|
|
485
515
|
id,
|
|
@@ -488,7 +518,7 @@ var FormFieldTextarea = ({
|
|
|
488
518
|
field,
|
|
489
519
|
fieldState
|
|
490
520
|
}) => {
|
|
491
|
-
return /* @__PURE__ */(0,
|
|
521
|
+
return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(import_ui10.Textarea, {
|
|
492
522
|
...field,
|
|
493
523
|
...textareaProps,
|
|
494
524
|
"aria-invalid": fieldState.error ? "true" : void 0
|
|
@@ -499,8 +529,8 @@ var FormFieldTextarea = ({
|
|
|
499
529
|
|
|
500
530
|
// src/FormGroup.tsx
|
|
501
531
|
var React3 = __toESM(require("react"));
|
|
502
|
-
var
|
|
503
|
-
var
|
|
532
|
+
var import_ui11 = require("@ttoss/ui");
|
|
533
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
504
534
|
var FormGroupLevelsManagerContext = React3.createContext({
|
|
505
535
|
levelsLength: 1,
|
|
506
536
|
registerChild: () => {
|
|
@@ -516,7 +546,7 @@ var FormGroupLevelsManager = ({
|
|
|
516
546
|
setLevelsLength(level + 1);
|
|
517
547
|
}
|
|
518
548
|
}, [levelsLength]);
|
|
519
|
-
return /* @__PURE__ */(0,
|
|
549
|
+
return /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormGroupLevelsManagerContext.Provider, {
|
|
520
550
|
value: {
|
|
521
551
|
levelsLength,
|
|
522
552
|
registerChild
|
|
@@ -559,7 +589,7 @@ var FormGroupWrapper = ({
|
|
|
559
589
|
gap: "md",
|
|
560
590
|
width: "100%"
|
|
561
591
|
};
|
|
562
|
-
return /* @__PURE__ */(0,
|
|
592
|
+
return /* @__PURE__ */(0, import_jsx_runtime11.jsxs)(import_ui11.Box, {
|
|
563
593
|
"aria-level": level,
|
|
564
594
|
...boxProps,
|
|
565
595
|
sx: {
|
|
@@ -567,18 +597,18 @@ var FormGroupWrapper = ({
|
|
|
567
597
|
marginBottom: "lg",
|
|
568
598
|
...boxProps.sx
|
|
569
599
|
},
|
|
570
|
-
children: [title && /* @__PURE__ */(0,
|
|
600
|
+
children: [title && /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui11.Box, {
|
|
571
601
|
sx: {
|
|
572
602
|
marginBottom: "md"
|
|
573
603
|
},
|
|
574
|
-
children: /* @__PURE__ */(0,
|
|
604
|
+
children: /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui11.Text, {
|
|
575
605
|
sx: {
|
|
576
606
|
fontSize: "2xl",
|
|
577
607
|
fontWeight: "bold"
|
|
578
608
|
},
|
|
579
609
|
children: title
|
|
580
610
|
})
|
|
581
|
-
}), /* @__PURE__ */(0,
|
|
611
|
+
}), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui11.Flex, {
|
|
582
612
|
sx: childrenContainerSx,
|
|
583
613
|
children
|
|
584
614
|
})]
|
|
@@ -589,15 +619,15 @@ var FormGroup = props => {
|
|
|
589
619
|
level
|
|
590
620
|
} = useFormGroup();
|
|
591
621
|
const currentLevel = level === void 0 ? 0 : level + 1;
|
|
592
|
-
return /* @__PURE__ */(0,
|
|
622
|
+
return /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormGroupContext.Provider, {
|
|
593
623
|
value: {
|
|
594
624
|
parentLevel: currentLevel
|
|
595
625
|
},
|
|
596
|
-
children: currentLevel === 0 ? /* @__PURE__ */(0,
|
|
597
|
-
children: /* @__PURE__ */(0,
|
|
626
|
+
children: currentLevel === 0 ? /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormGroupLevelsManager, {
|
|
627
|
+
children: /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormGroupWrapper, {
|
|
598
628
|
...props
|
|
599
629
|
})
|
|
600
|
-
}) : /* @__PURE__ */(0,
|
|
630
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormGroupWrapper, {
|
|
601
631
|
...props
|
|
602
632
|
})
|
|
603
633
|
});
|
|
@@ -608,6 +638,7 @@ var FormGroup = props => {
|
|
|
608
638
|
FormField,
|
|
609
639
|
FormFieldCheckbox,
|
|
610
640
|
FormFieldInput,
|
|
641
|
+
FormFieldNumericFormat,
|
|
611
642
|
FormFieldPassword,
|
|
612
643
|
FormFieldRadio,
|
|
613
644
|
FormFieldSelect,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -23,16 +23,17 @@
|
|
|
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": {
|
|
29
30
|
"react": ">=16.8.0",
|
|
30
|
-
"@ttoss/react-i18n": "^1.25.
|
|
31
|
-
"@ttoss/ui": "^3.1.
|
|
31
|
+
"@ttoss/react-i18n": "^1.25.1",
|
|
32
|
+
"@ttoss/ui": "^3.1.7"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/jest": "^29.5.5",
|
|
35
|
-
"@types/react": "^18.2.
|
|
36
|
+
"@types/react": "^18.2.29",
|
|
36
37
|
"jest": "^29.7.0",
|
|
37
38
|
"react": "^18.2.0",
|
|
38
39
|
"react-error-boundary": "^4.0.9",
|
|
@@ -42,9 +43,9 @@
|
|
|
42
43
|
"yup": "^1.2.0",
|
|
43
44
|
"@ttoss/config": "^1.31.0",
|
|
44
45
|
"@ttoss/i18n-cli": "^0.7.0",
|
|
45
|
-
"@ttoss/react-i18n": "^1.25.
|
|
46
|
-
"@ttoss/test-utils": "^1.24.
|
|
47
|
-
"@ttoss/ui": "^3.1.
|
|
46
|
+
"@ttoss/react-i18n": "^1.25.1",
|
|
47
|
+
"@ttoss/test-utils": "^1.24.1",
|
|
48
|
+
"@ttoss/ui": "^3.1.7"
|
|
48
49
|
},
|
|
49
50
|
"publishConfig": {
|
|
50
51
|
"access": "public",
|
package/src/FormFieldInput.tsx
CHANGED
|
@@ -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,
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ 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 { FormFieldNumericFormat } from './FormFieldNumericFormat';
|
|
10
11
|
export { FormFieldInput } from './FormFieldInput';
|
|
11
12
|
export { FormFieldPassword } from './FormFieldPassword';
|
|
12
13
|
export { FormFieldRadio } from './FormFieldRadio';
|