@digigov/form 0.6.5 → 0.6.6
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 +9 -1
- package/Questions/index.mdx +0 -2
- package/es/Questions/index.mdx +0 -2
- package/es/validators.js +35 -2
- package/es/validators.spec.js +13 -1
- package/esm/Questions/index.mdx +0 -2
- package/esm/index.js +1 -1
- package/esm/validators.js +35 -2
- package/esm/validators.spec.js +13 -1
- package/libs/form/src/index.d.ts +1 -1
- package/libs/form/src/validators.d.ts +1 -0
- package/libs/ui/src/app/CopyToClipboard.d.ts +2 -1
- package/libs/ui/src/locales/el.d.ts +2 -0
- package/libs-ui/react-extensions/src/admin/CopyToClipboardContainer/index.d.ts +14 -0
- package/package.json +2 -2
- package/validators.js +37 -2
- package/validators.spec.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Change Log - @digigov/form
|
|
2
2
|
|
|
3
|
-
This log was last generated on Tue,
|
|
3
|
+
This log was last generated on Tue, 24 May 2022 09:13:18 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.6.6
|
|
6
|
+
Tue, 24 May 2022 09:13:18 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Update MDX examples
|
|
11
|
+
- create postal code validator
|
|
4
12
|
|
|
5
13
|
## 0.6.5
|
|
6
14
|
Tue, 17 May 2022 11:04:22 GMT
|
package/Questions/index.mdx
CHANGED
|
@@ -10,8 +10,6 @@ import Questions, {
|
|
|
10
10
|
StepTitle,
|
|
11
11
|
} from '@digigov/form/Questions';
|
|
12
12
|
import { Field } from '@digigov/form';
|
|
13
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
14
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
15
13
|
const steps = [
|
|
16
14
|
{
|
|
17
15
|
name: 'intro',
|
package/es/Questions/index.mdx
CHANGED
|
@@ -10,8 +10,6 @@ import Questions, {
|
|
|
10
10
|
StepTitle,
|
|
11
11
|
} from '@digigov/form/Questions';
|
|
12
12
|
import { Field } from '@digigov/form';
|
|
13
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
14
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
15
13
|
const steps = [
|
|
16
14
|
{
|
|
17
15
|
name: 'intro',
|
package/es/validators.js
CHANGED
|
@@ -14,6 +14,19 @@ import dayjs from 'dayjs';
|
|
|
14
14
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
15
15
|
dayjs.extend(customParseFormat);
|
|
16
16
|
var DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
17
|
+
export function validatePostalCode(number, countries) {
|
|
18
|
+
if (!countries) {
|
|
19
|
+
return false;
|
|
20
|
+
} else {
|
|
21
|
+
if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {
|
|
22
|
+
// Greek postal code must be 5 digits long and shouldn't start with 0 or 9.
|
|
23
|
+
var CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
24
|
+
return CODE_REGEX.test(number);
|
|
25
|
+
} else {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
export function validateAFM(afm) {
|
|
18
31
|
if (afm.length !== 9) {
|
|
19
32
|
// "afm should be 9 digits"
|
|
@@ -69,6 +82,23 @@ function validateMobile(value) {
|
|
|
69
82
|
}
|
|
70
83
|
}
|
|
71
84
|
|
|
85
|
+
var POSTALCODE_VALIDATOR = function POSTALCODE_VALIDATOR(field) {
|
|
86
|
+
var _field$extra;
|
|
87
|
+
|
|
88
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
89
|
+
return {
|
|
90
|
+
name: 'postal-code-validator',
|
|
91
|
+
message: 'form.error.postalCode',
|
|
92
|
+
test: function test(value) {
|
|
93
|
+
if (!value || value.length === 0) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return validatePostalCode(value, countryCode);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
72
102
|
var MOBILE_PHONE_VALIDATOR = {
|
|
73
103
|
name: 'mobile-phone-validator',
|
|
74
104
|
message: 'form.error.mobile_phone',
|
|
@@ -267,9 +297,9 @@ export function validateIban(value, countryCode) {
|
|
|
267
297
|
}
|
|
268
298
|
|
|
269
299
|
var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
270
|
-
var _field$
|
|
300
|
+
var _field$extra2;
|
|
271
301
|
|
|
272
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$
|
|
302
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.country;
|
|
273
303
|
return {
|
|
274
304
|
name: 'iban-validator',
|
|
275
305
|
message: 'form.error.iban',
|
|
@@ -418,6 +448,9 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
418
448
|
iban: function iban(field) {
|
|
419
449
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
420
450
|
},
|
|
451
|
+
postal_code: function postal_code(field) {
|
|
452
|
+
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
453
|
+
},
|
|
421
454
|
mobile_phone: function mobile_phone() {
|
|
422
455
|
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
423
456
|
},
|
package/es/validators.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateUUID4, validateIban } from '@digigov/form/validators';
|
|
1
|
+
import { validateUUID4, validateIban, validatePostalCode } from '@digigov/form/validators';
|
|
2
2
|
it('validates wrong uuid4 for empty value', function () {
|
|
3
3
|
expect(validateUUID4('')).toBe(false);
|
|
4
4
|
});
|
|
@@ -31,4 +31,16 @@ it('validates wrong iban for non existing country code', function () {
|
|
|
31
31
|
});
|
|
32
32
|
it('validates correct greek iban whithout country code', function () {
|
|
33
33
|
expect(validateIban('7801100800000008009825202', '')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('validates wrong postal code without country code', function () {
|
|
36
|
+
expect(validatePostalCode('123', [])).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('validates wrong postal code with wrong country code', function () {
|
|
39
|
+
expect(validatePostalCode('123', ['FR'])).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('validates wrong postal code with greek country code', function () {
|
|
42
|
+
expect(validatePostalCode('123', ['GR'])).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('validates postal code with greek country code', function () {
|
|
45
|
+
expect(validatePostalCode('11143', ['GR'])).toBe(true);
|
|
34
46
|
});
|
package/esm/Questions/index.mdx
CHANGED
|
@@ -10,8 +10,6 @@ import Questions, {
|
|
|
10
10
|
StepTitle,
|
|
11
11
|
} from '@digigov/form/Questions';
|
|
12
12
|
import { Field } from '@digigov/form';
|
|
13
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
14
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
15
13
|
const steps = [
|
|
16
14
|
{
|
|
17
15
|
name: 'intro',
|
package/esm/index.js
CHANGED
package/esm/validators.js
CHANGED
|
@@ -14,6 +14,19 @@ import dayjs from 'dayjs';
|
|
|
14
14
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
15
15
|
dayjs.extend(customParseFormat);
|
|
16
16
|
var DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
17
|
+
export function validatePostalCode(number, countries) {
|
|
18
|
+
if (!countries) {
|
|
19
|
+
return false;
|
|
20
|
+
} else {
|
|
21
|
+
if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {
|
|
22
|
+
// Greek postal code must be 5 digits long and shouldn't start with 0 or 9.
|
|
23
|
+
var CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
24
|
+
return CODE_REGEX.test(number);
|
|
25
|
+
} else {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
export function validateAFM(afm) {
|
|
18
31
|
if (afm.length !== 9) {
|
|
19
32
|
// "afm should be 9 digits"
|
|
@@ -69,6 +82,23 @@ function validateMobile(value) {
|
|
|
69
82
|
}
|
|
70
83
|
}
|
|
71
84
|
|
|
85
|
+
var POSTALCODE_VALIDATOR = function POSTALCODE_VALIDATOR(field) {
|
|
86
|
+
var _field$extra;
|
|
87
|
+
|
|
88
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
89
|
+
return {
|
|
90
|
+
name: 'postal-code-validator',
|
|
91
|
+
message: 'form.error.postalCode',
|
|
92
|
+
test: function test(value) {
|
|
93
|
+
if (!value || value.length === 0) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return validatePostalCode(value, countryCode);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
72
102
|
var MOBILE_PHONE_VALIDATOR = {
|
|
73
103
|
name: 'mobile-phone-validator',
|
|
74
104
|
message: 'form.error.mobile_phone',
|
|
@@ -267,9 +297,9 @@ export function validateIban(value, countryCode) {
|
|
|
267
297
|
}
|
|
268
298
|
|
|
269
299
|
var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
270
|
-
var _field$
|
|
300
|
+
var _field$extra2;
|
|
271
301
|
|
|
272
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$
|
|
302
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.country;
|
|
273
303
|
return {
|
|
274
304
|
name: 'iban-validator',
|
|
275
305
|
message: 'form.error.iban',
|
|
@@ -418,6 +448,9 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
418
448
|
iban: function iban(field) {
|
|
419
449
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
420
450
|
},
|
|
451
|
+
postal_code: function postal_code(field) {
|
|
452
|
+
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
453
|
+
},
|
|
421
454
|
mobile_phone: function mobile_phone() {
|
|
422
455
|
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
423
456
|
},
|
package/esm/validators.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateUUID4, validateIban } from '@digigov/form/validators';
|
|
1
|
+
import { validateUUID4, validateIban, validatePostalCode } from '@digigov/form/validators';
|
|
2
2
|
it('validates wrong uuid4 for empty value', function () {
|
|
3
3
|
expect(validateUUID4('')).toBe(false);
|
|
4
4
|
});
|
|
@@ -31,4 +31,16 @@ it('validates wrong iban for non existing country code', function () {
|
|
|
31
31
|
});
|
|
32
32
|
it('validates correct greek iban whithout country code', function () {
|
|
33
33
|
expect(validateIban('7801100800000008009825202', '')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('validates wrong postal code without country code', function () {
|
|
36
|
+
expect(validatePostalCode('123', [])).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('validates wrong postal code with wrong country code', function () {
|
|
39
|
+
expect(validatePostalCode('123', ['FR'])).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('validates wrong postal code with greek country code', function () {
|
|
42
|
+
expect(validatePostalCode('123', ['GR'])).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('validates postal code with greek country code', function () {
|
|
45
|
+
expect(validatePostalCode('11143', ['GR'])).toBe(true);
|
|
34
46
|
});
|
package/libs/form/src/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface FieldCondition {
|
|
|
19
19
|
}
|
|
20
20
|
export interface FieldSpec {
|
|
21
21
|
key: string;
|
|
22
|
-
type?: 'int' | 'string' | 'boolean' | 'choice:multiple' | 'choice:single' | 'mobile_phone' | 'afm';
|
|
22
|
+
type?: 'int' | 'string' | 'boolean' | 'choice:multiple' | 'choice:single' | 'mobile_phone' | 'afm' | 'iban' | 'postal_code';
|
|
23
23
|
component?: any;
|
|
24
24
|
condition?: Record<string, FieldCondition>;
|
|
25
25
|
controlled?: boolean;
|
|
@@ -2,6 +2,7 @@ import * as yup from 'yup';
|
|
|
2
2
|
import { FieldSpec } from '@digigov/form';
|
|
3
3
|
import { MutableRefObject } from 'react';
|
|
4
4
|
export declare type ValidatorSchema = yup.BaseTestOptions;
|
|
5
|
+
export declare function validatePostalCode(number: string, countries: Array<string>): boolean;
|
|
5
6
|
export declare function validateAFM(afm: string): boolean;
|
|
6
7
|
export declare function validateUUID4(uuid4: string): boolean;
|
|
7
8
|
export declare function validateIban(value: string, countryCode: string): boolean;
|
|
@@ -3,6 +3,7 @@ declare type DivElementAttributes = JSX.IntrinsicElements['div'];
|
|
|
3
3
|
export interface CopyToClipboardProps extends DivElementAttributes {
|
|
4
4
|
text: string;
|
|
5
5
|
variant?: 'tooltip' | 'banner';
|
|
6
|
+
message?: string;
|
|
6
7
|
}
|
|
7
|
-
export declare const CopyToClipboard: React.ForwardRefExoticComponent<Pick<CopyToClipboardProps, "className" | "style" | "slot" | "title" | "text" | "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" | "variant"> & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export declare const CopyToClipboard: React.ForwardRefExoticComponent<Pick<CopyToClipboardProps, "message" | "className" | "style" | "slot" | "title" | "text" | "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" | "variant"> & React.RefAttributes<HTMLDivElement>>;
|
|
8
9
|
export default CopyToClipboard;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type DivElementAttributes = JSX.IntrinsicElements['div'];
|
|
3
|
+
export interface CopyToClipboardContainerProps extends DivElementAttributes {
|
|
4
|
+
/**
|
|
5
|
+
* 'tooltip' is used when you want to show the message inside a tooltip.
|
|
6
|
+
* 'banner' is used when you want to show the message inside a banner.
|
|
7
|
+
*/
|
|
8
|
+
variant?: 'tooltip' | 'banner';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* CopyToClipboardContainer is a wrapper component for CopyToClipboardMessage
|
|
12
|
+
*/
|
|
13
|
+
export declare const CopyToClipboardContainer: React.ForwardRefExoticComponent<Pick<CopyToClipboardContainerProps, "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" | "variant"> & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
export default CopyToClipboardContainer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/form",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "@digigov form builder",
|
|
5
5
|
"author": "GRNET Developers <devs@lists.grnet.gr>",
|
|
6
6
|
"license": "BSD-2-Clause",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dayjs": "1.10.4"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@digigov/ui": "0.20.
|
|
20
|
+
"@digigov/ui": "0.20.2",
|
|
21
21
|
"@material-ui/core": "4.11.3",
|
|
22
22
|
"@material-ui/icons": "4.11.2",
|
|
23
23
|
"clsx": "1.1.1",
|
package/validators.js
CHANGED
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
10
10
|
exports.useValidationSchema = useValidationSchema;
|
|
11
11
|
exports.validateAFM = validateAFM;
|
|
12
12
|
exports.validateIban = validateIban;
|
|
13
|
+
exports.validatePostalCode = validatePostalCode;
|
|
13
14
|
exports.validateUUID4 = validateUUID4;
|
|
14
15
|
|
|
15
16
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
@@ -40,6 +41,20 @@ _dayjs["default"].extend(_customParseFormat["default"]);
|
|
|
40
41
|
|
|
41
42
|
var DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
42
43
|
|
|
44
|
+
function validatePostalCode(number, countries) {
|
|
45
|
+
if (!countries) {
|
|
46
|
+
return false;
|
|
47
|
+
} else {
|
|
48
|
+
if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {
|
|
49
|
+
// Greek postal code must be 5 digits long and shouldn't start with 0 or 9.
|
|
50
|
+
var CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
51
|
+
return CODE_REGEX.test(number);
|
|
52
|
+
} else {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
43
58
|
function validateAFM(afm) {
|
|
44
59
|
if (afm.length !== 9) {
|
|
45
60
|
// "afm should be 9 digits"
|
|
@@ -95,6 +110,23 @@ function validateMobile(value) {
|
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
|
|
113
|
+
var POSTALCODE_VALIDATOR = function POSTALCODE_VALIDATOR(field) {
|
|
114
|
+
var _field$extra;
|
|
115
|
+
|
|
116
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
117
|
+
return {
|
|
118
|
+
name: 'postal-code-validator',
|
|
119
|
+
message: 'form.error.postalCode',
|
|
120
|
+
test: function test(value) {
|
|
121
|
+
if (!value || value.length === 0) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return validatePostalCode(value, countryCode);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
98
130
|
var MOBILE_PHONE_VALIDATOR = {
|
|
99
131
|
name: 'mobile-phone-validator',
|
|
100
132
|
message: 'form.error.mobile_phone',
|
|
@@ -296,9 +328,9 @@ function validateIban(value, countryCode) {
|
|
|
296
328
|
}
|
|
297
329
|
|
|
298
330
|
var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
299
|
-
var _field$
|
|
331
|
+
var _field$extra2;
|
|
300
332
|
|
|
301
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$
|
|
333
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.country;
|
|
302
334
|
return {
|
|
303
335
|
name: 'iban-validator',
|
|
304
336
|
message: 'form.error.iban',
|
|
@@ -447,6 +479,9 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
447
479
|
iban: function iban(field) {
|
|
448
480
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
449
481
|
},
|
|
482
|
+
postal_code: function postal_code(field) {
|
|
483
|
+
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
484
|
+
},
|
|
450
485
|
mobile_phone: function mobile_phone() {
|
|
451
486
|
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
452
487
|
},
|
package/validators.spec.js
CHANGED
|
@@ -34,4 +34,16 @@ it('validates wrong iban for non existing country code', function () {
|
|
|
34
34
|
});
|
|
35
35
|
it('validates correct greek iban whithout country code', function () {
|
|
36
36
|
expect((0, _validators.validateIban)('7801100800000008009825202', '')).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('validates wrong postal code without country code', function () {
|
|
39
|
+
expect((0, _validators.validatePostalCode)('123', [])).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('validates wrong postal code with wrong country code', function () {
|
|
42
|
+
expect((0, _validators.validatePostalCode)('123', ['FR'])).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
it('validates wrong postal code with greek country code', function () {
|
|
45
|
+
expect((0, _validators.validatePostalCode)('123', ['GR'])).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
it('validates postal code with greek country code', function () {
|
|
48
|
+
expect((0, _validators.validatePostalCode)('11143', ['GR'])).toBe(true);
|
|
37
49
|
});
|