@trimble-oss/moduswebcomponents
Version:
Modus Web Components is a modern, accessible UI library built with Stencil JS that provides reusable web components following Trimble's Modus design system. This updated version focuses on improved flexibility, enhanced theming options, comprehensive cust
122 lines (116 loc) • 5.92 kB
JavaScript
import { p as proxyCustomElement, H, e as createEvent, h, c as Host } from './p-BMvVSi6Y.js';
import { i as inheritAriaAttributes } from './p-COxr4v9W.js';
const convertPropsToClasses = ({ expanded, }) => {
let classes = '';
if (expanded) {
classes = `${classes} modus-wc-side-navigation-expanded`;
}
return classes.trim();
};
const modusWcSideNavigationCss = "modus-wc-side-navigation{display:block;height:100vh;position:relative}modus-wc-side-navigation .modus-wc-side-navigation{background:var(--modus-wc-color-white);box-shadow:rgba(36, 35, 45, 0.3) 1px 0 4px;color:var(--modus-wc-color-trimble-gray);display:flex;flex-direction:column;flex-shrink:0;height:100%;max-height:100vh;min-height:0;overflow:hidden;overflow-y:auto;position:absolute;transition:width 0.2s ease-out;z-index:999}modus-wc-side-navigation .side-navigation-content{background:var(--modus-wc-color-white);color:var(--modus-wc-color-trimble-gray);flex:1 1 auto}[data-theme=modus-classic-dark] modus-wc-side-navigation .side-navigation-content,[data-theme=modus-modern-dark] modus-wc-side-navigation .side-navigation-content{background:var(--modus-wc-color-gray-10);color:var(--modus-wc-color-white)}";
const ModusWcSideNavigation$1 = /*@__PURE__*/ proxyCustomElement(class ModusWcSideNavigation extends H {
constructor() {
super();
this.__registerHost();
this.expandedChange = createEvent(this, "expandedChange");
this.inheritedAttributes = {};
this.minWidth = '4rem';
/** Whether the side navigation should collapse when clicking outside of it. */
this.collapseOnClickOutside = true;
/** Custom CSS class to apply to the inner div. */
this.customClass = '';
/** Whether the side navigation is expanded. */
this.expanded = false;
/** Maximum width of the side navigation panel in an expanded state. */
this.maxWidth = '256px';
/** Mode to make side navigation either overlay or push the content for the selector specified in targetContent */
this.mode = 'overlay';
/** (optional) Specify the selector for the page's content for which paddings and margins will be set by side navigation based on the mode. */
this.targetContent = '';
this.handleClickOutside = (event) => {
if (!this.expanded || !this.collapseOnClickOutside || !this.navRef)
return;
const path = event.composedPath ? event.composedPath() : [event.target];
if (!path.includes(this.navRef)) {
this.expanded = false;
}
};
}
handleExpandedChange() {
this.setTargetContentMargin(this.expanded, this.mode, this.targetContent);
this.expandedChange.emit(this.expanded);
}
handleModeChange(mode) {
this.setTargetContentMargin(this.expanded, mode, this.targetContent);
}
handleTargetContentChange(target) {
this.setTargetContentMargin(this.expanded, this.mode, target);
}
componentWillLoad() {
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
connectedCallback() {
if (this.collapseOnClickOutside) {
document.addEventListener('click', this.handleClickOutside, true);
}
}
disconnectedCallback() {
document.removeEventListener('click', this.handleClickOutside, true);
}
getClasses() {
const classList = ['modus-wc-side-navigation'];
const propClasses = convertPropsToClasses({
expanded: this.expanded,
});
// The order CSS classes are added matters to CSS specificity
if (propClasses)
classList.push(propClasses);
if (this.customClass)
classList.push(this.customClass);
return classList.join(' ');
}
setTargetContentMargin(isExpanded, mode, target) {
const content = document.querySelector(target);
if (content && 'style' in content) {
content.style.marginLeft =
isExpanded && mode === 'push' ? this.maxWidth : this.minWidth;
}
}
render() {
return (h(Host, { key: '6bce6f85c55103144d1afeec06f484cc9babb6e6' }, h("nav", Object.assign({ key: 'cb621050963ab5b06053ca2a37cf0af495b75571' }, this.inheritedAttributes, { class: this.getClasses(), ref: (el) => (this.navRef = el), style: { width: this.expanded ? this.maxWidth : this.minWidth } }), h("div", { key: '49a2fead0e7231c45928e8d1b995bd8c47851955', class: "side-navigation-content" }, h("slot", { key: 'b53246d439a92e9e8354ef2ca5619dc3bd002b06' })))));
}
get el() { return this; }
static get watchers() { return {
"expanded": ["handleExpandedChange"],
"mode": ["handleModeChange"],
"targetContent": ["handleTargetContentChange"]
}; }
static get style() { return modusWcSideNavigationCss; }
}, [4, "modus-wc-side-navigation", {
"collapseOnClickOutside": [4, "collapse-on-click-outside"],
"customClass": [1, "custom-class"],
"expanded": [1540],
"maxWidth": [1, "max-width"],
"mode": [1],
"targetContent": [1, "target-content"]
}, undefined, {
"expanded": ["handleExpandedChange"],
"mode": ["handleModeChange"],
"targetContent": ["handleTargetContentChange"]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["modus-wc-side-navigation"];
components.forEach(tagName => { switch (tagName) {
case "modus-wc-side-navigation":
if (!customElements.get(tagName)) {
customElements.define(tagName, ModusWcSideNavigation$1);
}
break;
} });
}
const ModusWcSideNavigation = ModusWcSideNavigation$1;
const defineCustomElement = defineCustomElement$1;
export { ModusWcSideNavigation, defineCustomElement };