UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

817 lines (791 loc) • 1.43 MB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. */ import { HTMLElement as HTMLElement$1, createEvent, h, Host, Build, forceUpdate, Fragment, getAssetPath, proxyCustomElement } from '@stencil/core/internal/client'; export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client'; const accordionCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([scale=s]){--calcite-accordion-item-spacing-unit:0.25rem;--calcite-accordion-icon-margin:0.5rem;--calcite-accordion-item-padding:var(--calcite-accordion-item-spacing-unit) 0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]){--calcite-accordion-item-spacing-unit:0.5rem;--calcite-accordion-icon-margin:0.75rem;--calcite-accordion-item-padding:var(--calcite-accordion-item-spacing-unit) 0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=l]){--calcite-accordion-item-spacing-unit:0.75rem;--calcite-accordion-icon-margin:1rem;--calcite-accordion-item-padding:var(--calcite-accordion-item-spacing-unit) 1rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host{position:relative;display:block;max-width:100%;line-height:1.5rem;--calcite-accordion-item-border:var(--calcite-ui-border-2);--calcite-accordion-item-background:var(--calcite-ui-foreground-1)}.accordion--transparent{--calcite-accordion-item-border:transparent;--calcite-accordion-item-background:transparent}.accordion--minimal{--calcite-accordion-item-padding:var(--calcite-accordion-item-spacing-unit) 0}.accordion{border-width:1px;border-bottom-width:0px;border-style:solid;border-color:var(--calcite-ui-border-2)}"; const Accordion = class extends HTMLElement$1 { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteAccordionChange = createEvent(this, "calciteAccordionChange", 7); //-------------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------------- /** specify the appearance - default (containing border), or minimal (no containing border), defaults to default */ this.appearance = "default"; /** specify the placement of the icon in the header, defaults to end */ this.iconPosition = "end"; /** specify the type of the icon in the header, defaults to chevron */ this.iconType = "chevron"; /** specify the scale of accordion, defaults to m */ this.scale = "m"; /** specify the selection mode - multi (allow any number of open items), single (allow one open item), * or single-persist (allow and require one open item), defaults to multi */ this.selectionMode = "multi"; //-------------------------------------------------------------------------- // // Private State/Props // //-------------------------------------------------------------------------- /** created list of Accordion items */ this.items = []; /** keep track of whether the items have been sorted so we don't re-sort */ this.sorted = false; this.sortItems = (items) => items.sort((a, b) => a.position - b.position).map((a) => a.item); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- componentDidLoad() { if (!this.sorted) { this.items = this.sortItems(this.items); this.sorted = true; } } render() { return (h("div", { class: { "accordion--transparent": this.appearance === "transparent", "accordion--minimal": this.appearance === "minimal", accordion: this.appearance === "default" } }, h("slot", null))); } //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- calciteAccordionItemKeyEvent(e) { const item = e.detail.item; const parent = e.detail.parent; if (this.el === parent) { const key = item.key; const itemToFocus = e.target; const isFirstItem = this.itemIndex(itemToFocus) === 0; const isLastItem = this.itemIndex(itemToFocus) === this.items.length - 1; switch (key) { case "ArrowDown": if (isLastItem) { this.focusFirstItem(); } else { this.focusNextItem(itemToFocus); } break; case "ArrowUp": if (isFirstItem) { this.focusLastItem(); } else { this.focusPrevItem(itemToFocus); } break; case "Home": this.focusFirstItem(); break; case "End": this.focusLastItem(); break; } } } registerCalciteAccordionItem(e) { const item = { item: e.target, parent: e.detail.parent, position: e.detail.position }; if (this.el === item.parent) { this.items.push(item); } } updateActiveItemOnChange(event) { this.requestedAccordionItem = event.detail.requestedAccordionItem; this.calciteAccordionChange.emit({ requestedAccordionItem: this.requestedAccordionItem }); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- focusFirstItem() { const firstItem = this.items[0]; this.focusElement(firstItem); } focusLastItem() { const lastItem = this.items[this.items.length - 1]; this.focusElement(lastItem); } focusNextItem(e) { const index = this.itemIndex(e); const nextItem = this.items[index + 1] || this.items[0]; this.focusElement(nextItem); } focusPrevItem(e) { const index = this.itemIndex(e); const prevItem = this.items[index - 1] || this.items[this.items.length - 1]; this.focusElement(prevItem); } itemIndex(e) { return this.items.indexOf(e); } focusElement(item) { const target = item; target.focus(); } get el() { return this; } static get style() { return accordionCss; } }; const autoTheme = "calcite-theme-auto"; const darkTheme = "calcite-theme-dark"; const lightTheme = "calcite-theme-light"; const CSS_UTILITY = { autoTheme, darkTheme, lightTheme, rtl: "calcite--rtl" }; const TEXT$r = { loading: "Loading" }; function gen(counts) { return counts .map((count) => { let out = ""; for (let i = 0; i < count; i++) { out += (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); } return out; }) .join("-"); } const guid = () => gen([2, 1, 1, 1, 3]); /** * This helper will guarantee an ID on the provided element. * * If it already has an ID, it will be preserved, otherwise a unique one will be generated and assigned. * * @returns {string} The element's ID. */ function ensureId(el) { if (!el) { return ""; } return (el.id = el.id || `${el.tagName.toLowerCase()}-${guid()}`); } function nodeListToArray(nodeList) { return Array.isArray(nodeList) ? nodeList : Array.from(nodeList); } function getThemeName(el) { const closestElWithTheme = closestElementCrossShadowBoundary(el, `.${CSS_UTILITY.darkTheme}, .${CSS_UTILITY.lightTheme}`); return (closestElWithTheme === null || closestElWithTheme === void 0 ? void 0 : closestElWithTheme.classList.contains("calcite-theme-dark")) ? "dark" : "light"; } function getElementDir(el) { const prop = "dir"; const selector = `[${prop}]`; const closest = closestElementCrossShadowBoundary(el, selector); return closest ? closest.getAttribute(prop) : "ltr"; } function getElementProp(el, prop, fallbackValue) { const selector = `[${prop}]`; const closest = el.closest(selector); return closest ? closest.getAttribute(prop) : fallbackValue; } function getRootNode(el) { return el.getRootNode(); } function getHost(root) { return root.host || null; } /** * This helper queries an element's rootNodes and any ancestor rootNodes. * * @returns {Element[]} The elements. */ function queryElementsRoots(element, selector) { // Gets the rootNode and any ancestor rootNodes (shadowRoot or document) of an element and queries them for a selector. // Based on: https://stackoverflow.com/q/54520554/194216 function queryFromAll(el, allResults) { if (!el) { return allResults; } if (el.assignedSlot) { el = el.assignedSlot; } const rootNode = getRootNode(el); const results = Array.from(rootNode.querySelectorAll(selector)); const uniqueResults = results.filter((result) => !allResults.includes(result)); allResults = [...allResults, ...uniqueResults]; const host = getHost(rootNode); return host ? queryFromAll(host, allResults) : allResults; } return queryFromAll(element, []); } /** * This helper queries an element's rootNode and any ancestor rootNodes. * * If both an 'id' and 'selector' are supplied, 'id' will take precedence over 'selector'. * * @returns {Element} The element. */ function queryElementRoots(element, { selector, id }) { // Gets the rootNode and any ancestor rootNodes (shadowRoot or document) of an element and queries them for a selector. // Based on: https://stackoverflow.com/q/54520554/194216 function queryFrom(el) { if (!el) { return null; } if (el.assignedSlot) { el = el.assignedSlot; } const rootNode = getRootNode(el); const found = id ? rootNode.getElementById(id) : selector ? rootNode.querySelector(selector) : null; const host = getHost(rootNode); return found ? found : host ? queryFrom(host) : null; } return queryFrom(element); } function closestElementCrossShadowBoundary(element, selector) { // based on https://stackoverflow.com/q/54520554/194216 function closestFrom(el) { return el ? el.closest(selector) || closestFrom(getHost(getRootNode(el))) : null; } return closestFrom(element); } function isCalciteFocusable(el) { return typeof (el === null || el === void 0 ? void 0 : el.setFocus) === "function"; } async function focusElement(el) { if (!el) { return; } return isCalciteFocusable(el) ? el.setFocus() : el.focus(); } const defaultSlotSelector = ":not([slot])"; function getSlotted(element, slotName, options) { if (slotName && !Array.isArray(slotName) && typeof slotName !== "string") { options = slotName; slotName = null; } const slotSelector = slotName ? Array.isArray(slotName) ? slotName.map((name) => `[slot="${name}"]`).join(",") : `[slot="${slotName}"]` : defaultSlotSelector; if (options === null || options === void 0 ? void 0 : options.all) { return queryMultiple(element, slotSelector, options); } return querySingle(element, slotSelector, options); } function getDirectChildren(el, selector) { return el ? Array.from(el.children || []).filter((child) => child === null || child === void 0 ? void 0 : child.matches(selector)) : []; } function queryMultiple(element, slotSelector, options) { let matches = slotSelector === defaultSlotSelector ? getDirectChildren(element, defaultSlotSelector) : Array.from(element.querySelectorAll(slotSelector)); matches = options && options.direct === false ? matches : matches.filter((el) => el.parentElement === element); matches = (options === null || options === void 0 ? void 0 : options.matches) ? matches.filter((el) => el === null || el === void 0 ? void 0 : el.matches(options.matches)) : matches; const selector = options === null || options === void 0 ? void 0 : options.selector; return selector ? matches .map((item) => Array.from(item.querySelectorAll(selector))) .reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []) .filter((match) => !!match) : matches; } function querySingle(element, slotSelector, options) { let match = slotSelector === defaultSlotSelector ? getDirectChildren(element, defaultSlotSelector)[0] || null : element.querySelector(slotSelector); match = options && options.direct === false ? match : (match === null || match === void 0 ? void 0 : match.parentElement) === element ? match : null; match = (options === null || options === void 0 ? void 0 : options.matches) ? ((match === null || match === void 0 ? void 0 : match.matches(options.matches)) ? match : null) : match; const selector = options === null || options === void 0 ? void 0 : options.selector; return selector ? match === null || match === void 0 ? void 0 : match.querySelector(selector) : match; } function filterDirectChildren(el, selector) { return Array.from(el.children).filter((child) => child.matches(selector)); } // set a default icon from a defined set or allow an override with an icon name string function setRequestedIcon(iconObject, iconValue, matchedValue) { if (typeof iconValue === "string" && iconValue !== "") { return iconValue; } else if (iconValue === "") { return iconObject[matchedValue]; } } function intersects(rect1, rect2) { return !(rect2.left > rect1.right || rect2.right < rect1.left || rect2.top > rect1.bottom || rect2.bottom < rect1.top); } const accordionItemCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}.icon-position--end,.icon-position--start{--calcite-accordion-item-icon-rotation:calc(90deg * -1);--calcite-accordion-item-active-icon-rotation:0deg;--calcite-accordion-item-icon-rotation-rtl:90deg;--calcite-accordion-item-active-icon-rotation-rtl:0deg}.icon-position--start{--calcite-accordion-item-flex-direction:row-reverse;--calcite-accordion-item-icon-spacing-start:0;--calcite-accordion-item-icon-spacing-end:var(--calcite-accordion-icon-margin)}.icon-position--end{--calcite-accordion-item-flex-direction:row;--calcite-accordion-item-icon-spacing-start:var(--calcite-accordion-icon-margin);--calcite-accordion-item-icon-spacing-end:0}.icon-position--end:not(.icon-type--plus-minus){--calcite-accordion-item-icon-rotation:0deg;--calcite-accordion-item-active-icon-rotation:180deg;--calcite-accordion-item-icon-rotation-rtl:0deg;--calcite-accordion-item-active-icon-rotation-rtl:calc(180deg * -1)}:host{position:relative;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;color:var(--calcite-ui-text-3);-webkit-text-decoration-line:none;text-decoration-line:none;outline:2px solid transparent;outline-offset:2px;background-color:var(--calcite-accordion-item-background, var(--calcite-ui-foreground-1))}:host .accordion-item-header{outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out}:host(:focus) .accordion-item-header{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}:host([active]){color:var(--calcite-ui-text-1)}:host([active]) .accordion-item-content{display:block;color:var(--calcite-ui-text-1)}:host([active]) .accordion-item-header{border-bottom-color:transparent}:host .accordion-item-header{display:-ms-flexbox;display:flex;cursor:pointer;-ms-flex-align:center;align-items:center;-ms-flex-direction:var(--calcite-accordion-item-flex-direction);flex-direction:var(--calcite-accordion-item-flex-direction)}:host .accordion-item-icon{position:relative;margin:0px;display:-ms-inline-flexbox;display:inline-flex;color:var(--calcite-ui-text-3);-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-margin-end:var(--calcite-accordion-item-icon-spacing-start);margin-inline-end:var(--calcite-accordion-item-icon-spacing-start);-webkit-margin-start:var(--calcite-accordion-item-icon-spacing-end);margin-inline-start:var(--calcite-accordion-item-icon-spacing-end)}:host .accordion-item-content,:host .accordion-item-header{padding:var(--calcite-accordion-item-padding);border-bottom:1px solid var(--calcite-accordion-item-border, var(--calcite-ui-border-2))}:host .accordion-item-header *{display:-ms-inline-flexbox;display:inline-flex;-ms-flex-align:center;align-items:center;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host .accordion-item-content{display:none;padding-top:0px;color:var(--calcite-ui-text-3);text-align:initial}:host .accordion-item-expand-icon{color:var(--calcite-ui-text-3);-webkit-margin-start:var(--calcite-accordion-item-icon-spacing-start);margin-inline-start:var(--calcite-accordion-item-icon-spacing-start);-webkit-margin-end:var(--calcite-accordion-item-icon-spacing-end);margin-inline-end:var(--calcite-accordion-item-icon-spacing-end);-webkit-transform:rotate(var(--calcite-accordion-item-icon-rotation));transform:rotate(var(--calcite-accordion-item-icon-rotation))}.calcite--rtl .accordion-item-expand-icon{-webkit-transform:rotate(var(--calcite-accordion-item-icon-rotation-rtl));transform:rotate(var(--calcite-accordion-item-icon-rotation-rtl))}:host([active]) .accordion-item-expand-icon{color:var(--calcite-ui-text-1);-webkit-transform:rotate(var(--calcite-accordion-item-active-icon-rotation));transform:rotate(var(--calcite-accordion-item-active-icon-rotation))}:host([active]) .calcite--rtl .accordion-item-expand-icon{-webkit-transform:rotate(var(--calcite-accordion-item-active-icon-rotation-rtl));transform:rotate(var(--calcite-accordion-item-active-icon-rotation-rtl))}:host .accordion-item-header-text{margin-top:0px;margin-bottom:0px;-ms-flex-positive:1;flex-grow:1;-ms-flex-direction:column;flex-direction:column;padding-top:0px;padding-bottom:0px;text-align:initial;-webkit-margin-end:auto;margin-inline-end:auto}:host .accordion-item-title,:host .accordion-item-subtitle{display:-ms-flexbox;display:flex;width:100%}:host .accordion-item-title{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-2)}:host .accordion-item-subtitle{margin-top:0.25rem;color:var(--calcite-ui-text-3)}:host(:focus) .accordion-item-title,:host(:hover) .accordion-item-title{color:var(--calcite-ui-text-1)}:host(:focus) .accordion-item-icon,:host(:hover) .accordion-item-icon{color:var(--calcite-ui-text-1)}:host(:focus) .accordion-item-expand-icon,:host(:hover) .accordion-item-expand-icon{color:var(--calcite-ui-text-1)}:host(:focus) .accordion-item-subtitle,:host(:hover) .accordion-item-subtitle{color:var(--calcite-ui-text-2)}:host(:focus) .accordion-item-title,:host(:active) .accordion-item-title,:host([active]) .accordion-item-title{color:var(--calcite-ui-text-1)}:host(:focus) .accordion-item-icon,:host(:active) .accordion-item-icon,:host([active]) .accordion-item-icon{color:var(--calcite-ui-text-1)}:host(:focus) .accordion-item-expand-icon,:host(:active) .accordion-item-expand-icon,:host([active]) .accordion-item-expand-icon{color:var(--calcite-ui-text-1)}:host(:focus) .accordion-item-subtitle,:host(:active) .accordion-item-subtitle,:host([active]) .accordion-item-subtitle{color:var(--calcite-ui-text-2)}"; const AccordionItem = class extends HTMLElement$1 { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteAccordionItemKeyEvent = createEvent(this, "calciteAccordionItemKeyEvent", 7); this.calciteAccordionItemSelect = createEvent(this, "calciteAccordionItemSelect", 7); this.calciteAccordionItemClose = createEvent(this, "calciteAccordionItemClose", 7); this.calciteAccordionItemRegister = createEvent(this, "calciteAccordionItemRegister", 7); //-------------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------------- /** Indicates whether the item is active. */ this.active = false; //-------------------------------------------------------------------------- // // Private State/Props // //-------------------------------------------------------------------------- this.guid = guid(); /** what icon position does the parent accordion specify */ this.iconPosition = "end"; /** handle clicks on item header */ this.itemHeaderClickHandler = () => this.emitRequestedItem(); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { this.parent = this.el.parentElement; this.selectionMode = getElementProp(this.el, "selection-mode", "multi"); this.iconType = getElementProp(this.el, "icon-type", "chevron"); this.iconPosition = getElementProp(this.el, "icon-position", this.iconPosition); } componentDidLoad() { this.itemPosition = this.getItemPosition(); this.calciteAccordionItemRegister.emit({ parent: this.parent, position: this.itemPosition }); } render() { const dir = getElementDir(this.el); const iconEl = h("calcite-icon", { class: "accordion-item-icon", icon: this.icon, scale: "s" }); const { guid } = this; const regionId = `${guid}-region`; const buttonId = `${guid}-button`; return (h(Host, { tabindex: "0" }, h("div", { class: { [`icon-position--${this.iconPosition}`]: true, [`icon-type--${this.iconType}`]: true } }, h("div", { "aria-controls": regionId, class: { "accordion-item-header": true, [CSS_UTILITY.rtl]: dir === "rtl" }, id: buttonId, onClick: this.itemHeaderClickHandler, role: "button" }, this.icon ? iconEl : null, h("div", { class: "accordion-item-header-text" }, h("span", { class: "accordion-item-title" }, this.itemTitle), this.itemSubtitle ? (h("span", { class: "accordion-item-subtitle" }, this.itemSubtitle)) : null), h("calcite-icon", { class: "accordion-item-expand-icon", icon: this.iconType === "chevron" ? "chevronDown" : this.iconType === "caret" ? "caretDown" : this.active ? "minus" : "plus", scale: "s" })), h("div", { "aria-expanded": this.active.toString(), "aria-labelledby": buttonId, class: "accordion-item-content", id: regionId, role: "region" }, h("slot", null))))); } //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- keyDownHandler(e) { if (e.target === this.el) { switch (e.key) { case " ": case "Enter": this.emitRequestedItem(); e.preventDefault(); break; case "ArrowUp": case "ArrowDown": case "Home": case "End": this.calciteAccordionItemKeyEvent.emit({ parent: this.parent, item: e }); e.preventDefault(); break; } } } updateActiveItemOnChange(event) { this.requestedAccordionItem = event.detail .requestedAccordionItem; if (this.el.parentNode !== this.requestedAccordionItem.parentNode) { return; } this.determineActiveItem(); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- determineActiveItem() { switch (this.selectionMode) { case "multi": if (this.el === this.requestedAccordionItem) { this.active = !this.active; } break; case "single": this.active = this.el === this.requestedAccordionItem ? !this.active : false; break; case "single-persist": this.active = this.el === this.requestedAccordionItem; break; } } emitRequestedItem() { this.calciteAccordionItemSelect.emit({ requestedAccordionItem: this.el }); } getItemPosition() { return Array.prototype.indexOf.call(this.parent.querySelectorAll("calcite-accordion-item"), this.el); } get el() { return this; } static get style() { return accordionItemCss; } }; const CSS$P = { button: "button", buttonTextVisible: "button--text-visible", buttonCompact: "button--compact", iconContainer: "icon-container", slotContainer: "slot-container", slotContainerHidden: "slot-container--hidden", textContainer: "text-container", textContainerVisible: "text-container--visible" }; const TEXT$q = { loading: "Loading" }; /** * This utility ensures observers are created only for browser contexts. * * @param type - the type of observer to create * @param callback - the observer callback * @param options - the observer options */ function createObserver(type, callback, options) { const Observer = getObserver(type); return Build.isBrowser ? new Observer(callback, options) : undefined; } function getObserver(type) { return (type === "intersection" ? window.IntersectionObserver : type === "mutation" ? window.MutationObserver : window.ResizeObserver); } function noopClick() { /** noop **/ } /** * This helper updates the host element to prevent keyboard interaction on its subtree and sets the appropriate aria attribute for accessibility. * * This should be used in the `componentDidRender` lifecycle hook. * * **Notes** * * * this util is not needed for simple components whose root element or elements are an interactive component (custom element or native control). For those cases, set the `disabled` props on the root components instead. * * technically, users can override `tabindex` and restore keyboard navigation, but this will be considered user error */ function updateHostInteraction(component, hostIsTabbable = false) { if (component.disabled) { component.el.setAttribute("tabindex", "-1"); component.el.setAttribute("aria-disabled", "true"); if (component.el.contains(document.activeElement)) { document.activeElement.blur(); } component.el.click = noopClick; return; } component.el.click = HTMLElement.prototype.click; if (typeof hostIsTabbable === "function") { component.el.setAttribute("tabindex", hostIsTabbable.call(component) ? "0" : "-1"); } else if (hostIsTabbable === true) { component.el.setAttribute("tabindex", "0"); } else if (hostIsTabbable === false) { component.el.removeAttribute("tabindex"); } else ; component.el.removeAttribute("aria-disabled"); } const actionCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:host{-webkit-box-sizing:border-box;box-sizing:border-box;background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-2);font-size:var(--calcite-font-size--1)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:-ms-flexbox;display:flex;background-color:transparent}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.button{position:relative;margin:0px;display:-ms-flexbox;display:flex;width:auto;cursor:pointer;-ms-flex-align:center;align-items:center;-ms-flex-pack:start;justify-content:flex-start;border-style:none;background-color:var(--calcite-ui-foreground-1);fill:var(--calcite-ui-text-3);font-family:var(--calcite-sans-family);font-size:var(--calcite-font-size--2);line-height:1rem;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-3);outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;text-align:unset;-ms-flex:1 0 auto;flex:1 0 auto}.button:hover{background-color:var(--calcite-ui-foreground-2);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}.button:focus{background-color:var(--calcite-ui-foreground-2);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1);outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.button:active{background-color:var(--calcite-ui-foreground-3)}.button .icon-container{pointer-events:none;margin:0px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;min-width:1rem;min-height:1rem}.button .text-container{margin:0px;width:0px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1rem;opacity:0;-webkit-transition-property:opacity;transition-property:opacity;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-property:margin;transition-property:margin;-webkit-transition-property:width;transition-property:width}.button .text-container--visible{width:auto;-ms-flex:1 1 auto;flex:1 1 auto;opacity:1}:host([scale=s]) .button{padding:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem;font-weight:var(--calcite-font-weight-normal)}:host([scale=s]) .button--text-visible .icon-container{-webkit-margin-end:0.5rem;margin-inline-end:0.5rem}:host([scale=m]) .button{padding:1rem;font-size:var(--calcite-font-size--1);line-height:1rem;font-weight:var(--calcite-font-weight-normal)}:host([scale=m]) .button--text-visible .icon-container{-webkit-margin-end:0.75rem;margin-inline-end:0.75rem}:host([scale=l]) .button{padding:1.25rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;font-weight:var(--calcite-font-weight-normal)}:host([scale=l]) .button--text-visible .icon-container{-webkit-margin-end:1rem;margin-inline-end:1rem}:host([alignment=center]) .button{-ms-flex-pack:center;justify-content:center}:host([alignment=end]) .button{-ms-flex-pack:end;justify-content:flex-end}:host([alignment=center]) .button .text-container--visible,:host([alignment=end]) .button .text-container--visible{-ms-flex:0 1 auto;flex:0 1 auto}:host([scale=s][compact]) .button,:host([scale=m][compact]) .button,:host([scale=l][compact]) .button{padding-left:0px;padding-right:0px}.slot-container{display:-ms-flexbox;display:flex}.slot-container--hidden{display:none}.button--text-visible{width:100%}:host([active]) .button,:host([active]) .button:hover,:host([active]) .button:focus,:host([active][loading]) .button{background-color:var(--calcite-ui-foreground-3);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}:host([active]) .button:active{background-color:var(--calcite-ui-foreground-1)}:host([appearance=clear]) .button{background-color:transparent;-webkit-transition-property:-webkit-box-shadow;transition-property:-webkit-box-shadow;transition-property:box-shadow;transition-property:box-shadow, -webkit-box-shadow;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host([appearance=clear]) .button:hover,:host([appearance=clear]) .button:focus{background-color:transparent;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-border-1) inset;box-shadow:0 0 0 2px var(--calcite-ui-border-1) inset}:host([active][appearance=clear]) .button,:host([active][appearance=clear]) .button:hover,:host([active][appearance=clear]) .button:focus{background-color:var(--calcite-ui-foreground-3);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}:host([appearance=clear][loading]) .button,:host([appearance=clear][disabled]) .button{background-color:transparent}:host([loading]) .button,:host([loading]) .button:hover,:host([loading]) .button:focus{background-color:var(--calcite-ui-foreground-1)}:host([loading]) .button .text-container,:host([loading]) .button:hover .text-container,:host([loading]) .button:focus .text-container{opacity:var(--calcite-ui-opacity-disabled)}:host([loading]) calcite-loader[inline]{margin-right:0px;color:var(--calcite-ui-text-3)}:host([disabled]) .button,:host([disabled]) .button:hover,:host([disabled]) .button:focus{cursor:default;background-color:var(--calcite-ui-foreground-1);opacity:var(--calcite-ui-opacity-disabled)}:host([disabled][active]) .button,:host([disabled][active]) .button:hover,:host([disabled][active]) .button:focus{background-color:var(--calcite-ui-foreground-3);opacity:var(--calcite-ui-opacity-disabled)}:host([indicator]) .button::after{content:\"\";position:absolute;z-index:10;height:0.5rem;width:0.5rem;border-radius:9999px;border-width:2px;background-color:var(--calcite-ui-brand);border-color:var(--calcite-ui-foreground-1);inset-block-end:0.75rem;inset-inline-end:0.75rem}:host([indicator]) .button--text-visible::after{inset-block-end:auto}:host([indicator]) .button--text-visible .text-container--visible{-webkit-margin-end:1rem;margin-inline-end:1rem}:host([indicator]) .button:hover::after,:host([indicator]) .button:focus::after{border-color:var(--calcite-ui-foreground-1)}:host([indicator][scale=s]) .button::after{inset-block-end:0.25rem;inset-inline-end:0.25rem}:host([indicator][scale=s]) .button--text-visible::after{inset-block-end:auto;inset-inline-end:0.5rem}:host([indicator][active]) .button::after{border-color:var(--calcite-ui-foreground-3)}"; const Action = class extends HTMLElement$1 { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteActionClick = createEvent(this, "calciteActionClick", 7); // -------------------------------------------------------------------------- // // Properties // // -------------------------------------------------------------------------- /** * Indicates whether the action is highlighted. */ this.active = false; /** Specify the appearance style of the action, defaults to solid. */ this.appearance = "solid"; /** * Compact mode is used internally by components to reduce side padding, e.g. calcite-block-section. */ this.compact = false; /** * When true, disabled prevents interaction. This state shows items with lower opacity/grayed. */ this.disabled = false; /** * Indicates unread changes. */ this.indicator = false; /** string to override English loading text * @default "Loading" */ this.intlLoading = TEXT$q.loading; /** * When true, content is waiting to be loaded. This state shows a busy indicator. */ this.loading = false; /** * Specifies the size of the action. */ this.scale = "m"; /** * Indicates whether the text is displayed. */ this.textEnabled = false; this.mutationObserver = createObserver("mutation", () => forceUpdate(this)); // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.calciteActionClickHandler = () => { if (!this.disabled) { this.calciteActionClick.emit(); } }; } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { var _a; (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true }); } disconnectedCallback() { var _a; (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); } componentDidRender() { updateHostInteraction(this); } // -------------------------------------------------------------------------- // // Methods // // -------------------------------------------------------------------------- /** Sets focus on the component. */ async setFocus() { this.buttonEl.focus(); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderTextContainer() { const { text, textEnabled } = this; const textContainerClasses = { [CSS$P.textContainer]: true, [CSS$P.textContainerVisible]: textEnabled }; return text ? (h("div", { class: textContainerClasses, key: "text-container" }, text)) : null; } renderIconContainer() { var _a; const { loading, icon, scale, el, intlLoading } = this; const iconScale = scale === "l" ? "m" : "s"; const loaderScale = scale === "l" ? "l" : "m"; const calciteLoaderNode = loading ? (h("calcite-loader", { active: true, inline: true, label: intlLoading, scale: loaderScale })) : null; const calciteIconNode = icon ? h("calcite-icon", { icon: icon, scale: iconScale }) : null; const iconNode = calciteLoaderNode || calciteIconNode; const hasIconToDisplay = iconNode || ((_a = el.children) === null || _a === void 0 ? void 0 : _a.length); const slotContainerNode = (h("div", { class: { [CSS$P.slotContainer]: true, [CSS$P.slotContainerHidden]: loading } }, h("slot", null))); return hasIconToDisplay ? (h("div", { "aria-hidden": "true", class: CSS$P.iconContainer, key: "icon-container" }, iconNode, slotContainerNode)) : null; } render() { const { compact, disabled, loading, textEnabled, label, text } = this; const ariaLabel = label || text; const buttonClasses = { [CSS$P.button]: true, [CSS$P.buttonTextVisible]: textEnabled, [CSS$P.buttonCompact]: compact }; return (h(Host, { onClick: this.calciteActionClickHandler }, h("button", { "aria-busy": loading.toString(), "aria-disabled": disabled.toString(), "aria-label": ariaLabel, class: buttonClasses, disabled: disabled, ref: (buttonEl) => (this.buttonEl = buttonEl) }, this.renderIconContainer(), this.renderTextContainer()))); } get el() { return this; } static get style() { return actionCss; } }; const CSS$O = { menu: "menu", defaultTrigger: "default-trigger" }; const SLOTS$p = { tooltip: "tooltip", trigger: "trigger" }; const ICONS$f = { menu: "ellipsis" }; const SLOTS$o = { menuActions: "menu-actions", menuTooltip: "menu-tooltip" }; const TEXT$p = { more: "More" }; const ICONS$e = { menu: "ellipsis" }; const overflowActionsDebounceInMs = 150; const groupBufferHeight = 2; const getMaxActionCount = ({ height, actionHeight, groupCount }) => { return Math.floor((height - groupCount * groupBufferHeight) / actionHeight); }; const getOverflowCount = ({ actionCount, actionHeight, height, groupCount }) => { return Math.max(actionCount - getMaxActionCount({ height, actionHeight, groupCount }), 0); }; const queryActions = (el) => { return Array.from(el.querySelectorAll("calcite-action")).filter((action) => action.closest("calcite-action-menu") ? action.slot === SLOTS$p.trigger : true); }; const overflowActions = ({ actionGroups, expanded, overflowCount }) => { let needToSlotCount = overflowCount; actionGroups.reverse().forEach((group) => { let slottedWithinGroupCount = 0; const groupActions = queryActions(group).reverse(); groupActions.forEach((groupAction) => { if (groupAction.slot === SLOTS$o.menuActions) { groupAction.removeAttribute("slot"); groupAction.textEnabled = expanded; } }); if (needToSlotCount > 0) { groupActions.some((groupAction) => { const unslottedActions = groupActions.filter((action) => !action.slot); if (unslottedActions.length > 1 && groupActions.length > 2 && !groupAction.closest("calcite-action-menu")) { groupAction.textEnabled = true; groupAction.setAttribute("slot", SLOTS$o.menuActions); slottedWithinGroupCount++; if (slottedWithinGroupCount > 1) { needToSlotCount--; } } return needToSlotCount < 1; }); } forceUpdate(group); }); }; const ICONS$d = { chevronsLeft: "chevrons-left", chevronsRight: "chevrons-right" }; function getCalcitePosition(position, el) { var _a; return position || ((_a = el.closest("calcite-shell-panel")) === null || _a === void 0 ? void 0 : _a.position) || "start"; } function toggleChildActionText({ parent, expanded }) { queryActions(parent) .filter((el) => el.slot !== SLOTS$o.menuActions) .forEach((action) => (action.textEnabled = expanded)); parent.querySelectorAll("calcite-action-group").forEach((group) => (group.expanded = expanded)); } const setTooltipReference = ({ tooltip, referenceElement, expanded, ref }) => { if (tooltip) { tooltip.referenceElement = !expanded && referenceElement ? referenceElement : null; } if (ref) { ref(referenceElement); } return referenceElement; }; const ExpandToggle = ({ expanded, intlExpand, intlCollapse, toggle, el, position, tooltip, ref, scale }) => { const rtl = getElementDir(el) === "rtl"; const expandText = expanded ? intlCollapse : intlExpand; const icons = [ICONS$d.chevronsLeft, ICONS$d.chevronsRight]; if (rtl) { icons.reverse(); } const end = getCalcitePosition(position, el) === "end"; const expandIcon = end ? icons[1] : icons[0]; const collapseIcon = end ? icons[0] : icons[1]; const actionNode = (h("calcite-action", { icon: expanded ? expandIcon : collapseIcon, onClick: toggle, ref: (referenceElement) => setTooltipReference({ tooltip, referenceElement, expanded, ref }), scale: scale, text: expandText, textEnabled: expanded })); return tooltip ? h("calcite-tooltip-manager", null, actionNode) : actionNode; }; const CSS$N = { actionGroupBottom: "action-group--bottom" }; const SLOTS$n = { bottomActions: "bottom-actions", expandTooltip: "expand-tooltip" }; const TEXT$o = { expand: "Expand", collapse: "Collapse" }; /** Detect free variable `global` from Node.js. */ var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; /** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var root = freeGlobal || freeSelf || Function('return this')(); /** Built-in value references. */ var Symbol$1 = root.Symbol; /** Used for built-in method references. */ var objectProto$5 = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$3 = objectProto$5.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString$1 = objectProto$5.toString; /** Built-in value references. */ var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. * * @private * @param {*} value The value to query. * @returns {string} Returns the raw `toStringTag`. */ function getRawTag(value) { var isOwn = hasOwnProperty$3.call(value, symToStringTag$1), tag = value[symToStringTa