UNPKG

@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

151 lines (150 loc) 5.73 kB
import { h, Host } from "@stencil/core"; import { convertPropsToClasses } from "./modus-wc-side-navigation.tailwind"; import { inheritAriaAttributes } from "../utils"; /** * A customizable side navigation component for organizing primary navigation and content areas in an application. */ export class ModusWcSideNavigation { constructor() { 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'; 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; } }; } 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(' '); } render() { return (h(Host, { key: 'ae2bb252f4337e4724ef6fb131d6e8704a2005fe' }, h("nav", Object.assign({ key: '4a24b5ac6bf92dd1022403655adc821f37a836e0' }, this.inheritedAttributes, { class: this.getClasses(), ref: (el) => (this.navRef = el), style: { width: this.expanded ? this.maxWidth : this.minWidth } }), h("div", { key: '6663c0731510e0797ecc24784a09fe202e687e1b', class: "side-navigation-content" }, h("slot", { key: '0eea5a1c5bb3c34e0499fd3829e2284ff00b807c' }))))); } static get is() { return "modus-wc-side-navigation"; } static get originalStyleUrls() { return { "$": ["modus-wc-side-navigation.scss"] }; } static get styleUrls() { return { "$": ["modus-wc-side-navigation.css"] }; } static get properties() { return { "collapseOnClickOutside": { "type": "boolean", "attribute": "collapse-on-click-outside", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Whether the side navigation should collapse when clicking outside of it." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "true" }, "customClass": { "type": "string", "attribute": "custom-class", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Custom CSS class to apply to the inner div." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "''" }, "expanded": { "type": "boolean", "attribute": "expanded", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Whether the side navigation is expanded." }, "getter": false, "setter": false, "reflect": true, "defaultValue": "false" }, "maxWidth": { "type": "string", "attribute": "max-width", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Maximum width of the side navigation panel in an expanded state." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "'256px'" } }; } static get elementRef() { return "el"; } }