@mgdis/mg-components 5.2.0 → 5.3.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.
Files changed (55) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/{mg-badge_27.cjs.entry.js → mg-badge_29.cjs.entry.js} +376 -6
  3. package/dist/cjs/mg-components.cjs.js +1 -1
  4. package/dist/collection/collection-manifest.json +3 -1
  5. package/dist/collection/components/atoms/mg-badge/mg-badge.js +13 -18
  6. package/dist/collection/components/atoms/mg-icon/mg-icon.js +17 -7
  7. package/dist/collection/components/molecules/menu/mg-menu/doc/mg-menu.stories.js +87 -0
  8. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js +8 -0
  9. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.css +10 -0
  10. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +185 -0
  11. package/dist/collection/components/molecules/menu/mg-menu-item/doc/mg-menu-item.stories.js +32 -0
  12. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.conf.js +22 -0
  13. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.css +316 -0
  14. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +324 -0
  15. package/dist/collection/components/molecules/mg-tabs/mg-tabs.conf.js +3 -0
  16. package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +67 -17
  17. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +10 -4
  18. package/dist/collection/locales/index.js +3 -1
  19. package/dist/collection/variables.css +23 -1
  20. package/dist/components/index.d.ts +2 -0
  21. package/dist/components/index.js +2 -0
  22. package/dist/components/index2.js +3 -1
  23. package/dist/components/mg-menu-item.d.ts +11 -0
  24. package/dist/components/mg-menu-item.js +273 -0
  25. package/dist/components/mg-menu.conf.js +10 -0
  26. package/dist/components/mg-menu.d.ts +11 -0
  27. package/dist/components/mg-menu.js +149 -0
  28. package/dist/components/mg-tabs.js +6 -2
  29. package/dist/esm/loader.js +1 -1
  30. package/dist/esm/{mg-badge_27.entry.js → mg-badge_29.entry.js} +375 -7
  31. package/dist/esm/mg-components.js +1 -1
  32. package/dist/mg-components/mg-components.css +1 -1
  33. package/dist/mg-components/mg-components.esm.js +1 -1
  34. package/dist/mg-components/p-204af46f.entry.js +1 -0
  35. package/dist/mg-components/variables.css +23 -1
  36. package/dist/types/components/atoms/mg-badge/doc/mg-badge.stories.d.ts +2 -2
  37. package/dist/types/components/atoms/mg-badge/mg-badge.conf.d.ts +5 -5
  38. package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +8 -8
  39. package/dist/types/components/atoms/mg-icon/doc/mg-icon.stories.d.ts +2 -2
  40. package/dist/types/components/atoms/mg-icon/mg-icon.conf.d.ts +10 -2
  41. package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +7 -6
  42. package/dist/types/components/molecules/menu/mg-menu/doc/mg-menu.stories.d.ts +17 -0
  43. package/dist/types/components/molecules/menu/mg-menu/mg-menu.conf.d.ts +7 -0
  44. package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +69 -0
  45. package/dist/types/components/molecules/menu/mg-menu-item/doc/mg-menu-item.stories.d.ts +11 -0
  46. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.conf.d.ts +24 -0
  47. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +119 -0
  48. package/dist/types/components/molecules/mg-tabs/doc/mg-tabs.stories.d.ts +1 -1
  49. package/dist/types/components/molecules/mg-tabs/mg-tabs.conf.d.ts +12 -4
  50. package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +6 -6
  51. package/dist/types/components.d.ts +91 -14
  52. package/dist/types/locales/index.d.ts +7 -1
  53. package/dist/types/stories/icons.stories.d.ts +1 -1
  54. package/package.json +1 -1
  55. package/dist/mg-components/p-b2b07c3f.entry.js +0 -1
@@ -81,14 +81,9 @@ export class MgBadge {
81
81
  "type": "any",
82
82
  "mutable": true,
83
83
  "complexType": {
84
- "original": "BadgeType['value']",
84
+ "original": "string | number",
85
85
  "resolved": "number | string",
86
- "references": {
87
- "BadgeType": {
88
- "location": "import",
89
- "path": "./mg-badge.conf"
90
- }
91
- }
86
+ "references": {}
92
87
  },
93
88
  "required": true,
94
89
  "optional": false,
@@ -103,14 +98,9 @@ export class MgBadge {
103
98
  "type": "string",
104
99
  "mutable": false,
105
100
  "complexType": {
106
- "original": "BadgeType['label']",
101
+ "original": "string",
107
102
  "resolved": "string",
108
- "references": {
109
- "BadgeType": {
110
- "location": "import",
111
- "path": "./mg-badge.conf"
112
- }
113
- }
103
+ "references": {}
114
104
  },
115
105
  "required": true,
116
106
  "optional": false,
@@ -125,12 +115,17 @@ export class MgBadge {
125
115
  "type": "string",
126
116
  "mutable": false,
127
117
  "complexType": {
128
- "original": "string",
129
- "resolved": "string",
130
- "references": {}
118
+ "original": "BadgeVariantType",
119
+ "resolved": "\"danger\" | \"info\" | \"primary\" | \"secondary\" | \"success\" | \"warning\"",
120
+ "references": {
121
+ "BadgeVariantType": {
122
+ "location": "import",
123
+ "path": "./mg-badge.conf"
124
+ }
125
+ }
131
126
  },
132
127
  "required": false,
133
- "optional": false,
128
+ "optional": true,
134
129
  "docs": {
135
130
  "tags": [],
136
131
  "text": "Define button variant"
@@ -117,9 +117,14 @@ export class MgIcon {
117
117
  "type": "string",
118
118
  "mutable": false,
119
119
  "complexType": {
120
- "original": "string",
121
- "resolved": "string",
122
- "references": {}
120
+ "original": "IconSizeType",
121
+ "resolved": "\"extra-large\" | \"large\" | \"regular\" | \"small\"",
122
+ "references": {
123
+ "IconSizeType": {
124
+ "location": "import",
125
+ "path": "./mg-icon.conf"
126
+ }
127
+ }
123
128
  },
124
129
  "required": false,
125
130
  "optional": false,
@@ -135,12 +140,17 @@ export class MgIcon {
135
140
  "type": "string",
136
141
  "mutable": false,
137
142
  "complexType": {
138
- "original": "string",
139
- "resolved": "string",
140
- "references": {}
143
+ "original": "IconVariantType",
144
+ "resolved": "\"danger\" | \"info\" | \"success\" | \"warning\"",
145
+ "references": {
146
+ "IconVariantType": {
147
+ "location": "import",
148
+ "path": "./mg-icon.conf"
149
+ }
150
+ }
141
151
  },
142
152
  "required": false,
143
- "optional": false,
153
+ "optional": true,
144
154
  "docs": {
145
155
  "tags": [],
146
156
  "text": "Define icon variant\nAdd a background to the icon based on variant color"
@@ -0,0 +1,87 @@
1
+ import { h } from '@stencil/core';
2
+ import { filterArgs } from '../../../../../../.storybook/utils';
3
+ import { Status } from '../../mg-menu-item/mg-menu-item.conf';
4
+ import { Direction } from '../mg-menu.conf';
5
+ export default {
6
+ component: 'mg-menu',
7
+ title: 'Beta/menus/mg-menu',
8
+ argTypes: {
9
+ direction: {
10
+ options: [undefined, Direction.HORIZONTAL, Direction.VERTICAL],
11
+ control: { type: 'select' },
12
+ },
13
+ },
14
+ };
15
+ const getItemArgs = ({ size, label, direction, status, metadata, icon, badge, content, submenu }) => ({
16
+ size: size !== undefined ? size : direction === Direction.VERTICAL ? 'medium' : undefined,
17
+ status,
18
+ slot: {
19
+ label,
20
+ metadata,
21
+ icon,
22
+ badge,
23
+ content,
24
+ submenu,
25
+ },
26
+ });
27
+ const getMenuArgs = (direction, level = 0, isSubmenu = false) => ({
28
+ label: 'Batman menu',
29
+ direction,
30
+ slot: {
31
+ items: [
32
+ getItemArgs({
33
+ label: 'label 1',
34
+ direction,
35
+ }),
36
+ getItemArgs({
37
+ label: 'label 2',
38
+ direction,
39
+ status: Status.DISABLED,
40
+ }),
41
+ getItemArgs({
42
+ label: 'label 3 with long text',
43
+ direction,
44
+ badge: true,
45
+ icon: true,
46
+ }),
47
+ getItemArgs({
48
+ label: 'label 4',
49
+ direction,
50
+ badge: true,
51
+ icon: true,
52
+ status: Status.ACTIVE,
53
+ submenu: level,
54
+ }),
55
+ getItemArgs({
56
+ label: 'label 5',
57
+ direction,
58
+ icon: true,
59
+ metadata: 'my metadata',
60
+ content: true,
61
+ size: !isSubmenu && direction === Direction.HORIZONTAL ? 'regular' : undefined,
62
+ }),
63
+ ],
64
+ },
65
+ });
66
+ const menu = args => h("mg-menu", Object.assign({}, filterArgs(args, { direction: Direction.HORIZONTAL })), args.slot.items.map(item => menuItem(item)));
67
+ const menuItem = args => {
68
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
69
+ return (h("mg-menu-item", Object.assign({}, filterArgs(args)), ((_a = args.slot) === null || _a === void 0 ? void 0 : _a.label) && h("span", { slot: "label" }, (_b = args.slot) === null || _b === void 0 ? void 0 : _b.label), ((_c = args.slot) === null || _c === void 0 ? void 0 : _c.metadata) && h("span", { slot: "metadata" }, (_d = args.slot) === null || _d === void 0 ? void 0 : _d.metadata), ((_e = args.slot) === null || _e === void 0 ? void 0 : _e.icon) && h("mg-icon", { slot: "illustration", icon: "user" }), ((_f = args.slot) === null || _f === void 0 ? void 0 : _f.badge) && (h("mg-badge", { slot: "information", label: "information", value: "1" }, (_g = args.slot) === null || _g === void 0 ? void 0 : _g.icon)), ((_h = args.slot) === null || _h === void 0 ? void 0 : _h.content) && (h("div", null, h("h3", null, "Demo title"), h("p", null, "some content"))), ((_j = args.slot) === null || _j === void 0 ? void 0 : _j.submenu) && menu(getMenuArgs(Direction.VERTICAL, ((_k = args.slot) === null || _k === void 0 ? void 0 : _k.submenu) - 1, true))));
70
+ };
71
+ /**
72
+ * Template
73
+ *
74
+ * @param {any} args component arguments
75
+ * @returns {HTMLElement} HTMLElement
76
+ */
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ const Template = (args) => h("div", null, menu(args));
79
+ export const MgMenuHorizontal = Template.bind({});
80
+ MgMenuHorizontal.args = getMenuArgs(Direction.HORIZONTAL, 2);
81
+ export const MgMenuVertical = Template.bind({});
82
+ MgMenuVertical.args = getMenuArgs(Direction.VERTICAL, 2);
83
+ const TemplateSmallContainer = (args) => {
84
+ return h("div", { style: { width: '25rem', height: '20rem' } }, menu(args));
85
+ };
86
+ export const MgMenuVerticalSmallContainer = TemplateSmallContainer.bind({});
87
+ MgMenuVerticalSmallContainer.args = Object.assign({}, MgMenuVertical.args);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Menu direction type
3
+ */
4
+ export var Direction;
5
+ (function (Direction) {
6
+ Direction["VERTICAL"] = "vertical";
7
+ Direction["HORIZONTAL"] = "horizontal";
8
+ })(Direction || (Direction = {}));
@@ -0,0 +1,10 @@
1
+ :host {
2
+ display: flex;
3
+ background-color: hsl(var(--mg-menu-background-color-hsl, var(--color-light)));
4
+ }
5
+
6
+ :host(.mg-menu--vertical) {
7
+ flex-direction: column;
8
+ height: 100%;
9
+ overflow-y: auto;
10
+ }
@@ -0,0 +1,185 @@
1
+ import { h, Host } from '@stencil/core';
2
+ import { ClassList } from '../../../../utils/components.utils';
3
+ import { Direction } from './mg-menu.conf';
4
+ export class MgMenu {
5
+ constructor() {
6
+ /************
7
+ * Internal *
8
+ ************/
9
+ this.name = 'mg-menu';
10
+ this.focusedMenuItem = 0;
11
+ /**
12
+ * Component display direction. Default: "horizontal"
13
+ */
14
+ this.direction = Direction.HORIZONTAL;
15
+ /**
16
+ * Component classes
17
+ */
18
+ this.classList = new ClassList([this.name]);
19
+ /**
20
+ * Close matching menu-item
21
+ *
22
+ * @param {HTMLMgMenuItemElement} item menu-item to close
23
+ * @param {boolean} condition addionnal condition
24
+ * @returns {void}
25
+ */
26
+ this.closeMenuItem = (item, condition) => {
27
+ if (!this.isChildMenu && condition) {
28
+ item.expanded = false;
29
+ }
30
+ };
31
+ /**
32
+ * Store menu-items on component init and add listeners
33
+ */
34
+ this.initMenuItems = () => {
35
+ // store all menu-items
36
+ this.menuItems = Array.from(this.element.children).filter(child => child.nodeName === 'MG-MENU-ITEM');
37
+ // add listeners on menu item and edit index
38
+ this.menuItems.forEach((item, menuItemIndex) => {
39
+ ['click', 'focus'].forEach(trigger => {
40
+ (item.shadowRoot.querySelector('button') || item.shadowRoot.querySelector('a')).addEventListener(trigger, (event) => {
41
+ event.preventDefault();
42
+ event.stopPropagation();
43
+ this.focusedMenuItem = menuItemIndex;
44
+ // reset expanded on previous active menu item
45
+ this.menuItems.forEach((item, index) => {
46
+ this.closeMenuItem(item, index !== this.focusedMenuItem);
47
+ });
48
+ });
49
+ });
50
+ });
51
+ };
52
+ }
53
+ validateLabel(newValue) {
54
+ if (newValue === undefined) {
55
+ throw new Error(`<${this.name}> prop "label" is required.`);
56
+ }
57
+ }
58
+ validateDirection(newValue) {
59
+ if (newValue === Direction.VERTICAL) {
60
+ this.classList.add(`${this.name}--${Direction.VERTICAL}`);
61
+ }
62
+ else if (newValue === Direction.HORIZONTAL) {
63
+ this.classList.add(`${this.name}--${Direction.HORIZONTAL}`);
64
+ }
65
+ else {
66
+ throw new Error(`<${this.name}> prop "direction" must be one of : ${Direction.HORIZONTAL}, ${Direction.VERTICAL}.`);
67
+ }
68
+ }
69
+ /*************
70
+ * Lifecycle *
71
+ *************/
72
+ /**
73
+ * Validate props
74
+ *
75
+ * @returns {void}
76
+ */
77
+ componentWillLoad() {
78
+ this.validateDirection(this.direction);
79
+ this.validateLabel(this.label);
80
+ }
81
+ /**
82
+ * Check if component slots configuration
83
+ *
84
+ * @returns {ReturnType<typeof setTimeout>} timeout
85
+ */
86
+ componentDidLoad() {
87
+ this.initMenuItems();
88
+ // update props and states after componentDidLoad hook
89
+ // return a promise to process action only in the FIRST render().
90
+ // https://stenciljs.com/docs/component-lifecycle#componentwillload
91
+ return setTimeout(() => {
92
+ this.isChildMenu = this.element.closest('mg-menu-item') !== null;
93
+ // click outside management for child vertical menu
94
+ if (!this.isChildMenu && this.direction === Direction.HORIZONTAL) {
95
+ document.addEventListener('click', (event) => {
96
+ if (event.target.closest('mg-menu') === null) {
97
+ this.menuItems.forEach(item => {
98
+ this.closeMenuItem(item, this.direction === Direction.HORIZONTAL);
99
+ });
100
+ }
101
+ });
102
+ }
103
+ }, 0);
104
+ }
105
+ /**
106
+ * Render
107
+ *
108
+ * @returns {HTMLElement} HTML Element
109
+ */
110
+ render() {
111
+ return (h(Host, { role: this.isChildMenu ? 'menu' : 'menubar', "aria-label": this.label, classList: this.classList.join() }, h("slot", null)));
112
+ }
113
+ static get is() { return "mg-menu"; }
114
+ static get encapsulation() { return "shadow"; }
115
+ static get originalStyleUrls() {
116
+ return {
117
+ "$": ["mg-menu.scss"]
118
+ };
119
+ }
120
+ static get styleUrls() {
121
+ return {
122
+ "$": ["mg-menu.css"]
123
+ };
124
+ }
125
+ static get properties() {
126
+ return {
127
+ "label": {
128
+ "type": "string",
129
+ "mutable": false,
130
+ "complexType": {
131
+ "original": "string",
132
+ "resolved": "string",
133
+ "references": {}
134
+ },
135
+ "required": true,
136
+ "optional": false,
137
+ "docs": {
138
+ "tags": [],
139
+ "text": "Menu label. Include short menu description.\nRequired for accessibility"
140
+ },
141
+ "attribute": "label",
142
+ "reflect": false
143
+ },
144
+ "direction": {
145
+ "type": "string",
146
+ "mutable": false,
147
+ "complexType": {
148
+ "original": "Direction",
149
+ "resolved": "Direction.HORIZONTAL | Direction.VERTICAL",
150
+ "references": {
151
+ "Direction": {
152
+ "location": "import",
153
+ "path": "./mg-menu.conf"
154
+ }
155
+ }
156
+ },
157
+ "required": false,
158
+ "optional": false,
159
+ "docs": {
160
+ "tags": [],
161
+ "text": "Component display direction. Default: \"horizontal\""
162
+ },
163
+ "attribute": "direction",
164
+ "reflect": true,
165
+ "defaultValue": "Direction.HORIZONTAL"
166
+ }
167
+ };
168
+ }
169
+ static get states() {
170
+ return {
171
+ "isChildMenu": {},
172
+ "classList": {}
173
+ };
174
+ }
175
+ static get elementRef() { return "element"; }
176
+ static get watchers() {
177
+ return [{
178
+ "propName": "label",
179
+ "methodName": "validateLabel"
180
+ }, {
181
+ "propName": "direction",
182
+ "methodName": "validateDirection"
183
+ }];
184
+ }
185
+ }
@@ -0,0 +1,32 @@
1
+ import { h } from '@stencil/core';
2
+ import { filterArgs } from '../../../../../../.storybook/utils';
3
+ export default {
4
+ component: 'mg-menu-item',
5
+ title: 'Beta/menus/mg-menu-item',
6
+ };
7
+ /**
8
+ * Template
9
+ *
10
+ * @param {any} args component arguments
11
+ * @returns {HTMLElement} HTMLElement
12
+ */
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const Template = (args) => h("mg-menu-item", Object.assign({}, filterArgs(args)), args.slot);
15
+ export const MgMenuItem = Template.bind({});
16
+ MgMenuItem.args = {
17
+ identifier: 'identifier',
18
+ slot: h("span", { slot: "label" }, "My label"),
19
+ };
20
+ export const MgMenuItemWhitIcon = Template.bind({});
21
+ MgMenuItemWhitIcon.args = Object.assign(Object.assign({}, MgMenuItem.args), { slot: [h("span", { slot: "label" }, "My label"), h("mg-icon", { icon: "user", slot: "illustration" })] });
22
+ export const MgMenuItemWhitBadge = Template.bind({});
23
+ MgMenuItemWhitBadge.args = Object.assign(Object.assign({}, MgMenuItem.args), { slot: [h("span", { slot: "label" }, "My label"), h("mg-badge", { value: "2", label: "hello", slot: "information" })] });
24
+ export const MgMenuItemWhitBadgeAndIcon = Template.bind({});
25
+ MgMenuItemWhitBadgeAndIcon.args = Object.assign(Object.assign({}, MgMenuItem.args), { slot: [h("span", { slot: "label" }, "My label"), h("mg-badge", { value: "2", label: "hello", slot: "information" }), h("mg-icon", { icon: "user", slot: "illustration" })] });
26
+ export const MgMenuItemWhitMetadata = Template.bind({});
27
+ MgMenuItemWhitMetadata.args = Object.assign(Object.assign({}, MgMenuItem.args), { slot: [h("span", { slot: "label" }, "My label"), h("span", { slot: "metadata" }, "My metadata")] });
28
+ export const MgMenuItemWhithSubmenu = Template.bind({});
29
+ MgMenuItemWhithSubmenu.args = Object.assign(Object.assign({}, MgMenuItem.args), { slot: [
30
+ h("span", { slot: "label" }, "My label"),
31
+ h("mg-menu-vertical", { label: "submenu" }, h("mg-menu-item", null, h("span", { slot: "label" }, "Subitem 1")), h("mg-menu-item", null, h("mg-icon", { icon: "user", slot: "illustration" }), h("span", { slot: "label" }, "Subitem 2")), h("mg-menu-item", null, h("span", { slot: "label" }, "Subitem 3"), h("mg-icon", { icon: "user", slot: "illustration" }), h("mg-badge", { value: "2", label: "hello", slot: "information" }))),
32
+ ] });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Available menu-item positions
3
+ */
4
+ export var ElementPosition;
5
+ (function (ElementPosition) {
6
+ ElementPosition["FIRST"] = "first";
7
+ ElementPosition["LAST"] = "last";
8
+ })(ElementPosition || (ElementPosition = {}));
9
+ /**
10
+ * Available menu item status
11
+ */
12
+ export var Status;
13
+ (function (Status) {
14
+ Status["VISIBLE"] = "visible";
15
+ Status["HIDDEN"] = "hidden";
16
+ Status["DISABLED"] = "disabled";
17
+ Status["ACTIVE"] = "active";
18
+ })(Status || (Status = {}));
19
+ /**
20
+ * List of all possibles sizes
21
+ */
22
+ export const sizes = ['regular', 'medium', 'large'];