@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,8 +1,7 @@
|
|
|
1
|
-
import { Component, Event, h, Prop, State } from '@stencil/core';
|
|
1
|
+
import { Component, Element, Event, h, Prop, State, Method, Watch } from '@stencil/core';
|
|
2
2
|
import { MgInput } from '../MgInput';
|
|
3
3
|
import { createID, ClassList } from '../../../../utils/components.utils';
|
|
4
|
-
import {
|
|
5
|
-
import { InputClass } from '../MgInput.conf';
|
|
4
|
+
import { initLocales } from '../../../../locales';
|
|
6
5
|
export class MgInputTextarea {
|
|
7
6
|
constructor() {
|
|
8
7
|
/************
|
|
@@ -10,7 +9,9 @@ export class MgInputTextarea {
|
|
|
10
9
|
************/
|
|
11
10
|
// classes
|
|
12
11
|
this.classFocus = 'is-focused';
|
|
13
|
-
this.
|
|
12
|
+
this.classHasDisplayCharacterLeft = 'mg-input--has-display-character-left';
|
|
13
|
+
// hasError (triggered by blur event)
|
|
14
|
+
this.hasError = false;
|
|
14
15
|
/**
|
|
15
16
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
16
17
|
* If not set, it will be created.
|
|
@@ -44,15 +45,19 @@ export class MgInputTextarea {
|
|
|
44
45
|
/**
|
|
45
46
|
* Define input width
|
|
46
47
|
*/
|
|
47
|
-
this.
|
|
48
|
+
this.mgWidth = 'full';
|
|
48
49
|
/**
|
|
49
|
-
* Define
|
|
50
|
+
* Define the number of visible text lines for the control
|
|
50
51
|
*/
|
|
51
52
|
this.rows = 3;
|
|
52
53
|
/**
|
|
53
54
|
* Define if component should display character left
|
|
54
55
|
*/
|
|
55
56
|
this.displayCharacterLeft = true;
|
|
57
|
+
/**
|
|
58
|
+
* Define if input is resizable
|
|
59
|
+
*/
|
|
60
|
+
this.resizable = 'none';
|
|
56
61
|
/**
|
|
57
62
|
* Component classes
|
|
58
63
|
*/
|
|
@@ -61,9 +66,11 @@ export class MgInputTextarea {
|
|
|
61
66
|
* Handle input event
|
|
62
67
|
*/
|
|
63
68
|
this.handleInput = () => {
|
|
64
|
-
this.
|
|
69
|
+
if (this.hasError) {
|
|
70
|
+
this.checkValidity();
|
|
71
|
+
this.checkError();
|
|
72
|
+
}
|
|
65
73
|
this.value = this.input.value;
|
|
66
|
-
this.valueChange.emit(this.value);
|
|
67
74
|
};
|
|
68
75
|
/**
|
|
69
76
|
* Handle focus event
|
|
@@ -79,16 +86,44 @@ export class MgInputTextarea {
|
|
|
79
86
|
// Manage focus
|
|
80
87
|
this.classList.delete(this.classFocus);
|
|
81
88
|
this.classList = new ClassList(this.classList.classes);
|
|
82
|
-
//
|
|
83
|
-
this.
|
|
84
|
-
this.checkError();
|
|
89
|
+
// Display Error
|
|
90
|
+
this.displayError();
|
|
85
91
|
};
|
|
86
92
|
/**
|
|
87
93
|
* Get pattern validity
|
|
88
94
|
* Pattern is not defined on textarea field : https://developer.mozilla.org/fr/docs/Web/HTML/Element/Textarea
|
|
89
|
-
*
|
|
95
|
+
*
|
|
96
|
+
* @returns {boolean} is pattern valid
|
|
90
97
|
*/
|
|
91
98
|
this.getPatternValidity = () => this.pattern === undefined || new RegExp(`^${this.pattern}$`, 'u').test(this.value);
|
|
99
|
+
/**
|
|
100
|
+
* Check if input is valid
|
|
101
|
+
*/
|
|
102
|
+
this.checkValidity = () => {
|
|
103
|
+
if (!this.readonly && this.input !== undefined) {
|
|
104
|
+
const validity = this.input.checkValidity && this.input.checkValidity() && this.getPatternValidity();
|
|
105
|
+
// Set validity
|
|
106
|
+
this.valid = validity;
|
|
107
|
+
this.invalid = !validity;
|
|
108
|
+
//Send event
|
|
109
|
+
this.inputValid.emit(validity);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Check input errors
|
|
114
|
+
*/
|
|
115
|
+
this.checkError = () => {
|
|
116
|
+
// Set error message
|
|
117
|
+
this.errorMessage = undefined;
|
|
118
|
+
// Does not match pattern
|
|
119
|
+
if (!this.valid && !this.getPatternValidity()) {
|
|
120
|
+
this.errorMessage = this.patternErrorMessage;
|
|
121
|
+
}
|
|
122
|
+
// required
|
|
123
|
+
else if (!this.valid && this.input.validity.valueMissing) {
|
|
124
|
+
this.errorMessage = this.messages.errors.required;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
92
127
|
/**
|
|
93
128
|
* Validate pattern configuration
|
|
94
129
|
*/
|
|
@@ -101,52 +136,65 @@ export class MgInputTextarea {
|
|
|
101
136
|
}
|
|
102
137
|
};
|
|
103
138
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
checkValidity() {
|
|
108
|
-
if (!this.readonly && this.input !== undefined) {
|
|
109
|
-
const patternValidity = this.getPatternValidity();
|
|
110
|
-
const validity = this.input.checkValidity && this.input.checkValidity() && patternValidity;
|
|
111
|
-
// Set validity
|
|
112
|
-
this.valid = validity;
|
|
113
|
-
this.invalid = !validity;
|
|
114
|
-
}
|
|
139
|
+
handleValue(newValue) {
|
|
140
|
+
this.checkValidity();
|
|
141
|
+
this.valueChange.emit(newValue);
|
|
115
142
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
checkError() {
|
|
120
|
-
const patternValidity = this.getPatternValidity();
|
|
121
|
-
// Set error message
|
|
122
|
-
this.errorMessage = undefined;
|
|
123
|
-
if (!this.valid && !patternValidity) {
|
|
124
|
-
this.errorMessage = this.patternErrorMessage;
|
|
125
|
-
}
|
|
126
|
-
// required
|
|
127
|
-
else if (!this.valid && this.input.validity.valueMissing) {
|
|
128
|
-
this.errorMessage = messages.errors.required;
|
|
129
|
-
}
|
|
130
|
-
// Update class
|
|
131
|
-
if (this.valid) {
|
|
132
|
-
this.classList.delete(this.classError);
|
|
143
|
+
validateDisplayCharacterLeft(newValue) {
|
|
144
|
+
if (newValue) {
|
|
145
|
+
this.classList.add(this.classHasDisplayCharacterLeft);
|
|
133
146
|
}
|
|
134
147
|
else {
|
|
135
|
-
this.classList.
|
|
148
|
+
this.classList.delete(this.classHasDisplayCharacterLeft);
|
|
136
149
|
}
|
|
137
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Public method to display errors
|
|
153
|
+
*
|
|
154
|
+
* @returns {Promise<void>}
|
|
155
|
+
*/
|
|
156
|
+
async displayError() {
|
|
157
|
+
this.checkValidity();
|
|
158
|
+
this.checkError();
|
|
159
|
+
this.hasError = this.invalid;
|
|
160
|
+
}
|
|
138
161
|
/*************
|
|
139
162
|
* Lifecycle *
|
|
140
163
|
*************/
|
|
164
|
+
/**
|
|
165
|
+
* Check if component props are well configured on init
|
|
166
|
+
*
|
|
167
|
+
* @returns {ReturnType<typeof setTimeout>} timeout
|
|
168
|
+
*/
|
|
141
169
|
componentWillLoad() {
|
|
170
|
+
// Get locales
|
|
171
|
+
this.messages = initLocales(this.element).messages;
|
|
172
|
+
this.characterLeftId = `${this.identifier}-character-left`;
|
|
173
|
+
// Validate
|
|
174
|
+
this.validateDisplayCharacterLeft(this.displayCharacterLeft);
|
|
142
175
|
this.validatePattern();
|
|
176
|
+
// Check validity when component is ready
|
|
143
177
|
// return a promise to process action only in the FIRST render().
|
|
144
178
|
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
145
|
-
return setTimeout(() =>
|
|
179
|
+
return setTimeout(() => {
|
|
180
|
+
this.checkValidity();
|
|
181
|
+
}, 0);
|
|
146
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Render
|
|
185
|
+
*
|
|
186
|
+
* @returns {HTMLElement} HTML Element
|
|
187
|
+
*/
|
|
147
188
|
render() {
|
|
148
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly,
|
|
149
|
-
h("
|
|
189
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [this.characterLeftId], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false },
|
|
190
|
+
h("div", { class: "mg-input__with-character-left" },
|
|
191
|
+
h("textarea", { class: {
|
|
192
|
+
'mg-input__box': true,
|
|
193
|
+
'mg-input__box--resizable': this.resizable === 'both',
|
|
194
|
+
'mg-input__box--resizable-horizontal': this.resizable === 'horizontal',
|
|
195
|
+
'mg-input__box--resizable-vertical': this.resizable === 'vertical',
|
|
196
|
+
}, value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, rows: this.rows, maxlength: this.maxlength, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => (this.input = el) }),
|
|
197
|
+
this.displayCharacterLeft && this.maxlength && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength })))));
|
|
150
198
|
}
|
|
151
199
|
static get is() { return "mg-input-textarea"; }
|
|
152
200
|
static get encapsulation() { return "shadow"; }
|
|
@@ -183,7 +231,7 @@ export class MgInputTextarea {
|
|
|
183
231
|
"references": {}
|
|
184
232
|
},
|
|
185
233
|
"required": false,
|
|
186
|
-
"optional":
|
|
234
|
+
"optional": false,
|
|
187
235
|
"docs": {
|
|
188
236
|
"tags": [],
|
|
189
237
|
"text": "Identifier is used for the element ID (id is a reserved prop in Stencil.js)\nIf not set, it will be created."
|
|
@@ -201,7 +249,7 @@ export class MgInputTextarea {
|
|
|
201
249
|
"references": {}
|
|
202
250
|
},
|
|
203
251
|
"required": false,
|
|
204
|
-
"optional":
|
|
252
|
+
"optional": false,
|
|
205
253
|
"docs": {
|
|
206
254
|
"tags": [],
|
|
207
255
|
"text": "Input name\nIf not set the value equals the identifier"
|
|
@@ -222,7 +270,7 @@ export class MgInputTextarea {
|
|
|
222
270
|
"optional": false,
|
|
223
271
|
"docs": {
|
|
224
272
|
"tags": [],
|
|
225
|
-
"text": "Input label
|
|
273
|
+
"text": "Input label"
|
|
226
274
|
},
|
|
227
275
|
"attribute": "label",
|
|
228
276
|
"reflect": false
|
|
@@ -351,7 +399,7 @@ export class MgInputTextarea {
|
|
|
351
399
|
"reflect": false,
|
|
352
400
|
"defaultValue": "false"
|
|
353
401
|
},
|
|
354
|
-
"
|
|
402
|
+
"mgWidth": {
|
|
355
403
|
"type": "any",
|
|
356
404
|
"mutable": false,
|
|
357
405
|
"complexType": {
|
|
@@ -370,7 +418,7 @@ export class MgInputTextarea {
|
|
|
370
418
|
"tags": [],
|
|
371
419
|
"text": "Define input width"
|
|
372
420
|
},
|
|
373
|
-
"attribute": "width",
|
|
421
|
+
"attribute": "mg-width",
|
|
374
422
|
"reflect": false,
|
|
375
423
|
"defaultValue": "'full'"
|
|
376
424
|
},
|
|
@@ -420,7 +468,7 @@ export class MgInputTextarea {
|
|
|
420
468
|
"optional": false,
|
|
421
469
|
"docs": {
|
|
422
470
|
"tags": [],
|
|
423
|
-
"text": "Define
|
|
471
|
+
"text": "Define the number of visible text lines for the control"
|
|
424
472
|
},
|
|
425
473
|
"attribute": "rows",
|
|
426
474
|
"reflect": false,
|
|
@@ -461,23 +509,6 @@ export class MgInputTextarea {
|
|
|
461
509
|
"reflect": false,
|
|
462
510
|
"defaultValue": "true"
|
|
463
511
|
},
|
|
464
|
-
"characterLeftTemplate": {
|
|
465
|
-
"type": "string",
|
|
466
|
-
"mutable": false,
|
|
467
|
-
"complexType": {
|
|
468
|
-
"original": "string",
|
|
469
|
-
"resolved": "string",
|
|
470
|
-
"references": {}
|
|
471
|
-
},
|
|
472
|
-
"required": false,
|
|
473
|
-
"optional": false,
|
|
474
|
-
"docs": {
|
|
475
|
-
"tags": [],
|
|
476
|
-
"text": "Template to use for characters left sentence"
|
|
477
|
-
},
|
|
478
|
-
"attribute": "character-left-template",
|
|
479
|
-
"reflect": false
|
|
480
|
-
},
|
|
481
512
|
"helpText": {
|
|
482
513
|
"type": "string",
|
|
483
514
|
"mutable": false,
|
|
@@ -507,7 +538,7 @@ export class MgInputTextarea {
|
|
|
507
538
|
"optional": false,
|
|
508
539
|
"docs": {
|
|
509
540
|
"tags": [],
|
|
510
|
-
"text": "Define input
|
|
541
|
+
"text": "Define input valid state"
|
|
511
542
|
},
|
|
512
543
|
"attribute": "valid",
|
|
513
544
|
"reflect": false
|
|
@@ -524,10 +555,28 @@ export class MgInputTextarea {
|
|
|
524
555
|
"optional": false,
|
|
525
556
|
"docs": {
|
|
526
557
|
"tags": [],
|
|
527
|
-
"text": "Define input
|
|
558
|
+
"text": "Define input invalid state"
|
|
528
559
|
},
|
|
529
560
|
"attribute": "invalid",
|
|
530
561
|
"reflect": false
|
|
562
|
+
},
|
|
563
|
+
"resizable": {
|
|
564
|
+
"type": "string",
|
|
565
|
+
"mutable": false,
|
|
566
|
+
"complexType": {
|
|
567
|
+
"original": "'none' | 'both' | 'horizontal' | 'vertical'",
|
|
568
|
+
"resolved": "\"both\" | \"horizontal\" | \"none\" | \"vertical\"",
|
|
569
|
+
"references": {}
|
|
570
|
+
},
|
|
571
|
+
"required": false,
|
|
572
|
+
"optional": false,
|
|
573
|
+
"docs": {
|
|
574
|
+
"tags": [],
|
|
575
|
+
"text": "Define if input is resizable"
|
|
576
|
+
},
|
|
577
|
+
"attribute": "resizable",
|
|
578
|
+
"reflect": false,
|
|
579
|
+
"defaultValue": "'none'"
|
|
531
580
|
}
|
|
532
581
|
}; }
|
|
533
582
|
static get states() { return {
|
|
@@ -542,12 +591,56 @@ export class MgInputTextarea {
|
|
|
542
591
|
"composed": true,
|
|
543
592
|
"docs": {
|
|
544
593
|
"tags": [],
|
|
545
|
-
"text": "
|
|
594
|
+
"text": "Emited event when value change"
|
|
546
595
|
},
|
|
547
596
|
"complexType": {
|
|
548
597
|
"original": "string",
|
|
549
598
|
"resolved": "string",
|
|
550
599
|
"references": {}
|
|
551
600
|
}
|
|
601
|
+
}, {
|
|
602
|
+
"method": "inputValid",
|
|
603
|
+
"name": "input-valid",
|
|
604
|
+
"bubbles": true,
|
|
605
|
+
"cancelable": true,
|
|
606
|
+
"composed": true,
|
|
607
|
+
"docs": {
|
|
608
|
+
"tags": [],
|
|
609
|
+
"text": "Emited event when checking validity"
|
|
610
|
+
},
|
|
611
|
+
"complexType": {
|
|
612
|
+
"original": "boolean",
|
|
613
|
+
"resolved": "boolean",
|
|
614
|
+
"references": {}
|
|
615
|
+
}
|
|
616
|
+
}]; }
|
|
617
|
+
static get methods() { return {
|
|
618
|
+
"displayError": {
|
|
619
|
+
"complexType": {
|
|
620
|
+
"signature": "() => Promise<void>",
|
|
621
|
+
"parameters": [],
|
|
622
|
+
"references": {
|
|
623
|
+
"Promise": {
|
|
624
|
+
"location": "global"
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
"return": "Promise<void>"
|
|
628
|
+
},
|
|
629
|
+
"docs": {
|
|
630
|
+
"text": "Public method to display errors",
|
|
631
|
+
"tags": [{
|
|
632
|
+
"name": "returns",
|
|
633
|
+
"text": undefined
|
|
634
|
+
}]
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}; }
|
|
638
|
+
static get elementRef() { return "element"; }
|
|
639
|
+
static get watchers() { return [{
|
|
640
|
+
"propName": "value",
|
|
641
|
+
"methodName": "handleValue"
|
|
642
|
+
}, {
|
|
643
|
+
"propName": "displayCharacterLeft",
|
|
644
|
+
"methodName": "validateDisplayCharacterLeft"
|
|
552
645
|
}]; }
|
|
553
646
|
}
|
|
@@ -2,6 +2,7 @@ import { h } from '@stencil/core';
|
|
|
2
2
|
export default {
|
|
3
3
|
component: 'mg-input-toggle',
|
|
4
4
|
title: 'Molecules/Inputs/mg-input-toggle',
|
|
5
|
+
parameters: { actions: { handles: ['value-change', 'input-valid'] } },
|
|
5
6
|
};
|
|
6
7
|
const args = {
|
|
7
8
|
// Global
|
|
@@ -30,8 +31,12 @@ const args = {
|
|
|
30
31
|
/**
|
|
31
32
|
* 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
|
|
32
33
|
* 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
|
|
34
|
+
*
|
|
35
|
+
* @param {any} args component arguments
|
|
36
|
+
* @returns {HTMLElement} HTMLElement
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
const Template = (args) => {
|
|
35
40
|
// Extract slot so it won't be render as an attribute
|
|
36
41
|
const labelOnTop = args.labelOnTop;
|
|
37
42
|
delete args.labelOnTop;
|
|
@@ -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
|
* A11Y
|
|
91
101
|
*/
|
|
@@ -128,6 +138,9 @@
|
|
|
128
138
|
line-height: inherit;
|
|
129
139
|
cursor: pointer;
|
|
130
140
|
}
|
|
141
|
+
.mg-input__button-toggle:disabled {
|
|
142
|
+
cursor: default;
|
|
143
|
+
}
|
|
131
144
|
|
|
132
145
|
.mg-input__toggle-item-container {
|
|
133
146
|
padding: 0.5rem 0.9rem;
|
|
@@ -209,5 +222,4 @@
|
|
|
209
222
|
|
|
210
223
|
.mg-input.mg-input--toggle-disabled .mg-input__button-toggle {
|
|
211
224
|
opacity: 0.3;
|
|
212
|
-
cursor: not-allowed;
|
|
213
225
|
}
|