/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.97 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-a0010f96.js'); const dom = require('./dom-2ec8c9ed.js'); const floatingUi = require('./floating-ui-b48c8256.js'); const observers = require('./observers-5706326b.js'); const interactive = require('./interactive-32293bca.js'); const openCloseComponent = require('./openCloseComponent-178191c0.js'); const guid = require('./guid-f4f03a7a.js'); const key = require('./key-6a462411.js'); require('./resources-b5a5f8a7.js'); require('./debounce-2c8b61fb.js'); const SLOTS = { dropdownTrigger: "dropdown-trigger" }; const dropdownCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:inline-flex;flex:0 1 auto}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host .calcite-dropdown-wrapper{display:block;position:absolute;z-index:900;visibility:hidden;pointer-events:none;inline-size:0;block-size:0;overflow:hidden}.calcite-dropdown-wrapper .calcite-floating-ui-anim{position:relative;transition:var(--calcite-floating-ui-transition);visibility:hidden;transition-property:transform, visibility, opacity;opacity:0;box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);z-index:1;border-radius:0.25rem}.calcite-dropdown-wrapper[data-placement^=bottom] .calcite-floating-ui-anim{transform:translateY(-5px)}.calcite-dropdown-wrapper[data-placement^=top] .calcite-floating-ui-anim{transform:translateY(5px)}.calcite-dropdown-wrapper[data-placement^=left] .calcite-floating-ui-anim{transform:translateX(5px)}.calcite-dropdown-wrapper[data-placement^=right] .calcite-floating-ui-anim{transform:translateX(-5px)}.calcite-dropdown-wrapper[data-placement] .calcite-floating-ui-anim--active{opacity:1;visibility:visible;transform:translate(0)}:host([open]) .calcite-dropdown-wrapper{pointer-events:initial;visibility:visible;inline-size:unset;block-size:unset;overflow:unset}:host .calcite-dropdown-content{max-block-size:45vh;inline-size:auto;overflow-y:auto;overflow-x:hidden;background-color:var(--calcite-ui-foreground-1);inline-size:var(--calcite-dropdown-width)}.calcite-dropdown-trigger-container{position:relative;display:flex;flex:1 1 auto}@media (forced-colors: active){:host([open]) .calcite-dropdown-wrapper{border:1px solid canvasText}}:host([width=s]){--calcite-dropdown-width:12rem}:host([width=m]){--calcite-dropdown-width:14rem}:host([width=l]){--calcite-dropdown-width:16rem}"; const Dropdown = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteDropdownSelect = index.createEvent(this, "calciteDropdownSelect", 6); this.calciteDropdownBeforeClose = index.createEvent(this, "calciteDropdownBeforeClose", 6); this.calciteDropdownClose = index.createEvent(this, "calciteDropdownClose", 6); this.calciteDropdownBeforeOpen = index.createEvent(this, "calciteDropdownBeforeOpen", 6); this.calciteDropdownOpen = index.createEvent(this, "calciteDropdownOpen", 6); //-------------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------------- /** * Opens or closes the dropdown * * @deprecated use open instead. */ this.active = false; /** When true, opens the dropdown */ this.open = false; /** allow the dropdown to remain open after a selection is made if the selection-mode of the selected item's containing group is "none", the dropdown will always close */ this.disableCloseOnSelect = false; /** is the dropdown disabled */ this.disabled = false; /** specify the maximum number of calcite-dropdown-items to display before showing the scroller, must be greater than 0 - this value does not include groupTitles passed to calcite-dropdown-group */ this.maxItems = 0; /** * Determines the type of positioning to use for the overlaid content. * * Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout. * * `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`. * */ this.overlayPositioning = "absolute"; /** * Determines where the dropdown will be positioned relative to the button. * * @default "bottom-start" */ this.placement = floatingUi.defaultMenuPlacement; /** specify the scale of dropdown, defaults to m */ this.scale = "m"; /** * **read-only** The currently selected items * * @readonly */ this.selectedItems = []; /** specify whether the dropdown is opened by hover or click of a trigger element */ this.type = "click"; this.items = []; this.groups = []; this.mutationObserver = observers.createObserver("mutation", () => this.updateItems()); this.resizeObserver = observers.createObserver("resize", (entries) => this.resizeObserverCallback(entries)); this.openTransitionProp = "visibility"; this.guid = `calcite-dropdown-${guid.guid()}`; this.defaultAssignedElements = []; //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- this.slotChangeHandler = (event) => { this.defaultAssignedElements = event.target.assignedElements({ flatten: true }); this.updateItems(); }; this.setFilteredPlacements = () => { const { el, flipPlacements } = this; this.filteredFlipPlacements = flipPlacements ? floatingUi.filterComputedPlacements(flipPlacements, el) : null; }; this.updateTriggers = (event) => { this.triggers = event.target.assignedElements({ flatten: true }); this.reposition(true); }; this.updateItems = () => { this.items = this.groups .map((group) => Array.from(group === null || group === void 0 ? void 0 : group.querySelectorAll("calcite-dropdown-item"))) .reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []); this.updateSelectedItems(); this.reposition(true); }; this.updateGroups = (event) => { const groups = event.target .assignedElements({ flatten: true }) .filter((el) => el === null || el === void 0 ? void 0 : el.matches("calcite-dropdown-group")); this.groups = groups; this.updateItems(); }; this.resizeObserverCallback = (entries) => { entries.forEach((entry) => { const { target } = entry; if (target === this.referenceEl) { this.setDropdownWidth(); } else if (target === this.scrollerEl) { this.setMaxScrollerHeight(); } }); }; this.setDropdownWidth = () => { const { referenceEl, scrollerEl } = this; const referenceElWidth = referenceEl === null || referenceEl === void 0 ? void 0 : referenceEl.clientWidth; if (!referenceElWidth || !scrollerEl) { return; } scrollerEl.style.minWidth = `${referenceElWidth}px`; }; this.setMaxScrollerHeight = () => { const { scrollerEl } = this; if (!scrollerEl) { return; } this.reposition(true); const maxScrollerHeight = this.getMaxScrollerHeight(); scrollerEl.style.maxHeight = maxScrollerHeight > 0 ? `${maxScrollerHeight}px` : ""; this.reposition(true); }; this.setScrollerAndTransitionEl = (el) => { this.resizeObserver.observe(el); this.scrollerEl = el; this.transitionEl = el; openCloseComponent.connectOpenCloseComponent(this); }; this.setReferenceEl = (el) => { this.referenceEl = el; floatingUi.connectFloatingUI(this, this.referenceEl, this.floatingEl); this.resizeObserver.observe(el); }; this.setFloatingEl = (el) => { this.floatingEl = el; floatingUi.connectFloatingUI(this, this.referenceEl, this.floatingEl); }; this.keyDownHandler = (event) => { const target = event.target; if (target !== this.referenceEl) { return; } const { defaultPrevented, key: key$1 } = event; if (defaultPrevented) { return; } if (this.open) { if (key$1 === "Escape") { this.closeCalciteDropdown(); event.preventDefault(); return; } else if (event.shiftKey && key$1 === "Tab") { this.closeCalciteDropdown(); event.preventDefault(); return; } } if (key.isActivationKey(key$1)) { this.openCalciteDropdown(); event.preventDefault(); } else if (key$1 === "Escape") { this.closeCalciteDropdown(); event.preventDefault(); } }; this.focusOnFirstActiveOrFirstItem = () => { this.getFocusableElement(this.items.find((item) => item.selected) || this.items[0]); }; this.toggleOpenEnd = () => { this.focusOnFirstActiveOrFirstItem(); this.el.removeEventListener("calciteDropdownOpen", this.toggleOpenEnd); }; this.openCalciteDropdown = () => { this.open = !this.open; if (this.open) { this.el.addEventListener("calciteDropdownOpen", this.toggleOpenEnd); } }; } activeHandler(value) { this.open = value; } openHandler(value) { if (!this.disabled) { if (value) { this.reposition(true); } else { floatingUi.updateAfterClose(this.floatingEl); } this.active = value; return; } if (!value) { floatingUi.updateAfterClose(this.floatingEl); } this.open = false; } handleDisabledChange(value) { if (!value) { this.open = false; } } flipPlacementsHandler() { this.setFilteredPlacements(); this.reposition(true); } maxItemsHandler() { this.setMaxScrollerHeight(); } overlayPositioningHandler() { this.reposition(true); } placementHandler() { this.reposition(true); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { var _a; (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true }); this.setFilteredPlacements(); this.reposition(true); if (this.open) { this.openHandler(this.open); } if (this.active) { this.activeHandler(this.active); } openCloseComponent.connectOpenCloseComponent(this); } componentDidLoad() { this.reposition(true); } componentDidRender() { interactive.updateHostInteraction(this); } disconnectedCallback() { var _a, _b; (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); floatingUi.disconnectFloatingUI(this, this.referenceEl, this.floatingEl); (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect(); openCloseComponent.disconnectOpenCloseComponent(this); } render() { const { open, guid } = this; return (index.h(index.Host, null, index.h("div", { class: "calcite-dropdown-trigger-container", id: `${guid}-menubutton`, onClick: this.openCalciteDropdown, onKeyDown: this.keyDownHandler, ref: this.setReferenceEl }, index.h("slot", { "aria-controls": `${guid}-menu`, "aria-expanded": dom.toAriaBoolean(open), "aria-haspopup": "menu", name: SLOTS.dropdownTrigger, onSlotchange: this.updateTriggers })), index.h("div", { "aria-hidden": dom.toAriaBoolean(!open), class: "calcite-dropdown-wrapper", ref: this.setFloatingEl }, index.h("div", { "aria-labelledby": `${guid}-menubutton`, class: { ["calcite-dropdown-content"]: true, [floatingUi.FloatingCSS.animation]: true, [floatingUi.FloatingCSS.animationActive]: open }, id: `${guid}-menu`, ref: this.setScrollerAndTransitionEl, role: "menu" }, index.h("slot", { onSlotchange: this.updateGroups }))))); } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** * Updates the position of the component. * * @param delayed */ async reposition(delayed = false) { const { floatingEl, referenceEl, placement, overlayPositioning, filteredFlipPlacements } = this; return floatingUi.reposition(this, { floatingEl, referenceEl, overlayPositioning, placement, flipPlacements: filteredFlipPlacements, type: "menu" }, delayed); } closeCalciteDropdownOnClick(event) { if (!dom.isPrimaryPointerButton(event) || !this.open || event.composedPath().includes(this.el)) { return; } this.closeCalciteDropdown(false); } closeCalciteDropdownOnEvent(event) { this.closeCalciteDropdown(); event.stopPropagation(); } closeCalciteDropdownOnOpenEvent(event) { if (event.composedPath().includes(this.el)) { return; } this.open = false; } mouseEnterHandler() { if (this.type === "hover") { this.openCalciteDropdown(); } } mouseLeaveHandler() { if (this.type === "hover") { this.closeCalciteDropdown(); } } calciteInternalDropdownItemKeyEvent(event) { const { keyboardEvent } = event.detail; // handle edge const target = keyboardEvent.target; const itemToFocus = target.nodeName !== "A" ? target : target.parentNode; const isFirstItem = this.itemIndex(itemToFocus) === 0; const isLastItem = this.itemIndex(itemToFocus) === this.items.length - 1; switch (keyboardEvent.key) { case "Tab": if (isLastItem && !keyboardEvent.shiftKey) { this.closeCalciteDropdown(); } else if (isFirstItem && keyboardEvent.shiftKey) { this.closeCalciteDropdown(); } else if (keyboardEvent.shiftKey) { this.focusPrevItem(itemToFocus); } else { this.focusNextItem(itemToFocus); } break; case "ArrowDown": this.focusNextItem(itemToFocus); break; case "ArrowUp": this.focusPrevItem(itemToFocus); break; case "Home": this.focusFirstItem(); break; case "End": this.focusLastItem(); break; } event.stopPropagation(); } handleItemSelect(event) { this.updateSelectedItems(); event.stopPropagation(); this.calciteDropdownSelect.emit({ item: event.detail.requestedDropdownItem }); if (!this.disableCloseOnSelect || event.detail.requestedDropdownGroup.selectionMode === "none") { this.closeCalciteDropdown(); } event.stopPropagation(); } onBeforeOpen() { this.calciteDropdownBeforeOpen.emit(); } onOpen() { this.calciteDropdownOpen.emit(); } onBeforeClose() { this.calciteDropdownBeforeClose.emit(); } onClose() { this.calciteDropdownClose.emit(); } updateSelectedItems() { this.selectedItems = this.items.filter((item) => item.selected); } getMaxScrollerHeight() { const { maxItems, items } = this; let itemsToProcess = 0; let maxScrollerHeight = 0; let groupHeaderHeight; this.groups.forEach((group) => { if (maxItems > 0 && itemsToProcess < maxItems) { Array.from(group.children).forEach((item, index) => { if (index === 0) { if (isNaN(groupHeaderHeight)) { groupHeaderHeight = item.offsetTop; } maxScrollerHeight += groupHeaderHeight; } if (itemsToProcess < maxItems) { maxScrollerHeight += item.offsetHeight; itemsToProcess += 1; } }); } }); return items.length > maxItems ? maxScrollerHeight : 0; } closeCalciteDropdown(focusTrigger = true) { this.open = false; if (focusTrigger) { dom.focusElement(this.triggers[0]); } } focusFirstItem() { const firstItem = this.items[0]; this.getFocusableElement(firstItem); } focusLastItem() { const lastItem = this.items[this.items.length - 1]; this.getFocusableElement(lastItem); } focusNextItem(el) { const index = this.itemIndex(el); const nextItem = this.items[index + 1] || this.items[0]; this.getFocusableElement(nextItem); } focusPrevItem(el) { const index = this.itemIndex(el); const prevItem = this.items[index - 1] || this.items[this.items.length - 1]; this.getFocusableElement(prevItem); } itemIndex(el) { return this.items.indexOf(el); } getFocusableElement(item) { if (!item) { return; } const target = item.attributes.isLink ? item.shadowRoot.querySelector("a") : item; dom.focusElement(target); } get el() { return index.getElement(this); } static get watchers() { return { "active": ["activeHandler"], "open": ["openHandler"], "disabled": ["handleDisabledChange"], "flipPlacements": ["flipPlacementsHandler"], "maxItems": ["maxItemsHandler"], "overlayPositioning": ["overlayPositioningHandler"], "placement": ["placementHandler"] }; } }; Dropdown.style = dropdownCss; const CSS$1 = { containerSmall: "container--s", containerMedium: "container--m", containerLarge: "container--l" }; const dropdownGroupCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}.container{text-align:start}.container--s{font-size:var(--calcite-font-size--2);line-height:1rem}.container--s .dropdown-title{padding:0.5rem}.container--m{font-size:var(--calcite-font-size--1);line-height:1rem}.container--m .dropdown-title{padding:0.75rem}.container--l{font-size:var(--calcite-font-size-0);line-height:1.25rem}.container--l .dropdown-title{padding:1rem}.dropdown-title{margin-block-end:-1px;display:block;cursor:default;overflow-wrap:break-word;border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-2)}.dropdown-separator{display:block;block-size:1px;background-color:var(--calcite-ui-border-3)}"; const DropdownGroup = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteInternalDropdownItemChange = index.createEvent(this, "calciteInternalDropdownItemChange", 6); /** specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item), none (no active items), defaults to single */ this.selectionMode = "single"; } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- componentWillLoad() { this.groupPosition = this.getGroupPosition(); } render() { const scale = this.scale || dom.getElementProp(this.el, "scale", "m"); const groupTitle = this.groupTitle ? (index.h("span", { "aria-hidden": "true", class: "dropdown-title" }, this.groupTitle)) : null; const dropdownSeparator = this.groupPosition > 0 ? index.h("div", { class: "dropdown-separator", role: "separator" }) : null; return (index.h(index.Host, { "aria-label": this.groupTitle, role: "group" }, index.h("div", { class: { container: true, [CSS$1.containerSmall]: scale === "s", [CSS$1.containerMedium]: scale === "m", [CSS$1.containerLarge]: scale === "l" }, title: this.groupTitle }, dropdownSeparator, groupTitle, index.h("slot", null)))); } //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- updateActiveItemOnChange(event) { this.requestedDropdownGroup = event.detail.requestedDropdownGroup; this.requestedDropdownItem = event.detail.requestedDropdownItem; this.calciteInternalDropdownItemChange.emit({ requestedDropdownGroup: this.requestedDropdownGroup, requestedDropdownItem: this.requestedDropdownItem }); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- getGroupPosition() { return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-dropdown-group"), this.el); } get el() { return index.getElement(this); } }; DropdownGroup.style = dropdownGroupCss; const CSS = { containerLink: "container--link", containerSmall: "container--s", containerMedium: "container--m", containerLarge: "container--l", containerMulti: "container--multi-selection", containerSingle: "container--single-selection", containerNone: "container--none-selection" }; const dropdownItemCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}.container--s{padding-block:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;padding-inline-end:0.5rem;padding-inline-start:1.5rem}.container--m{padding-block:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;padding-inline-end:0.75rem;padding-inline-start:2rem}.container--l{padding-block:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;padding-inline-end:1rem;padding-inline-start:2.5rem}.container--s.container--none-selection{padding-inline-start:0.25rem}.container--s.container--none-selection .dropdown-link{padding-inline-start:0px}.container--m.container--none-selection{padding-inline-start:0.5rem}.container--m.container--none-selection .dropdown-link{padding-inline-start:0px}.container--l.container--none-selection{padding-inline-start:0.75rem}.container--l.container--none-selection .dropdown-link{padding-inline-start:0px}:host{position:relative;display:flex;flex-grow:1;align-items:center}.container{position:relative;display:flex;flex-grow:1;cursor:pointer;align-items:center;color:var(--calcite-ui-text-3);text-decoration-line:none;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);text-align:start}.dropdown-item-content{flex:1 1 auto;padding-inline-end:auto;padding-inline-start:0.25rem}:host,.container--link a{outline-color:transparent}:host(:focus){outline:2px solid transparent;outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.container--link{padding:0px}.container--link a{position:relative;display:flex;flex-grow:1;cursor:pointer;align-items:center;color:var(--calcite-ui-text-3);text-decoration-line:none;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}.container--s .dropdown-link{padding-block:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;padding-inline-end:0.5rem;padding-inline-start:1.5rem}.container--m .dropdown-link{padding-block:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;padding-inline-end:0.75rem;padding-inline-start:2rem}.container--l .dropdown-link{padding-block:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;padding-inline-end:1rem;padding-inline-start:2.5rem}:host(:hover) .container,:host(:active) .container{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1);text-decoration-line:none}:host(:hover) .container--link .dropdown-link,:host(:active) .container--link .dropdown-link{color:var(--calcite-ui-text-1)}:host(:focus) .container{color:var(--calcite-ui-text-1);text-decoration-line:none}:host(:active) .container{background-color:var(--calcite-ui-foreground-3)}:host(:hover) .container:before,:host(:active) .container:before,:host(:focus) .container:before{opacity:1}:host([selected]) .container:not(.container--none-selection),:host([selected]) .container--link .dropdown-link{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}:host([selected]) .container:not(.container--none-selection):before,:host([selected]) .container--link .dropdown-link:before{opacity:1;color:var(--calcite-ui-brand)}:host([selected]) .container:not(.container--none-selection) calcite-icon,:host([selected]) .container--link .dropdown-link calcite-icon{color:var(--calcite-ui-brand)}.container--multi-selection:before,.container--none-selection:before{display:none}.container--s:before{inset-inline-start:0.5rem}.container--m:before{inset-inline-start:0.75rem}.container--l:before{inset-inline-start:1rem}.dropdown-item-icon{position:absolute;opacity:0;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:scale(0.9)}.container--s .dropdown-item-icon{inset-inline-start:0.25rem}.container--m .dropdown-item-icon{inset-inline-start:0.5rem}.container--l .dropdown-item-icon{inset-inline-start:0.75rem}:host(:hover) .dropdown-item-icon{color:var(--calcite-ui-border-1);opacity:1}:host([active]) .dropdown-item-icon{color:var(--calcite-ui-brand);opacity:1}.container--s .dropdown-item-icon-start{margin-inline-end:0.5rem;margin-inline-start:0.25rem}.container--s .dropdown-item-icon-end{margin-inline-start:0.5rem}.container--m .dropdown-item-icon-start{margin-inline-end:0.75rem;margin-inline-start:0.25rem}.container--m .dropdown-item-icon-end{margin-inline-start:0.75rem}.container--l .dropdown-item-icon-start{margin-inline-end:1rem;margin-inline-start:0.25rem}.container--l .dropdown-item-icon-end{margin-inline-start:1rem}"; const DropdownItem = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteInternalDropdownItemSelect = index.createEvent(this, "calciteInternalDropdownItemSelect", 6); this.calciteInternalDropdownItemKeyEvent = index.createEvent(this, "calciteInternalDropdownItemKeyEvent", 6); this.calciteInternalDropdownCloseRequest = index.createEvent(this, "calciteInternalDropdownCloseRequest", 6); //-------------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------------- /** * Indicates whether the item is active. * * @deprecated Use selected instead. */ this.active = false; /** When true, item is selected */ this.selected = false; } activeHandler(value) { this.selected = value; } selectedHandler(value) { this.active = value; } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** Sets focus on the component. */ async setFocus() { var _a; (_a = this.el) === null || _a === void 0 ? void 0 : _a.focus(); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- componentWillLoad() { this.initialize(); } connectedCallback() { const isSelected = this.selected || this.active; if (isSelected) { this.activeHandler(isSelected); this.selectedHandler(isSelected); } this.initialize(); } render() { const scale = dom.getElementProp(this.el, "scale", "m"); const iconStartEl = (index.h("calcite-icon", { class: "dropdown-item-icon-start", flipRtl: this.iconFlipRtl === "start" || this.iconFlipRtl === "both", icon: this.iconStart, scale: "s" })); const contentNode = (index.h("span", { class: "dropdown-item-content" }, index.h("slot", null))); const iconEndEl = (index.h("calcite-icon", { class: "dropdown-item-icon-end", flipRtl: this.iconFlipRtl === "end" || this.iconFlipRtl === "both", icon: this.iconEnd, scale: "s" })); const slottedContent = this.iconStart && this.iconEnd ? [iconStartEl, contentNode, iconEndEl] : this.iconStart ? [iconStartEl, index.h("slot", null)] : this.iconEnd ? [contentNode, iconEndEl] : contentNode; const contentEl = !this.href ? (slottedContent) : (index.h("a", { "aria-label": this.label, class: "dropdown-link", href: this.href, ref: (el) => (this.childLink = el), rel: this.rel, target: this.target }, slottedContent)); const itemRole = this.href ? null : this.selectionMode === "single" ? "menuitemradio" : this.selectionMode === "multi" ? "menuitemcheckbox" : "menuitem"; const itemAria = this.selectionMode !== "none" ? dom.toAriaBoolean(this.selected) : null; return (index.h(index.Host, { "aria-checked": itemAria, role: itemRole, tabindex: "0" }, index.h("div", { class: { container: true, [CSS.containerLink]: !!this.href, [CSS.containerSmall]: scale === "s", [CSS.containerMedium]: scale === "m", [CSS.containerLarge]: scale === "l", [CSS.containerMulti]: this.selectionMode === "multi", [CSS.containerSingle]: this.selectionMode === "single", [CSS.containerNone]: this.selectionMode === "none" } }, this.selectionMode !== "none" ? (index.h("calcite-icon", { class: "dropdown-item-icon", icon: this.selectionMode === "multi" ? "check" : "bullet-point", scale: "s" })) : null, contentEl))); } //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- onClick() { this.emitRequestedItem(); } keyDownHandler(event) { switch (event.key) { case " ": case "Enter": this.emitRequestedItem(); if (this.href) { this.childLink.click(); } event.preventDefault(); break; case "Escape": this.calciteInternalDropdownCloseRequest.emit(); event.preventDefault(); break; case "Tab": this.calciteInternalDropdownItemKeyEvent.emit({ keyboardEvent: event }); break; case "ArrowUp": case "ArrowDown": case "Home": case "End": event.preventDefault(); this.calciteInternalDropdownItemKeyEvent.emit({ keyboardEvent: event }); break; } } updateActiveItemOnChange(event) { const parentEmittedChange = event.composedPath().includes(this.parentDropdownGroupEl); if (parentEmittedChange) { this.requestedDropdownGroup = event.detail.requestedDropdownGroup; this.requestedDropdownItem = event.detail.requestedDropdownItem; this.determineActiveItem(); } event.stopPropagation(); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- initialize() { this.selectionMode = dom.getElementProp(this.el, "selection-mode", "single"); this.parentDropdownGroupEl = this.el.closest("calcite-dropdown-group"); if (this.selectionMode === "none") { this.selected = false; } } determineActiveItem() { switch (this.selectionMode) { case "multi": if (this.el === this.requestedDropdownItem) { this.selected = !this.selected; } break; case "single": if (this.el === this.requestedDropdownItem) { this.selected = true; } else if (this.requestedDropdownGroup === this.parentDropdownGroupEl) { this.selected = false; } break; case "none": this.selected = false; break; } } emitRequestedItem() { this.calciteInternalDropdownItemSelect.emit({ requestedDropdownItem: this.el, requestedDropdownGroup: this.parentDropdownGroupEl }); } get el() { return index.getElement(this); } static get watchers() { return { "active": ["activeHandler"], "selected": ["selectedHandler"] }; } }; DropdownItem.style = dropdownItemCss; exports.calcite_dropdown = Dropdown; exports.calcite_dropdown_group = DropdownGroup; exports.calcite_dropdown_item = DropdownItem;