@momentum-design/components 0.80.3 → 0.80.5
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 +601 -317
- package/dist/browser/index.js.map +4 -4
- package/dist/components/list/list.component.d.ts +1 -1
- package/dist/components/listitem/listitem.component.js +10 -3
- package/dist/components/menupopover/menupopover.component.js +3 -1
- package/dist/components/navitem/index.d.ts +11 -0
- package/dist/components/navitem/index.js +8 -0
- package/dist/components/navitem/navitem.component.d.ts +125 -0
- package/dist/components/navitem/navitem.component.js +251 -0
- package/dist/components/navitem/navitem.constants.d.ts +16 -0
- package/dist/components/navitem/navitem.constants.js +21 -0
- package/dist/components/navitem/navitem.styles.d.ts +2 -0
- package/dist/components/navitem/navitem.styles.js +146 -0
- package/dist/components/navitem/navitem.types.d.ts +11 -0
- package/dist/components/navitem/navitem.types.js +1 -0
- package/dist/components/navitemlist/index.d.ts +7 -0
- package/dist/components/navitemlist/index.js +4 -0
- package/dist/components/navitemlist/navitemlist.component.d.ts +51 -0
- package/dist/components/navitemlist/navitemlist.component.js +92 -0
- package/dist/components/navitemlist/navitemlist.constants.d.ts +2 -0
- package/dist/components/navitemlist/navitemlist.constants.js +3 -0
- package/dist/components/navitemlist/navitemlist.styles.d.ts +2 -0
- package/dist/components/navitemlist/navitemlist.styles.js +23 -0
- package/dist/components/sidenavigation/index.d.ts +10 -0
- package/dist/components/sidenavigation/index.js +7 -0
- package/dist/components/sidenavigation/sidenavigation.component.d.ts +144 -0
- package/dist/components/sidenavigation/sidenavigation.component.js +244 -0
- package/dist/components/sidenavigation/sidenavigation.constants.d.ts +11 -0
- package/dist/components/sidenavigation/sidenavigation.constants.js +12 -0
- package/dist/components/sidenavigation/sidenavigation.context.d.ts +15 -0
- package/dist/components/sidenavigation/sidenavigation.context.js +78 -0
- package/dist/components/sidenavigation/sidenavigation.styles.d.ts +2 -0
- package/dist/components/sidenavigation/sidenavigation.styles.js +68 -0
- package/dist/components/sidenavigation/sidenavigation.types.d.ts +7 -0
- package/dist/components/sidenavigation/sidenavigation.types.js +1 -0
- package/dist/custom-elements.json +5820 -3900
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/react/index.d.ts +8 -5
- package/dist/react/index.js +8 -5
- package/dist/react/navitem/index.d.ts +43 -0
- package/dist/react/navitem/index.js +51 -0
- package/dist/react/navitemlist/index.d.ts +13 -0
- package/dist/react/navitemlist/index.js +22 -0
- package/dist/react/sidenavigation/index.d.ts +56 -0
- package/dist/react/sidenavigation/index.js +64 -0
- package/dist/utils/mixins/MenuMixin.js +45 -33
- package/dist/utils/roles.d.ts +1 -0
- package/dist/utils/roles.js +1 -0
- package/package.json +1 -1
@@ -0,0 +1,51 @@
|
|
1
|
+
import type { CSSResult } from 'lit';
|
2
|
+
import MenuBar from '../menubar/menubar.component';
|
3
|
+
declare const NavItemList_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/MenuMixin").MenuMixinInterface> & typeof MenuBar;
|
4
|
+
/**
|
5
|
+
* `mdc-navitemlist` is a container component used to group multiple mdc-navitem elements into a navigation list.
|
6
|
+
* It provides the structural foundation for organizing vertical nav items and
|
7
|
+
* ensures consistent behavior and layout within side navigation patterns.
|
8
|
+
*
|
9
|
+
* Note: mdc-navitemlist is typically used within the sidenavigation component.
|
10
|
+
* @tagname mdc-navitemlist
|
11
|
+
*
|
12
|
+
* @slot default - Slot for projecting one or more navigation items, optional section headers and dividers.
|
13
|
+
*/
|
14
|
+
declare class NavItemList extends NavItemList_base {
|
15
|
+
/**
|
16
|
+
* Determines whether the navItemList is expanded or not.
|
17
|
+
*
|
18
|
+
* @internal
|
19
|
+
*/
|
20
|
+
showLabel?: boolean;
|
21
|
+
/**
|
22
|
+
* Aria-label attribute to be set for accessibility
|
23
|
+
*/
|
24
|
+
ariaLabel: string | null;
|
25
|
+
/**
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
private readonly sideNavigationContext;
|
29
|
+
connectedCallback(): void;
|
30
|
+
disconnectedCallback(): void;
|
31
|
+
protected updated(): void;
|
32
|
+
/**
|
33
|
+
* Handle the navItem active change event fired from the nested navItem.
|
34
|
+
* @internal
|
35
|
+
* @param event - Custom Event fired from the nested navItem.
|
36
|
+
*/
|
37
|
+
private handleNestedNavItemActiveChange;
|
38
|
+
/**
|
39
|
+
* Matches new navItem with navId.
|
40
|
+
* @param NavItem - The new active navItem.
|
41
|
+
*
|
42
|
+
* @internal
|
43
|
+
*/
|
44
|
+
private findNav;
|
45
|
+
/**
|
46
|
+
* Returns all nested, non-disabled mdc-navitem elements inside this component.
|
47
|
+
*/
|
48
|
+
private get navItems();
|
49
|
+
static styles: Array<CSSResult>;
|
50
|
+
}
|
51
|
+
export default NavItemList;
|
@@ -0,0 +1,92 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { property } from 'lit/decorators.js';
|
11
|
+
import styles from './navitemlist.styles';
|
12
|
+
import MenuBar from '../menubar/menubar.component';
|
13
|
+
import { MenuMixin } from '../../utils/mixins/MenuMixin';
|
14
|
+
import { ORIENTATION } from '../menubar/menubar.constants';
|
15
|
+
import providerUtils from '../../utils/provider';
|
16
|
+
import { TAG_NAME as NAVITEM_TAGNAME } from '../navitem/navitem.constants';
|
17
|
+
import SideNavigation from '../sidenavigation/sidenavigation.component';
|
18
|
+
/**
|
19
|
+
* `mdc-navitemlist` is a container component used to group multiple mdc-navitem elements into a navigation list.
|
20
|
+
* It provides the structural foundation for organizing vertical nav items and
|
21
|
+
* ensures consistent behavior and layout within side navigation patterns.
|
22
|
+
*
|
23
|
+
* Note: mdc-navitemlist is typically used within the sidenavigation component.
|
24
|
+
* @tagname mdc-navitemlist
|
25
|
+
*
|
26
|
+
* @slot default - Slot for projecting one or more navigation items, optional section headers and dividers.
|
27
|
+
*/
|
28
|
+
class NavItemList extends MenuMixin(MenuBar) {
|
29
|
+
constructor() {
|
30
|
+
super(...arguments);
|
31
|
+
/**
|
32
|
+
* Aria-label attribute to be set for accessibility
|
33
|
+
*/
|
34
|
+
this.ariaLabel = null;
|
35
|
+
/**
|
36
|
+
* @internal
|
37
|
+
*/
|
38
|
+
this.sideNavigationContext = providerUtils.consume({ host: this, context: SideNavigation.Context });
|
39
|
+
/**
|
40
|
+
* Handle the navItem active change event fired from the nested navItem.
|
41
|
+
* @internal
|
42
|
+
* @param event - Custom Event fired from the nested navItem.
|
43
|
+
*/
|
44
|
+
this.handleNestedNavItemActiveChange = (event) => {
|
45
|
+
var _a;
|
46
|
+
const newNavItem = this.findNav(this.navItems || [], event.detail.navId);
|
47
|
+
if ((_a = this.sideNavigationContext) === null || _a === void 0 ? void 0 : _a.value) {
|
48
|
+
this.sideNavigationContext.value.setCurrentActiveNavItem(newNavItem);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
/**
|
52
|
+
* Matches new navItem with navId.
|
53
|
+
* @param NavItem - The new active navItem.
|
54
|
+
*
|
55
|
+
* @internal
|
56
|
+
*/
|
57
|
+
this.findNav = (navs, navId) => navs.find((nav) => nav.navId === navId);
|
58
|
+
}
|
59
|
+
connectedCallback() {
|
60
|
+
super.connectedCallback();
|
61
|
+
this.ariaOrientation = ORIENTATION.VERTICAL;
|
62
|
+
this.addEventListener('activechange', this.handleNestedNavItemActiveChange);
|
63
|
+
}
|
64
|
+
disconnectedCallback() {
|
65
|
+
super.disconnectedCallback();
|
66
|
+
this.removeEventListener('activechange', this.handleNestedNavItemActiveChange);
|
67
|
+
}
|
68
|
+
updated() {
|
69
|
+
var _a;
|
70
|
+
const context = (_a = this.sideNavigationContext) === null || _a === void 0 ? void 0 : _a.value;
|
71
|
+
if (!context)
|
72
|
+
return;
|
73
|
+
const { expanded } = context;
|
74
|
+
this.showLabel = expanded;
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* Returns all nested, non-disabled mdc-navitem elements inside this component.
|
78
|
+
*/
|
79
|
+
get navItems() {
|
80
|
+
return Array.from(this.querySelectorAll(`${NAVITEM_TAGNAME}:not([disabled])`));
|
81
|
+
}
|
82
|
+
}
|
83
|
+
NavItemList.styles = [...MenuBar.styles, ...styles];
|
84
|
+
__decorate([
|
85
|
+
property({ type: Boolean, reflect: true, attribute: 'show-label' }),
|
86
|
+
__metadata("design:type", Boolean)
|
87
|
+
], NavItemList.prototype, "showLabel", void 0);
|
88
|
+
__decorate([
|
89
|
+
property({ type: String, attribute: 'aria-label' }),
|
90
|
+
__metadata("design:type", Object)
|
91
|
+
], NavItemList.prototype, "ariaLabel", void 0);
|
92
|
+
export default NavItemList;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { css } from 'lit';
|
2
|
+
const styles = css `
|
3
|
+
:host {
|
4
|
+
gap: 0.25rem;
|
5
|
+
}
|
6
|
+
|
7
|
+
:host(:not([show-label])) ::slotted(mdc-text) {
|
8
|
+
display: none;
|
9
|
+
}
|
10
|
+
|
11
|
+
:host(:dir(ltr)) ::slotted(mdc-text) {
|
12
|
+
padding-left: 1.75rem;
|
13
|
+
}
|
14
|
+
|
15
|
+
:host(:dir(rtl)) ::slotted(mdc-text) {
|
16
|
+
padding-right: 1.75rem;
|
17
|
+
}
|
18
|
+
|
19
|
+
::slotted(mdc-divider) {
|
20
|
+
margin: 0.75rem 0;
|
21
|
+
}
|
22
|
+
`;
|
23
|
+
export default [styles];
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import { CSSResult } from 'lit';
|
2
|
+
import { Provider } from '../../models';
|
3
|
+
import SideNavigationContext from './sidenavigation.context';
|
4
|
+
import type { SideNavigationVariant } from './sidenavigation.types';
|
5
|
+
/**
|
6
|
+
* The `mdc-sidenavigation` component provides a vertically stacked navigation experience,
|
7
|
+
* typically used in layouts with persistent or collapsible sidebars.
|
8
|
+
*
|
9
|
+
* ## Features:
|
10
|
+
* - Supports four layout variants: `fixed-collapsed`, `fixed-expanded`, `flexible`, and `hidden`
|
11
|
+
* - Toggleable expand/collapse behavior
|
12
|
+
* - Displays brand logo and customer name
|
13
|
+
* - Serves as a context provider for descendant components - `mdc-navitemlist` and `mdc-navitem`
|
14
|
+
*
|
15
|
+
* ### Usage:
|
16
|
+
* In a sidenavigation, navitems can be used in the following ways:
|
17
|
+
*
|
18
|
+
* 1. **Simple navitem** – No submenu or interaction beyond selection.
|
19
|
+
*
|
20
|
+
* 2. **Navitem with submenu**:
|
21
|
+
* - Provide an `id` on the `mdc-navitem`
|
22
|
+
* - Set the `triggerId` on the corresponding `mdc-menupopover` to match the navitem's `id`
|
23
|
+
* - Set `parent-nav-tooltip-text` with appropriate text that will display when a child menu item
|
24
|
+
* inside the nested menupopover is active, conveying which submenu item is currently selected
|
25
|
+
*
|
26
|
+
* 3. **Actionable navitem (no submenu)**:
|
27
|
+
* - Performs an action such as navigation or alert trigger
|
28
|
+
* - Set `disable-aria-current="true"` to maintain visual active state without navigation behavior
|
29
|
+
*
|
30
|
+
* ### Recommendations:
|
31
|
+
* - Use `mdc-text` for section headers
|
32
|
+
* - Use `mdc-divider` with the attribute `variant="gradient"` for section dividers
|
33
|
+
* - For the brand logo, use an informative icon. Refer to `Momentum Informative Icons`
|
34
|
+
*
|
35
|
+
* #### Accessibility Notes:
|
36
|
+
* - Always provide meaningful `aria-label` attributes for both `mdc-navitem` and `mdc-navitemlist`
|
37
|
+
* to ensure screen reader support
|
38
|
+
* - Set `grabber-btn-aria-label` to provide accessible labels for the expand/collapse grabber button
|
39
|
+
*
|
40
|
+
* @dependency mdc-text
|
41
|
+
* @dependency mdc-button
|
42
|
+
* @dependency mdc-divider
|
43
|
+
*
|
44
|
+
* @event activechange - (React: onActiveChange) Dispatched when the active state of the navitem changes.
|
45
|
+
*
|
46
|
+
* @tagname mdc-sidenavigation
|
47
|
+
*
|
48
|
+
* @slot scrollable-section - Slot for the scrollable content area of the side navigation.
|
49
|
+
* @slot fixed-section - Slot for the fixed content area of the side navigation.
|
50
|
+
* @slot brand-logo - Slot for the brand logo (e.g., icon or img).
|
51
|
+
*
|
52
|
+
* @cssproperty --mdc-sidenavigation-expanded-width - width of the sideNavigation when expanded
|
53
|
+
* @cssproperty --mdc-sidenavigation-collapsed-width - width of the sideNavigation when collpased
|
54
|
+
*/
|
55
|
+
declare class SideNavigation extends Provider<SideNavigationContext> {
|
56
|
+
constructor();
|
57
|
+
connectedCallback(): void;
|
58
|
+
static get Context(): {
|
59
|
+
__context__: SideNavigationContext;
|
60
|
+
};
|
61
|
+
/**
|
62
|
+
* Four variants of the sideNavigation
|
63
|
+
* - **fixed-collapsed**: Shows icons without labels and has fixed width, 4.5rem.
|
64
|
+
* - **fixed-expanded**: Shows icons with labels and has fixed width, 15rem.
|
65
|
+
* - **flexible**: Toggles between collapsed/expanded states.
|
66
|
+
* - **hidden**: Removes the sidenavigation from the DOM.
|
67
|
+
* @default flexible
|
68
|
+
*/
|
69
|
+
variant: SideNavigationVariant;
|
70
|
+
/**
|
71
|
+
* Name of the customer. This is displayed in the bottom section of the side-navigation component.
|
72
|
+
* @default ''
|
73
|
+
*/
|
74
|
+
customerName: string;
|
75
|
+
/**
|
76
|
+
* Determines whether the sideNavigation is expanded or not.
|
77
|
+
*
|
78
|
+
* @internal
|
79
|
+
*/
|
80
|
+
expanded?: boolean;
|
81
|
+
/**
|
82
|
+
* Provides an accessible label for the grabber button.
|
83
|
+
* This value is used to set the `aria-label` attribute for the button.
|
84
|
+
*
|
85
|
+
* @default ''
|
86
|
+
*/
|
87
|
+
grabberBtnAriaLabel?: string;
|
88
|
+
/**
|
89
|
+
* Tooltip text shown on parent nav items when a child is active.
|
90
|
+
*/
|
91
|
+
parentNavTooltipText?: string;
|
92
|
+
/**
|
93
|
+
* Toggles between true and false when it's variant is flexible.
|
94
|
+
* @default true
|
95
|
+
*
|
96
|
+
* @internal
|
97
|
+
*/
|
98
|
+
private flexibleExpanded;
|
99
|
+
/**
|
100
|
+
* Direction of the arrow icon, if applicable.
|
101
|
+
* - **positive**
|
102
|
+
* - **negative**
|
103
|
+
*
|
104
|
+
* Note: Positive and Negative directions are defined based on Cartesian plane.
|
105
|
+
* @default 'negative'
|
106
|
+
*
|
107
|
+
* @internal
|
108
|
+
*/
|
109
|
+
private arrowDirection;
|
110
|
+
protected updated(changedProperties: Map<string, any>): void;
|
111
|
+
/**
|
112
|
+
* Update all observing components of this
|
113
|
+
* provider to update the values
|
114
|
+
*
|
115
|
+
* Is called on every re-render, see Provider class
|
116
|
+
*/
|
117
|
+
protected updateContext(): void;
|
118
|
+
/**
|
119
|
+
* Syncs `expanded` and `aria-expanded` based on `variant` and `flexibleExpanded`.
|
120
|
+
*
|
121
|
+
* @internal
|
122
|
+
*/
|
123
|
+
private updateExpansionState;
|
124
|
+
/**
|
125
|
+
* Sets the variant attribute for the sideNavigation component.
|
126
|
+
* If the provided variant is not included in the variant,
|
127
|
+
* it defaults to the value specified in DEFAULTS.VARIANT.
|
128
|
+
*
|
129
|
+
* @param variant - The variant to set.
|
130
|
+
*
|
131
|
+
* @internal
|
132
|
+
*/
|
133
|
+
private setVariant;
|
134
|
+
/**
|
135
|
+
* Toggles navigation state for the flexible variant.
|
136
|
+
* Updates `flexibleExpanded`, `ariaExpanded`, and `arrowDirection`.
|
137
|
+
*
|
138
|
+
* @internal
|
139
|
+
*/
|
140
|
+
private toggleSideNavigation;
|
141
|
+
render(): import("lit-html").TemplateResult<1>;
|
142
|
+
static styles: Array<CSSResult>;
|
143
|
+
}
|
144
|
+
export default SideNavigation;
|
@@ -0,0 +1,244 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html, nothing } from 'lit';
|
11
|
+
import { property, state } from 'lit/decorators.js';
|
12
|
+
import styles from './sidenavigation.styles';
|
13
|
+
import { Component, Provider } from '../../models';
|
14
|
+
import SideNavigationContext from './sidenavigation.context';
|
15
|
+
import { DEFAULTS, VARIANTS } from './sidenavigation.constants';
|
16
|
+
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
17
|
+
import { DIRECTIONS, DIVIDER_VARIANT, DIVIDER_ORIENTATION } from '../divider/divider.constants';
|
18
|
+
import { ROLE } from '../../utils/roles';
|
19
|
+
/**
|
20
|
+
* The `mdc-sidenavigation` component provides a vertically stacked navigation experience,
|
21
|
+
* typically used in layouts with persistent or collapsible sidebars.
|
22
|
+
*
|
23
|
+
* ## Features:
|
24
|
+
* - Supports four layout variants: `fixed-collapsed`, `fixed-expanded`, `flexible`, and `hidden`
|
25
|
+
* - Toggleable expand/collapse behavior
|
26
|
+
* - Displays brand logo and customer name
|
27
|
+
* - Serves as a context provider for descendant components - `mdc-navitemlist` and `mdc-navitem`
|
28
|
+
*
|
29
|
+
* ### Usage:
|
30
|
+
* In a sidenavigation, navitems can be used in the following ways:
|
31
|
+
*
|
32
|
+
* 1. **Simple navitem** – No submenu or interaction beyond selection.
|
33
|
+
*
|
34
|
+
* 2. **Navitem with submenu**:
|
35
|
+
* - Provide an `id` on the `mdc-navitem`
|
36
|
+
* - Set the `triggerId` on the corresponding `mdc-menupopover` to match the navitem's `id`
|
37
|
+
* - Set `parent-nav-tooltip-text` with appropriate text that will display when a child menu item
|
38
|
+
* inside the nested menupopover is active, conveying which submenu item is currently selected
|
39
|
+
*
|
40
|
+
* 3. **Actionable navitem (no submenu)**:
|
41
|
+
* - Performs an action such as navigation or alert trigger
|
42
|
+
* - Set `disable-aria-current="true"` to maintain visual active state without navigation behavior
|
43
|
+
*
|
44
|
+
* ### Recommendations:
|
45
|
+
* - Use `mdc-text` for section headers
|
46
|
+
* - Use `mdc-divider` with the attribute `variant="gradient"` for section dividers
|
47
|
+
* - For the brand logo, use an informative icon. Refer to `Momentum Informative Icons`
|
48
|
+
*
|
49
|
+
* #### Accessibility Notes:
|
50
|
+
* - Always provide meaningful `aria-label` attributes for both `mdc-navitem` and `mdc-navitemlist`
|
51
|
+
* to ensure screen reader support
|
52
|
+
* - Set `grabber-btn-aria-label` to provide accessible labels for the expand/collapse grabber button
|
53
|
+
*
|
54
|
+
* @dependency mdc-text
|
55
|
+
* @dependency mdc-button
|
56
|
+
* @dependency mdc-divider
|
57
|
+
*
|
58
|
+
* @event activechange - (React: onActiveChange) Dispatched when the active state of the navitem changes.
|
59
|
+
*
|
60
|
+
* @tagname mdc-sidenavigation
|
61
|
+
*
|
62
|
+
* @slot scrollable-section - Slot for the scrollable content area of the side navigation.
|
63
|
+
* @slot fixed-section - Slot for the fixed content area of the side navigation.
|
64
|
+
* @slot brand-logo - Slot for the brand logo (e.g., icon or img).
|
65
|
+
*
|
66
|
+
* @cssproperty --mdc-sidenavigation-expanded-width - width of the sideNavigation when expanded
|
67
|
+
* @cssproperty --mdc-sidenavigation-collapsed-width - width of the sideNavigation when collpased
|
68
|
+
*/
|
69
|
+
class SideNavigation extends Provider {
|
70
|
+
constructor() {
|
71
|
+
super({
|
72
|
+
context: SideNavigationContext.context,
|
73
|
+
initialValue: new SideNavigationContext(DEFAULTS.VARIANT, true),
|
74
|
+
});
|
75
|
+
/**
|
76
|
+
* Four variants of the sideNavigation
|
77
|
+
* - **fixed-collapsed**: Shows icons without labels and has fixed width, 4.5rem.
|
78
|
+
* - **fixed-expanded**: Shows icons with labels and has fixed width, 15rem.
|
79
|
+
* - **flexible**: Toggles between collapsed/expanded states.
|
80
|
+
* - **hidden**: Removes the sidenavigation from the DOM.
|
81
|
+
* @default flexible
|
82
|
+
*/
|
83
|
+
this.variant = DEFAULTS.VARIANT;
|
84
|
+
/**
|
85
|
+
* Name of the customer. This is displayed in the bottom section of the side-navigation component.
|
86
|
+
* @default ''
|
87
|
+
*/
|
88
|
+
this.customerName = '';
|
89
|
+
/**
|
90
|
+
* Toggles between true and false when it's variant is flexible.
|
91
|
+
* @default true
|
92
|
+
*
|
93
|
+
* @internal
|
94
|
+
*/
|
95
|
+
this.flexibleExpanded = this.variant === DEFAULTS.VARIANT;
|
96
|
+
/**
|
97
|
+
* Direction of the arrow icon, if applicable.
|
98
|
+
* - **positive**
|
99
|
+
* - **negative**
|
100
|
+
*
|
101
|
+
* Note: Positive and Negative directions are defined based on Cartesian plane.
|
102
|
+
* @default 'negative'
|
103
|
+
*
|
104
|
+
* @internal
|
105
|
+
*/
|
106
|
+
this.arrowDirection = this.flexibleExpanded ? DIRECTIONS.NEGATIVE : DIRECTIONS.POSITIVE;
|
107
|
+
/**
|
108
|
+
* Syncs `expanded` and `aria-expanded` based on `variant` and `flexibleExpanded`.
|
109
|
+
*
|
110
|
+
* @internal
|
111
|
+
*/
|
112
|
+
this.updateExpansionState = () => {
|
113
|
+
switch (this.variant) {
|
114
|
+
case VARIANTS.FLEXIBLE:
|
115
|
+
this.expanded = this.flexibleExpanded;
|
116
|
+
break;
|
117
|
+
case VARIANTS.FIXED_EXPANDED:
|
118
|
+
this.expanded = true;
|
119
|
+
break;
|
120
|
+
case VARIANTS.FIXED_COLLAPSED:
|
121
|
+
this.expanded = false;
|
122
|
+
break;
|
123
|
+
default:
|
124
|
+
}
|
125
|
+
};
|
126
|
+
}
|
127
|
+
connectedCallback() {
|
128
|
+
super.connectedCallback();
|
129
|
+
this.role = ROLE.NAVIGATION;
|
130
|
+
}
|
131
|
+
static get Context() {
|
132
|
+
return SideNavigationContext.context;
|
133
|
+
}
|
134
|
+
updated(changedProperties) {
|
135
|
+
super.updated(changedProperties);
|
136
|
+
if (changedProperties.has('variant')) {
|
137
|
+
this.setVariant(this.variant);
|
138
|
+
this.updateExpansionState();
|
139
|
+
}
|
140
|
+
if (changedProperties.has('variant') || changedProperties.has('expanded')) {
|
141
|
+
this.updateContext();
|
142
|
+
}
|
143
|
+
}
|
144
|
+
/**
|
145
|
+
* Update all observing components of this
|
146
|
+
* provider to update the values
|
147
|
+
*
|
148
|
+
* Is called on every re-render, see Provider class
|
149
|
+
*/
|
150
|
+
updateContext() {
|
151
|
+
if (this.context.value.variant !== this.variant
|
152
|
+
|| this.context.value.expanded !== this.expanded
|
153
|
+
|| this.context.value.parentNavTooltipText !== this.parentNavTooltipText) {
|
154
|
+
this.context.value.variant = this.variant;
|
155
|
+
this.context.value.expanded = this.expanded;
|
156
|
+
this.context.value.parentNavTooltipText = this.parentNavTooltipText;
|
157
|
+
this.context.updateObservers();
|
158
|
+
}
|
159
|
+
}
|
160
|
+
/**
|
161
|
+
* Sets the variant attribute for the sideNavigation component.
|
162
|
+
* If the provided variant is not included in the variant,
|
163
|
+
* it defaults to the value specified in DEFAULTS.VARIANT.
|
164
|
+
*
|
165
|
+
* @param variant - The variant to set.
|
166
|
+
*
|
167
|
+
* @internal
|
168
|
+
*/
|
169
|
+
setVariant(variant) {
|
170
|
+
this.setAttribute('variant', Object.values(VARIANTS).includes(variant) ? variant : DEFAULTS.VARIANT);
|
171
|
+
}
|
172
|
+
/**
|
173
|
+
* Toggles navigation state for the flexible variant.
|
174
|
+
* Updates `flexibleExpanded`, `ariaExpanded`, and `arrowDirection`.
|
175
|
+
*
|
176
|
+
* @internal
|
177
|
+
*/
|
178
|
+
toggleSideNavigation() {
|
179
|
+
this.flexibleExpanded = !this.flexibleExpanded;
|
180
|
+
this.arrowDirection = this.arrowDirection === DIRECTIONS.NEGATIVE ? DIRECTIONS.POSITIVE : DIRECTIONS.NEGATIVE;
|
181
|
+
this.updateExpansionState();
|
182
|
+
}
|
183
|
+
render() {
|
184
|
+
var _a;
|
185
|
+
if (this.variant === VARIANTS.HIDDEN) {
|
186
|
+
return html ``;
|
187
|
+
}
|
188
|
+
return html `
|
189
|
+
<div part="side-navigation-container" id='side-nav-container'>
|
190
|
+
<div part="scrollable-section">
|
191
|
+
<slot name="scrollable-section"></slot>
|
192
|
+
</div>
|
193
|
+
<mdc-divider variant="gradient" part="separator"></mdc-divider>
|
194
|
+
<div part="fixed-section">
|
195
|
+
<slot name="fixed-section"></slot>
|
196
|
+
<div part="brand-logo-container">
|
197
|
+
<slot name="brand-logo"></slot>
|
198
|
+
${this.expanded ? html `<mdc-text type=${TYPE.BODY_MIDSIZE_MEDIUM} tagname=${VALID_TEXT_TAGS.SPAN}
|
199
|
+
part="label">${this.customerName}</mdc-text>` : nothing}
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
</div>
|
203
|
+
${this.variant === VARIANTS.FLEXIBLE ? html `<mdc-divider
|
204
|
+
orientation=${DIVIDER_ORIENTATION.VERTICAL}
|
205
|
+
variant=${DIVIDER_VARIANT.GRADIENT}
|
206
|
+
arrow-direction=${this.arrowDirection}
|
207
|
+
button-position=${DIRECTIONS.POSITIVE}
|
208
|
+
> <mdc-button aria-label=${(_a = this.grabberBtnAriaLabel) !== null && _a !== void 0 ? _a : ''} @click=${this.toggleSideNavigation}
|
209
|
+
aria-expanded="${!!this.expanded}" aria-controls='side-nav-container'
|
210
|
+
part="grabber-btn"></mdc-button>
|
211
|
+
</mdc-divider>` : nothing}
|
212
|
+
`;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
SideNavigation.styles = [...Component.styles, ...styles];
|
216
|
+
__decorate([
|
217
|
+
property({ type: String, reflect: true }),
|
218
|
+
__metadata("design:type", String)
|
219
|
+
], SideNavigation.prototype, "variant", void 0);
|
220
|
+
__decorate([
|
221
|
+
property({ type: String, reflect: true, attribute: 'customer-name' }),
|
222
|
+
__metadata("design:type", String)
|
223
|
+
], SideNavigation.prototype, "customerName", void 0);
|
224
|
+
__decorate([
|
225
|
+
property({ type: Boolean, reflect: true }),
|
226
|
+
__metadata("design:type", Boolean)
|
227
|
+
], SideNavigation.prototype, "expanded", void 0);
|
228
|
+
__decorate([
|
229
|
+
property({ type: String, reflect: true, attribute: 'grabber-btn-aria-label' }),
|
230
|
+
__metadata("design:type", String)
|
231
|
+
], SideNavigation.prototype, "grabberBtnAriaLabel", void 0);
|
232
|
+
__decorate([
|
233
|
+
property({ type: String, reflect: true, attribute: 'parent-nav-tooltip-text' }),
|
234
|
+
__metadata("design:type", String)
|
235
|
+
], SideNavigation.prototype, "parentNavTooltipText", void 0);
|
236
|
+
__decorate([
|
237
|
+
state(),
|
238
|
+
__metadata("design:type", Object)
|
239
|
+
], SideNavigation.prototype, "flexibleExpanded", void 0);
|
240
|
+
__decorate([
|
241
|
+
state(),
|
242
|
+
__metadata("design:type", String)
|
243
|
+
], SideNavigation.prototype, "arrowDirection", void 0);
|
244
|
+
export default SideNavigation;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
declare const TAG_NAME: "mdc-sidenavigation";
|
2
|
+
declare const VARIANTS: {
|
3
|
+
FIXED_EXPANDED: string;
|
4
|
+
FIXED_COLLAPSED: string;
|
5
|
+
FLEXIBLE: string;
|
6
|
+
HIDDEN: string;
|
7
|
+
};
|
8
|
+
declare const DEFAULTS: {
|
9
|
+
readonly VARIANT: string;
|
10
|
+
};
|
11
|
+
export { DEFAULTS, VARIANTS, TAG_NAME };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import utils from '../../utils/tag-name';
|
2
|
+
const TAG_NAME = utils.constructTagName('sidenavigation');
|
3
|
+
const VARIANTS = {
|
4
|
+
FIXED_EXPANDED: 'fixed-expanded',
|
5
|
+
FIXED_COLLAPSED: 'fixed-collapsed',
|
6
|
+
FLEXIBLE: 'flexible',
|
7
|
+
HIDDEN: 'hidden',
|
8
|
+
};
|
9
|
+
const DEFAULTS = {
|
10
|
+
VARIANT: VARIANTS.FLEXIBLE,
|
11
|
+
};
|
12
|
+
export { DEFAULTS, VARIANTS, TAG_NAME };
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type NavItem from '../navitem/navitem.component';
|
2
|
+
declare class SideNavigationContext {
|
3
|
+
variant?: string;
|
4
|
+
expanded?: boolean;
|
5
|
+
private currentActiveNavItem?;
|
6
|
+
parentNavTooltipText?: string;
|
7
|
+
static context: {
|
8
|
+
__context__: SideNavigationContext;
|
9
|
+
};
|
10
|
+
constructor(defaultVariant?: string, defaultExpanded?: boolean, defaultParentNavTooltipText?: string);
|
11
|
+
hasSiblingWithTriggerId(navItem: NavItem | undefined): boolean;
|
12
|
+
private getParentNavItems;
|
13
|
+
setCurrentActiveNavItem(navItem: NavItem | undefined): void;
|
14
|
+
}
|
15
|
+
export default SideNavigationContext;
|