@digigov/form 2.0.0-6e3977bc → 2.0.0-834daea4
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/Field/FieldBaseContainer/index.js +3 -3
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/types.d.ts +1 -0
- package/FieldArray/index.js +4 -4
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.js +2 -2
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +5 -5
- package/Fieldset/index.js.map +2 -2
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/index.js +3 -3
- package/FormBuilder/index.js.map +2 -2
- package/MultiplicityField/add-objects/index.js +4 -4
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +12 -10
- package/MultiplicityField/index.js.map +2 -2
- package/Questions/Step/StepTitle/index.js +4 -3
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +3 -3
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/types.js.map +1 -1
- package/cjs/FieldArray/index.js +6 -6
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +3 -3
- package/cjs/FieldObject/index.js.map +3 -3
- package/cjs/Fieldset/index.js +10 -10
- package/cjs/Fieldset/index.js.map +3 -3
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +5 -5
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/MultiplicityField/add-objects/index.js +8 -8
- package/cjs/MultiplicityField/add-objects.js.map +3 -3
- package/cjs/MultiplicityField/index.js +11 -14
- package/cjs/MultiplicityField/index.js.map +3 -3
- package/cjs/Questions/Step/StepTitle/index.js +5 -5
- package/cjs/Questions/Step/StepTitle.js.map +3 -3
- package/cjs/inputs/AutoCompleteInput/index.js +4 -4
- package/cjs/inputs/AutoCompleteInput/index.js.map +3 -3
- package/cjs/inputs/Checkboxes/index.js +6 -8
- package/cjs/inputs/Checkboxes/index.js.map +3 -3
- package/cjs/inputs/DateInput/index.js +3 -4
- package/cjs/inputs/DateInput/index.js.map +3 -3
- package/cjs/inputs/FileInput/index.js +7 -8
- package/cjs/inputs/FileInput/index.js.map +3 -3
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +2 -1
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +2 -2
- package/cjs/inputs/ImageInput/index.js +7 -8
- package/cjs/inputs/ImageInput/index.js.map +3 -3
- package/cjs/inputs/Input/index.js +4 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js +3 -3
- package/cjs/inputs/Label/index.js.map +3 -3
- package/cjs/inputs/Radio/index.js +11 -13
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +3 -4
- package/cjs/inputs/Select/index.js.map +3 -3
- package/cjs/lazy/index.js +4 -0
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +2 -0
- package/cjs/registry.js.map +2 -2
- package/cjs/validators/index.js +6 -65
- package/cjs/validators/index.js.map +3 -3
- package/cjs/validators/utils/date/index.js +138 -0
- package/cjs/validators/utils/date.js.map +7 -0
- package/cjs/validators/utils/index.js +3 -1
- package/cjs/validators/utils/index.js.map +2 -2
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/index.js +6 -4
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/index.js +7 -5
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/index.js +5 -3
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/FileInput/index.js +5 -6
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +2 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +2 -2
- package/inputs/ImageInput/index.js +6 -7
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/index.js +4 -4
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/index.js +2 -2
- package/inputs/Label/index.js.map +2 -2
- package/inputs/Radio/index.js +7 -5
- package/inputs/Radio/index.js.map +2 -2
- package/inputs/Select/index.js +1 -2
- package/inputs/Select/index.js.map +2 -2
- package/lazy/index.js +4 -0
- package/lazy.d.ts +4 -0
- package/lazy.js.map +2 -2
- package/package.json +4 -4
- package/registry/index.js +2 -0
- package/registry.d.ts +1 -0
- package/registry.js.map +2 -2
- package/src/Field/FieldBaseContainer.tsx +4 -2
- package/src/Field/types.tsx +20 -19
- package/src/FieldArray/index.tsx +9 -8
- package/src/FieldObject/index.tsx +2 -2
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/{FormBuilder.mdx → doc.mdx} +20 -33
- package/src/FormBuilder/index.tsx +3 -3
- package/src/MultiplicityField/add-objects.tsx +5 -6
- package/src/MultiplicityField/{MultiplicityField.mdx → doc.mdx} +12 -16
- package/src/MultiplicityField/index.tsx +13 -12
- package/src/Questions/Step/StepTitle.tsx +4 -3
- package/src/Questions/__snapshots__/index.spec.tsx.snap +17 -13
- package/src/Questions/{index.mdx → doc.mdx} +9 -12
- package/src/create-simple-form.mdx +2 -6
- package/src/{index.mdx → doc.mdx} +4 -8
- package/src/inputs/AutoCompleteInput/{index.mdx → doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.tsx +31 -26
- package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.tsx +29 -27
- package/src/inputs/DateInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/DateInput/index.tsx +5 -3
- package/src/inputs/FileInput/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/FileInput/index.tsx +5 -6
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +2 -0
- package/src/inputs/ImageInput/doc.mdx +23 -0
- package/src/inputs/ImageInput/index.tsx +9 -11
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.tsx +19 -11
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.tsx +2 -3
- package/src/inputs/OtpInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/Radio/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Radio/index.tsx +57 -55
- package/src/inputs/Select/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/Select/index.tsx +1 -2
- package/src/installation.mdx +2 -5
- package/src/lazy.js +4 -0
- package/src/registry.js +2 -0
- package/src/validators/index.ts +10 -70
- package/src/validators/utils/date.ts +107 -0
- package/src/validators/utils/index.ts +1 -0
- package/validators/index.js +10 -66
- package/validators/index.js.map +2 -2
- package/validators/utils/date/index.js +103 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +1 -0
- package/validators/utils/index.js.map +2 -2
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Label/index.mdx +0 -0
- /package/src/Field/{index.mdx → doc.mdx} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Image Input
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Image input
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Input element of type `image` defines an image as a submit button, i.e. submit buttons that take the form of an image rather than text.
|
|
10
|
+
|
|
11
|
+
## How to use
|
|
12
|
+
|
|
13
|
+
### Default
|
|
14
|
+
|
|
15
|
+
<code src="@digigov/form/inputs/ImageInput/__stories__/Default.tsx" />
|
|
16
|
+
|
|
17
|
+
### Display with max size
|
|
18
|
+
|
|
19
|
+
<code src="@digigov/form/inputs/ImageInput/__stories__/MaxSize.tsx" />
|
|
20
|
+
|
|
21
|
+
### Display with min and max image dimensions
|
|
22
|
+
|
|
23
|
+
<code src="@digigov/form/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx" />
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React, { useState, useCallback } from 'react';
|
|
2
2
|
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
-
import
|
|
4
|
-
import FileUploadContainer from '@digigov/
|
|
5
|
-
import CoreHint from '@digigov/react-core/Hint';
|
|
6
|
-
import Button, { ButtonGroup } from '@digigov/ui/form/Button';
|
|
3
|
+
import { Button, ButtonGroup } from '@digigov/ui/form/Button';
|
|
4
|
+
import { FileUpload, FileUploadContainer } from '@digigov/ui/form/FileUpload';
|
|
7
5
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
7
|
+
import { Paragraph } from '@digigov/ui/typography/Paragraph';
|
|
8
|
+
import { Base } from '@digigov/ui/utils/Base';
|
|
10
9
|
export interface ImageProps {
|
|
11
10
|
src?: any;
|
|
12
11
|
}
|
|
@@ -20,7 +19,7 @@ export interface Limit {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export const Image: React.FC<ImageProps> = React.memo(function Image({ src }) {
|
|
23
|
-
return <Base as=
|
|
22
|
+
return <Base as="img" src={src} className="ds-image--ratio" />;
|
|
24
23
|
});
|
|
25
24
|
export interface ImageInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
26
25
|
extra?: {
|
|
@@ -72,13 +71,12 @@ export const ImageInput: React.FC<ImageInputProps> = React.forwardRef(
|
|
|
72
71
|
{selectedImage !== null ? (
|
|
73
72
|
<>
|
|
74
73
|
<Paragraph>
|
|
75
|
-
<Base as=
|
|
74
|
+
<Base as="b">{t('upload.image')}:</Base>{' '}
|
|
75
|
+
{`${selectedImage?.name}`}
|
|
76
76
|
</Paragraph>
|
|
77
77
|
</>
|
|
78
78
|
) : (
|
|
79
|
-
<
|
|
80
|
-
{t('upload.no_image')}
|
|
81
|
-
</CoreHint>
|
|
79
|
+
<Hint className="ds-dashed--border">{t('upload.no_image')}</Hint>
|
|
82
80
|
)}
|
|
83
81
|
<>
|
|
84
82
|
{selectedImage !== null && <Image src={imageUrl} />}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Input
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Input
|
|
6
|
+
|
|
7
|
+
The input element of type `string` is used to create interactive controls for web-based forms in order to accept data from the user;
|
|
8
|
+
a wide variety of types of input data and control widgets are available, depending on the device and user agent. The input element is one of the most powerful and complex in all of HTML due to the sheer number of combinations of input types and attributes.
|
|
9
|
+
|
|
10
|
+
## How to use
|
|
11
|
+
|
|
12
|
+
### String
|
|
13
|
+
|
|
14
|
+
<code src="@digigov/form/inputs/Input/__stories__/String.tsx" />
|
|
15
|
+
|
|
16
|
+
### Boolean
|
|
17
|
+
|
|
18
|
+
<code src="@digigov/form/inputs/Input/__stories__/Boolean.tsx" />
|
|
19
|
+
|
|
20
|
+
### AFM
|
|
21
|
+
|
|
22
|
+
<code src="@digigov/form/inputs/Input/__stories__/AFM.tsx" />
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### IBAN
|
|
26
|
+
|
|
27
|
+
<code src="@digigov/form/inputs/Input/__stories__/IBAN.tsx" />
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Integer
|
|
31
|
+
|
|
32
|
+
<code src="@digigov/form/inputs/Input/__stories__/Integer.tsx" />
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Landline number
|
|
36
|
+
|
|
37
|
+
<code src="@digigov/form/inputs/Input/__stories__/LandlineNumber.tsx" />
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Mobile phone
|
|
41
|
+
|
|
42
|
+
<code src="@digigov/form/inputs/Input/__stories__/MobilePhone.tsx" />
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Phone number
|
|
46
|
+
|
|
47
|
+
<code src="@digigov/form/inputs/Input/__stories__/PhoneNumber.tsx" />
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Postal code
|
|
51
|
+
|
|
52
|
+
<code src="@digigov/form/inputs/Input/__stories__/PostalCode.tsx" />
|
|
53
|
+
|
|
54
|
+
### Text with character limit
|
|
55
|
+
|
|
56
|
+
<code src="@digigov/form/inputs/Input/__stories__/TextWithLimit.tsx" />
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useWatch } from 'react-hook-form';
|
|
3
3
|
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { TextInput } from '@digigov/react-core/TextInput';
|
|
4
|
+
import { TextArea } from '@digigov/ui/form/TextArea';
|
|
5
|
+
import { TextInput } from '@digigov/ui/form/TextInput';
|
|
7
6
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
7
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
8
|
+
|
|
8
9
|
const TYPES_MAP = {
|
|
9
10
|
string: 'text',
|
|
10
11
|
int: 'text',
|
|
@@ -27,7 +28,7 @@ export interface InputProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export const Input: React.ExoticComponent<InputProps> = React.forwardRef(
|
|
30
|
-
function WrappedInput({ name, control, type, extra, ...props }, ref: never) {
|
|
31
|
+
function WrappedInput({ name, control, type, extra, Field, ...props }, ref: never) {
|
|
31
32
|
// eslint-disable-next-line prefer-const
|
|
32
33
|
let { multiline = false, rows, limit } = extra || {};
|
|
33
34
|
const { className } = extra || {};
|
|
@@ -42,17 +43,23 @@ export const Input: React.ExoticComponent<InputProps> = React.forwardRef(
|
|
|
42
43
|
|
|
43
44
|
const getRemainingChars = (currentValue, limit) => {
|
|
44
45
|
if (currentValue) {
|
|
45
|
-
return limit?.max - currentValue.length
|
|
46
|
+
return limit?.max - currentValue.length;
|
|
46
47
|
}
|
|
47
48
|
return limit?.max;
|
|
48
|
-
}
|
|
49
|
+
};
|
|
49
50
|
|
|
50
51
|
const constructRemainingText = (currentValue, limit) => {
|
|
51
52
|
const remainingChars = getRemainingChars(currentValue, limit);
|
|
52
|
-
let remainingText =
|
|
53
|
-
|
|
53
|
+
let remainingText =
|
|
54
|
+
Math.abs(remainingChars) === 1
|
|
55
|
+
? t('form.info.text.character')
|
|
56
|
+
: t('form.info.text.characters');
|
|
57
|
+
remainingText +=
|
|
58
|
+
remainingChars > 0
|
|
59
|
+
? ` ${t('form.info.text.remaining')}.`
|
|
60
|
+
: ` ${t('form.info.text.too_many')}.`;
|
|
54
61
|
return remainingText;
|
|
55
|
-
}
|
|
62
|
+
};
|
|
56
63
|
|
|
57
64
|
if (multiline === true) {
|
|
58
65
|
return (
|
|
@@ -72,8 +79,9 @@ export const Input: React.ExoticComponent<InputProps> = React.forwardRef(
|
|
|
72
79
|
{limit?.max && (
|
|
73
80
|
<Hint display={'flex'}>
|
|
74
81
|
{t('form.info.text.you_have')}
|
|
75
|
-
<Hint fontWeight=
|
|
76
|
-
{`${Math.abs(getRemainingChars(currentValue, limit))}`}
|
|
82
|
+
<Hint fontWeight="bold">
|
|
83
|
+
{`${Math.abs(getRemainingChars(currentValue, limit))}`}
|
|
84
|
+
|
|
77
85
|
</Hint>
|
|
78
86
|
{constructRemainingText(currentValue, limit)}
|
|
79
87
|
</Hint>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Label
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Label
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
The Label component is used to display descriptive text for form sections or fields. It supports both primary and secondary text, allowing for a title and optional subtitle.
|
|
9
|
+
|
|
10
|
+
## How to use
|
|
11
|
+
|
|
12
|
+
### Default
|
|
13
|
+
|
|
14
|
+
<code src="@digigov/form/inputs/Label/__stories__/Default.tsx" />
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FieldLabelProps } from '@digigov/form/types';
|
|
3
|
-
import
|
|
4
|
-
import LabelTitle from '@digigov/react-core/LabelTitle';
|
|
3
|
+
import { LabelTitle } from '@digigov/ui/form/LabelContainer';
|
|
5
4
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
5
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
6
6
|
|
|
7
7
|
export interface FieldOptionProps {
|
|
8
8
|
label?: FieldLabelProps;
|
|
@@ -39,5 +39,4 @@ export const Label: React.FC<LabelProps> = ({ className, label, value }) => {
|
|
|
39
39
|
);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
|
|
43
42
|
export default Label;
|
|
@@ -10,24 +10,14 @@ Radios are used to let a user select one option of a limited number of choices.
|
|
|
10
10
|
|
|
11
11
|
### Default
|
|
12
12
|
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
component="inputs/Radio"
|
|
16
|
-
story="Default.tsx"
|
|
17
|
-
/>
|
|
13
|
+
<code src="@digigov/form/inputs/Radio/__stories__/Default.tsx" />
|
|
14
|
+
|
|
18
15
|
|
|
19
16
|
### Conditional
|
|
20
17
|
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
component="inputs/Radio"
|
|
24
|
-
story="Conditional.tsx"
|
|
25
|
-
/>
|
|
18
|
+
<code src="@digigov/form/inputs/Radio/__stories__/Conditional.tsx" />
|
|
19
|
+
|
|
26
20
|
|
|
27
21
|
### With divider
|
|
28
22
|
|
|
29
|
-
<
|
|
30
|
-
packageName="@digigov/form"
|
|
31
|
-
component="inputs/Radio"
|
|
32
|
-
story="WithDivider.tsx"
|
|
33
|
-
/>
|
|
23
|
+
<code src="@digigov/form/inputs/Radio/__stories__/WithDivider.tsx" />
|
|
@@ -2,12 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import { useWatch } from 'react-hook-form';
|
|
3
3
|
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
4
4
|
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import {
|
|
6
|
+
RadioContainer,
|
|
7
|
+
RadioItem,
|
|
8
|
+
RadioConditional,
|
|
9
|
+
} from '@digigov/ui/form/RadioContainer';
|
|
10
10
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
11
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
12
|
+
import { Base } from '@digigov/ui/utils/Base';
|
|
11
13
|
|
|
12
14
|
export interface RadioButtonsGroupProps
|
|
13
15
|
extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
@@ -87,55 +89,55 @@ export const ControlledRadioButtonsGroup: React.FC<
|
|
|
87
89
|
Field,
|
|
88
90
|
...props
|
|
89
91
|
}) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
92
|
+
const currentValue: string | undefined = value;
|
|
93
|
+
const { t } = useTranslation();
|
|
94
|
+
return (
|
|
95
|
+
<RadioContainer className={className} id={name}>
|
|
96
|
+
{options.map(
|
|
97
|
+
({
|
|
98
|
+
label,
|
|
99
|
+
value: v,
|
|
100
|
+
show,
|
|
101
|
+
disabled: optionDisabled,
|
|
102
|
+
selected,
|
|
103
|
+
...option
|
|
104
|
+
}) => (
|
|
105
|
+
<React.Fragment key={`${name}.${v}`}>
|
|
106
|
+
<RadioItem
|
|
107
|
+
onChange={(e) => {
|
|
108
|
+
console.log(e);
|
|
109
|
+
onChange(e);
|
|
110
|
+
}}
|
|
111
|
+
id={`${name}.${v}`}
|
|
112
|
+
value={v}
|
|
113
|
+
checked={currentValue === v}
|
|
114
|
+
disabled={disabled || optionDisabled}
|
|
115
|
+
{...option}
|
|
116
|
+
{...{
|
|
117
|
+
...props,
|
|
118
|
+
reset: undefined,
|
|
119
|
+
required: undefined,
|
|
120
|
+
error: undefined,
|
|
121
|
+
'aria-describedby': undefined,
|
|
122
|
+
type: 'radio',
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
{(label && label.primary && t(label.primary)) || v}
|
|
126
|
+
{label && label.secondary && <Hint>{t(label.secondary)}</Hint>}
|
|
127
|
+
</RadioItem>
|
|
128
|
+
{selected && selected()}
|
|
129
|
+
{currentValue === v && show && (
|
|
130
|
+
<RadioConditional>
|
|
131
|
+
{show.map((fieldName) => (
|
|
132
|
+
<Field name={fieldName} key={fieldName} />
|
|
133
|
+
))}
|
|
134
|
+
</RadioConditional>
|
|
135
|
+
)}
|
|
136
|
+
</React.Fragment>
|
|
137
|
+
)
|
|
138
|
+
)}
|
|
139
|
+
</RadioContainer>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
140
142
|
|
|
141
143
|
export default RadioButtonsGroup;
|
|
@@ -10,8 +10,4 @@ The select element represents a control that provides a menu of options.
|
|
|
10
10
|
|
|
11
11
|
### Default
|
|
12
12
|
|
|
13
|
-
<
|
|
14
|
-
packageName="@digigov/form"
|
|
15
|
-
component="inputs/Select"
|
|
16
|
-
story="Default.tsx"
|
|
17
|
-
/>
|
|
13
|
+
<code src="@digigov/form/inputs/Select/__stories__/Default.tsx" />
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
3
|
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
|
-
import SelectContainer from '@digigov/
|
|
5
|
-
import SelectOption from '@digigov/react-core/SelectOption';
|
|
4
|
+
import { SelectContainer, SelectOption } from '@digigov/ui/form/SelectContainer';
|
|
6
5
|
|
|
7
6
|
export interface SelectProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
8
7
|
extra: {
|
package/src/installation.mdx
CHANGED
|
@@ -7,12 +7,9 @@ sidebar_label: Installation
|
|
|
7
7
|
import Tabs from '@theme/Tabs';
|
|
8
8
|
import TabItem from '@theme/TabItem';
|
|
9
9
|
import CodeBlock from '@theme/CodeBlock';
|
|
10
|
-
import LeadText from '@site/src/components/LeadText';
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
you use and the application architecture.
|
|
15
|
-
</LeadText>
|
|
11
|
+
This page will help you install Digigov Form depending on the framework that
|
|
12
|
+
you use and the application architecture.
|
|
16
13
|
|
|
17
14
|
We assume that your stack uses some of the following tools.
|
|
18
15
|
|
package/src/lazy.js
CHANGED
|
@@ -29,6 +29,7 @@ export default {
|
|
|
29
29
|
'Radio': lazy(() => import('@digigov/form/inputs').then((module)=> ({default: module['Radio']}))),
|
|
30
30
|
'Select': lazy(() => import('@digigov/form/inputs/Select').then((module)=> ({default: module['Select']}))),
|
|
31
31
|
'INPUTS_FIELDS': lazy(() => import('@digigov/form/inputs/inputsScenarios').then((module)=> ({default: module['INPUTS_FIELDS']}))),
|
|
32
|
+
'MultipleInput': lazy(() => import('@digigov/form/inputs/MultipleInput').then((module)=> ({default: module['MultipleInput']}))),
|
|
32
33
|
'REMOVE_SPACES': lazy(() => import('@digigov/form/inputs/OtpInput').then((module)=> ({default: module['REMOVE_SPACES']}))),
|
|
33
34
|
'RE_DIGIT': lazy(() => import('@digigov/form/inputs/OtpInput').then((module)=> ({default: module['RE_DIGIT']}))),
|
|
34
35
|
'ControlledRadioButtonsGroup': lazy(() => import('@digigov/form/inputs/Radio').then((module)=> ({default: module['ControlledRadioButtonsGroup']}))),
|
|
@@ -50,6 +51,9 @@ export default {
|
|
|
50
51
|
'Questions': lazy(() => import('@digigov/form/Questions/Questions').then((module)=> ({default: module['Questions']}))),
|
|
51
52
|
'QuestionsContext': lazy(() => import('@digigov/form/Questions/QuestionsContext').then((module)=> ({default: module['QuestionsContext']}))),
|
|
52
53
|
'AFM_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/afm').then((module)=> ({default: module['AFM_VALIDATOR']}))),
|
|
54
|
+
'DATE_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/date').then((module)=> ({default: module['DATE_VALIDATOR']}))),
|
|
55
|
+
'EARLIER_THAN_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/date').then((module)=> ({default: module['EARLIER_THAN_VALIDATOR']}))),
|
|
56
|
+
'LATER_THAN_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/date').then((module)=> ({default: module['LATER_THAN_VALIDATOR']}))),
|
|
53
57
|
'FILE_MAX_SIZE_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/file').then((module)=> ({default: module['FILE_MAX_SIZE_VALIDATOR']}))),
|
|
54
58
|
'IBAN_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/iban').then((module)=> ({default: module['IBAN_VALIDATOR']}))),
|
|
55
59
|
'IMAGE_DIMENSION_VALIDATOR': lazy(() => import('@digigov/form/validators/utils/image').then((module)=> ({default: module['IMAGE_DIMENSION_VALIDATOR']}))),
|
package/src/registry.js
CHANGED
|
@@ -55,6 +55,7 @@ import * as _digigov_form_utils from '@digigov/form/utils';
|
|
|
55
55
|
import * as _digigov_form_validators from '@digigov/form/validators';
|
|
56
56
|
import * as _digigov_form_validators_types from '@digigov/form/validators/types';
|
|
57
57
|
import * as _digigov_form_validators_utils_afm from '@digigov/form/validators/utils/afm';
|
|
58
|
+
import * as _digigov_form_validators_utils_date from '@digigov/form/validators/utils/date';
|
|
58
59
|
import * as _digigov_form_validators_utils_file from '@digigov/form/validators/utils/file';
|
|
59
60
|
import * as _digigov_form_validators_utils_iban from '@digigov/form/validators/utils/iban';
|
|
60
61
|
import * as _digigov_form_validators_utils_image from '@digigov/form/validators/utils/image';
|
|
@@ -142,6 +143,7 @@ export default {
|
|
|
142
143
|
'@digigov/form/validators': lazyImport(_digigov_form_validators),
|
|
143
144
|
'@digigov/form/validators/types': lazyImport(_digigov_form_validators_types),
|
|
144
145
|
'@digigov/form/validators/utils/afm': lazyImport(_digigov_form_validators_utils_afm),
|
|
146
|
+
'@digigov/form/validators/utils/date': lazyImport(_digigov_form_validators_utils_date),
|
|
145
147
|
'@digigov/form/validators/utils/file': lazyImport(_digigov_form_validators_utils_file),
|
|
146
148
|
'@digigov/form/validators/utils/iban': lazyImport(_digigov_form_validators_utils_iban),
|
|
147
149
|
'@digigov/form/validators/utils/image': lazyImport(_digigov_form_validators_utils_image),
|
package/src/validators/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MutableRefObject, useMemo } from 'react';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
2
|
import * as yup from 'yup';
|
|
5
3
|
import { AnyObjectSchema, StringSchema } from 'yup';
|
|
6
4
|
import { RequiredArraySchema } from 'yup/lib/array';
|
|
@@ -22,16 +20,12 @@ import {
|
|
|
22
20
|
POSTALCODE_VALIDATOR,
|
|
23
21
|
UUID4_VALIDATOR,
|
|
24
22
|
IMAGE_DIMENSION_VALIDATOR,
|
|
23
|
+
DATE_VALIDATOR,
|
|
24
|
+
LATER_THAN_VALIDATOR,
|
|
25
|
+
EARLIER_THAN_VALIDATOR,
|
|
25
26
|
} from '@digigov/form/validators/utils';
|
|
26
27
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
27
28
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
28
|
-
dayjs.extend(customParseFormat);
|
|
29
|
-
|
|
30
|
-
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
31
|
-
const DATE_CACHE = {};
|
|
32
|
-
const getDate = (v) => {
|
|
33
|
-
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
34
|
-
};
|
|
35
29
|
|
|
36
30
|
export const getYUPTypeMap = (): Record<string, any> => {
|
|
37
31
|
const yupTypeMap = {
|
|
@@ -150,69 +144,15 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
150
144
|
AnyObject,
|
|
151
145
|
string | null | undefined
|
|
152
146
|
> => yup.string().nullable(),
|
|
153
|
-
date: (field) => {
|
|
154
|
-
|
|
155
|
-
.string()
|
|
156
|
-
.nullable(true)
|
|
157
|
-
.test('date', 'form.error.date.invalid', function (value) {
|
|
158
|
-
if (!value) return true;
|
|
159
|
-
const date = getDate(value);
|
|
160
|
-
return date.isValid();
|
|
161
|
-
});
|
|
162
|
-
const params = field.extra || {};
|
|
163
|
-
if (params.max) {
|
|
164
|
-
let maxDate;
|
|
165
|
-
if (params.max === 'now') {
|
|
166
|
-
const today = new Date();
|
|
167
|
-
maxDate = new Date(today);
|
|
168
|
-
} else {
|
|
169
|
-
maxDate = getDate(params.max).toDate();
|
|
170
|
-
}
|
|
171
|
-
const maxNextDate = new Date(maxDate);
|
|
172
|
-
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
173
|
-
simpleDate = simpleDate.test({
|
|
174
|
-
name: 'earlier-than',
|
|
175
|
-
message: {
|
|
176
|
-
key: 'form.error.date.earlier_than',
|
|
177
|
-
context: {
|
|
178
|
-
maxDate: maxNextDate.toLocaleDateString(),
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
test: function (value) {
|
|
182
|
-
if (!value) return true;
|
|
183
|
-
const date = getDate(value);
|
|
184
|
-
const isValid = +date.toDate() < +maxDate;
|
|
185
|
-
return isValid;
|
|
186
|
-
},
|
|
187
|
-
});
|
|
147
|
+
date: (field): yup.StringSchema => {
|
|
148
|
+
if (field?.extra?.min) {
|
|
149
|
+
return yup.string().test(LATER_THAN_VALIDATOR(field));
|
|
188
150
|
}
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
minDate = new Date(today);
|
|
194
|
-
} else {
|
|
195
|
-
minDate = getDate(params.min).toDate();
|
|
196
|
-
}
|
|
197
|
-
const minPreviousDate = new Date(minDate);
|
|
198
|
-
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
199
|
-
simpleDate = simpleDate.test({
|
|
200
|
-
name: 'later-than',
|
|
201
|
-
message: {
|
|
202
|
-
key: 'form.error.date.later_than',
|
|
203
|
-
context: {
|
|
204
|
-
minDate: minPreviousDate.toLocaleDateString(),
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
test: function (value) {
|
|
208
|
-
if (!value) return true;
|
|
209
|
-
const date = getDate(value);
|
|
210
|
-
const isValid = +date.toDate() > +minDate;
|
|
211
|
-
return isValid;
|
|
212
|
-
},
|
|
213
|
-
});
|
|
151
|
+
if (field?.extra?.max) {
|
|
152
|
+
return yup.string().test(EARLIER_THAN_VALIDATOR(field));
|
|
153
|
+
} else {
|
|
154
|
+
return yup.string().test(DATE_VALIDATOR);
|
|
214
155
|
}
|
|
215
|
-
return simpleDate;
|
|
216
156
|
},
|
|
217
157
|
};
|
|
218
158
|
return yupTypeMap;
|