@mgdis/mg-components 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-85a4a0b6.js → index-88560a66.js} +123 -48
- package/dist/cjs/index-a39c5567.js +233 -0
- package/dist/cjs/loader.cjs.js +3 -17
- package/dist/cjs/mg-badge_21.cjs.entry.js +3538 -0
- package/dist/cjs/mg-components.cjs.js +3 -7
- package/dist/cjs/mg-modal.cjs.entry.js +117 -0
- package/dist/cjs/mg-popover.cjs.entry.js +170 -0
- package/dist/cjs/popper-71bf3058.js +1790 -0
- package/dist/collection/collection-manifest.json +4 -1
- package/dist/collection/components/atoms/mg-badge/{mg-badge.stories.js → doc/mg-badge.stories.js} +4 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.conf.js +1 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.css +0 -2
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +26 -10
- package/dist/collection/components/atoms/mg-button/{mg-button.stories.js → doc/mg-button.stories.js} +7 -2
- package/dist/collection/components/atoms/mg-button/mg-button.conf.js +1 -1
- package/dist/collection/components/atoms/mg-button/mg-button.css +46 -49
- package/dist/collection/components/atoms/mg-button/mg-button.js +78 -4
- package/dist/collection/components/atoms/mg-character-left/{mg-character-left.stories.js → doc/mg-character-left.stories.js} +8 -0
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.js +20 -46
- package/dist/collection/components/atoms/mg-icon/{mg-icon.stories.js → doc/mg-icon.stories.js} +1 -1
- package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +104 -9
- package/dist/collection/components/atoms/mg-icon/mg-icon.css +9 -7
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +33 -7
- package/dist/collection/components/atoms/mg-input-title/{mg-input-title.stories.js → doc/mg-input-title.stories.js} +0 -0
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.css +4 -4
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +14 -3
- package/dist/collection/components/atoms/mg-tag/{mg-tag.stories.js → doc/mg-tag.stories.js} +4 -1
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +28 -6
- package/dist/collection/components/atoms/mg-tooltip/{mg-tooltip.stories.js → doc/mg-tooltip.stories.js} +14 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js +20 -0
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +16 -2
- package/dist/collection/components/molecules/inputs/MgInput.conf.js +1 -7
- package/dist/collection/components/molecules/inputs/MgInput.js +25 -29
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/{mg-input-checkbox.stories.js → doc/mg-input-checkbox.stories.js} +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.css +25 -11
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +102 -52
- package/dist/collection/components/molecules/inputs/mg-input-date/{mg-input-date.stories.js → doc/mg-input-date.stories.js} +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.css +37 -9
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +136 -66
- package/dist/collection/components/molecules/inputs/mg-input-numeric/{mg-input-numeric.stories.js → doc/mg-input-numeric.stories.js} +15 -3
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +38 -10
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +180 -80
- package/dist/collection/components/molecules/inputs/mg-input-password/{mg-input-password.stories.js → doc/mg-input-password.stories.js} +16 -2
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +37 -9
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +108 -47
- package/dist/collection/components/molecules/inputs/mg-input-radio/{mg-input-radio.stories.js → doc/mg-input-radio.stories.js} +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.css +25 -11
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +113 -42
- package/dist/collection/components/molecules/inputs/mg-input-select/{mg-input-select.stories.js → doc/mg-input-select.stories.js} +22 -2
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +39 -10
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +145 -71
- package/dist/collection/components/molecules/inputs/mg-input-text/{mg-input-text.stories.js → doc/mg-input-text.stories.js} +17 -8
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +69 -19
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +184 -83
- package/dist/collection/components/molecules/inputs/mg-input-textarea/{mg-input-textarea.stories.js → doc/mg-input-textarea.stories.js} +16 -5
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +69 -13
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +163 -70
- package/dist/collection/components/molecules/inputs/mg-input-toggle/{mg-input-toggle.stories.js → doc/mg-input-toggle.stories.js} +6 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.css +22 -10
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +68 -33
- package/dist/collection/components/molecules/mg-form/doc/mg-form.stories.js +58 -0
- package/dist/collection/components/molecules/mg-form/mg-form.css +19 -0
- package/dist/collection/components/molecules/mg-form/mg-form.js +271 -0
- package/dist/collection/components/molecules/mg-message/{mg-message.stories.js → doc/mg-message.stories.js} +6 -2
- package/dist/collection/components/molecules/mg-message/mg-message.css +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js +26 -11
- package/dist/collection/components/molecules/mg-modal/doc/mg-modal.stories.js +51 -0
- package/dist/collection/components/molecules/mg-modal/mg-modal.css +52 -0
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +240 -0
- package/dist/collection/components/molecules/mg-pagination/{mg-pagination.stories.js → doc/mg-pagination.stories.js} +1 -0
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +47 -28
- package/dist/collection/components/molecules/mg-panel/doc/mg-panel.stories.js +39 -0
- package/dist/collection/components/molecules/mg-panel/mg-panel.css +53 -0
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +356 -0
- package/dist/collection/components/molecules/mg-popover/{mg-popover.stories.js → doc/mg-popover.stories.js} +10 -0
- package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js +20 -0
- package/dist/collection/components/molecules/mg-popover/mg-popover.css +2 -2
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +37 -12
- package/dist/collection/components/molecules/mg-tabs/{mg-tabs.stories.js → doc/mg-tabs.stories.js} +20 -4
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.conf.js +11 -1
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +17 -3
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +139 -26
- package/dist/collection/locales/index.js +33 -4
- package/dist/collection/stories/helpers.stories.js +33 -0
- package/dist/collection/utils/components.utils.js +16 -9
- package/dist/collection/utils/locale.utils.js +13 -7
- package/dist/collection/utils/test.utils.js +27 -15
- package/dist/collection/variables.css +39 -5
- package/dist/collection/variables.scss +39 -5
- package/dist/components/MgInput.js +26 -37
- package/dist/components/components.utils.js +16 -9
- package/dist/components/index.d.ts +24 -6
- package/dist/components/index.js +23 -0
- package/dist/components/index2.js +116 -17
- package/dist/components/locale.utils.js +13 -8
- package/dist/components/mg-badge2.js +25 -9
- package/dist/components/mg-button2.js +29 -5
- package/dist/components/mg-character-left2.js +14 -26
- package/dist/components/mg-form.d.ts +11 -0
- package/dist/components/mg-form.js +148 -0
- package/dist/components/mg-icon2.js +138 -17
- package/dist/components/mg-input-checkbox.js +66 -53
- package/dist/components/mg-input-date.js +100 -69
- package/dist/components/mg-input-numeric.js +125 -81
- package/dist/components/mg-input-password.js +69 -48
- package/dist/components/mg-input-radio.js +74 -46
- package/dist/components/mg-input-select2.js +103 -71
- package/dist/components/mg-input-text.js +1 -237
- package/dist/components/mg-input-text2.js +300 -0
- package/dist/components/mg-input-textarea.js +100 -46
- package/dist/components/mg-input-title2.js +13 -4
- package/dist/components/mg-input-toggle.js +39 -31
- package/dist/components/mg-message.js +25 -10
- package/dist/components/mg-modal.d.ts +11 -0
- package/dist/components/mg-modal.js +153 -0
- package/dist/components/mg-pagination.js +45 -31
- package/dist/components/mg-panel.d.ts +11 -0
- package/dist/components/mg-panel.js +244 -0
- package/dist/components/mg-popover.js +31 -11
- package/dist/components/mg-tabs.js +113 -23
- package/dist/components/mg-tag.js +27 -5
- package/dist/components/mg-tooltip2.js +10 -1
- package/dist/components/popper.js +6 -2
- package/dist/esm/{index-e3e84606.js → index-bca81100.js} +124 -46
- package/dist/esm/index-e51ae032.js +228 -0
- package/dist/esm/loader.js +3 -17
- package/dist/esm/mg-badge_21.entry.js +3514 -0
- package/dist/esm/mg-components.js +3 -7
- package/dist/esm/mg-modal.entry.js +113 -0
- package/dist/esm/mg-popover.entry.js +166 -0
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm/popper-93ecb064.js +1788 -0
- package/dist/index.js +1 -1
- package/dist/mg-components/mg-components.css +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/p-003a1344.entry.js +1 -0
- package/dist/mg-components/p-462d648a.entry.js +1 -0
- package/dist/mg-components/p-4c66f794.js +1 -0
- package/dist/mg-components/p-5126ab10.entry.js +1 -0
- package/dist/mg-components/p-780bd52d.js +1 -0
- package/dist/mg-components/p-b14a3443.js +2 -0
- package/dist/mg-components/variables.css +39 -5
- package/dist/mg-components/variables.scss +39 -5
- package/dist/types/components/atoms/mg-badge/{mg-badge.stories.d.ts → doc/mg-badge.stories.d.ts} +5 -0
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +16 -5
- package/dist/types/components/atoms/mg-button/{mg-button.stories.d.ts → doc/mg-button.stories.d.ts} +5 -0
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +23 -3
- package/dist/types/components/atoms/mg-character-left/{mg-character-left.stories.d.ts → doc/mg-character-left.stories.d.ts} +9 -0
- package/dist/types/components/atoms/mg-character-left/mg-character-left.d.ts +16 -13
- package/dist/types/components/atoms/mg-icon/{mg-icon.stories.d.ts → doc/mg-icon.stories.d.ts} +0 -0
- package/dist/types/components/atoms/mg-icon/mg-icon.conf.d.ts +1 -1
- package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +14 -4
- package/dist/types/components/atoms/mg-input-title/{mg-input-title.stories.d.ts → doc/mg-input-title.stories.d.ts} +0 -0
- package/dist/types/components/atoms/mg-input-title/mg-input-title.d.ts +11 -1
- package/dist/types/components/atoms/mg-tag/{mg-tag.stories.d.ts → doc/mg-tag.stories.d.ts} +5 -0
- package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +18 -4
- package/dist/types/components/atoms/mg-tooltip/doc/mg-tooltip.stories.d.ts +29 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.conf.d.ts +8 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +13 -3
- package/dist/types/components/molecules/inputs/MgInput.conf.d.ts +6 -4
- package/dist/types/components/molecules/inputs/MgInput.d.ts +7 -8
- package/dist/types/components/molecules/inputs/mg-input-checkbox/{mg-input-checkbox.stories.d.ts → doc/mg-input-checkbox.stories.d.ts} +5 -0
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +36 -13
- package/dist/types/components/molecules/inputs/mg-input-date/{mg-input-date.stories.d.ts → doc/mg-input-date.stories.d.ts} +5 -0
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +46 -15
- package/dist/types/components/molecules/inputs/mg-input-numeric/{mg-input-numeric.stories.d.ts → doc/mg-input-numeric.stories.d.ts} +11 -0
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +61 -16
- package/dist/types/components/molecules/inputs/mg-input-password/doc/mg-input-password.stories.d.ts +22 -0
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +35 -11
- package/dist/types/components/molecules/inputs/mg-input-radio/{mg-input-radio.stories.d.ts → doc/mg-input-radio.stories.d.ts} +5 -0
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.conf.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +42 -9
- package/dist/types/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.d.ts +34 -0
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.conf.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +37 -9
- package/dist/types/components/molecules/inputs/mg-input-text/{mg-input-text.stories.d.ts → doc/mg-input-text.stories.d.ts} +13 -0
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +52 -16
- package/dist/types/components/molecules/inputs/mg-input-textarea/doc/mg-input-textarea.stories.d.ts +19 -0
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +45 -17
- package/dist/types/components/molecules/inputs/mg-input-toggle/{mg-input-toggle.stories.d.ts → doc/mg-input-toggle.stories.d.ts} +5 -0
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.conf.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +29 -12
- package/dist/types/components/molecules/{mg-popover/mg-popover.stories.d.ts → mg-form/doc/mg-form.stories.d.ts} +3 -4
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +83 -0
- package/dist/types/components/molecules/mg-message/{mg-message.stories.d.ts → doc/mg-message.stories.d.ts} +10 -0
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +13 -4
- package/dist/types/components/molecules/mg-modal/doc/mg-modal.stories.d.ts +13 -0
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +85 -0
- package/dist/types/components/molecules/mg-pagination/{mg-pagination.stories.d.ts → doc/mg-pagination.stories.d.ts} +5 -0
- package/dist/types/components/molecules/mg-pagination/mg-pagination.d.ts +31 -7
- package/dist/types/components/molecules/mg-panel/doc/mg-panel.stories.d.ts +11 -0
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +139 -0
- package/dist/types/components/molecules/mg-popover/doc/mg-popover.stories.d.ts +25 -0
- package/dist/types/components/molecules/mg-popover/mg-popover.conf.d.ts +8 -0
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +27 -4
- package/dist/types/components/molecules/mg-tabs/doc/mg-tabs.stories.d.ts +20 -0
- package/dist/types/components/molecules/mg-tabs/mg-tabs.conf.d.ts +11 -0
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +70 -6
- package/dist/types/components.d.ts +528 -211
- package/dist/types/locales/index.d.ts +108 -38
- package/dist/types/stories/{buttons.stories.d.ts → helpers.stories.d.ts} +1 -1
- package/dist/types/utils/components.utils.d.ts +16 -9
- package/dist/types/utils/locale.utils.d.ts +13 -6
- package/dist/types/utils/test.utils.d.ts +13 -1
- package/loader/index.js +1 -1
- package/package.json +45 -14
- package/readme.md +9 -35
- package/dist/cjs/css-shim-a22512c4.js +0 -6
- package/dist/cjs/mg-badge_20.cjs.entry.js +0 -4661
- package/dist/cjs/shadow-css-8940f82d.js +0 -390
- package/dist/collection/stories/buttons.stories.js +0 -43
- package/dist/collection/stories/messages.stories.js +0 -44
- package/dist/collection/stories/tags.stories.js +0 -13
- package/dist/esm/css-shim-7c240feb.js +0 -4
- package/dist/esm/mg-badge_20.entry.js +0 -4638
- package/dist/esm/shadow-css-5d2d01ce.js +0 -388
- package/dist/esm-es5/css-shim-7c240feb.js +0 -1
- package/dist/esm-es5/index-e3e84606.js +0 -1
- package/dist/esm-es5/index.js +0 -0
- package/dist/esm-es5/loader.js +0 -1
- package/dist/esm-es5/mg-badge_20.entry.js +0 -2
- package/dist/esm-es5/mg-components.js +0 -1
- package/dist/esm-es5/shadow-css-5d2d01ce.js +0 -12
- package/dist/mg-components/mg-components.js +0 -132
- package/dist/mg-components/p-1cd24462.system.js +0 -1
- package/dist/mg-components/p-2e2f6b27.system.entry.js +0 -2
- package/dist/mg-components/p-366a224e.js +0 -1
- package/dist/mg-components/p-422c429b.system.js +0 -1
- package/dist/mg-components/p-50ea2036.system.js +0 -1
- package/dist/mg-components/p-62fa3797.js +0 -1
- package/dist/mg-components/p-71d57b8b.system.js +0 -13
- package/dist/mg-components/p-9a215712.system.js +0 -1
- package/dist/mg-components/p-cbf0464b.entry.js +0 -1
- package/dist/mg-components/p-f6455ab3.js +0 -12
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.stories.d.ts +0 -11
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.stories.d.ts +0 -9
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.stories.d.ts +0 -14
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.stories.d.ts +0 -6
- package/dist/types/components/molecules/mg-tabs/mg-tabs.stories.d.ts +0 -7
- package/dist/types/stories/messages.stories.d.ts +0 -13
- package/dist/types/stories/tags.stories.d.ts +0 -5
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { Component, Event, h, Prop, State, Watch } from '@stencil/core';
|
|
1
|
+
import { Component, Element, Event, h, Prop, State, Watch, Method } from '@stencil/core';
|
|
2
2
|
import { MgInput } from '../MgInput';
|
|
3
3
|
import { InputError } from './mg-input-date.conf';
|
|
4
4
|
import { createID, ClassList } from '../../../../utils/components.utils';
|
|
5
5
|
import { localeDate, dateRegExp } from '../../../../utils/locale.utils';
|
|
6
|
-
import {
|
|
7
|
-
import { InputClass } from '../MgInput.conf';
|
|
6
|
+
import { initLocales } from '../../../../locales';
|
|
8
7
|
export class MgInputDate {
|
|
9
8
|
constructor() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
************/
|
|
13
|
-
// classes
|
|
14
|
-
this.classError = InputClass.ERROR;
|
|
9
|
+
// hasError (triggered by blur event)
|
|
10
|
+
this.hasError = false;
|
|
15
11
|
/**
|
|
16
12
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
17
13
|
* If not set, it will be created.
|
|
@@ -47,19 +43,34 @@ export class MgInputDate {
|
|
|
47
43
|
*/
|
|
48
44
|
this.handleInput = () => {
|
|
49
45
|
this.checkValidity();
|
|
46
|
+
if (this.hasError) {
|
|
47
|
+
this.checkError();
|
|
48
|
+
}
|
|
50
49
|
this.value = this.input.value;
|
|
51
|
-
this.valueChange.emit(this.value);
|
|
52
50
|
};
|
|
53
51
|
/**
|
|
54
52
|
* Handle blur event
|
|
55
53
|
*/
|
|
56
54
|
this.handleBlur = () => {
|
|
57
|
-
this.
|
|
58
|
-
|
|
55
|
+
this.displayError();
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Check if input is valid
|
|
59
|
+
*/
|
|
60
|
+
this.checkValidity = () => {
|
|
61
|
+
if (!this.readonly && this.input !== undefined) {
|
|
62
|
+
const validity = this.input.checkValidity();
|
|
63
|
+
// Set validity
|
|
64
|
+
this.valid = validity;
|
|
65
|
+
this.invalid = !validity;
|
|
66
|
+
//Send event
|
|
67
|
+
this.inputValid.emit(validity);
|
|
68
|
+
}
|
|
59
69
|
};
|
|
60
70
|
/**
|
|
61
71
|
* get input error code
|
|
62
|
-
*
|
|
72
|
+
*
|
|
73
|
+
* @returns {null | InputError} error code
|
|
63
74
|
*/
|
|
64
75
|
this.getInputError = () => {
|
|
65
76
|
var _a, _b;
|
|
@@ -82,11 +93,48 @@ export class MgInputDate {
|
|
|
82
93
|
}
|
|
83
94
|
return inputError;
|
|
84
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Set error message
|
|
98
|
+
*
|
|
99
|
+
* @returns {void}
|
|
100
|
+
*/
|
|
101
|
+
this.setErrorMessage = () => {
|
|
102
|
+
var _a;
|
|
103
|
+
const inputError = this.getInputError();
|
|
104
|
+
// required
|
|
105
|
+
if (inputError === InputError.REQUIRED) {
|
|
106
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
107
|
+
}
|
|
108
|
+
// min, max & minMax
|
|
109
|
+
else if ([InputError.MIN, InputError.MAX, InputError.MINMAX].includes(inputError)) {
|
|
110
|
+
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
111
|
+
}
|
|
112
|
+
// wrong date format
|
|
113
|
+
// element.validity.badInput is default error message
|
|
114
|
+
else {
|
|
115
|
+
this.errorMessage = this.messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min, this.locale) : localeDate('1900-01-01', this.locale));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Check input errors
|
|
120
|
+
*
|
|
121
|
+
* @returns {void}
|
|
122
|
+
*/
|
|
123
|
+
this.checkError = () => {
|
|
124
|
+
// Set error message
|
|
125
|
+
this.errorMessage = undefined;
|
|
126
|
+
if (!this.valid) {
|
|
127
|
+
this.setErrorMessage();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
85
130
|
}
|
|
86
131
|
validateValue(newValue) {
|
|
87
132
|
if (newValue !== undefined && newValue !== '' && !(typeof newValue === 'string' && dateRegExp.test(newValue))) {
|
|
88
133
|
throw new Error("<mg-input-date> props 'value' doesn't match pattern: yyyy-mm-dd");
|
|
89
134
|
}
|
|
135
|
+
else {
|
|
136
|
+
this.valueChange.emit(this.value);
|
|
137
|
+
}
|
|
90
138
|
}
|
|
91
139
|
validateMin(newValue) {
|
|
92
140
|
this.validateDateFormat(newValue);
|
|
@@ -94,73 +142,58 @@ export class MgInputDate {
|
|
|
94
142
|
validateMax(newValue) {
|
|
95
143
|
this.validateDateFormat(newValue);
|
|
96
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Public method to display errors
|
|
147
|
+
*
|
|
148
|
+
* @returns {Promise<void>}
|
|
149
|
+
*/
|
|
150
|
+
async displayError() {
|
|
151
|
+
this.checkValidity();
|
|
152
|
+
this.checkError();
|
|
153
|
+
this.hasError = this.invalid;
|
|
154
|
+
}
|
|
97
155
|
/**
|
|
98
156
|
* Date format validation
|
|
99
|
-
*
|
|
157
|
+
*
|
|
158
|
+
* @param {string} date date to validate
|
|
159
|
+
* @returns {void}
|
|
100
160
|
*/
|
|
101
161
|
validateDateFormat(date) {
|
|
102
162
|
if ((date === null || date === void 0 ? void 0 : date.length) > 0 && !(typeof date === 'string' && dateRegExp.test(date))) {
|
|
103
163
|
throw new Error("<mg-input-date> props 'min/max' doesn't match pattern: yyyy-mm-dd");
|
|
104
164
|
}
|
|
105
165
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Check if input is valid
|
|
108
|
-
*/
|
|
109
|
-
checkValidity() {
|
|
110
|
-
if (!this.readonly && this.input !== undefined) {
|
|
111
|
-
const validity = this.input.checkValidity();
|
|
112
|
-
// Set validity
|
|
113
|
-
this.valid = validity;
|
|
114
|
-
this.invalid = !validity;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Set error message
|
|
119
|
-
*/
|
|
120
|
-
setErrorMessage() {
|
|
121
|
-
var _a;
|
|
122
|
-
const inputError = this.getInputError();
|
|
123
|
-
// required
|
|
124
|
-
if (inputError === InputError.REQUIRED) {
|
|
125
|
-
this.errorMessage = messages.errors[inputError];
|
|
126
|
-
}
|
|
127
|
-
// min, max & minMax
|
|
128
|
-
else if ([InputError.MIN, InputError.MAX, InputError.MINMAX].includes(inputError)) {
|
|
129
|
-
this.errorMessage = messages.errors.date[inputError].replace('{min}', localeDate(this.min)).replace('{max}', localeDate(this.max));
|
|
130
|
-
}
|
|
131
|
-
// wrong date format
|
|
132
|
-
// element.validity.badInput is default error message
|
|
133
|
-
else {
|
|
134
|
-
this.errorMessage = messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min) : localeDate('1900-01-01'));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Check input errors
|
|
139
|
-
*/
|
|
140
|
-
checkError() {
|
|
141
|
-
// Set error message
|
|
142
|
-
this.errorMessage = undefined;
|
|
143
|
-
if (!this.valid) {
|
|
144
|
-
this.setErrorMessage();
|
|
145
|
-
this.classList.add(this.classError);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
this.classList.delete(this.classError);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
166
|
/*************
|
|
152
167
|
* Lifecycle *
|
|
153
168
|
*************/
|
|
169
|
+
/**
|
|
170
|
+
* Check if component props are well configured on init
|
|
171
|
+
*
|
|
172
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
173
|
+
*/
|
|
154
174
|
componentWillLoad() {
|
|
175
|
+
// Get locales
|
|
176
|
+
const locales = initLocales(this.element);
|
|
177
|
+
this.locale = locales.locale;
|
|
178
|
+
this.messages = locales.messages;
|
|
179
|
+
// Validate
|
|
155
180
|
this.validateValue(this.value);
|
|
156
181
|
this.validateMin(this.min);
|
|
157
182
|
this.validateMax(this.max);
|
|
183
|
+
// Check validity when component is ready
|
|
158
184
|
// return a promise to process action only in the FIRST render().
|
|
159
185
|
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
160
|
-
return setTimeout(() =>
|
|
186
|
+
return setTimeout(() => {
|
|
187
|
+
this.checkValidity();
|
|
188
|
+
}, 0);
|
|
161
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Render
|
|
192
|
+
*
|
|
193
|
+
* @returns {HTMLElement} HTML Element
|
|
194
|
+
*/
|
|
162
195
|
render() {
|
|
163
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly,
|
|
196
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: undefined, disabled: this.disabled, value: this.value, readonlyValue: localeDate(this.value, this.locale), tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
|
|
164
197
|
h("input", { type: "date", class: "mg-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}", ref: el => (this.input = el) })));
|
|
165
198
|
}
|
|
166
199
|
static get is() { return "mg-input-date"; }
|
|
@@ -198,7 +231,7 @@ export class MgInputDate {
|
|
|
198
231
|
"references": {}
|
|
199
232
|
},
|
|
200
233
|
"required": false,
|
|
201
|
-
"optional":
|
|
234
|
+
"optional": false,
|
|
202
235
|
"docs": {
|
|
203
236
|
"tags": [],
|
|
204
237
|
"text": "Identifier is used for the element ID (id is a reserved prop in Stencil.js)\nIf not set, it will be created."
|
|
@@ -216,7 +249,7 @@ export class MgInputDate {
|
|
|
216
249
|
"references": {}
|
|
217
250
|
},
|
|
218
251
|
"required": false,
|
|
219
|
-
"optional":
|
|
252
|
+
"optional": false,
|
|
220
253
|
"docs": {
|
|
221
254
|
"tags": [],
|
|
222
255
|
"text": "Input name\nIf not set the value equals the identifier"
|
|
@@ -237,7 +270,7 @@ export class MgInputDate {
|
|
|
237
270
|
"optional": false,
|
|
238
271
|
"docs": {
|
|
239
272
|
"tags": [],
|
|
240
|
-
"text": "Input label
|
|
273
|
+
"text": "Input label"
|
|
241
274
|
},
|
|
242
275
|
"attribute": "label",
|
|
243
276
|
"reflect": false
|
|
@@ -377,7 +410,7 @@ export class MgInputDate {
|
|
|
377
410
|
"optional": false,
|
|
378
411
|
"docs": {
|
|
379
412
|
"tags": [],
|
|
380
|
-
"text": "Define input
|
|
413
|
+
"text": "Define input valid state"
|
|
381
414
|
},
|
|
382
415
|
"attribute": "valid",
|
|
383
416
|
"reflect": false
|
|
@@ -394,7 +427,7 @@ export class MgInputDate {
|
|
|
394
427
|
"optional": false,
|
|
395
428
|
"docs": {
|
|
396
429
|
"tags": [],
|
|
397
|
-
"text": "Define input
|
|
430
|
+
"text": "Define input invalid state"
|
|
398
431
|
},
|
|
399
432
|
"attribute": "invalid",
|
|
400
433
|
"reflect": false
|
|
@@ -446,14 +479,51 @@ export class MgInputDate {
|
|
|
446
479
|
"composed": true,
|
|
447
480
|
"docs": {
|
|
448
481
|
"tags": [],
|
|
449
|
-
"text": "
|
|
482
|
+
"text": "Emited event when value change"
|
|
450
483
|
},
|
|
451
484
|
"complexType": {
|
|
452
485
|
"original": "string",
|
|
453
486
|
"resolved": "string",
|
|
454
487
|
"references": {}
|
|
455
488
|
}
|
|
489
|
+
}, {
|
|
490
|
+
"method": "inputValid",
|
|
491
|
+
"name": "input-valid",
|
|
492
|
+
"bubbles": true,
|
|
493
|
+
"cancelable": true,
|
|
494
|
+
"composed": true,
|
|
495
|
+
"docs": {
|
|
496
|
+
"tags": [],
|
|
497
|
+
"text": "Emited event when checking validity"
|
|
498
|
+
},
|
|
499
|
+
"complexType": {
|
|
500
|
+
"original": "boolean",
|
|
501
|
+
"resolved": "boolean",
|
|
502
|
+
"references": {}
|
|
503
|
+
}
|
|
456
504
|
}]; }
|
|
505
|
+
static get methods() { return {
|
|
506
|
+
"displayError": {
|
|
507
|
+
"complexType": {
|
|
508
|
+
"signature": "() => Promise<void>",
|
|
509
|
+
"parameters": [],
|
|
510
|
+
"references": {
|
|
511
|
+
"Promise": {
|
|
512
|
+
"location": "global"
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
"return": "Promise<void>"
|
|
516
|
+
},
|
|
517
|
+
"docs": {
|
|
518
|
+
"text": "Public method to display errors",
|
|
519
|
+
"tags": [{
|
|
520
|
+
"name": "returns",
|
|
521
|
+
"text": undefined
|
|
522
|
+
}]
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}; }
|
|
526
|
+
static get elementRef() { return "element"; }
|
|
457
527
|
static get watchers() { return [{
|
|
458
528
|
"propName": "value",
|
|
459
529
|
"methodName": "validateValue"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h } from '@stencil/core';
|
|
2
|
-
import { types } from '
|
|
2
|
+
import { types } from '../mg-input-numeric.conf';
|
|
3
3
|
export default {
|
|
4
4
|
component: 'mg-input-numeric',
|
|
5
5
|
title: 'Molecules/Inputs/mg-input-numeric',
|
|
@@ -8,21 +8,32 @@ export default {
|
|
|
8
8
|
options: types,
|
|
9
9
|
control: { type: 'select' },
|
|
10
10
|
},
|
|
11
|
+
mgWidth: {
|
|
12
|
+
options: [undefined, 2, 4, 16, 'full'],
|
|
13
|
+
control: { type: 'select' },
|
|
14
|
+
},
|
|
11
15
|
},
|
|
16
|
+
parameters: { actions: { handles: ['value-change', 'input-valid'] } },
|
|
12
17
|
};
|
|
13
18
|
/**
|
|
14
19
|
* 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
|
|
15
20
|
* 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
|
|
21
|
+
*
|
|
22
|
+
* @param {any} args component arguments
|
|
23
|
+
* @returns {HTMLElement} HTMLElement
|
|
16
24
|
*/
|
|
17
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const Template = (args) => {
|
|
18
27
|
const labelOnTop = args.labelOnTop;
|
|
19
28
|
delete args.labelOnTop;
|
|
20
29
|
const labelHide = args.labelHide;
|
|
21
30
|
delete args.labelHide;
|
|
22
31
|
const helpText = args.helpText;
|
|
23
32
|
delete args.helpText;
|
|
33
|
+
const mgWidth = args.mgWidth;
|
|
34
|
+
delete args.mgWidth;
|
|
24
35
|
// return element
|
|
25
|
-
return h("mg-input-numeric", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText }));
|
|
36
|
+
return h("mg-input-numeric", Object.assign({}, args, { "label-on-top": labelOnTop, "label-hide": labelHide, "help-text": helpText, "mg-width": mgWidth }));
|
|
26
37
|
};
|
|
27
38
|
/**
|
|
28
39
|
* Global use
|
|
@@ -45,6 +56,7 @@ MgInputNumeric.args = {
|
|
|
45
56
|
readonly: false,
|
|
46
57
|
max: undefined,
|
|
47
58
|
min: undefined,
|
|
59
|
+
mgWidth: undefined,
|
|
48
60
|
// Tooltip
|
|
49
61
|
tooltip: 'This is a tooltip',
|
|
50
62
|
// Help Text
|
|
@@ -10,16 +10,10 @@
|
|
|
10
10
|
align-items: flex-start;
|
|
11
11
|
min-height: var(--default-size);
|
|
12
12
|
max-width: 100%;
|
|
13
|
-
|
|
13
|
+
margin-bottom: var(--mg-inputs-margin-bottom, 0);
|
|
14
14
|
/* Label */
|
|
15
15
|
/* Label-on-top */
|
|
16
16
|
}
|
|
17
|
-
.mg-input.is-not-valid {
|
|
18
|
-
color: hsl(var(--color-danger));
|
|
19
|
-
}
|
|
20
|
-
.mg-input.is-not-valid .mg-input__box {
|
|
21
|
-
border-color: hsl(var(--color-danger));
|
|
22
|
-
}
|
|
23
17
|
.mg-input mg-input-title {
|
|
24
18
|
flex-shrink: var(--mg-inputs-shrink, 1);
|
|
25
19
|
width: var(--mg-inputs-title-width, auto);
|
|
@@ -73,6 +67,11 @@
|
|
|
73
67
|
.mg-input__input-container mg-icon {
|
|
74
68
|
display: flex;
|
|
75
69
|
}
|
|
70
|
+
.mg-input__input-container .mg-input__help-text,
|
|
71
|
+
.mg-input__input-container .mg-input__error {
|
|
72
|
+
text-align: start;
|
|
73
|
+
font-size: 1.2rem;
|
|
74
|
+
}
|
|
76
75
|
|
|
77
76
|
.mg-input__input {
|
|
78
77
|
display: flex;
|
|
@@ -81,11 +80,22 @@
|
|
|
81
80
|
.mg-input__input mg-tooltip {
|
|
82
81
|
margin-top: calc((var(--default-size) - var(--mg-icon-regular-size)) / 2);
|
|
83
82
|
}
|
|
84
|
-
.mg-input__input
|
|
85
|
-
|
|
83
|
+
.mg-input__input.mg-input__input--has-error .mg-input__box {
|
|
84
|
+
border-color: hsl(var(--color-danger));
|
|
85
|
+
}
|
|
86
|
+
.mg-input__input + .mg-input__help-text, .mg-input__input + .mg-input__error {
|
|
86
87
|
margin-top: 0.5rem;
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
.mg-input__error {
|
|
91
|
+
display: inline-block;
|
|
92
|
+
margin-top: 0.2rem;
|
|
93
|
+
padding: 0.3rem 0.8rem;
|
|
94
|
+
border-radius: 0.3rem;
|
|
95
|
+
background: hsl(var(--mg-inputs-error-bg-color));
|
|
96
|
+
color: hsl(var(--color-danger));
|
|
97
|
+
}
|
|
98
|
+
|
|
89
99
|
/**
|
|
90
100
|
* Style for input "box":
|
|
91
101
|
* - input[type="text"]
|
|
@@ -106,6 +116,7 @@
|
|
|
106
116
|
font-family: inherit;
|
|
107
117
|
color: hsl(var(--color-dark));
|
|
108
118
|
font-size: var(--font-size);
|
|
119
|
+
text-align: var(--mg-inputs-text-align, left);
|
|
109
120
|
}
|
|
110
121
|
.mg-input__box::placeholder {
|
|
111
122
|
color: var(--mg-inputs-color);
|
|
@@ -145,6 +156,23 @@
|
|
|
145
156
|
display: none;
|
|
146
157
|
}
|
|
147
158
|
|
|
159
|
+
.mg-input.mg-input--label-on-top .mg-input__box {
|
|
160
|
+
width: auto;
|
|
161
|
+
max-width: 100%;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]) {
|
|
165
|
+
--mg-button-border-radius-top-right: 0;
|
|
166
|
+
--mg-button-border-radius-bottom-right: 0;
|
|
167
|
+
}
|
|
168
|
+
.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)) {
|
|
169
|
+
--mg-button-border-right-width: 0;
|
|
170
|
+
}
|
|
171
|
+
.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type) {
|
|
172
|
+
--mg-button-border-radius-top-right: var(--mg-inputs-border-radius);
|
|
173
|
+
--mg-button-border-radius-bottom-right: var(--mg-inputs-border-radius);
|
|
174
|
+
}
|
|
175
|
+
|
|
148
176
|
.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]) {
|
|
149
177
|
padding-top: calc((var(--default-size) - var(--mg-icon-regular-size)) / 2);
|
|
150
178
|
}
|
|
@@ -195,5 +223,5 @@
|
|
|
195
223
|
}
|
|
196
224
|
|
|
197
225
|
.mg-input .mg-input__box {
|
|
198
|
-
text-align: right;
|
|
226
|
+
text-align: var(--mg-inputs-text-align, right);
|
|
199
227
|
}
|