@digigov/form 0.4.11 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Change Log - @digigov/form
2
2
 
3
- This log was last generated on Mon, 14 Feb 2022 09:56:29 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 16 Feb 2022 12:49:28 GMT and should not be manually modified.
4
+
5
+ ## 0.5.0
6
+ Wed, 16 Feb 2022 12:49:28 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Add new `date` field type that renders a three-block date input
11
+
12
+ ### Patches
13
+
14
+ - Pin dayjs dependency
4
15
 
5
16
  ## 0.4.11
6
17
  Mon, 14 Feb 2022 09:56:29 GMT
package/Field/index.js CHANGED
@@ -43,6 +43,8 @@ var _Select = _interopRequireDefault(require("@digigov/form/inputs/Select"));
43
43
 
44
44
  var _FileInput = _interopRequireDefault(require("@digigov/form/inputs/FileInput"));
45
45
 
46
+ var _DateInput = _interopRequireDefault(require("@digigov/form/inputs/DateInput"));
47
+
46
48
  var _Label2 = _interopRequireDefault(require("@digigov/form/inputs/Label"));
47
49
 
48
50
  var _i18n = require("@digigov/ui/app/i18n");
@@ -63,6 +65,11 @@ var FIELD_COMPONENTS = {
63
65
  file: {
64
66
  component: _FileInput["default"]
65
67
  },
68
+ date: {
69
+ wrapper: 'fieldset',
70
+ controlled: true,
71
+ component: _DateInput["default"]
72
+ },
66
73
  'choice:multiple': {
67
74
  wrapper: 'fieldset',
68
75
  controlled: true,
package/es/Field/index.js CHANGED
@@ -16,6 +16,7 @@ import Checkboxes from '@digigov/form/inputs/Checkboxes';
16
16
  import Radio from '@digigov/form/inputs/Radio';
17
17
  import Select from '@digigov/form/inputs/Select';
18
18
  import FileInput from '@digigov/form/inputs/FileInput';
19
+ import DateInput from '@digigov/form/inputs/DateInput';
19
20
  import Label from '@digigov/form/inputs/Label';
20
21
  import { useTranslation } from '@digigov/ui/app/i18n';
21
22
  var FIELD_COMPONENTS = {
@@ -28,6 +29,11 @@ var FIELD_COMPONENTS = {
28
29
  file: {
29
30
  component: FileInput
30
31
  },
32
+ date: {
33
+ wrapper: 'fieldset',
34
+ controlled: true,
35
+ component: DateInput
36
+ },
31
37
  'choice:multiple': {
32
38
  wrapper: 'fieldset',
33
39
  controlled: true,
@@ -0,0 +1,149 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ var _excluded = ["label"],
4
+ _excluded2 = ["name", "type"];
5
+ import React, { useMemo, useState } from 'react';
6
+ import dayjs from 'dayjs';
7
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
8
+ import { useTranslation } from '@digigov/ui/app/i18n';
9
+ import CoreDateInput from '@digigov/react-core/DateInput';
10
+ import CoreDateInputItem from '@digigov/react-core/DateInputItem';
11
+ dayjs.extend(customParseFormat);
12
+
13
+ function useDate(value, onChange) {
14
+ var _useMemo = useMemo(function () {
15
+ if (!value || value.length === '') {
16
+ return ['', '', ''];
17
+ }
18
+
19
+ var _value$split = value.split('/'),
20
+ _value$split2 = _slicedToArray(_value$split, 3),
21
+ day = _value$split2[0],
22
+ month = _value$split2[1],
23
+ year = _value$split2[2];
24
+
25
+ return [year, month, day];
26
+ }, [value]),
27
+ _useMemo2 = _slicedToArray(_useMemo, 3),
28
+ year = _useMemo2[0],
29
+ month = _useMemo2[1],
30
+ day = _useMemo2[2];
31
+
32
+ function set(year, month, day) {
33
+ var value = "".concat(day || '', "/").concat(month || '', "/").concat(year || '');
34
+
35
+ if (!year && !month && !day) {
36
+ onChange(null);
37
+ } else {
38
+ onChange(value);
39
+ }
40
+ }
41
+
42
+ function setYear(evt) {
43
+ var val = evt.target.value;
44
+ set(val, month, day);
45
+ }
46
+
47
+ function setMonth(evt, cast) {
48
+ var val = evt.target.value;
49
+
50
+ if (cast && val && val.length === 1) {
51
+ val = '0' + val;
52
+ }
53
+
54
+ set(year, val, day);
55
+ }
56
+
57
+ function setDay(evt, cast) {
58
+ var val = evt.target.value;
59
+
60
+ if (cast && val && val.length === 1) {
61
+ val = '0' + val;
62
+ }
63
+
64
+ set(year, month, val);
65
+ }
66
+
67
+ return {
68
+ day: day,
69
+ month: month,
70
+ year: year,
71
+ setYear: setYear,
72
+ setMonth: setMonth,
73
+ setDay: setDay
74
+ };
75
+ }
76
+
77
+ var VALID_FORMATS = ['DD/MM/YYYY'];
78
+
79
+ var makeDate = function makeDate(val) {
80
+ var date = dayjs(val, VALID_FORMATS, true);
81
+
82
+ if (date.isValid()) {
83
+ return date.format('DD/MM/YYYY');
84
+ }
85
+
86
+ return '';
87
+ };
88
+
89
+ var DatePart = function DatePart(_ref) {
90
+ var label = _ref.label,
91
+ props = _objectWithoutProperties(_ref, _excluded);
92
+
93
+ return /*#__PURE__*/React.createElement(CoreDateInputItem, props, label);
94
+ };
95
+
96
+ var DateInput = function DateInput(_ref2) {
97
+ var name = _ref2.name,
98
+ type = _ref2.type,
99
+ props = _objectWithoutProperties(_ref2, _excluded2);
100
+
101
+ var _useTranslation = useTranslation(),
102
+ t = _useTranslation.t;
103
+
104
+ var _useState = useState(props.value),
105
+ _useState2 = _slicedToArray(_useState, 1),
106
+ initial = _useState2[0];
107
+
108
+ var value = useMemo(function () {
109
+ if (initial === props.value) {
110
+ return makeDate(props.value);
111
+ }
112
+
113
+ return props.value;
114
+ }, [props.value, initial]);
115
+ var date = useDate(value || makeDate(props.defaultValue), props.onChange);
116
+ return /*#__PURE__*/React.createElement(CoreDateInput, null, /*#__PURE__*/React.createElement(DatePart, {
117
+ label: t('form.label.day'),
118
+ onChange: date.setDay,
119
+ onBlur: function onBlur(e) {
120
+ return date.setDay(e, true);
121
+ },
122
+ value: date.day,
123
+ width: 2,
124
+ name: "".concat(name, "-day"),
125
+ maxlength: "2",
126
+ disabled: props.disabled
127
+ }), /*#__PURE__*/React.createElement(DatePart, {
128
+ label: t('form.label.month'),
129
+ onChange: date.setMonth,
130
+ onBlur: function onBlur(e) {
131
+ return date.setMonth(e, true);
132
+ },
133
+ value: date.month,
134
+ width: 2,
135
+ name: "".concat(props.name, "-month"),
136
+ maxlength: "2",
137
+ disabled: props.disabled
138
+ }), /*#__PURE__*/React.createElement(DatePart, {
139
+ label: t('form.label.year'),
140
+ onChange: date.setYear,
141
+ value: date.year,
142
+ width: 4,
143
+ name: "".concat(props.name, "-year"),
144
+ maxlength: "4",
145
+ disabled: props.disabled
146
+ }));
147
+ };
148
+
149
+ export default DateInput;
package/es/validators.js CHANGED
@@ -10,6 +10,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
10
10
  import * as yup from 'yup';
11
11
  import * as gPhoneNumber from 'google-libphonenumber';
12
12
  import { useMemo } from 'react';
13
+ import dayjs from 'dayjs';
14
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
15
+ dayjs.extend(customParseFormat);
13
16
  var DEFAULT_FILE_MAX_SIZE = 10000000;
14
17
  export function validateAFM(afm) {
15
18
  if (afm.length !== 9) {
@@ -280,6 +283,13 @@ var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
280
283
  };
281
284
  };
282
285
 
286
+ var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
287
+ var DATE_CACHE = {};
288
+
289
+ var getDate = function getDate(v) {
290
+ return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
291
+ };
292
+
283
293
  function getYupField(field, yupTypeMap) {
284
294
  var yupField = yupTypeMap[field.type] || yupTypeMap.string;
285
295
  return yupField(field);
@@ -416,6 +426,75 @@ var getYUPTypeMap = function getYUPTypeMap() {
416
426
  },
417
427
  'choice:single': function choiceSingle() {
418
428
  return yup.string().nullable();
429
+ },
430
+ date: function date(field) {
431
+ var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
432
+ if (!value) return true;
433
+ value = getDate(value);
434
+ return value.isValid();
435
+ });
436
+ var params = field.extra || {};
437
+
438
+ if (params.max) {
439
+ var maxDate;
440
+
441
+ if (params.max === 'now') {
442
+ var today = new Date();
443
+ maxDate = new Date(today);
444
+ } else {
445
+ maxDate = getDate(params.max).toDate();
446
+ }
447
+
448
+ var maxNextDate = new Date(maxDate);
449
+ maxNextDate.setDate(maxDate.getDate() + 1);
450
+ simpleDate = simpleDate.test({
451
+ name: 'earlier-than',
452
+ message: {
453
+ key: 'form.error.date.earlier_than',
454
+ context: {
455
+ maxDate: maxNextDate.toLocaleDateString()
456
+ }
457
+ },
458
+ test: function test(value) {
459
+ if (!value) return true;
460
+ value = getDate(value);
461
+ var isValid = +value.toDate() < +maxDate;
462
+ return isValid;
463
+ }
464
+ });
465
+ }
466
+
467
+ if (params.min) {
468
+ var minDate;
469
+
470
+ if (params.min === 'now') {
471
+ var _today = new Date();
472
+
473
+ minDate = new Date(_today);
474
+ } else {
475
+ minDate = getDate(params.min).toDate();
476
+ }
477
+
478
+ var minPreviousDate = new Date(minDate);
479
+ minPreviousDate.setDate(minDate.getDate() - 1);
480
+ simpleDate = simpleDate.test({
481
+ name: 'later-than',
482
+ message: {
483
+ key: 'form.error.date.later_than',
484
+ context: {
485
+ minDate: minPreviousDate.toLocaleDateString()
486
+ }
487
+ },
488
+ test: function test(value) {
489
+ if (!value) return true;
490
+ value = getDate(value);
491
+ var isValid = +value.toDate() > +minDate;
492
+ return isValid;
493
+ }
494
+ });
495
+ }
496
+
497
+ return simpleDate;
419
498
  }
420
499
  };
421
500
  return yupTypeMap;
@@ -16,6 +16,7 @@ import Checkboxes from '@digigov/form/inputs/Checkboxes';
16
16
  import Radio from '@digigov/form/inputs/Radio';
17
17
  import Select from '@digigov/form/inputs/Select';
18
18
  import FileInput from '@digigov/form/inputs/FileInput';
19
+ import DateInput from '@digigov/form/inputs/DateInput';
19
20
  import Label from '@digigov/form/inputs/Label';
20
21
  import { useTranslation } from '@digigov/ui/app/i18n';
21
22
  var FIELD_COMPONENTS = {
@@ -28,6 +29,11 @@ var FIELD_COMPONENTS = {
28
29
  file: {
29
30
  component: FileInput
30
31
  },
32
+ date: {
33
+ wrapper: 'fieldset',
34
+ controlled: true,
35
+ component: DateInput
36
+ },
31
37
  'choice:multiple': {
32
38
  wrapper: 'fieldset',
33
39
  controlled: true,
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Digigov v0.4.11
1
+ /** @license Digigov v0.5.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -0,0 +1,149 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ var _excluded = ["label"],
4
+ _excluded2 = ["name", "type"];
5
+ import React, { useMemo, useState } from 'react';
6
+ import dayjs from 'dayjs';
7
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
8
+ import { useTranslation } from '@digigov/ui/app/i18n';
9
+ import CoreDateInput from '@digigov/react-core/DateInput';
10
+ import CoreDateInputItem from '@digigov/react-core/DateInputItem';
11
+ dayjs.extend(customParseFormat);
12
+
13
+ function useDate(value, onChange) {
14
+ var _useMemo = useMemo(function () {
15
+ if (!value || value.length === '') {
16
+ return ['', '', ''];
17
+ }
18
+
19
+ var _value$split = value.split('/'),
20
+ _value$split2 = _slicedToArray(_value$split, 3),
21
+ day = _value$split2[0],
22
+ month = _value$split2[1],
23
+ year = _value$split2[2];
24
+
25
+ return [year, month, day];
26
+ }, [value]),
27
+ _useMemo2 = _slicedToArray(_useMemo, 3),
28
+ year = _useMemo2[0],
29
+ month = _useMemo2[1],
30
+ day = _useMemo2[2];
31
+
32
+ function set(year, month, day) {
33
+ var value = "".concat(day || '', "/").concat(month || '', "/").concat(year || '');
34
+
35
+ if (!year && !month && !day) {
36
+ onChange(null);
37
+ } else {
38
+ onChange(value);
39
+ }
40
+ }
41
+
42
+ function setYear(evt) {
43
+ var val = evt.target.value;
44
+ set(val, month, day);
45
+ }
46
+
47
+ function setMonth(evt, cast) {
48
+ var val = evt.target.value;
49
+
50
+ if (cast && val && val.length === 1) {
51
+ val = '0' + val;
52
+ }
53
+
54
+ set(year, val, day);
55
+ }
56
+
57
+ function setDay(evt, cast) {
58
+ var val = evt.target.value;
59
+
60
+ if (cast && val && val.length === 1) {
61
+ val = '0' + val;
62
+ }
63
+
64
+ set(year, month, val);
65
+ }
66
+
67
+ return {
68
+ day: day,
69
+ month: month,
70
+ year: year,
71
+ setYear: setYear,
72
+ setMonth: setMonth,
73
+ setDay: setDay
74
+ };
75
+ }
76
+
77
+ var VALID_FORMATS = ['DD/MM/YYYY'];
78
+
79
+ var makeDate = function makeDate(val) {
80
+ var date = dayjs(val, VALID_FORMATS, true);
81
+
82
+ if (date.isValid()) {
83
+ return date.format('DD/MM/YYYY');
84
+ }
85
+
86
+ return '';
87
+ };
88
+
89
+ var DatePart = function DatePart(_ref) {
90
+ var label = _ref.label,
91
+ props = _objectWithoutProperties(_ref, _excluded);
92
+
93
+ return /*#__PURE__*/React.createElement(CoreDateInputItem, props, label);
94
+ };
95
+
96
+ var DateInput = function DateInput(_ref2) {
97
+ var name = _ref2.name,
98
+ type = _ref2.type,
99
+ props = _objectWithoutProperties(_ref2, _excluded2);
100
+
101
+ var _useTranslation = useTranslation(),
102
+ t = _useTranslation.t;
103
+
104
+ var _useState = useState(props.value),
105
+ _useState2 = _slicedToArray(_useState, 1),
106
+ initial = _useState2[0];
107
+
108
+ var value = useMemo(function () {
109
+ if (initial === props.value) {
110
+ return makeDate(props.value);
111
+ }
112
+
113
+ return props.value;
114
+ }, [props.value, initial]);
115
+ var date = useDate(value || makeDate(props.defaultValue), props.onChange);
116
+ return /*#__PURE__*/React.createElement(CoreDateInput, null, /*#__PURE__*/React.createElement(DatePart, {
117
+ label: t('form.label.day'),
118
+ onChange: date.setDay,
119
+ onBlur: function onBlur(e) {
120
+ return date.setDay(e, true);
121
+ },
122
+ value: date.day,
123
+ width: 2,
124
+ name: "".concat(name, "-day"),
125
+ maxlength: "2",
126
+ disabled: props.disabled
127
+ }), /*#__PURE__*/React.createElement(DatePart, {
128
+ label: t('form.label.month'),
129
+ onChange: date.setMonth,
130
+ onBlur: function onBlur(e) {
131
+ return date.setMonth(e, true);
132
+ },
133
+ value: date.month,
134
+ width: 2,
135
+ name: "".concat(props.name, "-month"),
136
+ maxlength: "2",
137
+ disabled: props.disabled
138
+ }), /*#__PURE__*/React.createElement(DatePart, {
139
+ label: t('form.label.year'),
140
+ onChange: date.setYear,
141
+ value: date.year,
142
+ width: 4,
143
+ name: "".concat(props.name, "-year"),
144
+ maxlength: "4",
145
+ disabled: props.disabled
146
+ }));
147
+ };
148
+
149
+ export default DateInput;
package/esm/validators.js CHANGED
@@ -10,6 +10,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
10
10
  import * as yup from 'yup';
11
11
  import * as gPhoneNumber from 'google-libphonenumber';
12
12
  import { useMemo } from 'react';
13
+ import dayjs from 'dayjs';
14
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
15
+ dayjs.extend(customParseFormat);
13
16
  var DEFAULT_FILE_MAX_SIZE = 10000000;
14
17
  export function validateAFM(afm) {
15
18
  if (afm.length !== 9) {
@@ -280,6 +283,13 @@ var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
280
283
  };
281
284
  };
282
285
 
286
+ var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
287
+ var DATE_CACHE = {};
288
+
289
+ var getDate = function getDate(v) {
290
+ return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
291
+ };
292
+
283
293
  function getYupField(field, yupTypeMap) {
284
294
  var yupField = yupTypeMap[field.type] || yupTypeMap.string;
285
295
  return yupField(field);
@@ -416,6 +426,75 @@ var getYUPTypeMap = function getYUPTypeMap() {
416
426
  },
417
427
  'choice:single': function choiceSingle() {
418
428
  return yup.string().nullable();
429
+ },
430
+ date: function date(field) {
431
+ var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
432
+ if (!value) return true;
433
+ value = getDate(value);
434
+ return value.isValid();
435
+ });
436
+ var params = field.extra || {};
437
+
438
+ if (params.max) {
439
+ var maxDate;
440
+
441
+ if (params.max === 'now') {
442
+ var today = new Date();
443
+ maxDate = new Date(today);
444
+ } else {
445
+ maxDate = getDate(params.max).toDate();
446
+ }
447
+
448
+ var maxNextDate = new Date(maxDate);
449
+ maxNextDate.setDate(maxDate.getDate() + 1);
450
+ simpleDate = simpleDate.test({
451
+ name: 'earlier-than',
452
+ message: {
453
+ key: 'form.error.date.earlier_than',
454
+ context: {
455
+ maxDate: maxNextDate.toLocaleDateString()
456
+ }
457
+ },
458
+ test: function test(value) {
459
+ if (!value) return true;
460
+ value = getDate(value);
461
+ var isValid = +value.toDate() < +maxDate;
462
+ return isValid;
463
+ }
464
+ });
465
+ }
466
+
467
+ if (params.min) {
468
+ var minDate;
469
+
470
+ if (params.min === 'now') {
471
+ var _today = new Date();
472
+
473
+ minDate = new Date(_today);
474
+ } else {
475
+ minDate = getDate(params.min).toDate();
476
+ }
477
+
478
+ var minPreviousDate = new Date(minDate);
479
+ minPreviousDate.setDate(minDate.getDate() - 1);
480
+ simpleDate = simpleDate.test({
481
+ name: 'later-than',
482
+ message: {
483
+ key: 'form.error.date.later_than',
484
+ context: {
485
+ minDate: minPreviousDate.toLocaleDateString()
486
+ }
487
+ },
488
+ test: function test(value) {
489
+ if (!value) return true;
490
+ value = getDate(value);
491
+ var isValid = +value.toDate() > +minDate;
492
+ return isValid;
493
+ }
494
+ });
495
+ }
496
+
497
+ return simpleDate;
419
498
  }
420
499
  };
421
500
  return yupTypeMap;
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = void 0;
11
+
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _react = _interopRequireWildcard(require("react"));
17
+
18
+ var _dayjs = _interopRequireDefault(require("dayjs"));
19
+
20
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
21
+
22
+ var _i18n = require("@digigov/ui/app/i18n");
23
+
24
+ var _DateInput = _interopRequireDefault(require("@digigov/react-core/DateInput"));
25
+
26
+ var _DateInputItem = _interopRequireDefault(require("@digigov/react-core/DateInputItem"));
27
+
28
+ var _excluded = ["label"],
29
+ _excluded2 = ["name", "type"];
30
+
31
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
32
+
33
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
34
+
35
+ _dayjs["default"].extend(_customParseFormat["default"]);
36
+
37
+ function useDate(value, onChange) {
38
+ var _useMemo = (0, _react.useMemo)(function () {
39
+ if (!value || value.length === '') {
40
+ return ['', '', ''];
41
+ }
42
+
43
+ var _value$split = value.split('/'),
44
+ _value$split2 = (0, _slicedToArray2["default"])(_value$split, 3),
45
+ day = _value$split2[0],
46
+ month = _value$split2[1],
47
+ year = _value$split2[2];
48
+
49
+ return [year, month, day];
50
+ }, [value]),
51
+ _useMemo2 = (0, _slicedToArray2["default"])(_useMemo, 3),
52
+ year = _useMemo2[0],
53
+ month = _useMemo2[1],
54
+ day = _useMemo2[2];
55
+
56
+ function set(year, month, day) {
57
+ var value = "".concat(day || '', "/").concat(month || '', "/").concat(year || '');
58
+
59
+ if (!year && !month && !day) {
60
+ onChange(null);
61
+ } else {
62
+ onChange(value);
63
+ }
64
+ }
65
+
66
+ function setYear(evt) {
67
+ var val = evt.target.value;
68
+ set(val, month, day);
69
+ }
70
+
71
+ function setMonth(evt, cast) {
72
+ var val = evt.target.value;
73
+
74
+ if (cast && val && val.length === 1) {
75
+ val = '0' + val;
76
+ }
77
+
78
+ set(year, val, day);
79
+ }
80
+
81
+ function setDay(evt, cast) {
82
+ var val = evt.target.value;
83
+
84
+ if (cast && val && val.length === 1) {
85
+ val = '0' + val;
86
+ }
87
+
88
+ set(year, month, val);
89
+ }
90
+
91
+ return {
92
+ day: day,
93
+ month: month,
94
+ year: year,
95
+ setYear: setYear,
96
+ setMonth: setMonth,
97
+ setDay: setDay
98
+ };
99
+ }
100
+
101
+ var VALID_FORMATS = ['DD/MM/YYYY'];
102
+
103
+ var makeDate = function makeDate(val) {
104
+ var date = (0, _dayjs["default"])(val, VALID_FORMATS, true);
105
+
106
+ if (date.isValid()) {
107
+ return date.format('DD/MM/YYYY');
108
+ }
109
+
110
+ return '';
111
+ };
112
+
113
+ var DatePart = function DatePart(_ref) {
114
+ var label = _ref.label,
115
+ props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
116
+ return /*#__PURE__*/_react["default"].createElement(_DateInputItem["default"], props, label);
117
+ };
118
+
119
+ var DateInput = function DateInput(_ref2) {
120
+ var name = _ref2.name,
121
+ type = _ref2.type,
122
+ props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2);
123
+
124
+ var _useTranslation = (0, _i18n.useTranslation)(),
125
+ t = _useTranslation.t;
126
+
127
+ var _useState = (0, _react.useState)(props.value),
128
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 1),
129
+ initial = _useState2[0];
130
+
131
+ var value = (0, _react.useMemo)(function () {
132
+ if (initial === props.value) {
133
+ return makeDate(props.value);
134
+ }
135
+
136
+ return props.value;
137
+ }, [props.value, initial]);
138
+ var date = useDate(value || makeDate(props.defaultValue), props.onChange);
139
+ return /*#__PURE__*/_react["default"].createElement(_DateInput["default"], null, /*#__PURE__*/_react["default"].createElement(DatePart, {
140
+ label: t('form.label.day'),
141
+ onChange: date.setDay,
142
+ onBlur: function onBlur(e) {
143
+ return date.setDay(e, true);
144
+ },
145
+ value: date.day,
146
+ width: 2,
147
+ name: "".concat(name, "-day"),
148
+ maxlength: "2",
149
+ disabled: props.disabled
150
+ }), /*#__PURE__*/_react["default"].createElement(DatePart, {
151
+ label: t('form.label.month'),
152
+ onChange: date.setMonth,
153
+ onBlur: function onBlur(e) {
154
+ return date.setMonth(e, true);
155
+ },
156
+ value: date.month,
157
+ width: 2,
158
+ name: "".concat(props.name, "-month"),
159
+ maxlength: "2",
160
+ disabled: props.disabled
161
+ }), /*#__PURE__*/_react["default"].createElement(DatePart, {
162
+ label: t('form.label.year'),
163
+ onChange: date.setYear,
164
+ value: date.year,
165
+ width: 4,
166
+ name: "".concat(props.name, "-year"),
167
+ maxlength: "4",
168
+ disabled: props.disabled
169
+ }));
170
+ };
171
+
172
+ var _default = DateInput;
173
+ exports["default"] = _default;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { UncontrolledFieldProps } from '@digigov/form/Field';
3
+ export interface DateInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
4
+ extra?: {
5
+ max?: string;
6
+ min?: string;
7
+ };
8
+ }
9
+ declare const DateInput: ({ name, type, ...props }: {
10
+ [x: string]: any;
11
+ name: any;
12
+ type: any;
13
+ }) => JSX.Element;
14
+ export default DateInput;
@@ -1,5 +1,10 @@
1
1
  declare const _default: {
2
2
  form: {
3
+ label: {
4
+ day: string;
5
+ month: string;
6
+ year: string;
7
+ };
3
8
  error: {
4
9
  required: string;
5
10
  number: string;
@@ -10,6 +15,11 @@ declare const _default: {
10
15
  file_size: string;
11
16
  mobile_phone: string;
12
17
  uuid4: string;
18
+ date: {
19
+ invalid: string;
20
+ earlier_than: string;
21
+ later_than: string;
22
+ };
13
23
  };
14
24
  };
15
25
  button: {
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ declare type SVGElementAttributes = JSX.IntrinsicElements['svg'];
3
+ export interface ArrowIconProps extends SVGElementAttributes {
4
+ /**
5
+ * direction is optional.
6
+ * direction prop declares the direction of the svg icon.
7
+ */
8
+ direction?: 'up' | 'right' | 'down' | 'left';
9
+ }
10
+ /**
11
+ * ArrowIcon component is used to add arrow icon.
12
+ * ArrowIcon component can be used inside other components, for example CallToAction component.
13
+ */
14
+ export declare const ArrowIcon: React.ForwardRefExoticComponent<Pick<ArrowIconProps, "string" | "path" | "type" | "className" | "style" | "clipPath" | "filter" | "mask" | "key" | "id" | "lang" | "tabIndex" | "role" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "name" | "mode" | "min" | "max" | "crossOrigin" | "height" | "width" | "fontSize" | "fontWeight" | "direction" | "spacing" | "media" | "method" | "target" | "accentHeight" | "accumulate" | "additive" | "alignmentBaseline" | "allowReorder" | "alphabetic" | "amplitude" | "arabicForm" | "ascent" | "attributeName" | "attributeType" | "autoReverse" | "azimuth" | "baseFrequency" | "baselineShift" | "baseProfile" | "bbox" | "begin" | "bias" | "by" | "calcMode" | "capHeight" | "clip" | "clipPathUnits" | "clipRule" | "colorInterpolation" | "colorInterpolationFilters" | "colorProfile" | "colorRendering" | "contentScriptType" | "contentStyleType" | "cursor" | "cx" | "cy" | "d" | "decelerate" | "descent" | "diffuseConstant" | "display" | "divisor" | "dominantBaseline" | "dur" | "dx" | "dy" | "edgeMode" | "elevation" | "enableBackground" | "end" | "exponent" | "externalResourcesRequired" | "fill" | "fillOpacity" | "fillRule" | "filterRes" | "filterUnits" | "floodColor" | "floodOpacity" | "focusable" | "fontFamily" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontVariant" | "format" | "from" | "fx" | "fy" | "g1" | "g2" | "glyphName" | "glyphOrientationHorizontal" | "glyphOrientationVertical" | "glyphRef" | "gradientTransform" | "gradientUnits" | "hanging" | "horizAdvX" | "horizOriginX" | "href" | "ideographic" | "imageRendering" | "in2" | "in" | "intercept" | "k1" | "k2" | "k3" | "k4" | "k" | "kernelMatrix" | "kernelUnitLength" | "kerning" | "keyPoints" | "keySplines" | "keyTimes" | "lengthAdjust" | "letterSpacing" | "lightingColor" | "limitingConeAngle" | "local" | "markerEnd" | "markerHeight" | "markerMid" | "markerStart" | "markerUnits" | "markerWidth" | "maskContentUnits" | "maskUnits" | "mathematical" | "numOctaves" | "offset" | "opacity" | "operator" | "order" | "orient" | "orientation" | "origin" | "overflow" | "overlinePosition" | "overlineThickness" | "paintOrder" | "panose1" | "pathLength" | "patternContentUnits" | "patternTransform" | "patternUnits" | "pointerEvents" | "points" | "pointsAtX" | "pointsAtY" | "pointsAtZ" | "preserveAlpha" | "preserveAspectRatio" | "primitiveUnits" | "r" | "radius" | "refX" | "refY" | "renderingIntent" | "repeatCount" | "repeatDur" | "requiredExtensions" | "requiredFeatures" | "restart" | "result" | "rotate" | "rx" | "ry" | "scale" | "seed" | "shapeRendering" | "slope" | "specularConstant" | "specularExponent" | "speed" | "spreadMethod" | "startOffset" | "stdDeviation" | "stemh" | "stemv" | "stitchTiles" | "stopColor" | "stopOpacity" | "strikethroughPosition" | "strikethroughThickness" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "surfaceScale" | "systemLanguage" | "tableValues" | "targetX" | "targetY" | "textAnchor" | "textDecoration" | "textLength" | "textRendering" | "to" | "transform" | "u1" | "u2" | "underlinePosition" | "underlineThickness" | "unicode" | "unicodeBidi" | "unicodeRange" | "unitsPerEm" | "vAlphabetic" | "values" | "vectorEffect" | "version" | "vertAdvY" | "vertOriginX" | "vertOriginY" | "vHanging" | "vIdeographic" | "viewBox" | "viewTarget" | "visibility" | "vMathematical" | "widths" | "wordSpacing" | "writingMode" | "x1" | "x2" | "x" | "xChannelSelector" | "xHeight" | "xlinkActuate" | "xlinkArcrole" | "xlinkHref" | "xlinkRole" | "xlinkShow" | "xlinkTitle" | "xlinkType" | "xmlBase" | "xmlLang" | "xmlns" | "xmlnsXlink" | "xmlSpace" | "y1" | "y2" | "y" | "yChannelSelector" | "z" | "zoomAndPan"> & React.RefAttributes<SVGSVGElement>>;
15
+ export default ArrowIcon;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ declare type SVGElementAttributes = JSX.IntrinsicElements['svg'];
3
+ export interface CaretIconProps extends SVGElementAttributes {
4
+ /**
5
+ * direction is optional.
6
+ * direction prop declares the direction of the svg icon.
7
+ */
8
+ direction?: 'up' | 'right' | 'down' | 'left';
9
+ }
10
+ /**
11
+ * CaretIcon component is used to add caret icon.
12
+ * CaretIcon can be used inside other components, for example BackLink component.
13
+ */
14
+ export declare const CaretIcon: React.ForwardRefExoticComponent<Pick<CaretIconProps, "string" | "path" | "type" | "className" | "style" | "clipPath" | "filter" | "mask" | "key" | "id" | "lang" | "tabIndex" | "role" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "name" | "mode" | "min" | "max" | "crossOrigin" | "height" | "width" | "fontSize" | "fontWeight" | "direction" | "spacing" | "media" | "method" | "target" | "accentHeight" | "accumulate" | "additive" | "alignmentBaseline" | "allowReorder" | "alphabetic" | "amplitude" | "arabicForm" | "ascent" | "attributeName" | "attributeType" | "autoReverse" | "azimuth" | "baseFrequency" | "baselineShift" | "baseProfile" | "bbox" | "begin" | "bias" | "by" | "calcMode" | "capHeight" | "clip" | "clipPathUnits" | "clipRule" | "colorInterpolation" | "colorInterpolationFilters" | "colorProfile" | "colorRendering" | "contentScriptType" | "contentStyleType" | "cursor" | "cx" | "cy" | "d" | "decelerate" | "descent" | "diffuseConstant" | "display" | "divisor" | "dominantBaseline" | "dur" | "dx" | "dy" | "edgeMode" | "elevation" | "enableBackground" | "end" | "exponent" | "externalResourcesRequired" | "fill" | "fillOpacity" | "fillRule" | "filterRes" | "filterUnits" | "floodColor" | "floodOpacity" | "focusable" | "fontFamily" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontVariant" | "format" | "from" | "fx" | "fy" | "g1" | "g2" | "glyphName" | "glyphOrientationHorizontal" | "glyphOrientationVertical" | "glyphRef" | "gradientTransform" | "gradientUnits" | "hanging" | "horizAdvX" | "horizOriginX" | "href" | "ideographic" | "imageRendering" | "in2" | "in" | "intercept" | "k1" | "k2" | "k3" | "k4" | "k" | "kernelMatrix" | "kernelUnitLength" | "kerning" | "keyPoints" | "keySplines" | "keyTimes" | "lengthAdjust" | "letterSpacing" | "lightingColor" | "limitingConeAngle" | "local" | "markerEnd" | "markerHeight" | "markerMid" | "markerStart" | "markerUnits" | "markerWidth" | "maskContentUnits" | "maskUnits" | "mathematical" | "numOctaves" | "offset" | "opacity" | "operator" | "order" | "orient" | "orientation" | "origin" | "overflow" | "overlinePosition" | "overlineThickness" | "paintOrder" | "panose1" | "pathLength" | "patternContentUnits" | "patternTransform" | "patternUnits" | "pointerEvents" | "points" | "pointsAtX" | "pointsAtY" | "pointsAtZ" | "preserveAlpha" | "preserveAspectRatio" | "primitiveUnits" | "r" | "radius" | "refX" | "refY" | "renderingIntent" | "repeatCount" | "repeatDur" | "requiredExtensions" | "requiredFeatures" | "restart" | "result" | "rotate" | "rx" | "ry" | "scale" | "seed" | "shapeRendering" | "slope" | "specularConstant" | "specularExponent" | "speed" | "spreadMethod" | "startOffset" | "stdDeviation" | "stemh" | "stemv" | "stitchTiles" | "stopColor" | "stopOpacity" | "strikethroughPosition" | "strikethroughThickness" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "surfaceScale" | "systemLanguage" | "tableValues" | "targetX" | "targetY" | "textAnchor" | "textDecoration" | "textLength" | "textRendering" | "to" | "transform" | "u1" | "u2" | "underlinePosition" | "underlineThickness" | "unicode" | "unicodeBidi" | "unicodeRange" | "unitsPerEm" | "vAlphabetic" | "values" | "vectorEffect" | "version" | "vertAdvY" | "vertOriginX" | "vertOriginY" | "vHanging" | "vIdeographic" | "viewBox" | "viewTarget" | "visibility" | "vMathematical" | "widths" | "wordSpacing" | "writingMode" | "x1" | "x2" | "x" | "xChannelSelector" | "xHeight" | "xlinkActuate" | "xlinkArcrole" | "xlinkHref" | "xlinkRole" | "xlinkShow" | "xlinkTitle" | "xlinkType" | "xmlBase" | "xmlLang" | "xmlns" | "xmlnsXlink" | "xmlSpace" | "y1" | "y2" | "y" | "yChannelSelector" | "z" | "zoomAndPan"> & React.RefAttributes<SVGSVGElement>>;
15
+ export default CaretIcon;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ declare type DivElementAttributes = JSX.IntrinsicElements['div'];
3
+ export interface DateInputProps extends DivElementAttributes {
4
+ }
5
+ /**
6
+ * Details for the DateInput.
7
+ * DateInput component is used for helping users enter a memorable date or one they can easily look up
8
+ * It is used as a parent component to wrap DateInputItem component
9
+ *
10
+ */
11
+ export declare const DateInput: React.ForwardRefExoticComponent<Pick<DateInputProps, "className" | "style" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & React.RefAttributes<HTMLDivElement>>;
12
+ export default DateInput;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ declare type DivElementAttributes = JSX.IntrinsicElements['input'];
3
+ export interface DateInputItemProps extends DivElementAttributes {
4
+ /**
5
+ * Name property is optional and it contains a single value which describes the name of the <input> element.
6
+ */
7
+ name?: string;
8
+ /**
9
+ * Width property is optional.
10
+ * Use this property for year field to grow width.
11
+ */
12
+ width?: 2 | 4;
13
+ /**
14
+ * error is optional. The default value is false.
15
+ * Use this prop when there is an error at the input.
16
+ */
17
+ error?: boolean;
18
+ }
19
+ /**
20
+ * Details for the DateInputItem.
21
+ * DateInputItem component is used for displaying date.
22
+ * DateInputItem component must be included inside DateInput component as children component
23
+ */
24
+ export declare const DateInputItem: React.ForwardRefExoticComponent<Pick<DateInputItemProps, "type" | "className" | "style" | "form" | "slot" | "title" | "pattern" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "required" | "disabled" | "name" | "list" | "step" | "size" | "error" | "min" | "max" | "maxLength" | "minLength" | "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "height" | "multiple" | "readOnly" | "src" | "value" | "width"> & React.RefAttributes<HTMLInputElement>>;
25
+ export default DateInputItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digigov/form",
3
- "version": "0.4.11",
3
+ "version": "0.5.0",
4
4
  "description": "@digigov form builder",
5
5
  "author": "GRNET Developers <devs@lists.grnet.gr>",
6
6
  "license": "MIT",
@@ -13,10 +13,11 @@
13
13
  "dependencies": {
14
14
  "react-hook-form": "6.12.2",
15
15
  "yup": "0.30.0",
16
- "google-libphonenumber": "3.2.8"
16
+ "google-libphonenumber": "3.2.8",
17
+ "dayjs": "1.10.4"
17
18
  },
18
19
  "peerDependencies": {
19
- "@digigov/ui": "0.11.0",
20
+ "@digigov/ui": "0.12.0",
20
21
  "@material-ui/core": "4.11.3",
21
22
  "@material-ui/icons": "4.11.2",
22
23
  "clsx": "1.1.1",
package/validators.js CHANGED
@@ -22,6 +22,10 @@ var gPhoneNumber = _interopRequireWildcard(require("google-libphonenumber"));
22
22
 
23
23
  var _react = require("react");
24
24
 
25
+ var _dayjs = _interopRequireDefault(require("dayjs"));
26
+
27
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
28
+
25
29
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
26
30
 
27
31
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -32,6 +36,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
32
36
 
33
37
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
34
38
 
39
+ _dayjs["default"].extend(_customParseFormat["default"]);
40
+
35
41
  var DEFAULT_FILE_MAX_SIZE = 10000000;
36
42
 
37
43
  function validateAFM(afm) {
@@ -306,6 +312,13 @@ var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
306
312
  };
307
313
  };
308
314
 
315
+ var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
316
+ var DATE_CACHE = {};
317
+
318
+ var getDate = function getDate(v) {
319
+ return DATE_CACHE[v] ? DATE_CACHE[v] : (0, _dayjs["default"])(v, VALID_DATE_FORMATS, true);
320
+ };
321
+
309
322
  function getYupField(field, yupTypeMap) {
310
323
  var yupField = yupTypeMap[field.type] || yupTypeMap.string;
311
324
  return yupField(field);
@@ -442,6 +455,75 @@ var getYUPTypeMap = function getYUPTypeMap() {
442
455
  },
443
456
  'choice:single': function choiceSingle() {
444
457
  return yup.string().nullable();
458
+ },
459
+ date: function date(field) {
460
+ var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
461
+ if (!value) return true;
462
+ value = getDate(value);
463
+ return value.isValid();
464
+ });
465
+ var params = field.extra || {};
466
+
467
+ if (params.max) {
468
+ var maxDate;
469
+
470
+ if (params.max === 'now') {
471
+ var today = new Date();
472
+ maxDate = new Date(today);
473
+ } else {
474
+ maxDate = getDate(params.max).toDate();
475
+ }
476
+
477
+ var maxNextDate = new Date(maxDate);
478
+ maxNextDate.setDate(maxDate.getDate() + 1);
479
+ simpleDate = simpleDate.test({
480
+ name: 'earlier-than',
481
+ message: {
482
+ key: 'form.error.date.earlier_than',
483
+ context: {
484
+ maxDate: maxNextDate.toLocaleDateString()
485
+ }
486
+ },
487
+ test: function test(value) {
488
+ if (!value) return true;
489
+ value = getDate(value);
490
+ var isValid = +value.toDate() < +maxDate;
491
+ return isValid;
492
+ }
493
+ });
494
+ }
495
+
496
+ if (params.min) {
497
+ var minDate;
498
+
499
+ if (params.min === 'now') {
500
+ var _today = new Date();
501
+
502
+ minDate = new Date(_today);
503
+ } else {
504
+ minDate = getDate(params.min).toDate();
505
+ }
506
+
507
+ var minPreviousDate = new Date(minDate);
508
+ minPreviousDate.setDate(minDate.getDate() - 1);
509
+ simpleDate = simpleDate.test({
510
+ name: 'later-than',
511
+ message: {
512
+ key: 'form.error.date.later_than',
513
+ context: {
514
+ minDate: minPreviousDate.toLocaleDateString()
515
+ }
516
+ },
517
+ test: function test(value) {
518
+ if (!value) return true;
519
+ value = getDate(value);
520
+ var isValid = +value.toDate() > +minDate;
521
+ return isValid;
522
+ }
523
+ });
524
+ }
525
+
526
+ return simpleDate;
445
527
  }
446
528
  };
447
529
  return yupTypeMap;