@nysds/nys-breadcrumbs 1.19.2 → 1.19.4
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/nys-breadcrumbs.js
CHANGED
|
@@ -5,7 +5,7 @@ import { property as d } from "lit/decorators.js";
|
|
|
5
5
|
* █ █ █ █▄▄▄█ ▀▀▀▄▄ █ █ ▀▀▀▄▄
|
|
6
6
|
* █ ▀█ █ █▄▄▄█ █▄▄▀ █▄▄▄█
|
|
7
7
|
*
|
|
8
|
-
* Breadcrumbs Component v1.19.
|
|
8
|
+
* Breadcrumbs Component v1.19.4
|
|
9
9
|
* Part of the New York State Design System
|
|
10
10
|
* Repository: https://github.com/its-hcd/nysds
|
|
11
11
|
* License: MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nys-breadcrumbs.js","sources":["../src/nys-breadcrumbs.ts"],"sourcesContent":["import { LitElement, html, unsafeCSS } from \"lit\";\nimport { property } from \"lit/decorators.js\";\n// @ts-ignore: SCSS module imported via bundler as inline\nimport styles from \"./nys-breadcrumbs.scss?inline\";\n\nlet componentIdCounter = 0;\n\n/**\n * A breadcrumb navigation trail composed of `nys-breadcrumbitem` elements.\n * Collapses when the trail exceeds 5 items on desktop or 3 items on mobile,\n * showing the first, last, and item before the current page, with an ellipsis to expand.\n * A single item renders as a back-to-parent link instead of a trail.\n *\n * @summary Breadcrumb navigation trail with responsive collapse support.\n * @element nys-breadcrumbs\n *\n * @slot - One or more `nys-breadcrumbitem` elements defining the trail.\n *\n * @fires nys-breadcrumbs-expand - Fired when the user clicks the ellipsis to expand the trail.\n *\n * @example Full trail with current page\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/services\">Services</a></li>\n * <li>Current Page</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Trail without current page\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/services\">Services</a></li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Single item renders as back-to-parent\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/services\">Services</a></li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n */\n\nexport class NysBreadcrumbs extends LitElement {\n static styles = unsafeCSS(styles);\n\n /**\n * Unique identifier. Auto-generated if not provided.\n */\n @property({ type: String, reflect: true }) id = \"\";\n\n /**\n * Accessible label for the `<nav>` landmark. Defaults to \"path to this page\" if not set.\n * Override when multiple crumbs exist on the same page.\n */\n @property({ type: String }) ariaLabel = \"\";\n\n /**\n * Controls the visual size of the breadcrumb text and spacing: `sm` for dense layouts, `md` (default) for standard use.\n * @default \"md\"\n */\n @property({ type: String, reflect: true }) size: \"sm\" | \"md\" | \"\" = \"md\";\n\n /**\n * On mobile, renders the trail as a single back-to-parent link pointing to the item before the current page.\n * Has no effect on desktop or when only one item is present (which always renders as a back link).\n * @default false\n */\n @property({ type: Boolean }) backToParent = false;\n\n /**\n * Forces the trail into its collapsed state.\n * It shows only the first item, an ellipsis, and the last two items.\n * The user can still expand the trail by clicking the ellipsis.\n * @default false\n */\n @property({ type: Boolean }) collapsed = false;\n\n /**\n * Renders a filled light theme background bar behind the breadcrumb trail.\n * @default false\n */\n @property({ type: Boolean }) backgroundBar = false;\n\n /**\n * Prevents interaction.\n * @default false\n */\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n private _collapseThreshold = 5; // default for desktop\n private _manuallyExpanded = false;\n private _mediaQuery: MediaQueryList | null = null;\n\n /**\n * Lifecycle methods\n * --------------------------------------------------------------------------\n */\n\n constructor() {\n super();\n }\n\n // Generate a unique ID if one is not provided\n connectedCallback() {\n super.connectedCallback();\n if (!this.id) {\n this.id = `nys-breadcrumbs-${Date.now()}-${componentIdCounter++}`;\n }\n\n this._mediaQuery = window.matchMedia(\"(max-width: 767px)\");\n this._mediaQuery.addEventListener(\"change\", this._updateCollapseThreshold);\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this._mediaQuery?.removeEventListener(\n \"change\",\n this._updateCollapseThreshold,\n );\n this._mediaQuery = null;\n }\n\n firstUpdated() {\n this._handleSlotChange();\n }\n\n updated(changedProperties: Map<string | number | symbol, unknown>) {\n if (\n changedProperties.has(\"collapsed\") ||\n changedProperties.has(\"backToParent\") ||\n changedProperties.has(\"disabled\")\n ) {\n this._handleSlotChange();\n }\n }\n\n /**\n * Functions\n * --------------------------------------------------------------------------\n */\n\n private _updateCollapseThreshold = () => {\n const isMobile = this._mediaQuery?.matches ?? window.innerWidth < 768; // NYSDS sets anything below 768px as mobile. Desktop and Tablet is above 768px.\n const newThreshold = isMobile ? 3 : 5;\n\n if (newThreshold !== this._collapseThreshold) {\n this._collapseThreshold = newThreshold;\n this._manuallyExpanded = false;\n this._handleSlotChange();\n }\n };\n\n private _getSlottedOl(): HTMLOListElement | null {\n const slot = this.shadowRoot?.querySelector(\n \"slot\",\n ) as HTMLSlotElement | null;\n const assigned = slot?.assignedElements({ flatten: true }) ?? [];\n return (\n (assigned.find((el) => el.tagName === \"OL\") as HTMLOListElement) ?? null\n );\n }\n\n private _getSlottedItems(): HTMLLIElement[] {\n const ol = this._getSlottedOl();\n if (!ol) return [];\n return Array.from(ol.children).filter(\n (el) => el.tagName === \"LI\",\n ) as HTMLLIElement[];\n }\n\n private _getAnchor(li: HTMLLIElement): HTMLAnchorElement | null {\n return li.querySelector(\"a\");\n }\n\n private _isCurrentPage(li: HTMLLIElement): boolean {\n const a = this._getAnchor(li);\n if (!a) return true;\n return false;\n }\n\n private _createBackToParentElement(li: HTMLLIElement) {\n const anchor = this._getAnchor(li);\n const link = anchor?.getAttribute(\"href\") ?? \"\";\n const label = anchor?.textContent?.trim() ?? li.textContent?.trim() ?? \"\";\n\n const liEL = document.createElement(\"li\");\n liEL.className = \"nys-breadcrumbitem\";\n\n const icon = document.createElement(\"nys-icon\");\n icon.setAttribute(\"name\", \"arrow_back\");\n icon.setAttribute(\"size\", \"16\");\n\n const a = document.createElement(\"a\");\n if (!this.disabled) {\n a.href = link;\n }\n a.textContent = label;\n if (this.disabled) {\n a.setAttribute(\"aria-disabled\", \"true\");\n }\n\n liEL.appendChild(icon);\n liEL.appendChild(a);\n\n return liEL;\n }\n\n private _createCrumbElement(li: HTMLLIElement, isCurrentPage: boolean) {\n const anchor = this._getAnchor(li);\n const link = anchor?.getAttribute(\"href\") ?? \"\";\n const label = anchor?.textContent?.trim() ?? li.textContent?.trim() ?? \"\";\n\n const liEl = document.createElement(\"li\");\n liEl.className = \"nys-breadcrumbitem\";\n\n if (isCurrentPage) {\n liEl.textContent = label;\n liEl.setAttribute(\"aria-current\", \"page\");\n return liEl;\n }\n\n const a = document.createElement(\"a\");\n if (!this.disabled) {\n a.href = link;\n }\n a.textContent = label;\n if (this.disabled) {\n a.setAttribute(\"aria-disabled\", \"true\");\n }\n\n const icon = document.createElement(\"nys-icon\");\n icon.setAttribute(\"name\", \"chevron_right\");\n icon.setAttribute(\"size\", \"14\");\n\n liEl.appendChild(a);\n liEl.appendChild(icon);\n return liEl;\n }\n\n /**\n * Main logic for cloning and handling user slots.\n * New <ol>, <li>, and <a> tags are created and rendered out as crumbs for the breadcrumbs trail.\n */\n private _handleSlotChange() {\n const isMobile = this._mediaQuery?.matches ?? window.innerWidth < 768;\n const ol = this.shadowRoot?.getElementById(\"crumb-list\");\n if (!ol) return;\n\n const items = this._getSlottedItems();\n if (items.length === 0) return;\n\n ol.innerHTML = \"\";\n\n // ---------------------------------------------------------\n\n const setCrumbAsBackToParentBtn = (index = 0) => {\n const clone = items[index].cloneNode(true) as HTMLLIElement;\n\n const backToParentBtn = this._createBackToParentElement(clone);\n ol.appendChild(backToParentBtn);\n };\n\n // Single breadcrumb item OR backToParent=true for mobile - render as backToParent button\n if (items.length === 1) {\n setCrumbAsBackToParentBtn();\n return;\n }\n\n if (isMobile && this.backToParent) {\n const currentPageExist = this._isCurrentPage(items[items.length - 1]);\n\n if (currentPageExist) {\n setCrumbAsBackToParentBtn(items.length - 2);\n } else {\n setCrumbAsBackToParentBtn(items.length - 1);\n }\n return;\n }\n\n // ---------------------------------------------------------\n const shouldAutoCollapse =\n !this._manuallyExpanded && items.length > this._collapseThreshold;\n const collapseTrail = this.collapsed || shouldAutoCollapse;\n\n const lastItem = items[items.length - 1];\n const hasCurrentPage = this._isCurrentPage(lastItem);\n const itemsBeforeCollapse = Math.min(1, items.length - 1);\n const itemsAfterCollapse = Math.min(\n hasCurrentPage ? 2 : 1,\n items.length - itemsBeforeCollapse,\n );\n\n // Normal multi-item breadcrumb trail\n items.forEach((crumb, index) => {\n const crumbIsBeforeCollapse = index < itemsBeforeCollapse;\n const crumbIsAfterCollapse = index >= items.length - itemsAfterCollapse;\n const isAlwaysVisible = crumbIsBeforeCollapse || crumbIsAfterCollapse;\n const shouldHide = collapseTrail && !isAlwaysVisible; // Determines which of the crumbs is hidden\n\n const liEl = this._createCrumbElement(crumb, this._isCurrentPage(crumb));\n liEl.setAttribute(\"data-cloned\", \"true\");\n\n if (shouldHide) {\n liEl.classList.add(\"hide\");\n }\n\n if (!isAlwaysVisible) {\n // Assigning which crumb is an intermediate item (aka hidable) allows us to later redirect focus on the first of these intermediates.\n liEl.classList.add(\"intermediate\");\n }\n\n ol.appendChild(liEl);\n\n // Insert ellipsis before the first hidden cloned item when collapsed\n if (\n index === itemsBeforeCollapse - 1 &&\n collapseTrail &&\n items.length > 2\n ) {\n const ellipsis = document.createElement(\"li\");\n ellipsis.classList.add(\"nys-breadcrumbs__ellipsis\");\n\n // Ellipse button\n const button = document.createElement(\"a\");\n button.classList.add(\"ellipsis-btn\");\n button.setAttribute(\"aria-label\", \"Show more links\");\n button.setAttribute(\"role\", \"button\");\n button.setAttribute(\"href\", \"#\");\n button.textContent = \"…\";\n\n const expandTrail = (e: Event) => {\n e.preventDefault();\n this._manuallyExpanded = true;\n this.collapsed = false;\n this._handleSlotChange();\n this._dispatchExpandEvent();\n this._moveFocusToFirstExpandCrumb();\n };\n\n button.addEventListener(\"click\", expandTrail);\n button.addEventListener(\"keydown\", (e: KeyboardEvent) => {\n if (e.key === \" \") expandTrail(e);\n });\n\n // Chevron Icon\n const icon = document.createElement(\"nys-icon\");\n icon.setAttribute(\"name\", \"chevron_right\");\n icon.setAttribute(\"size\", \"14\");\n\n ellipsis.appendChild(button);\n ellipsis.appendChild(icon);\n ol.appendChild(ellipsis);\n }\n });\n }\n\n private _moveFocusToFirstExpandCrumb() {\n setTimeout(() => {\n const ol = this.shadowRoot?.getElementById(\"crumb-list\");\n const firstClone = ol?.querySelector(\"li[data-cloned].intermediate\");\n firstClone?.querySelector<HTMLAnchorElement>(\"a\")?.focus();\n }, 0);\n }\n\n /**\n * Event Handlers\n * --------------------------------------------------------------------------\n */\n private _dispatchExpandEvent() {\n this.dispatchEvent(\n new CustomEvent(\"nys-expand\", {\n detail: { id: this.id },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n render() {\n return html`<nav\n class=\"nys-breadcrumbs ${this.backgroundBar\n ? \"nys-breadcrumbs--background-bar\"\n : \"\"}\"\n aria-label=${this.ariaLabel || \"path to this page\"}\n >\n <ol id=\"crumb-list\"></ol>\n <slot style=\"display: none;\" @slotchange=${this._handleSlotChange}></slot>\n </nav>`;\n }\n}\n\nif (!customElements.get(\"nys-breadcrumbs\")) {\n customElements.define(\"nys-breadcrumbs\", NysBreadcrumbs);\n}\n"],"names":["componentIdCounter","_NysBreadcrumbs","LitElement","newThreshold","changedProperties","el","ol","li","anchor","link","label","liEL","icon","a","isCurrentPage","liEl","isMobile","items","setCrumbAsBackToParentBtn","index","clone","backToParentBtn","currentPageExist","shouldAutoCollapse","collapseTrail","lastItem","hasCurrentPage","itemsBeforeCollapse","itemsAfterCollapse","crumb","crumbIsBeforeCollapse","crumbIsAfterCollapse","isAlwaysVisible","shouldHide","ellipsis","button","expandTrail","e","html","unsafeCSS","styles","NysBreadcrumbs","__decorateClass","property"],"mappings":";;;;;;;;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EAAA;AAAA,EAA3CC,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GA7C/BF,EA6CiC,WAAA,UAAA;AAgTzC,eAAe,IAAI,iBAAiB,KACvC,eAAe,OAAO,mBAAmBA,CAAc;"}
|
|
1
|
+
{"version":3,"file":"nys-breadcrumbs.js","sources":["../src/nys-breadcrumbs.ts"],"sourcesContent":["import { LitElement, html, unsafeCSS } from \"lit\";\nimport { property } from \"lit/decorators.js\";\n// @ts-ignore: SCSS module imported via bundler as inline\nimport styles from \"./nys-breadcrumbs.scss?inline\";\n\nlet componentIdCounter = 0;\n\n/**\n * A breadcrumb navigation trail composed of `li` elements.\n * Collapses when the trail exceeds 5 items on desktop or 3 items on mobile,\n * showing the first, last, and item before the current page, with an ellipsis to expand.\n * A single item renders as a back-to-parent link instead of a trail.\n *\n * @summary Breadcrumb navigation trail with responsive collapse support.\n * @element nys-breadcrumbs\n *\n * @slot - One or more `li` elements defining the trail.\n *\n * @fires nys-breadcrumbs-expand - Fired when the user clicks the ellipsis to expand the trail.\n *\n * @example Basic\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/services\">Services</a></li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Current page\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/services\">Services</a></li>\n * <li>Current Page</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Single item list\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/services\">Services</a></li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Long list\n * ```html\n * <nys-breadcrumbs>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/government\">Government</a></li>\n * <li><a href=\"/government/agencies\">Agencies</a></li>\n * <li><a href=\"/government/agencies/parks\">Parks & Recreation</a></li>\n * <li><a href=\"/parks/state-parks\">State Parks</a></li>\n * <li><a href=\"/parks/state-parks/delaware\">Delaware Region</a></li>\n * <li><a href=\"/parks/state-parks/delaware/water-gap\">Delaware Water Gap</a></li>\n * <li>Trail Conditions</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Size small\n * ```html\n * <nys-breadcrumbs size=\"sm\">\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/government\">Government</a></li>\n * <li><a href=\"/government/agencies\">Agencies</a></li>\n * <li>Parks & Recreation</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Back to parent (mobile)\n * ```html\n * <nys-breadcrumbs backToParent>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/government\">Government</a></li>\n * <li><a href=\"/government/agencies\">Agencies</a></li>\n * <li><a href=\"/government/agencies/parks\">Parks & Recreation</a></li>\n * <li><a href=\"/parks/state-parks\">State Parks</a></li>\n * <li><a href=\"/parks/state-parks/delaware\">Delaware Region</a></li>\n * <li><a href=\"/parks/state-parks/delaware/water-gap\">Delaware Water Gap</a></li>\n * <li>Trail Conditions</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Background bar\n * ```html\n * <nys-breadcrumbs backgroundBar>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/services\">Services</a></li>\n * <li><a href=\"/tickets\">Ticket System</a></li>\n * <li>Del Water Gap</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n *\n * @example Disabled\n * ```html\n * <nys-breadcrumbs disabled>\n * <ol>\n * <li><a href=\"/\">Home</a></li>\n * <li><a href=\"/services\">Services</a></li>\n * <li><a href=\"/tickets\">Ticket System</a></li>\n * <li>Del Water Gap</li>\n * </ol>\n * </nys-breadcrumbs>\n * ```\n */\n\nexport class NysBreadcrumbs extends LitElement {\n static styles = unsafeCSS(styles);\n\n /**\n * Unique identifier. Auto-generated if not provided.\n */\n @property({ type: String, reflect: true }) id = \"\";\n\n /**\n * Accessible label for the `<nav>` landmark. Defaults to \"path to this page\" if not set.\n * Override when multiple crumbs exist on the same page.\n */\n @property({ type: String }) ariaLabel = \"\";\n\n /**\n * Controls the visual size of the breadcrumb text and spacing: `sm` for dense layouts, `md` (default) for standard use.\n * @default \"md\"\n */\n @property({ type: String, reflect: true }) size: \"sm\" | \"md\" = \"md\";\n\n /**\n * On mobile, renders the trail as a single back-to-parent link pointing to the item before the current page.\n * Has no effect on desktop or when only one item is present (which always renders as a back link).\n * @default false\n */\n @property({ type: Boolean }) backToParent = false;\n\n /**\n * Forces the trail into its collapsed state.\n * It shows only the first item, an ellipsis, and the last two items.\n * The user can still expand the trail by clicking the ellipsis.\n * @default false\n */\n @property({ type: Boolean }) collapsed = false;\n\n /**\n * Renders a filled light theme background bar behind the breadcrumb trail.\n * @default false\n */\n @property({ type: Boolean }) backgroundBar = false;\n\n /**\n * Prevents interaction.\n * @default false\n */\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n private _collapseThreshold = 5; // default for desktop\n private _manuallyExpanded = false;\n private _mediaQuery: MediaQueryList | null = null;\n\n /**\n * Lifecycle methods\n * --------------------------------------------------------------------------\n */\n\n constructor() {\n super();\n }\n\n // Generate a unique ID if one is not provided\n connectedCallback() {\n super.connectedCallback();\n if (!this.id) {\n this.id = `nys-breadcrumbs-${Date.now()}-${componentIdCounter++}`;\n }\n\n this._mediaQuery = window.matchMedia(\"(max-width: 767px)\");\n this._mediaQuery.addEventListener(\"change\", this._updateCollapseThreshold);\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this._mediaQuery?.removeEventListener(\n \"change\",\n this._updateCollapseThreshold,\n );\n this._mediaQuery = null;\n }\n\n firstUpdated() {\n this._handleSlotChange();\n }\n\n updated(changedProperties: Map<string | number | symbol, unknown>) {\n if (\n changedProperties.has(\"collapsed\") ||\n changedProperties.has(\"backToParent\") ||\n changedProperties.has(\"disabled\")\n ) {\n this._handleSlotChange();\n }\n }\n\n /**\n * Functions\n * --------------------------------------------------------------------------\n */\n\n private _updateCollapseThreshold = () => {\n const isMobile = this._mediaQuery?.matches ?? window.innerWidth < 768; // NYSDS sets anything below 768px as mobile. Desktop and Tablet is above 768px.\n const newThreshold = isMobile ? 3 : 5;\n\n if (newThreshold !== this._collapseThreshold) {\n this._collapseThreshold = newThreshold;\n this._manuallyExpanded = false;\n this._handleSlotChange();\n }\n };\n\n private _getSlottedOl(): HTMLOListElement | null {\n const slot = this.shadowRoot?.querySelector(\n \"slot\",\n ) as HTMLSlotElement | null;\n const assigned = slot?.assignedElements({ flatten: true }) ?? [];\n return (\n (assigned.find((el) => el.tagName === \"OL\") as HTMLOListElement) ?? null\n );\n }\n\n private _getSlottedItems(): HTMLLIElement[] {\n const ol = this._getSlottedOl();\n if (!ol) return [];\n return Array.from(ol.children).filter(\n (el) => el.tagName === \"LI\",\n ) as HTMLLIElement[];\n }\n\n private _getAnchor(li: HTMLLIElement): HTMLAnchorElement | null {\n return li.querySelector(\"a\");\n }\n\n private _isCurrentPage(li: HTMLLIElement): boolean {\n const a = this._getAnchor(li);\n if (!a) return true;\n return false;\n }\n\n private _createBackToParentElement(li: HTMLLIElement) {\n const anchor = this._getAnchor(li);\n const link = anchor?.getAttribute(\"href\") ?? \"\";\n const label = anchor?.textContent?.trim() ?? li.textContent?.trim() ?? \"\";\n\n const liEL = document.createElement(\"li\");\n liEL.className = \"nys-breadcrumbitem\";\n\n const icon = document.createElement(\"nys-icon\");\n icon.setAttribute(\"name\", \"arrow_back\");\n icon.setAttribute(\"size\", \"16\");\n\n const a = document.createElement(\"a\");\n if (!this.disabled) {\n a.href = link;\n }\n a.textContent = label;\n if (this.disabled) {\n a.setAttribute(\"aria-disabled\", \"true\");\n }\n\n liEL.appendChild(icon);\n liEL.appendChild(a);\n\n return liEL;\n }\n\n private _createCrumbElement(li: HTMLLIElement, isCurrentPage: boolean) {\n const anchor = this._getAnchor(li);\n const link = anchor?.getAttribute(\"href\") ?? \"\";\n const label = anchor?.textContent?.trim() ?? li.textContent?.trim() ?? \"\";\n\n const liEl = document.createElement(\"li\");\n liEl.className = \"nys-breadcrumbitem\";\n\n if (isCurrentPage) {\n liEl.textContent = label;\n liEl.setAttribute(\"aria-current\", \"page\");\n return liEl;\n }\n\n const a = document.createElement(\"a\");\n if (!this.disabled) {\n a.href = link;\n }\n a.textContent = label;\n if (this.disabled) {\n a.setAttribute(\"aria-disabled\", \"true\");\n }\n\n const icon = document.createElement(\"nys-icon\");\n icon.setAttribute(\"name\", \"chevron_right\");\n icon.setAttribute(\"size\", \"14\");\n\n liEl.appendChild(a);\n liEl.appendChild(icon);\n return liEl;\n }\n\n /**\n * Main logic for cloning and handling user slots.\n * New <ol>, <li>, and <a> tags are created and rendered out as crumbs for the breadcrumbs trail.\n */\n private _handleSlotChange() {\n const isMobile = this._mediaQuery?.matches ?? window.innerWidth < 768;\n const ol = this.shadowRoot?.getElementById(\"crumb-list\");\n if (!ol) return;\n\n const items = this._getSlottedItems();\n if (items.length === 0) return;\n\n ol.innerHTML = \"\";\n\n // ---------------------------------------------------------\n\n const setCrumbAsBackToParentBtn = (index = 0) => {\n const clone = items[index].cloneNode(true) as HTMLLIElement;\n\n const backToParentBtn = this._createBackToParentElement(clone);\n ol.appendChild(backToParentBtn);\n };\n\n // Single breadcrumb item OR backToParent=true for mobile - render as backToParent button\n if (items.length === 1) {\n setCrumbAsBackToParentBtn();\n return;\n }\n\n if (isMobile && this.backToParent) {\n const currentPageExist = this._isCurrentPage(items[items.length - 1]);\n\n if (currentPageExist) {\n setCrumbAsBackToParentBtn(items.length - 2);\n } else {\n setCrumbAsBackToParentBtn(items.length - 1);\n }\n return;\n }\n\n // ---------------------------------------------------------\n const shouldAutoCollapse =\n !this._manuallyExpanded && items.length > this._collapseThreshold;\n const collapseTrail = this.collapsed || shouldAutoCollapse;\n\n const lastItem = items[items.length - 1];\n const hasCurrentPage = this._isCurrentPage(lastItem);\n const itemsBeforeCollapse = Math.min(1, items.length - 1);\n const itemsAfterCollapse = Math.min(\n hasCurrentPage ? 2 : 1,\n items.length - itemsBeforeCollapse,\n );\n\n // Normal multi-item breadcrumb trail\n items.forEach((crumb, index) => {\n const crumbIsBeforeCollapse = index < itemsBeforeCollapse;\n const crumbIsAfterCollapse = index >= items.length - itemsAfterCollapse;\n const isAlwaysVisible = crumbIsBeforeCollapse || crumbIsAfterCollapse;\n const shouldHide = collapseTrail && !isAlwaysVisible; // Determines which of the crumbs is hidden\n\n const liEl = this._createCrumbElement(crumb, this._isCurrentPage(crumb));\n liEl.setAttribute(\"data-cloned\", \"true\");\n\n if (shouldHide) {\n liEl.classList.add(\"hide\");\n }\n\n if (!isAlwaysVisible) {\n // Assigning which crumb is an intermediate item (aka hidable) allows us to later redirect focus on the first of these intermediates.\n liEl.classList.add(\"intermediate\");\n }\n\n ol.appendChild(liEl);\n\n // Insert ellipsis before the first hidden cloned item when collapsed\n if (\n index === itemsBeforeCollapse - 1 &&\n collapseTrail &&\n items.length > 2\n ) {\n const ellipsis = document.createElement(\"li\");\n ellipsis.classList.add(\"nys-breadcrumbs__ellipsis\");\n\n // Ellipse button\n const button = document.createElement(\"a\");\n button.classList.add(\"ellipsis-btn\");\n button.setAttribute(\"aria-label\", \"Show more links\");\n button.setAttribute(\"role\", \"button\");\n button.setAttribute(\"href\", \"#\");\n button.textContent = \"…\";\n\n const expandTrail = (e: Event) => {\n e.preventDefault();\n this._manuallyExpanded = true;\n this.collapsed = false;\n this._handleSlotChange();\n this._dispatchExpandEvent();\n this._moveFocusToFirstExpandCrumb();\n };\n\n button.addEventListener(\"click\", expandTrail);\n button.addEventListener(\"keydown\", (e: KeyboardEvent) => {\n if (e.key === \" \") expandTrail(e);\n });\n\n // Chevron Icon\n const icon = document.createElement(\"nys-icon\");\n icon.setAttribute(\"name\", \"chevron_right\");\n icon.setAttribute(\"size\", \"14\");\n\n ellipsis.appendChild(button);\n ellipsis.appendChild(icon);\n ol.appendChild(ellipsis);\n }\n });\n }\n\n private _moveFocusToFirstExpandCrumb() {\n setTimeout(() => {\n const ol = this.shadowRoot?.getElementById(\"crumb-list\");\n const firstClone = ol?.querySelector(\"li[data-cloned].intermediate\");\n firstClone?.querySelector<HTMLAnchorElement>(\"a\")?.focus();\n }, 0);\n }\n\n /**\n * Event Handlers\n * --------------------------------------------------------------------------\n */\n private _dispatchExpandEvent() {\n this.dispatchEvent(\n new CustomEvent(\"nys-expand\", {\n detail: { id: this.id },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n render() {\n return html`<nav\n class=\"nys-breadcrumbs ${this.backgroundBar\n ? \"nys-breadcrumbs--background-bar\"\n : \"\"}\"\n aria-label=${this.ariaLabel || \"path to this page\"}\n >\n <ol id=\"crumb-list\"></ol>\n <slot style=\"display: none;\" @slotchange=${this._handleSlotChange}></slot>\n </nav>`;\n }\n}\n\nif (!customElements.get(\"nys-breadcrumbs\")) {\n customElements.define(\"nys-breadcrumbs\", NysBreadcrumbs);\n}\n"],"names":["componentIdCounter","_NysBreadcrumbs","LitElement","newThreshold","changedProperties","el","ol","li","anchor","link","label","liEL","icon","a","isCurrentPage","liEl","isMobile","items","setCrumbAsBackToParentBtn","index","clone","backToParentBtn","currentPageExist","shouldAutoCollapse","collapseTrail","lastItem","hasCurrentPage","itemsBeforeCollapse","itemsAfterCollapse","crumb","crumbIsBeforeCollapse","crumbIsAfterCollapse","isAlwaysVisible","shouldHide","ellipsis","button","expandTrail","e","html","unsafeCSS","styles","NysBreadcrumbs","__decorateClass","property"],"mappings":";;;;;;;;;;;;;;;;;;AAKA,IAAIA,IAAqB;AAkHlB,MAAMC,IAAN,MAAMA,UAAuBC,EAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAwD7C,cAAc;AACZ,UAAA,GAnDyC,KAAA,KAAK,IAMpB,KAAA,YAAY,IAMG,KAAA,OAAoB,MAOlC,KAAA,eAAe,IAQf,KAAA,YAAY,IAMZ,KAAA,gBAAgB,IAMD,KAAA,WAAW,IAEvD,KAAQ,qBAAqB,GAC7B,KAAQ,oBAAoB,IAC5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breadcrumbs component from the NYS Design System.",
|
|
5
5
|
"module": "dist/nys-breadcrumbs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lit-analyze": "lit-analyzer 'src/**/*.ts'"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@nysds/nys-icon": "^1.19.
|
|
26
|
+
"@nysds/nys-icon": "^1.19.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"lit": "^3.3.1",
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
],
|
|
41
41
|
"author": "New York State Design System Team",
|
|
42
42
|
"license": "MIT",
|
|
43
|
-
"sideEffects": true
|
|
43
|
+
"sideEffects": true,
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"lit": "^3.3.1"
|
|
46
|
+
}
|
|
44
47
|
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { LitElement } from "lit";
|
|
2
|
-
/**
|
|
3
|
-
* A breadcrumb navigation trail composed of `nys-breadcrumbitem` elements.
|
|
4
|
-
* Collapses when the trail exceeds 5 items on desktop or 3 items on mobile,
|
|
5
|
-
* showing the first, last, and item before the current page, with an ellipsis to expand.
|
|
6
|
-
* A single item renders as a back-to-parent link instead of a trail.
|
|
7
|
-
*
|
|
8
|
-
* @summary Breadcrumb navigation trail with responsive collapse support.
|
|
9
|
-
* @element nys-breadcrumbs
|
|
10
|
-
*
|
|
11
|
-
* @slot - One or more `nys-breadcrumbitem` elements defining the trail.
|
|
12
|
-
*
|
|
13
|
-
* @fires nys-breadcrumbs-expand - Fired when the user clicks the ellipsis to expand the trail.
|
|
14
|
-
*
|
|
15
|
-
* @example Full trail with current page
|
|
16
|
-
* ```html
|
|
17
|
-
* <nys-breadcrumbs>
|
|
18
|
-
* <ol>
|
|
19
|
-
* <li><a href="/">Home</a></li>
|
|
20
|
-
* <li><a href="/services">Services</a></li>
|
|
21
|
-
* <li>Current Page</li>
|
|
22
|
-
* </ol>
|
|
23
|
-
* </nys-breadcrumbs>
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @example Trail without current page
|
|
27
|
-
* ```html
|
|
28
|
-
* <nys-breadcrumbs>
|
|
29
|
-
* <ol>
|
|
30
|
-
* <li><a href="/">Home</a></li>
|
|
31
|
-
* <li><a href="/services">Services</a></li>
|
|
32
|
-
* </ol>
|
|
33
|
-
* </nys-breadcrumbs>
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example Single item renders as back-to-parent
|
|
37
|
-
* ```html
|
|
38
|
-
* <nys-breadcrumbs>
|
|
39
|
-
* <ol>
|
|
40
|
-
* <li><a href="/services">Services</a></li>
|
|
41
|
-
* </ol>
|
|
42
|
-
* </nys-breadcrumbs>
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare class NysBreadcrumbs extends LitElement {
|
|
46
|
-
static styles: import("lit").CSSResult;
|
|
47
|
-
/**
|
|
48
|
-
* Unique identifier. Auto-generated if not provided.
|
|
49
|
-
*/
|
|
50
|
-
id: string;
|
|
51
|
-
/**
|
|
52
|
-
* Accessible label for the `<nav>` landmark. Defaults to "path to this page" if not set.
|
|
53
|
-
* Override when multiple crumbs exist on the same page.
|
|
54
|
-
*/
|
|
55
|
-
ariaLabel: string;
|
|
56
|
-
/**
|
|
57
|
-
* Controls the visual size of the breadcrumb text and spacing: `sm` for dense layouts, `md` (default) for standard use.
|
|
58
|
-
* @default "md"
|
|
59
|
-
*/
|
|
60
|
-
size: "sm" | "md" | "";
|
|
61
|
-
/**
|
|
62
|
-
* On mobile, renders the trail as a single back-to-parent link pointing to the item before the current page.
|
|
63
|
-
* Has no effect on desktop or when only one item is present (which always renders as a back link).
|
|
64
|
-
* @default false
|
|
65
|
-
*/
|
|
66
|
-
backToParent: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Forces the trail into its collapsed state.
|
|
69
|
-
* It shows only the first item, an ellipsis, and the last two items.
|
|
70
|
-
* The user can still expand the trail by clicking the ellipsis.
|
|
71
|
-
* @default false
|
|
72
|
-
*/
|
|
73
|
-
collapsed: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Renders a filled light theme background bar behind the breadcrumb trail.
|
|
76
|
-
* @default false
|
|
77
|
-
*/
|
|
78
|
-
backgroundBar: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Prevents interaction.
|
|
81
|
-
* @default false
|
|
82
|
-
*/
|
|
83
|
-
disabled: boolean;
|
|
84
|
-
private _collapseThreshold;
|
|
85
|
-
private _manuallyExpanded;
|
|
86
|
-
private _mediaQuery;
|
|
87
|
-
/**
|
|
88
|
-
* Lifecycle methods
|
|
89
|
-
* --------------------------------------------------------------------------
|
|
90
|
-
*/
|
|
91
|
-
constructor();
|
|
92
|
-
connectedCallback(): void;
|
|
93
|
-
disconnectedCallback(): void;
|
|
94
|
-
firstUpdated(): void;
|
|
95
|
-
updated(changedProperties: Map<string | number | symbol, unknown>): void;
|
|
96
|
-
/**
|
|
97
|
-
* Functions
|
|
98
|
-
* --------------------------------------------------------------------------
|
|
99
|
-
*/
|
|
100
|
-
private _updateCollapseThreshold;
|
|
101
|
-
private _getSlottedOl;
|
|
102
|
-
private _getSlottedItems;
|
|
103
|
-
private _getAnchor;
|
|
104
|
-
private _isCurrentPage;
|
|
105
|
-
private _createBackToParentElement;
|
|
106
|
-
private _createCrumbElement;
|
|
107
|
-
/**
|
|
108
|
-
* Main logic for cloning and handling user slots.
|
|
109
|
-
* New <ol>, <li>, and <a> tags are created and rendered out as crumbs for the breadcrumbs trail.
|
|
110
|
-
*/
|
|
111
|
-
private _handleSlotChange;
|
|
112
|
-
private _moveFocusToFirstExpandCrumb;
|
|
113
|
-
/**
|
|
114
|
-
* Event Handlers
|
|
115
|
-
* --------------------------------------------------------------------------
|
|
116
|
-
*/
|
|
117
|
-
private _dispatchExpandEvent;
|
|
118
|
-
render(): import("lit-html").TemplateResult<1>;
|
|
119
|
-
}
|