@digigov/form 0.10.8 → 0.10.10
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/CHANGELOG.md +8 -1
- package/Form.stories.playwright.json +0 -72
- package/FormBuilder/FormBuilder.mdx +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.js +6 -6
- package/Questions/__stories__/Default.js +2 -2
- package/Questions/index.mdx +1 -1
- package/es/Form.stories.playwright.json +0 -72
- package/es/FormBuilder/FormBuilder.mdx +1 -1
- package/es/MultiplicityField/__stories__/PreviewDisplay.js +6 -6
- package/es/Questions/__stories__/Default.js +1 -1
- package/es/Questions/index.mdx +1 -1
- package/esm/Form.stories.playwright.json +0 -72
- package/esm/FormBuilder/FormBuilder.mdx +1 -1
- package/esm/MultiplicityField/__stories__/PreviewDisplay.js +6 -6
- package/esm/Questions/__stories__/Default.js +1 -1
- package/esm/Questions/index.mdx +1 -1
- package/esm/index.js +1 -1
- package/package.json +4 -4
- package/src/Field/FieldBase.tsx +99 -0
- package/src/Field/FieldBaseContainer.tsx +57 -0
- package/src/Field/FieldConditional.tsx +75 -0
- package/src/Field/index.mdx +6 -0
- package/src/Field/index.tsx +92 -0
- package/src/Field/types.tsx +102 -0
- package/src/Field/utils.ts +164 -0
- package/src/FieldArray/FieldArray.stories.js +8 -0
- package/src/FieldArray/FieldArray.stories.playwright.json +353 -0
- package/src/FieldArray/__stories__/Default.tsx +95 -0
- package/src/FieldArray/__stories__/WithExactLength.tsx +95 -0
- package/src/FieldArray/index.tsx +83 -0
- package/src/FieldObject/index.tsx +92 -0
- package/src/Fieldset/FieldsetWithContext.tsx +41 -0
- package/src/Fieldset/index.tsx +40 -0
- package/src/Fieldset/types.tsx +6 -0
- package/src/Form.stories.js +5 -0
- package/src/Form.stories.playwright.json +71 -0
- package/src/FormBuilder/FormBuilder.mdx +271 -0
- package/src/FormBuilder/FormBuilder.stories.js +7 -0
- package/src/FormBuilder/FormBuilder.stories.playwright.json +52 -0
- package/src/FormBuilder/FormBuilder.tsx +165 -0
- package/src/FormBuilder/__stories__/Default.tsx +23 -0
- package/src/FormBuilder/index.tsx +3 -0
- package/src/FormContext.tsx +8 -0
- package/src/MultiplicityField/MultiplicityField.mdx +580 -0
- package/src/MultiplicityField/MultiplicityField.stories.js +12 -0
- package/src/MultiplicityField/MultiplicityField.stories.playwright.json +1370 -0
- package/src/MultiplicityField/__stories__/Default.tsx +100 -0
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +160 -0
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +99 -0
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +102 -0
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +103 -0
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +102 -0
- package/src/MultiplicityField/add-objects.tsx +186 -0
- package/src/MultiplicityField/index.tsx +166 -0
- package/src/Questions/Questions.stories.js +7 -0
- package/src/Questions/Questions.tsx +74 -0
- package/src/Questions/QuestionsContext.tsx +9 -0
- package/src/Questions/Step/ReviewStep.tsx +63 -0
- package/src/Questions/Step/Step.tsx +67 -0
- package/src/Questions/Step/StepArrayReview.tsx +68 -0
- package/src/Questions/Step/StepContext.tsx +21 -0
- package/src/Questions/Step/StepDescription.tsx +33 -0
- package/src/Questions/Step/StepForm.tsx +60 -0
- package/src/Questions/Step/StepQuote.tsx +8 -0
- package/src/Questions/Step/StepTitle.tsx +60 -0
- package/src/Questions/Step/getAddMoreFields.tsx +28 -0
- package/src/Questions/Step/index.ts +13 -0
- package/src/Questions/Step/types.tsx +32 -0
- package/src/Questions/__snapshots__/index.spec.tsx.snap +887 -0
- package/src/Questions/__stories__/Default.tsx +130 -0
- package/src/Questions/getNextStep.tsx +24 -0
- package/src/Questions/index.mdx +418 -0
- package/src/Questions/index.spec.tsx +72 -0
- package/src/Questions/index.tsx +5 -0
- package/src/Questions/types.tsx +25 -0
- package/src/__stories__/AutoCompleteField.tsx +45 -0
- package/src/__stories__/IntField.tsx +38 -0
- package/src/create-simple-form.mdx +518 -0
- package/src/index.mdx +44 -0
- package/src/index.ts +3 -0
- package/src/inputs/AutoComplete/index.tsx +85 -0
- package/src/inputs/Checkboxes/Checkboxes.stories.js +7 -0
- package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +69 -0
- package/src/inputs/Checkboxes/__stories__/Default.tsx +39 -0
- package/src/inputs/Checkboxes/index.mdx +0 -0
- package/src/inputs/Checkboxes/index.tsx +77 -0
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/DateInput.stories.playwright.json +72 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +41 -0
- package/src/inputs/DateInput/index.tsx +130 -0
- package/src/inputs/FileInput/FileInput.stories.js +7 -0
- package/src/inputs/FileInput/FileInput.stories.playwright.json +75 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +23 -0
- package/src/inputs/FileInput/index.tsx +76 -0
- package/src/inputs/Input/Input.stories.js +14 -0
- package/src/inputs/Input/Input.stories.playwright.json +376 -0
- package/src/inputs/Input/__stories__/AFM.tsx +24 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +26 -0
- package/src/inputs/Input/__stories__/Default.tsx +25 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +26 -0
- package/src/inputs/Input/__stories__/Integer.tsx +25 -0
- package/src/inputs/Input/__stories__/MobilePhone.tsx +24 -0
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +24 -0
- package/src/inputs/Input/__stories__/PostalCode.tsx +25 -0
- package/src/inputs/Input/index.mdx +8 -0
- package/src/inputs/Input/index.tsx +62 -0
- package/src/inputs/Label/Label.stories.js +7 -0
- package/src/inputs/Label/Label.stories.playwright.json +40 -0
- package/src/inputs/Label/__stories__/Default.tsx +28 -0
- package/src/inputs/Label/index.mdx +0 -0
- package/src/inputs/Label/index.tsx +44 -0
- package/src/inputs/Radio/Radio.stories.js +7 -0
- package/src/inputs/Radio/Radio.stories.playwright.json +57 -0
- package/src/inputs/Radio/__stories__/Default.tsx +42 -0
- package/src/inputs/Radio/index.mdx +0 -0
- package/src/inputs/Radio/index.tsx +57 -0
- package/src/inputs/Select/Select.stories.js +7 -0
- package/src/inputs/Select/Select.stories.playwright.json +22 -0
- package/src/inputs/Select/__stories__/Default.tsx +47 -0
- package/src/inputs/Select/index.tsx +37 -0
- package/src/inputs/index.ts +7 -0
- package/src/installation.mdx +72 -0
- package/src/internal.ts +34 -0
- package/src/registry.js +134 -0
- package/src/types.tsx +110 -0
- package/src/utils.ts +78 -0
- package/src/validators/index.ts +203 -0
- package/src/validators/types.ts +2 -0
- package/src/validators/utils/afm.ts +37 -0
- package/src/validators/utils/file.ts +25 -0
- package/src/validators/utils/iban.ts +119 -0
- package/src/validators/utils/index.ts +94 -0
- package/src/validators/utils/int.ts +22 -0
- package/src/validators/utils/number.ts +18 -0
- package/src/validators/utils/phone.ts +120 -0
- package/src/validators/utils/postal_code.ts +33 -0
- package/src/validators/utils/uuid4.ts +21 -0
- package/src/validators/validators.spec.ts +122 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import UIAutoComplete, {
|
|
3
|
+
AutoCompleteProps as UIAutoCompleteProps,
|
|
4
|
+
} from '@digigov/ui/admin/AutoComplete';
|
|
5
|
+
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
6
|
+
import { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
7
|
+
import { Hint } from '@digigov/react-core';
|
|
8
|
+
|
|
9
|
+
export interface AutoCompleteExtra
|
|
10
|
+
extends Omit<
|
|
11
|
+
UIAutoCompleteProps,
|
|
12
|
+
| 'source'
|
|
13
|
+
| 'id'
|
|
14
|
+
| 'templates'
|
|
15
|
+
| 'defaultValue'
|
|
16
|
+
| 'onConfirm'
|
|
17
|
+
| 'dropdownArrow'
|
|
18
|
+
> {
|
|
19
|
+
options: Array<FieldOptionProps>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AutoCompleteProps
|
|
23
|
+
extends Omit<ControlledFieldProps, 'value' | 'onChange' | 'extra'> {
|
|
24
|
+
extra: AutoCompleteExtra;
|
|
25
|
+
value: string;
|
|
26
|
+
onChange: (v: string) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const AutoComplete: React.FC<AutoCompleteProps> = ({
|
|
30
|
+
name,
|
|
31
|
+
extra: { options },
|
|
32
|
+
onChange,
|
|
33
|
+
value,
|
|
34
|
+
...props
|
|
35
|
+
}) => {
|
|
36
|
+
const suggest = useCallback(function suggest(
|
|
37
|
+
query: string,
|
|
38
|
+
syncResults: (options: any[]) => void
|
|
39
|
+
): void {
|
|
40
|
+
syncResults(
|
|
41
|
+
query
|
|
42
|
+
? options.filter(function (option) {
|
|
43
|
+
return (
|
|
44
|
+
`${option.value} ${option.label?.primary || ''} ${
|
|
45
|
+
option.label?.secondary || ''
|
|
46
|
+
}`
|
|
47
|
+
.toLowerCase()
|
|
48
|
+
.indexOf(query.toLowerCase()) !== -1
|
|
49
|
+
);
|
|
50
|
+
})
|
|
51
|
+
: []
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
[]);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<UIAutoComplete
|
|
58
|
+
source={suggest}
|
|
59
|
+
onConfirm={(value) => {
|
|
60
|
+
onChange(value.value);
|
|
61
|
+
}}
|
|
62
|
+
templates={{
|
|
63
|
+
suggestion({ label, value }) {
|
|
64
|
+
return (
|
|
65
|
+
<div>
|
|
66
|
+
{(label && label.primary && label.primary) || value}
|
|
67
|
+
{label && label.secondary && <Hint>{label.secondary}</Hint>}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
inputValue: (option) => {
|
|
72
|
+
if (!option) {
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
return option.label.primary || option.value;
|
|
76
|
+
},
|
|
77
|
+
}}
|
|
78
|
+
{...props}
|
|
79
|
+
id={`${name}-id`}
|
|
80
|
+
defaultValue={value}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default AutoComplete;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "4",
|
|
3
|
+
"stories": {
|
|
4
|
+
"digigov-form-inputs-checkboxes--default": {
|
|
5
|
+
"actionSets": [
|
|
6
|
+
{
|
|
7
|
+
"actions": [
|
|
8
|
+
{
|
|
9
|
+
"name": "click",
|
|
10
|
+
"args": {
|
|
11
|
+
"selector": "html>body>div:nth-child(5)>form>button"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"id": "6mm9fbbYacA3",
|
|
16
|
+
"title": "show validation error"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"actions": [
|
|
20
|
+
{
|
|
21
|
+
"name": "keyboard.press",
|
|
22
|
+
"args": {
|
|
23
|
+
"key": "Tab"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "keyboard.press",
|
|
28
|
+
"args": {
|
|
29
|
+
"key": "Tab"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "keyboard.press",
|
|
34
|
+
"args": {
|
|
35
|
+
"key": "Space"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "keyboard.press",
|
|
40
|
+
"args": {
|
|
41
|
+
"key": "Tab"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "keyboard.press",
|
|
46
|
+
"args": {
|
|
47
|
+
"key": "Space"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "click",
|
|
52
|
+
"args": {
|
|
53
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(1)>label>input"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "click",
|
|
58
|
+
"args": {
|
|
59
|
+
"selector": "html>body>div:nth-child(5)>form>button"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"id": "hBiOJ8xaQSWv",
|
|
64
|
+
"title": "Focus and check using keyboard, click box and submit"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
export const Default = () => (
|
|
6
|
+
<FormBuilder
|
|
7
|
+
onSubmit={(data) => {
|
|
8
|
+
debugger;
|
|
9
|
+
console.log(data);
|
|
10
|
+
}}
|
|
11
|
+
>
|
|
12
|
+
<Field
|
|
13
|
+
key={'string'}
|
|
14
|
+
name="string"
|
|
15
|
+
type="choice:multiple"
|
|
16
|
+
required
|
|
17
|
+
label={{ primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' }}
|
|
18
|
+
extra={{
|
|
19
|
+
options: [
|
|
20
|
+
{
|
|
21
|
+
label: { primary: 'Έχω συνάχι' },
|
|
22
|
+
value: 'runny-nose',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: { primary: 'Έχω πυρετό' },
|
|
26
|
+
value: 'fever',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: { primary: 'Αισθάνομαι κούραση' },
|
|
30
|
+
value: 'fatigue',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
<Button type="submit">Συνέχεια</Button>
|
|
36
|
+
</FormBuilder>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export default Default;
|
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
3
|
+
import { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
4
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
5
|
+
import CoreCheckboxes from '@digigov/react-core/Checkbox';
|
|
6
|
+
import CheckboxItem from '@digigov/react-core/CheckboxItem';
|
|
7
|
+
import Hint from '@digigov/react-core/Hint';
|
|
8
|
+
|
|
9
|
+
export interface CheckboxesProps
|
|
10
|
+
extends Omit<ControlledFieldProps, 'extra' | 'value'> {
|
|
11
|
+
value?: string[];
|
|
12
|
+
extra: {
|
|
13
|
+
className?: string;
|
|
14
|
+
options: Array<FieldOptionProps>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Checkboxes: React.FC<CheckboxesProps> = function Checkboxes({
|
|
19
|
+
name,
|
|
20
|
+
onChange,
|
|
21
|
+
value,
|
|
22
|
+
extra: { options, className },
|
|
23
|
+
disabled,
|
|
24
|
+
...props
|
|
25
|
+
}) {
|
|
26
|
+
if (!value) value = [];
|
|
27
|
+
const handleChange = (optionValue) => (evt): void => {
|
|
28
|
+
let newValue;
|
|
29
|
+
if (evt.currentTarget.checked) {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
newValue = value.concat([optionValue]);
|
|
33
|
+
} else {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
newValue = value.filter((val) => val !== optionValue);
|
|
37
|
+
}
|
|
38
|
+
// reset value to undefined instead of an empty array
|
|
39
|
+
// so the error state mechanism can throw validation errors
|
|
40
|
+
if (newValue.length === 0) newValue = undefined;
|
|
41
|
+
onChange(newValue);
|
|
42
|
+
};
|
|
43
|
+
const { t } = useTranslation();
|
|
44
|
+
return (
|
|
45
|
+
<CoreCheckboxes className={className}>
|
|
46
|
+
{options.map((option, key) => (
|
|
47
|
+
<CheckboxItem
|
|
48
|
+
name={name}
|
|
49
|
+
disabled={disabled}
|
|
50
|
+
key={key}
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
checked={value.includes(option.value)}
|
|
54
|
+
onChange={handleChange(option.value)}
|
|
55
|
+
{...option}
|
|
56
|
+
{...{
|
|
57
|
+
...props,
|
|
58
|
+
reset: undefined,
|
|
59
|
+
defaultValue: undefined,
|
|
60
|
+
onBlur: undefined,
|
|
61
|
+
required: undefined,
|
|
62
|
+
'aria-describedby': undefined,
|
|
63
|
+
type: 'checkbox',
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
{(option.label && option.label.primary && t(option.label.primary)) ||
|
|
67
|
+
value}
|
|
68
|
+
{option.label && option.label.secondary && (
|
|
69
|
+
<Hint>{t(option.label.secondary)}</Hint>
|
|
70
|
+
)}
|
|
71
|
+
</CheckboxItem>
|
|
72
|
+
))}
|
|
73
|
+
</CoreCheckboxes>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default Checkboxes;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "4",
|
|
3
|
+
"stories": {
|
|
4
|
+
"digigov-form-inputs-dateinput--default": {
|
|
5
|
+
"actionSets": [
|
|
6
|
+
{
|
|
7
|
+
"actions": [
|
|
8
|
+
{
|
|
9
|
+
"name": "keyboard.press",
|
|
10
|
+
"args": {
|
|
11
|
+
"key": "Tab"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "keyboard.press",
|
|
16
|
+
"args": {
|
|
17
|
+
"key": "Tab"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "keyboard.press",
|
|
22
|
+
"args": {
|
|
23
|
+
"key": "Tab"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"id": "n5PFnx7RcuJV",
|
|
28
|
+
"title": "navigate with keyboard"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"actions": [
|
|
32
|
+
{
|
|
33
|
+
"name": "click",
|
|
34
|
+
"args": {
|
|
35
|
+
"selector": "html>body>div:nth-child(5)>form>button"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "type",
|
|
40
|
+
"args": {
|
|
41
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(1)>label>input",
|
|
42
|
+
"text": "33"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "type",
|
|
47
|
+
"args": {
|
|
48
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(2)>label>input",
|
|
49
|
+
"text": "33"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "type",
|
|
54
|
+
"args": {
|
|
55
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(3)>label>input",
|
|
56
|
+
"text": "3333"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "click",
|
|
61
|
+
"args": {
|
|
62
|
+
"selector": "html>body>div:nth-child(5)>form>button"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"id": "Ck7_BFdgITMe",
|
|
67
|
+
"title": "show validation errors"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
export const Default = () => (
|
|
6
|
+
<FormBuilder
|
|
7
|
+
onSubmit={(data) => {
|
|
8
|
+
debugger;
|
|
9
|
+
console.log(data);
|
|
10
|
+
}}
|
|
11
|
+
>
|
|
12
|
+
<Field
|
|
13
|
+
key={'string'}
|
|
14
|
+
name="string"
|
|
15
|
+
type="date"
|
|
16
|
+
required
|
|
17
|
+
label={{
|
|
18
|
+
primary: 'Πότε εκδόθηκε το διαβατήριο σας;',
|
|
19
|
+
secondary: 'Για παράδειγμα, 05 11 2020',
|
|
20
|
+
}}
|
|
21
|
+
extra={{
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
label: { primary: 'Έχω συνάχι' },
|
|
25
|
+
value: 'runny-nose',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: { primary: 'Έχω πυρετό' },
|
|
29
|
+
value: 'fever',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: { primary: 'Αισθάνομαι κούραση' },
|
|
33
|
+
value: 'fatigue',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
<Button type="submit">Συνέχεια</Button>
|
|
39
|
+
</FormBuilder>
|
|
40
|
+
);
|
|
41
|
+
export default Default;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
5
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
6
|
+
import DateInputContainer from '@digigov/react-core/DateInputContainer';
|
|
7
|
+
import CoreDateInputItem from '@digigov/react-core/DateInputItem';
|
|
8
|
+
dayjs.extend(customParseFormat);
|
|
9
|
+
|
|
10
|
+
export interface DateInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
11
|
+
extra?: {
|
|
12
|
+
max?: string;
|
|
13
|
+
min?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function useDate(value, onChange) {
|
|
18
|
+
const [year, month, day] = useMemo(() => {
|
|
19
|
+
if (!value || value.length === '') {
|
|
20
|
+
return ['', '', ''];
|
|
21
|
+
}
|
|
22
|
+
const [day, month, year] = value.split('/');
|
|
23
|
+
return [year, month, day];
|
|
24
|
+
}, [value]);
|
|
25
|
+
|
|
26
|
+
function set(year, month, day) {
|
|
27
|
+
const value = `${day || ''}/${month || ''}/${year || ''}`;
|
|
28
|
+
if (!year && !month && !day) {
|
|
29
|
+
onChange(null);
|
|
30
|
+
} else {
|
|
31
|
+
onChange(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function setYear(evt) {
|
|
36
|
+
const val = evt.target.value;
|
|
37
|
+
set(val, month, day);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function setMonth(evt, cast) {
|
|
41
|
+
let val = evt.target.value;
|
|
42
|
+
if (cast && val && val.length === 1) {
|
|
43
|
+
val = '0' + val;
|
|
44
|
+
}
|
|
45
|
+
set(year, val, day);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setDay(evt, cast) {
|
|
49
|
+
let val = evt.target.value;
|
|
50
|
+
if (cast && val && val.length === 1) {
|
|
51
|
+
val = '0' + val;
|
|
52
|
+
}
|
|
53
|
+
set(year, month, val);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
day,
|
|
58
|
+
month,
|
|
59
|
+
year,
|
|
60
|
+
setYear,
|
|
61
|
+
setMonth,
|
|
62
|
+
setDay,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const VALID_FORMATS = ['DD/MM/YYYY'];
|
|
67
|
+
|
|
68
|
+
const makeDate = (val) => {
|
|
69
|
+
const date = dayjs(val, VALID_FORMATS, true);
|
|
70
|
+
if (date.isValid()) {
|
|
71
|
+
return date.format('DD/MM/YYYY');
|
|
72
|
+
}
|
|
73
|
+
return '';
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const DatePart = ({ label, ...props }) => {
|
|
77
|
+
return <CoreDateInputItem {...props}>{label}</CoreDateInputItem>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const DateInput = function DateInput({ name, type, ...props }) {
|
|
81
|
+
const { t } = useTranslation();
|
|
82
|
+
const [initial] = useState(props.value);
|
|
83
|
+
const value = useMemo(() => {
|
|
84
|
+
if (initial === props.value) {
|
|
85
|
+
return makeDate(props.value);
|
|
86
|
+
}
|
|
87
|
+
return props.value;
|
|
88
|
+
}, [props.value, initial]);
|
|
89
|
+
|
|
90
|
+
const date = useDate(value || makeDate(props.defaultValue), props.onChange);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<DateInputContainer>
|
|
94
|
+
<DatePart
|
|
95
|
+
label={t('form.label.day')}
|
|
96
|
+
onChange={date.setDay}
|
|
97
|
+
onBlur={(e) => date.setDay(e, true)}
|
|
98
|
+
value={date.day}
|
|
99
|
+
width={2}
|
|
100
|
+
name={`${name}-day`}
|
|
101
|
+
maxlength="2"
|
|
102
|
+
disabled={props.disabled}
|
|
103
|
+
aria-required={props['aria-required']}
|
|
104
|
+
/>
|
|
105
|
+
<DatePart
|
|
106
|
+
label={t('form.label.month')}
|
|
107
|
+
onChange={date.setMonth}
|
|
108
|
+
onBlur={(e) => date.setMonth(e, true)}
|
|
109
|
+
value={date.month}
|
|
110
|
+
width={2}
|
|
111
|
+
name={`${props.name}-month`}
|
|
112
|
+
maxlength="2"
|
|
113
|
+
disabled={props.disabled}
|
|
114
|
+
aria-required={props['aria-required']}
|
|
115
|
+
/>
|
|
116
|
+
<DatePart
|
|
117
|
+
label={t('form.label.year')}
|
|
118
|
+
onChange={date.setYear}
|
|
119
|
+
value={date.year}
|
|
120
|
+
width={4}
|
|
121
|
+
name={`${props.name}-year`}
|
|
122
|
+
maxlength="4"
|
|
123
|
+
disabled={props.disabled}
|
|
124
|
+
aria-required={props['aria-required']}
|
|
125
|
+
/>
|
|
126
|
+
</DateInputContainer>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export default DateInput;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "4",
|
|
3
|
+
"stories": {
|
|
4
|
+
"digigov-form-inputs-fileinput--default": {
|
|
5
|
+
"actionSets": [
|
|
6
|
+
{
|
|
7
|
+
"actions": [
|
|
8
|
+
{
|
|
9
|
+
"name": "click",
|
|
10
|
+
"args": {
|
|
11
|
+
"selector": "html>body>div:nth-child(5)>form>button"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"id": "c4Jhtju9oCJZ",
|
|
16
|
+
"title": "show validation error"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"actions": [
|
|
20
|
+
{
|
|
21
|
+
"name": "setFiles",
|
|
22
|
+
"args": {
|
|
23
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>label",
|
|
24
|
+
"file": {
|
|
25
|
+
"name": "arxeio.txt",
|
|
26
|
+
"size": 200
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "click",
|
|
32
|
+
"args": {
|
|
33
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>button"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"id": "WPIcVVWz-299",
|
|
38
|
+
"title": "add file and remove"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"actions": [
|
|
42
|
+
{
|
|
43
|
+
"name": "setFiles",
|
|
44
|
+
"args": {
|
|
45
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>label",
|
|
46
|
+
"file": {
|
|
47
|
+
"name": "arxeio.txt",
|
|
48
|
+
"size": 200
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "setFiles",
|
|
54
|
+
"args": {
|
|
55
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>label",
|
|
56
|
+
"file": {
|
|
57
|
+
"name": "neo_arxeio.txt",
|
|
58
|
+
"size": 200
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "click",
|
|
64
|
+
"args": {
|
|
65
|
+
"selector": "html>body>div:nth-child(5)>form>button"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"id": "inSBFd25dzkC",
|
|
70
|
+
"title": "add file, replace and remove"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
export const Default = () => (
|
|
6
|
+
<FormBuilder
|
|
7
|
+
onSubmit={(data) => {
|
|
8
|
+
debugger;
|
|
9
|
+
console.log(data);
|
|
10
|
+
}}
|
|
11
|
+
>
|
|
12
|
+
<Field
|
|
13
|
+
key={'string'}
|
|
14
|
+
name="file"
|
|
15
|
+
type="file"
|
|
16
|
+
required
|
|
17
|
+
label={{ primary: 'Βιογραφικό σημείωμα' }}
|
|
18
|
+
/>
|
|
19
|
+
<Button>Συνέχεια</Button>
|
|
20
|
+
</FormBuilder>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default Default;
|