@momentum-design/components 0.91.0 → 0.91.2
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/browser/index.js +413 -404
- package/dist/browser/index.js.map +4 -4
- package/dist/components/badge/badge.styles.js +5 -0
- package/dist/components/listitem/listitem.component.js +16 -19
- package/dist/components/listitem/listitem.constants.d.ts +1 -3
- package/dist/components/listitem/listitem.constants.js +1 -4
- package/dist/components/listitem/listitem.utils.d.ts +3 -0
- package/dist/components/listitem/listitem.utils.js +4 -0
- package/dist/components/menubar/menubar.component.d.ts +6 -2
- package/dist/components/menubar/menubar.component.js +52 -23
- package/dist/components/menupopover/menupopover.utils.d.ts +1 -2
- package/dist/components/menupopover/menupopover.utils.js +9 -6
- package/dist/components/menusection/menusection.component.d.ts +15 -0
- package/dist/components/menusection/menusection.component.js +38 -2
- package/dist/components/menusection/menusection.styles.js +9 -1
- package/dist/components/{navitem → navmenuitem}/index.d.ts +3 -3
- package/dist/components/navmenuitem/index.js +8 -0
- package/dist/components/{navitem/navitem.component.d.ts → navmenuitem/navmenuitem.component.d.ts} +35 -35
- package/dist/components/{navitem/navitem.component.js → navmenuitem/navmenuitem.component.js} +43 -45
- package/dist/components/{navitem/navitem.constants.d.ts → navmenuitem/navmenuitem.constants.d.ts} +1 -1
- package/dist/components/{navitem/navitem.constants.js → navmenuitem/navmenuitem.constants.js} +1 -1
- package/dist/components/{navitem/navitem.styles.js → navmenuitem/navmenuitem.styles.js} +33 -29
- package/dist/components/{navitem/navitem.types.d.ts → navmenuitem/navmenuitem.types.d.ts} +1 -1
- package/dist/components/popover/popover.component.js +1 -1
- package/dist/components/sidenavigation/index.d.ts +1 -0
- package/dist/components/sidenavigation/index.js +1 -0
- package/dist/components/sidenavigation/sidenavigation.component.d.ts +30 -11
- package/dist/components/sidenavigation/sidenavigation.component.js +60 -17
- package/dist/components/sidenavigation/sidenavigation.context.d.ts +5 -5
- package/dist/components/sidenavigation/sidenavigation.context.js +26 -25
- package/dist/custom-elements.json +441 -798
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/react/index.d.ts +3 -4
- package/dist/react/index.js +3 -4
- package/dist/react/navmenuitem/index.d.ts +43 -0
- package/dist/react/navmenuitem/index.js +51 -0
- package/dist/react/sidenavigation/index.d.ts +10 -9
- package/dist/react/sidenavigation/index.js +10 -9
- package/package.json +1 -1
- package/dist/components/navitem/index.js +0 -8
- package/dist/components/navitemlist/index.d.ts +0 -7
- package/dist/components/navitemlist/index.js +0 -4
- package/dist/components/navitemlist/navitemlist.component.d.ts +0 -50
- package/dist/components/navitemlist/navitemlist.component.js +0 -89
- package/dist/components/navitemlist/navitemlist.constants.d.ts +0 -2
- package/dist/components/navitemlist/navitemlist.constants.js +0 -3
- package/dist/components/navitemlist/navitemlist.styles.d.ts +0 -2
- package/dist/components/navitemlist/navitemlist.styles.js +0 -23
- package/dist/react/navitem/index.d.ts +0 -43
- package/dist/react/navitem/index.js +0 -51
- package/dist/react/navitemlist/index.d.ts +0 -13
- package/dist/react/navitemlist/index.js +0 -22
- /package/dist/components/{navitem/navitem.styles.d.ts → navmenuitem/navmenuitem.styles.d.ts} +0 -0
- /package/dist/components/{navitem/navitem.types.js → navmenuitem/navmenuitem.types.js} +0 -0
@@ -14,11 +14,11 @@ import { KEYS } from '../../utils/keys';
|
|
14
14
|
import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
|
15
15
|
import { TabIndexMixin } from '../../utils/mixins/TabIndexMixin';
|
16
16
|
import { ROLE } from '../../utils/roles';
|
17
|
-
import { TAG_NAME as NAVITEMLIST_TAG_NAME } from '../navitemlist/navitemlist.constants';
|
18
17
|
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
19
18
|
import { TAG_NAME as TOOLTIP_TAG_NAME } from '../tooltip/tooltip.constants';
|
20
|
-
import { DEFAULTS
|
19
|
+
import { DEFAULTS } from './listitem.constants';
|
21
20
|
import styles from './listitem.styles';
|
21
|
+
import { generateListItemId, generateTooltipId } from './listitem.utils';
|
22
22
|
/**
|
23
23
|
* mdc-listitem component is used to display a label with different types of controls.
|
24
24
|
* There can be three types of controls, a radio button, a checkbox on the
|
@@ -88,6 +88,8 @@ class ListItem extends DisabledMixin(TabIndexMixin(Component)) {
|
|
88
88
|
connectedCallback() {
|
89
89
|
super.connectedCallback();
|
90
90
|
this.role = this.role || ROLE.LISTITEM;
|
91
|
+
// Add a unique id to the listitem if it does not have one.
|
92
|
+
this.id = this.id || generateListItemId();
|
91
93
|
}
|
92
94
|
/**
|
93
95
|
* Fires the click event when the enter or space key is pressed down.
|
@@ -124,41 +126,36 @@ class ListItem extends DisabledMixin(TabIndexMixin(Component)) {
|
|
124
126
|
* Create the tooltip programmatically after the nearest parent element.
|
125
127
|
*/
|
126
128
|
displayTooltipForLongText() {
|
127
|
-
var _a, _b
|
129
|
+
var _a, _b;
|
128
130
|
if (!this.tooltipText) {
|
129
131
|
return;
|
130
132
|
}
|
131
|
-
// Add a unique id to the listitem if it does not have one to attach the tooltip.
|
132
|
-
this.id = this.id || LISTITEM_ID;
|
133
133
|
// Remove any existing tooltip.
|
134
|
-
|
135
|
-
if (existingTooltip)
|
136
|
-
existingTooltip.remove();
|
134
|
+
this.hideTooltipOnLeave();
|
137
135
|
// Create tooltip for the listitem element.
|
138
136
|
const tooltip = document.createElement(TOOLTIP_TAG_NAME);
|
139
|
-
tooltip.id =
|
137
|
+
tooltip.id = generateTooltipId();
|
140
138
|
tooltip.textContent = this.tooltipText;
|
141
139
|
tooltip.setAttribute('triggerid', this.id);
|
142
140
|
tooltip.setAttribute('placement', this.tooltipPlacement);
|
143
141
|
tooltip.setAttribute('visible', '');
|
144
142
|
tooltip.setAttribute('show-arrow', '');
|
145
|
-
//
|
146
|
-
if ((
|
147
|
-
this.
|
148
|
-
}
|
149
|
-
else {
|
150
|
-
// Add tooltip programmatically after the parent element.
|
151
|
-
(_c = this.parentElement) === null || _c === void 0 ? void 0 : _c.after(tooltip);
|
143
|
+
// Set the slot attribute if the parent element has a slot.
|
144
|
+
if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.hasAttribute('slot')) {
|
145
|
+
tooltip.setAttribute('slot', this.parentElement.getAttribute('slot') || '');
|
152
146
|
}
|
147
|
+
// Attach the tooltip programmatically after the nearest parent element.
|
148
|
+
(_b = this.parentElement) === null || _b === void 0 ? void 0 : _b.after(tooltip);
|
153
149
|
}
|
154
150
|
/**
|
155
151
|
* Removes the dynamically created tooltip for long text label on focus or mouse leave.
|
156
152
|
* This is triggered on focusout and mouseout events.
|
157
153
|
*/
|
158
154
|
hideTooltipOnLeave() {
|
159
|
-
|
160
|
-
|
161
|
-
|
155
|
+
const existingTooltip = document.querySelector(`${TOOLTIP_TAG_NAME}[triggerid="${this.id}"]`);
|
156
|
+
if (existingTooltip) {
|
157
|
+
existingTooltip.remove();
|
158
|
+
}
|
162
159
|
}
|
163
160
|
/**
|
164
161
|
* Generates a template for a text slot with the specified content.
|
@@ -1,6 +1,4 @@
|
|
1
1
|
declare const TAG_NAME: "mdc-listitem";
|
2
|
-
declare const TOOLTIP_ID: string;
|
3
|
-
declare const LISTITEM_ID: string;
|
4
2
|
declare const LISTITEM_VARIANTS: {
|
5
3
|
readonly FULL_WIDTH: "full-width";
|
6
4
|
readonly INSET_PILL: "inset-pill";
|
@@ -10,4 +8,4 @@ declare const DEFAULTS: {
|
|
10
8
|
readonly VARIANT: "full-width";
|
11
9
|
readonly TOOLTIP_PLACEMENT: "top";
|
12
10
|
};
|
13
|
-
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS
|
11
|
+
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS };
|
@@ -1,9 +1,6 @@
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid';
|
2
1
|
import utils from '../../utils/tag-name';
|
3
2
|
import { POPOVER_PLACEMENT } from '../popover/popover.constants';
|
4
3
|
const TAG_NAME = utils.constructTagName('listitem');
|
5
|
-
const TOOLTIP_ID = `listitem-tooltip-popover-${uuidv4()}`;
|
6
|
-
const LISTITEM_ID = `listitem-tooltip-triggerid-${uuidv4()}`;
|
7
4
|
const LISTITEM_VARIANTS = {
|
8
5
|
FULL_WIDTH: 'full-width',
|
9
6
|
INSET_PILL: 'inset-pill',
|
@@ -13,4 +10,4 @@ const DEFAULTS = {
|
|
13
10
|
VARIANT: LISTITEM_VARIANTS.FULL_WIDTH,
|
14
11
|
TOOLTIP_PLACEMENT: POPOVER_PLACEMENT.TOP,
|
15
12
|
};
|
16
|
-
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS
|
13
|
+
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS };
|
@@ -30,6 +30,10 @@ declare class MenuBar extends Component {
|
|
30
30
|
* Returns all menuitem elements, including those nested inside menusection.
|
31
31
|
*/
|
32
32
|
get menuItems(): Array<HTMLElement>;
|
33
|
+
/**
|
34
|
+
* Returns all menupopovers, including direct and slotted ones .
|
35
|
+
*/
|
36
|
+
private getAllPopovers;
|
33
37
|
update(changedProperties: PropertyValues): void;
|
34
38
|
firstUpdated(changedProperties: PropertyValues): void;
|
35
39
|
/**
|
@@ -41,10 +45,11 @@ declare class MenuBar extends Component {
|
|
41
45
|
*/
|
42
46
|
private resetTabIndexAndSetActiveTabIndex;
|
43
47
|
private getCurrentIndex;
|
48
|
+
private getSubmenu;
|
49
|
+
private showSubmenu;
|
44
50
|
private updatePopoverPlacement;
|
45
51
|
private updateTabIndexAndFocus;
|
46
52
|
private navigateToMenuItem;
|
47
|
-
private showSubmenu;
|
48
53
|
private getKeyWithDirectionFix;
|
49
54
|
/**
|
50
55
|
* Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)
|
@@ -54,7 +59,6 @@ declare class MenuBar extends Component {
|
|
54
59
|
private closeAllMenuPopovers;
|
55
60
|
private crossMenubarNavigationOnLeft;
|
56
61
|
private crossMenubarNavigationOnRight;
|
57
|
-
private hasSubmenu;
|
58
62
|
private getParentMenuItemIndex;
|
59
63
|
private handleKeyDown;
|
60
64
|
render(): import("lit-html").TemplateResult<1>;
|
@@ -4,6 +4,7 @@ import { ROLE } from '../../utils/roles';
|
|
4
4
|
import { POPOVER_PLACEMENT } from '../popover/popover.constants';
|
5
5
|
import { TAG_NAME as MENUPOPOVER_TAGNAME } from '../menupopover/menupopover.constants';
|
6
6
|
import { TAG_NAME as MENUSECTION_TAGNAME } from '../menusection/menusection.constants';
|
7
|
+
import { TAG_NAME as SIDENAV_TAGNAME } from '../sidenavigation/sidenavigation.constants';
|
7
8
|
import { KEYS } from '../../utils/keys';
|
8
9
|
import { popoverStack } from '../popover/popover.stack';
|
9
10
|
import { DEFAULTS, TAG_NAME as MENUBAR_TAGNAME } from './menubar.constants';
|
@@ -60,13 +61,38 @@ class MenuBar extends Component {
|
|
60
61
|
assigned.forEach(collect);
|
61
62
|
return items;
|
62
63
|
}
|
64
|
+
/**
|
65
|
+
* Returns all menupopovers, including direct and slotted ones .
|
66
|
+
*/
|
67
|
+
getAllPopovers() {
|
68
|
+
var _a, _b;
|
69
|
+
if (!this.menuItems.length)
|
70
|
+
return [];
|
71
|
+
const root = (_b = (_a = this.menuItems[0]) === null || _a === void 0 ? void 0 : _a.closest(SIDENAV_TAGNAME)) !== null && _b !== void 0 ? _b : this;
|
72
|
+
if (!root)
|
73
|
+
return [];
|
74
|
+
const popovers = [];
|
75
|
+
const searchPopovers = (node) => {
|
76
|
+
// Check direct popovers
|
77
|
+
node.querySelectorAll(`${MENUPOPOVER_TAGNAME}`).forEach(el => {
|
78
|
+
popovers.push(el);
|
79
|
+
});
|
80
|
+
// Handle slots
|
81
|
+
node.querySelectorAll('slot').forEach(slot => {
|
82
|
+
const assigned = slot.assignedElements({ flatten: true });
|
83
|
+
assigned.forEach(searchPopovers);
|
84
|
+
});
|
85
|
+
};
|
86
|
+
searchPopovers(root);
|
87
|
+
return popovers;
|
88
|
+
}
|
63
89
|
update(changedProperties) {
|
64
90
|
super.update(changedProperties);
|
65
|
-
this.updatePopoverPlacement();
|
66
91
|
}
|
67
92
|
firstUpdated(changedProperties) {
|
68
93
|
super.firstUpdated(changedProperties);
|
69
94
|
this.resetTabIndexAndSetActiveTabIndex(this.menuItems);
|
95
|
+
this.updatePopoverPlacement();
|
70
96
|
}
|
71
97
|
/**
|
72
98
|
* Resets all list items tabindex to -1 and sets the tabindex of the
|
@@ -84,10 +110,26 @@ class MenuBar extends Component {
|
|
84
110
|
getCurrentIndex(target) {
|
85
111
|
return this.menuItems.findIndex(item => item === target || item === target.parentElement);
|
86
112
|
}
|
113
|
+
getSubmenu(triggerId) {
|
114
|
+
if (!triggerId)
|
115
|
+
return undefined;
|
116
|
+
return this.getAllPopovers().find(popover => popover.getAttribute('triggerid') === triggerId);
|
117
|
+
}
|
118
|
+
showSubmenu(triggerId) {
|
119
|
+
if (!triggerId)
|
120
|
+
return;
|
121
|
+
const triggerElement = this.menuItems.find(item => item.getAttribute('id') === triggerId);
|
122
|
+
if (!triggerElement)
|
123
|
+
return;
|
124
|
+
const submenu = this.getSubmenu(triggerId);
|
125
|
+
if (submenu)
|
126
|
+
submenu.showPopover();
|
127
|
+
}
|
87
128
|
updatePopoverPlacement() {
|
88
|
-
const allPopovers = this.querySelectorAll(`${MENUPOPOVER_TAGNAME}:not([disabled])`);
|
89
129
|
const placement = POPOVER_PLACEMENT.RIGHT_START;
|
90
|
-
|
130
|
+
this.getAllPopovers().forEach(popover => {
|
131
|
+
popover.setAttribute('placement', placement);
|
132
|
+
});
|
91
133
|
}
|
92
134
|
updateTabIndexAndFocus(menuItems, currentIndex, newIndex) {
|
93
135
|
var _a, _b, _c;
|
@@ -105,24 +147,15 @@ class MenuBar extends Component {
|
|
105
147
|
if (length === 0)
|
106
148
|
return;
|
107
149
|
let newIndex = currentIndex;
|
108
|
-
|
109
|
-
newIndex = (currentIndex - 1 + length) % length;
|
110
|
-
}
|
111
|
-
else {
|
112
|
-
newIndex = (currentIndex + 1) % length;
|
113
|
-
}
|
150
|
+
newIndex = direction === 'prev' ? (currentIndex - 1 + length) % length : (currentIndex + 1) % length;
|
114
151
|
this.updateTabIndexAndFocus(this.menuItems, currentIndex, newIndex);
|
115
152
|
if (shouldOpenSubmenu) {
|
116
153
|
const triggerId = (_a = this.menuItems[newIndex]) === null || _a === void 0 ? void 0 : _a.getAttribute('id');
|
117
|
-
if (this.
|
154
|
+
if (this.getSubmenu(triggerId) && !this.menuItems[newIndex].hasAttribute('soft-disabled')) {
|
118
155
|
this.showSubmenu(triggerId);
|
119
156
|
}
|
120
157
|
}
|
121
158
|
}
|
122
|
-
showSubmenu(triggerId) {
|
123
|
-
const submenu = this.querySelector(`${MENUPOPOVER_TAGNAME}[triggerid="${triggerId}"]`);
|
124
|
-
submenu === null || submenu === void 0 ? void 0 : submenu.showPopover();
|
125
|
-
}
|
126
159
|
getKeyWithDirectionFix(originalKey) {
|
127
160
|
const isRtl = window.getComputedStyle(this).direction === 'rtl';
|
128
161
|
if (!isRtl)
|
@@ -142,11 +175,10 @@ class MenuBar extends Component {
|
|
142
175
|
if (!parent || element.role !== ROLE.MENUITEM)
|
143
176
|
return false;
|
144
177
|
const parentTag = parent.tagName.toLowerCase();
|
145
|
-
|
178
|
+
const grandParentTag = (_a = parent.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase();
|
179
|
+
if (parentTag === MENUBAR_TAGNAME || parentTag === SIDENAV_TAGNAME)
|
146
180
|
return true;
|
147
|
-
|
148
|
-
if (parentTag === MENUSECTION_TAGNAME &&
|
149
|
-
((_a = parent.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) === MENUBAR_TAGNAME) {
|
181
|
+
if (parentTag === MENUSECTION_TAGNAME && (grandParentTag === MENUBAR_TAGNAME || grandParentTag === SIDENAV_TAGNAME)) {
|
150
182
|
return true;
|
151
183
|
}
|
152
184
|
return false;
|
@@ -182,19 +214,16 @@ class MenuBar extends Component {
|
|
182
214
|
}
|
183
215
|
}
|
184
216
|
async crossMenubarNavigationOnRight(element) {
|
185
|
-
if (this.isTopLevelMenuItem(element) && this.
|
217
|
+
if (this.isTopLevelMenuItem(element) && this.getSubmenu(element.id) && !element.hasAttribute('soft-disabled')) {
|
186
218
|
this.showSubmenu(element.id);
|
187
219
|
}
|
188
|
-
else if (this.isNestedMenuItem(element) && !this.
|
220
|
+
else if (this.isNestedMenuItem(element) && !this.getSubmenu(element.id)) {
|
189
221
|
await this.closeAllMenuPopovers();
|
190
222
|
const parentIndex = this.getParentMenuItemIndex(element);
|
191
223
|
if (parentIndex >= 0)
|
192
224
|
this.navigateToMenuItem(parentIndex, 'next', true);
|
193
225
|
}
|
194
226
|
}
|
195
|
-
hasSubmenu(triggerId) {
|
196
|
-
return !!this.querySelector(`${MENUPOPOVER_TAGNAME}[triggerid="${triggerId}"]`);
|
197
|
-
}
|
198
227
|
getParentMenuItemIndex(element) {
|
199
228
|
let parent = element.parentElement;
|
200
229
|
while (parent) {
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import type MenuItem from '../menuitem';
|
2
1
|
import type MenuPopover from './menupopover.component';
|
3
2
|
/**
|
4
3
|
* Checks if the given menu item is a valid menu item.
|
@@ -7,5 +6,5 @@ import type MenuPopover from './menupopover.component';
|
|
7
6
|
*/
|
8
7
|
declare const isValidMenuItem: (menuItem: Element | null) => boolean;
|
9
8
|
declare const isValidPopover: (el: Element | null) => el is MenuPopover;
|
10
|
-
declare const isActiveMenuItem: (menuItem: Element | null) =>
|
9
|
+
declare const isActiveMenuItem: (menuItem: Element | null) => boolean;
|
11
10
|
export { isValidMenuItem, isValidPopover, isActiveMenuItem };
|
@@ -1,6 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import { TAG_NAME as MENUITEMCHECKBOX_TAGNAME } from '../menuitemcheckbox/menuitemcheckbox.constants';
|
3
|
-
import { TAG_NAME as MENUITEMRADIO_TAGNAME } from '../menuitemradio/menuitemradio.constants';
|
1
|
+
import { ROLE } from '../../utils/roles';
|
4
2
|
import { TAG_NAME as MENUPOPOVER_TAGNAME } from './menupopover.constants';
|
5
3
|
/**
|
6
4
|
* Checks if the given menu item is a valid menu item.
|
@@ -8,11 +6,16 @@ import { TAG_NAME as MENUPOPOVER_TAGNAME } from './menupopover.constants';
|
|
8
6
|
* @returns True if the menu item is a valid menu item, false otherwise.
|
9
7
|
*/
|
10
8
|
const isValidMenuItem = (menuItem) => {
|
9
|
+
var _a;
|
11
10
|
if (!menuItem)
|
12
11
|
return false;
|
13
|
-
const
|
14
|
-
return
|
12
|
+
const role = (_a = menuItem.getAttribute('role')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
13
|
+
return role === ROLE.MENUITEM || role === ROLE.MENUITEMCHECKBOX || role === ROLE.MENUITEMRADIO;
|
15
14
|
};
|
16
15
|
const isValidPopover = (el) => { var _a; return ((_a = el === null || el === void 0 ? void 0 : el.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === MENUPOPOVER_TAGNAME; };
|
17
|
-
const isActiveMenuItem = (menuItem) => {
|
16
|
+
const isActiveMenuItem = (menuItem) => {
|
17
|
+
var _a;
|
18
|
+
const role = (_a = menuItem === null || menuItem === void 0 ? void 0 : menuItem.getAttribute('role')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
19
|
+
return !!menuItem && role === ROLE.MENUITEM && !menuItem.hasAttribute('disabled');
|
20
|
+
};
|
18
21
|
export { isValidMenuItem, isValidPopover, isActiveMenuItem };
|
@@ -34,6 +34,21 @@ declare class MenuSection extends Component {
|
|
34
34
|
* If not provided, no icon will be rendered and text will be aligned to the start.
|
35
35
|
*/
|
36
36
|
prefixIcon?: IconNames;
|
37
|
+
/**
|
38
|
+
* Whether to show a divider below the section header.
|
39
|
+
* This is useful for visually separating sections in the menu.
|
40
|
+
*/
|
41
|
+
showDivider: boolean;
|
42
|
+
/**
|
43
|
+
* Shows or hides the section headers based on the expanded state of the side navigation.
|
44
|
+
*
|
45
|
+
* @internal
|
46
|
+
*/
|
47
|
+
hideHeaderText: boolean;
|
48
|
+
/**
|
49
|
+
* @internal
|
50
|
+
*/
|
51
|
+
private readonly sideNavigationContext;
|
37
52
|
connectedCallback(): void;
|
38
53
|
update(changedProperties: PropertyValues): void;
|
39
54
|
private renderHeader;
|
@@ -11,7 +11,9 @@ import { html } from 'lit';
|
|
11
11
|
import { property } from 'lit/decorators.js';
|
12
12
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
13
13
|
import { Component } from '../../models';
|
14
|
+
import providerUtils from '../../utils/provider';
|
14
15
|
import { ROLE } from '../../utils/roles';
|
16
|
+
import SideNavigation from '../sidenavigation/sidenavigation.component';
|
15
17
|
import styles from './menusection.styles';
|
16
18
|
/**
|
17
19
|
* `mdc-menusection` is a container element used to group a set of menu items.
|
@@ -42,12 +44,28 @@ class MenuSection extends Component {
|
|
42
44
|
* This appears on the leading side of the list item.
|
43
45
|
*/
|
44
46
|
this.headerText = null;
|
47
|
+
/**
|
48
|
+
* Whether to show a divider below the section header.
|
49
|
+
* This is useful for visually separating sections in the menu.
|
50
|
+
*/
|
51
|
+
this.showDivider = false;
|
52
|
+
/**
|
53
|
+
* Shows or hides the section headers based on the expanded state of the side navigation.
|
54
|
+
*
|
55
|
+
* @internal
|
56
|
+
*/
|
57
|
+
this.hideHeaderText = false;
|
58
|
+
/**
|
59
|
+
* @internal
|
60
|
+
*/
|
61
|
+
this.sideNavigationContext = providerUtils.consume({ host: this, context: SideNavigation.Context });
|
45
62
|
}
|
46
63
|
connectedCallback() {
|
47
64
|
super.connectedCallback();
|
48
65
|
this.setAttribute('role', ROLE.GROUP);
|
49
66
|
}
|
50
67
|
update(changedProperties) {
|
68
|
+
var _a;
|
51
69
|
super.update(changedProperties);
|
52
70
|
if ((changedProperties.has('ariaLabel') || changedProperties.has('headerText')) &&
|
53
71
|
(!this.ariaLabel || this.ariaLabel === changedProperties.get('headerText'))) {
|
@@ -57,11 +75,17 @@ class MenuSection extends Component {
|
|
57
75
|
// more details: https://nolanlawson.com/2022/11/28/shadow-dom-and-accessibility-the-trouble-with-aria/
|
58
76
|
this.ariaLabel = this.headerText || '';
|
59
77
|
}
|
78
|
+
const context = (_a = this.sideNavigationContext) === null || _a === void 0 ? void 0 : _a.value;
|
79
|
+
if (!context)
|
80
|
+
return;
|
81
|
+
const { expanded } = context;
|
82
|
+
this.hideHeaderText = !expanded;
|
60
83
|
}
|
61
84
|
renderHeader() {
|
85
|
+
var _a, _b;
|
62
86
|
if (this.headerText) {
|
63
87
|
return html ` <mdc-listheader
|
64
|
-
part="header"
|
88
|
+
part="header ${((_b = (_a = this.sideNavigationContext) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.expanded) ? 'align-header' : ''}"
|
65
89
|
header-text="${this.headerText}"
|
66
90
|
prefix-icon="${ifDefined(this.prefixIcon)}"
|
67
91
|
>
|
@@ -70,7 +94,11 @@ class MenuSection extends Component {
|
|
70
94
|
return null;
|
71
95
|
}
|
72
96
|
render() {
|
73
|
-
return html
|
97
|
+
return html `
|
98
|
+
${!this.hideHeaderText ? this.renderHeader() : null}
|
99
|
+
<slot></slot>
|
100
|
+
${this.showDivider ? html `<mdc-divider variant="gradient" part="divider"></mdc-divider>` : null}
|
101
|
+
`;
|
74
102
|
}
|
75
103
|
}
|
76
104
|
MenuSection.styles = [...Component.styles, ...styles];
|
@@ -86,4 +114,12 @@ __decorate([
|
|
86
114
|
property({ type: String, attribute: 'prefix-icon' }),
|
87
115
|
__metadata("design:type", String)
|
88
116
|
], MenuSection.prototype, "prefixIcon", void 0);
|
117
|
+
__decorate([
|
118
|
+
property({ type: Boolean, reflect: true, attribute: 'show-divider' }),
|
119
|
+
__metadata("design:type", Object)
|
120
|
+
], MenuSection.prototype, "showDivider", void 0);
|
121
|
+
__decorate([
|
122
|
+
property({ type: Boolean, reflect: true, attribute: 'hide-header-text' }),
|
123
|
+
__metadata("design:type", Object)
|
124
|
+
], MenuSection.prototype, "hideHeaderText", void 0);
|
89
125
|
export default MenuSection;
|
@@ -6,8 +6,16 @@ const styles = css `
|
|
6
6
|
height: 100%;
|
7
7
|
}
|
8
8
|
|
9
|
-
::
|
9
|
+
:host::part(divider) {
|
10
10
|
margin-block: 0.25rem;
|
11
11
|
}
|
12
|
+
|
13
|
+
:host(:dir(ltr))::part(align-header) {
|
14
|
+
padding-left: 1.75rem;
|
15
|
+
}
|
16
|
+
|
17
|
+
:host(:dir(rtl))::part(align-header) {
|
18
|
+
padding-right: 1.75rem;
|
19
|
+
}
|
12
20
|
`;
|
13
21
|
export default [styles];
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import
|
1
|
+
import NavMenuItem from './navmenuitem.component';
|
2
2
|
import '../text';
|
3
3
|
import '../badge';
|
4
4
|
import '../icon';
|
5
5
|
import '../tooltip';
|
6
6
|
declare global {
|
7
7
|
interface HTMLElementTagNameMap {
|
8
|
-
['mdc-
|
8
|
+
['mdc-navmenuitem']: NavMenuItem;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
export default
|
11
|
+
export default NavMenuItem;
|
package/dist/components/{navitem/navitem.component.d.ts → navmenuitem/navmenuitem.component.d.ts}
RENAMED
@@ -1,45 +1,45 @@
|
|
1
1
|
import type { CSSResult, PropertyValues } from 'lit';
|
2
2
|
import MenuItem from '../menuitem/menuitem.component';
|
3
|
-
import type { BadgeType } from './
|
4
|
-
declare const
|
3
|
+
import type { BadgeType } from './navmenuitem.types';
|
4
|
+
declare const NavMenuItem_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/IconNameMixin").IconNameMixinInterface> & typeof MenuItem;
|
5
5
|
/**
|
6
|
-
* `mdc-
|
6
|
+
* `mdc-navmenuitem` is a menuitem styled to work as a navigation tab.
|
7
7
|
* It supports a leading icon, optional badge and dynamic text rendering.
|
8
8
|
*
|
9
|
-
* Note: `mdc-
|
9
|
+
* Note: `mdc-navmenuitem` is intended to be used inside `mdc-menubar` as part of the sideNavigation
|
10
10
|
* component. Its structure, spacing, and interactions are designed to align with
|
11
11
|
* the visual and functional requirements of side navigation layouts.
|
12
12
|
*
|
13
|
-
* @tagname mdc-
|
13
|
+
* @tagname mdc-navmenuitem
|
14
14
|
*
|
15
15
|
* @dependency mdc-icon
|
16
16
|
* @dependency mdc-text
|
17
17
|
* @dependency mdc-badge
|
18
18
|
* @dependency mdc-tooltip
|
19
19
|
*
|
20
|
-
* @event click - (React: onClick) This event is dispatched when the
|
21
|
-
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the
|
22
|
-
* @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the
|
23
|
-
* @event focus - (React: onFocus) This event is dispatched when the
|
24
|
-
* @event activechange - (React: onActiveChange) Dispatched when the active state of the
|
20
|
+
* @event click - (React: onClick) This event is dispatched when the navmenuitem is clicked.
|
21
|
+
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the navmenuitem.
|
22
|
+
* @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the navmenuitem.
|
23
|
+
* @event focus - (React: onFocus) This event is dispatched when the navmenuitem receives focus.
|
24
|
+
* @event activechange - (React: onActiveChange) Dispatched when the active state of the navmenuitem changes.
|
25
25
|
*
|
26
|
-
* @cssproperty --mdc-
|
27
|
-
* @cssproperty --mdc-
|
28
|
-
* @cssproperty --mdc-
|
29
|
-
* @cssproperty --mdc-
|
30
|
-
* @cssproperty --mdc-
|
31
|
-
* @cssproperty --mdc-
|
32
|
-
* @cssproperty --mdc-
|
33
|
-
* @cssproperty --mdc-
|
34
|
-
* @cssproperty --mdc-
|
35
|
-
* @cssproperty --mdc-
|
36
|
-
* @cssproperty --mdc-
|
26
|
+
* @cssproperty --mdc-navmenuitem-color - Text color of the navmenuitem in its normal state.
|
27
|
+
* @cssproperty --mdc-navmenuitem-border-color - Border color of the navmenuitem in its normal state.
|
28
|
+
* @cssproperty --mdc-navmenuitem-disabled-color - Text color of the navmenuitem when disabled.
|
29
|
+
* @cssproperty --mdc-navmenuitem-expanded-width - Width of the navmenuitem when expanded.
|
30
|
+
* @cssproperty --mdc-navmenuitem-hover-background-color - Background color of the navmenuitem when hovered.
|
31
|
+
* @cssproperty --mdc-navmenuitem-hover-active-background-color - Background color of the active navmenuitem when hovered.
|
32
|
+
* @cssproperty --mdc-navmenuitem-pressed-background-color - Background color of the navmenuitem when pressed.
|
33
|
+
* @cssproperty --mdc-navmenuitem-pressed-active-background-color - Background color of the active navmenuitem when pressed.
|
34
|
+
* @cssproperty --mdc-navmenuitem-disabled-background-color - Background color of the navmenuitem when disabled.
|
35
|
+
* @cssproperty --mdc-navmenuitem-disabled-active-background-color - Background color of the active navmenuitem when disabled.
|
36
|
+
* @cssproperty --mdc-navmenuitem-rest-active-background-color - Background color of the active nav item in its rest state.
|
37
37
|
*/
|
38
|
-
declare class
|
38
|
+
declare class NavMenuItem extends NavMenuItem_base {
|
39
39
|
/**
|
40
|
-
* The
|
41
|
-
* When the active state is true, the
|
42
|
-
* Conversely, when the active state is false, the
|
40
|
+
* The navmenuitem's active state indicates whether it is currently toggled on (active) or off (inactive).
|
41
|
+
* When the active state is true, the navmenuitem is considered to be in an active state, meaning it is toggled on.
|
42
|
+
* Conversely, when the active state is false, the navmenuitem is in an inactive state, indicating it is toggled off.
|
43
43
|
* @default undefined
|
44
44
|
*/
|
45
45
|
active?: boolean;
|
@@ -59,14 +59,14 @@ declare class NavItem extends NavItem_base {
|
|
59
59
|
*/
|
60
60
|
maxCounter: number;
|
61
61
|
/**
|
62
|
-
* Id of the
|
62
|
+
* Id of the navMenuItem (used as a identificator when used in the menubar)
|
63
63
|
* Note: It has to be unique.
|
64
64
|
*
|
65
65
|
* @default undefined
|
66
66
|
*/
|
67
67
|
navId?: string;
|
68
68
|
/**
|
69
|
-
* Determines whether the
|
69
|
+
* Determines whether the navMenuItem is expanded or not.
|
70
70
|
*
|
71
71
|
* @internal
|
72
72
|
*/
|
@@ -76,7 +76,7 @@ declare class NavItem extends NavItem_base {
|
|
76
76
|
*/
|
77
77
|
ariaLabel: string | null;
|
78
78
|
/**
|
79
|
-
* When set to true, prevents the automatic setting of the `aria-current` attribute on the
|
79
|
+
* When set to true, prevents the automatic setting of the `aria-current` attribute on the navmenuitem
|
80
80
|
* when it becomes active. This is useful for cases where you want to maintain the visual active styling
|
81
81
|
* but need to handle aria-current attribute differently or not at all.
|
82
82
|
* The active button styling will still be applied regardless of this setting.
|
@@ -90,19 +90,19 @@ declare class NavItem extends NavItem_base {
|
|
90
90
|
* @internal
|
91
91
|
*/
|
92
92
|
private readonly sideNavigationContext;
|
93
|
+
constructor();
|
93
94
|
connectedCallback(): void;
|
94
|
-
disconnectedCallback(): void;
|
95
95
|
protected updated(): void;
|
96
96
|
/**
|
97
|
-
* Check whether the
|
97
|
+
* Check whether the navmenuitem is inside a nested nav structure.
|
98
98
|
* Returns `true` if there is a parent `mdc-menupopover`
|
99
99
|
* This method assumes nesting implies deeper levels of nav hierarchy.
|
100
100
|
*/
|
101
101
|
private isNested;
|
102
102
|
/**
|
103
103
|
* Modifies the icon name based on the active state.
|
104
|
-
* If the
|
105
|
-
* If the
|
104
|
+
* If the navMenuItem is active, the icon name is suffixed with '-filled'.
|
105
|
+
* If the navMenuItem is inactive, the icon name is restored to its original value.
|
106
106
|
* If '-filled' icon is not available, the icon name remains unchanged.
|
107
107
|
* @internal
|
108
108
|
* @param active - The active state.
|
@@ -111,9 +111,9 @@ declare class NavItem extends NavItem_base {
|
|
111
111
|
/**
|
112
112
|
* Dispatch the activechange event.
|
113
113
|
* @internal
|
114
|
-
* @param active - The active state of the
|
114
|
+
* @param active - The active state of the navMenuItem.
|
115
115
|
*/
|
116
|
-
private
|
116
|
+
private emitNavMenuItemActiveChange;
|
117
117
|
private handleClickEvent;
|
118
118
|
update(changedProperties: PropertyValues): void;
|
119
119
|
private renderTextLabel;
|
@@ -122,4 +122,4 @@ declare class NavItem extends NavItem_base {
|
|
122
122
|
render(): import("lit-html").TemplateResult<1>;
|
123
123
|
static styles: Array<CSSResult>;
|
124
124
|
}
|
125
|
-
export default
|
125
|
+
export default NavMenuItem;
|