123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- /*!
- * 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.82
- */
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- const index = require('./index-5c65e149.js');
- const dom = require('./dom-9ac0341c.js');
- const popper = require('./popper-3f97eb01.js');
- const observers = require('./observers-d9fdf006.js');
- const interactive = require('./interactive-e294111f.js');
- require('./guid-8b6d6cb4.js');
- const SLOTS = {
- dropdownTrigger: "dropdown-trigger"
- };
- const dropdownCss = "@-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{display:-ms-inline-flexbox;display:inline-flex;-ms-flex:0 1 auto;flex:0 1 auto}: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}:host .calcite-dropdown-wrapper{display:block;position:absolute;z-index:900;-webkit-transform:scale(0);transform:scale(0);visibility:hidden;pointer-events:none}.calcite-dropdown-wrapper .calcite-popper-anim{position:relative;z-index:1;-webkit-transition:var(--calcite-popper-transition);transition:var(--calcite-popper-transition);visibility:hidden;-webkit-transition-property:visibility, opacity, -webkit-transform;transition-property:visibility, opacity, -webkit-transform;transition-property:transform, visibility, opacity;transition-property:transform, visibility, opacity, -webkit-transform;opacity:0;-webkit-box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);border-radius:0.25rem}.calcite-dropdown-wrapper[data-popper-placement^=bottom] .calcite-popper-anim{-webkit-transform:translateY(-5px);transform:translateY(-5px)}.calcite-dropdown-wrapper[data-popper-placement^=top] .calcite-popper-anim{-webkit-transform:translateY(5px);transform:translateY(5px)}.calcite-dropdown-wrapper[data-popper-placement^=left] .calcite-popper-anim{-webkit-transform:translateX(5px);transform:translateX(5px)}.calcite-dropdown-wrapper[data-popper-placement^=right] .calcite-popper-anim{-webkit-transform:translateX(-5px);transform:translateX(-5px)}.calcite-dropdown-wrapper[data-popper-placement] .calcite-popper-anim--active{opacity:1;visibility:visible;-webkit-transform:translate(0);transform:translate(0)}:host([active]) .calcite-dropdown-wrapper{pointer-events:initial;visibility:visible}:host .calcite-dropdown-content{width:auto;overflow-y:auto;overflow-x:hidden;background-color:var(--calcite-ui-foreground-1);max-height:90vh;width:var(--calcite-dropdown-width)}.calcite-dropdown-trigger-container{position:relative;display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto}: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", 7);
- this.calciteDropdownOpen = index.createEvent(this, "calciteDropdownOpen", 7);
- this.calciteDropdownClose = index.createEvent(this, "calciteDropdownClose", 7);
- //--------------------------------------------------------------------------
- //
- // Public Properties
- //
- //--------------------------------------------------------------------------
- /** Opens or closes the dropdown */
- this.active = 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;
- /** Describes the type of positioning to use for the overlaid content. If your element is in a fixed container, use the 'fixed' value. */
- this.overlayPositioning = "absolute";
- /**
- * Determines where the dropdown will be positioned relative to the button.
- * @default "bottom-leading"
- */
- this.placement = popper.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";
- /** specify the width of dropdown, defaults to m */
- this.width = "m";
- this.items = [];
- this.groups = [];
- this.activeTransitionProp = "visibility";
- this.mutationObserver = observers.createObserver("mutation", () => this.updateItems());
- this.resizeObserver = observers.createObserver("resize", () => this.setMaxScrollerHeight());
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- this.setFilteredPlacements = () => {
- const { el, flipPlacements } = this;
- this.filteredFlipPlacements = flipPlacements
- ? popper.filterComputedPlacements(flipPlacements, el)
- : null;
- };
- this.updateTriggers = (event) => {
- this.triggers = event.target.assignedElements({
- flatten: true
- });
- this.reposition();
- };
- 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();
- };
- 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.setMaxScrollerHeight = () => {
- const { active, scrollerEl } = this;
- if (!scrollerEl || !active) {
- return;
- }
- this.reposition();
- const maxScrollerHeight = this.getMaxScrollerHeight();
- scrollerEl.style.maxHeight = maxScrollerHeight > 0 ? `${maxScrollerHeight}px` : "";
- this.reposition();
- };
- this.setScrollerEl = (scrollerEl) => {
- this.resizeObserver.observe(scrollerEl);
- this.scrollerEl = scrollerEl;
- };
- this.transitionEnd = (event) => {
- if (event.propertyName === this.activeTransitionProp) {
- this.active ? this.calciteDropdownOpen.emit() : this.calciteDropdownClose.emit();
- }
- };
- this.setReferenceEl = (el) => {
- this.referenceEl = el;
- };
- this.setMenuEl = (el) => {
- this.menuEl = el;
- };
- this.keyDownHandler = (e) => {
- const target = e.target;
- if (target !== this.referenceEl) {
- return;
- }
- const key = e.key;
- if (this.active && (key === "Escape" || (e.shiftKey && key === "Tab"))) {
- this.closeCalciteDropdown();
- return;
- }
- switch (key) {
- case " ":
- case "Enter":
- this.openCalciteDropdown();
- break;
- case "Escape":
- this.closeCalciteDropdown();
- break;
- }
- };
- this.focusOnFirstActiveOrFirstItem = () => {
- this.getFocusableElement(this.items.find((item) => item.active) || this.items[0]);
- };
- this.toggleOpenEnd = () => {
- this.focusOnFirstActiveOrFirstItem();
- this.el.removeEventListener("calciteDropdownOpen", this.toggleOpenEnd);
- };
- this.openCalciteDropdown = () => {
- this.active = !this.active;
- if (this.active) {
- this.el.addEventListener("calciteDropdownOpen", this.toggleOpenEnd);
- }
- };
- }
- activeHandler() {
- if (!this.disabled) {
- this.reposition();
- return;
- }
- this.active = false;
- }
- handleDisabledChange(value) {
- if (!value) {
- this.active = false;
- }
- }
- flipPlacementsHandler() {
- this.setFilteredPlacements();
- }
- maxItemsHandler() {
- this.setMaxScrollerHeight();
- }
- placementHandler() {
- this.reposition();
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- var _a;
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
- this.createPopper();
- this.setFilteredPlacements();
- }
- componentDidLoad() {
- this.reposition();
- }
- componentDidRender() {
- interactive.updateHostInteraction(this);
- }
- disconnectedCallback() {
- var _a, _b;
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
- (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
- this.destroyPopper();
- }
- render() {
- const { active } = this;
- return (index.h(index.Host, null, index.h("div", { class: "calcite-dropdown-trigger-container", onClick: this.openCalciteDropdown, onKeyDown: this.keyDownHandler, ref: this.setReferenceEl }, index.h("slot", { "aria-expanded": dom.toAriaBoolean(active), "aria-haspopup": "true", name: SLOTS.dropdownTrigger, onSlotchange: this.updateTriggers })), index.h("div", { "aria-hidden": dom.toAriaBoolean(!active), class: "calcite-dropdown-wrapper", ref: this.setMenuEl }, index.h("div", { class: {
- ["calcite-dropdown-content"]: true,
- [popper.CSS.animation]: true,
- [popper.CSS.animationActive]: active
- }, onTransitionEnd: this.transitionEnd, ref: this.setScrollerEl }, index.h("div", { hidden: !this.active }, index.h("slot", { onSlotchange: this.updateGroups }))))));
- }
- //--------------------------------------------------------------------------
- //
- // Public Methods
- //
- //--------------------------------------------------------------------------
- /** Updates the position of the component. */
- async reposition() {
- const { popper: popper$1, menuEl, placement } = this;
- const modifiers = this.getModifiers();
- popper$1
- ? await popper.updatePopper({
- el: menuEl,
- modifiers,
- placement,
- popper: popper$1
- })
- : this.createPopper();
- }
- closeCalciteDropdownOnClick(e) {
- if (!this.active || e.composedPath().includes(this.el)) {
- return;
- }
- this.closeCalciteDropdown(false);
- }
- closeCalciteDropdownOnEvent() {
- this.closeCalciteDropdown();
- }
- closeCalciteDropdownOnOpenEvent(e) {
- if (e.composedPath().includes(this.el)) {
- return;
- }
- this.active = false;
- }
- mouseEnterHandler() {
- if (this.type === "hover") {
- this.openCalciteDropdown();
- }
- }
- mouseLeaveHandler() {
- if (this.type === "hover") {
- this.closeCalciteDropdown();
- }
- }
- calciteDropdownItemKeyEvent(e) {
- const { keyboardEvent } = e.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;
- }
- e.stopPropagation();
- }
- handleItemSelect(event) {
- this.updateSelectedItems();
- event.stopPropagation();
- this.calciteDropdownSelect.emit();
- if (!this.disableCloseOnSelect ||
- event.detail.requestedDropdownGroup.selectionMode === "none") {
- this.closeCalciteDropdown();
- }
- }
- getModifiers() {
- const flipModifier = {
- name: "flip",
- enabled: true
- };
- flipModifier.options = {
- fallbackPlacements: this.filteredFlipPlacements || popper.popperMenuComputedPlacements
- };
- const eventListenerModifier = {
- name: "eventListeners",
- enabled: this.active
- };
- return [flipModifier, eventListenerModifier];
- }
- createPopper() {
- this.destroyPopper();
- const { menuEl, referenceEl, placement, overlayPositioning } = this;
- const modifiers = this.getModifiers();
- this.popper = popper.createPopper({
- el: menuEl,
- modifiers,
- overlayPositioning,
- placement,
- referenceEl
- });
- }
- destroyPopper() {
- const { popper } = this;
- if (popper) {
- popper.destroy();
- }
- this.popper = null;
- }
- updateSelectedItems() {
- this.selectedItems = this.items.filter((item) => item.active);
- }
- getMaxScrollerHeight() {
- const { maxItems } = 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 maxScrollerHeight;
- }
- closeCalciteDropdown(focusTrigger = true) {
- this.active = 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(e) {
- const index = this.itemIndex(e);
- const nextItem = this.items[index + 1] || this.items[0];
- this.getFocusableElement(nextItem);
- }
- focusPrevItem(e) {
- const index = this.itemIndex(e);
- const prevItem = this.items[index - 1] || this.items[this.items.length - 1];
- this.getFocusableElement(prevItem);
- }
- itemIndex(e) {
- return this.items.indexOf(e);
- }
- 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"],
- "disabled": ["handleDisabledChange"],
- "flipPlacements": ["flipPlacementsHandler"],
- "maxItems": ["maxItemsHandler"],
- "placement": ["placementHandler"]
- }; }
- };
- Dropdown.style = dropdownCss;
- const CSS$1 = {
- containerSmall: "container--s",
- containerMedium: "container--m",
- containerLarge: "container--l"
- };
- const dropdownGroupCss = "@-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{display:block}.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-bottom:-1px;display:block;cursor:default;overflow-wrap:break-word;border-width:0px;border-bottom-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;height:1px;background-color:var(--calcite-ui-border-3)}";
- const DropdownGroup = class {
- constructor(hostRef) {
- index.registerInstance(this, hostRef);
- this.calciteDropdownItemChange = index.createEvent(this, "calciteDropdownItemChange", 7);
- /** 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, { role: "menu" }, 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.calciteDropdownItemChange.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 = "@-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}.container--s{padding-top:0.25rem;padding-bottom:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;-webkit-padding-end:0.5rem;padding-inline-end:0.5rem;-webkit-padding-start:1.5rem;padding-inline-start:1.5rem}.container--m{padding-top:0.5rem;padding-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;-webkit-padding-end:0.75rem;padding-inline-end:0.75rem;-webkit-padding-start:2rem;padding-inline-start:2rem}.container--l{padding-top:0.75rem;padding-bottom:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;-webkit-padding-end:1rem;padding-inline-end:1rem;-webkit-padding-start:2.5rem;padding-inline-start:2.5rem}.container--s.container--none-selection{-webkit-padding-start:0.25rem;padding-inline-start:0.25rem}.container--s.container--none-selection .dropdown-link{-webkit-padding-start:0px;padding-inline-start:0px}.container--m.container--none-selection{-webkit-padding-start:0.5rem;padding-inline-start:0.5rem}.container--m.container--none-selection .dropdown-link{-webkit-padding-start:0px;padding-inline-start:0px}.container--l.container--none-selection{-webkit-padding-start:0.75rem;padding-inline-start:0.75rem}.container--l.container--none-selection .dropdown-link{-webkit-padding-start:0px;padding-inline-start:0px}:host{position:relative;display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:center;align-items:center}.container{position:relative;display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;cursor:pointer;-ms-flex-align:center;align-items:center;color:var(--calcite-ui-text-3);-webkit-text-decoration-line:none;text-decoration-line:none;outline:2px solid transparent;outline-offset:2px;-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)}.dropdown-item-content{-ms-flex:1 1 auto;flex:1 1 auto;-webkit-padding-end:auto;padding-inline-end:auto;-webkit-padding-start:0.25rem;padding-inline-start:0.25rem}:host,.container--link a{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){outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.container--link{padding:0px}.container--link a{position:relative;display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;cursor:pointer;-ms-flex-align:center;align-items:center;color:var(--calcite-ui-text-3);-webkit-text-decoration-line:none;text-decoration-line:none;outline:2px solid transparent;outline-offset:2px;-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)}.container--s .dropdown-link{padding-top:0.25rem;padding-bottom:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;-webkit-padding-end:0.5rem;padding-inline-end:0.5rem;-webkit-padding-start:1.5rem;padding-inline-start:1.5rem}.container--m .dropdown-link{padding-top:0.5rem;padding-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;-webkit-padding-end:0.75rem;padding-inline-end:0.75rem;-webkit-padding-start:2rem;padding-inline-start:2rem}.container--l .dropdown-link{padding-top:0.75rem;padding-bottom:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;-webkit-padding-end:1rem;padding-inline-end:1rem;-webkit-padding-start:2.5rem;padding-inline-start:2.5rem}:host(:hover) .container,:host(:active) .container{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1);-webkit-text-decoration-line:none;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);-webkit-text-decoration-line:none;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([active]) .container:not(.container--none-selection),:host([active]) .container--link .dropdown-link{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}:host([active]) .container:not(.container--none-selection):before,:host([active]) .container--link .dropdown-link:before{opacity:1;color:var(--calcite-ui-brand)}:host([active]) .container:not(.container--none-selection) calcite-icon,:host([active]) .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;-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-transform:scale(0.9);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{-webkit-margin-end:0.5rem;margin-inline-end:0.5rem;-webkit-margin-start:0.25rem;margin-inline-start:0.25rem}.container--s .dropdown-item-icon-end{-webkit-margin-start:0.5rem;margin-inline-start:0.5rem}.container--m .dropdown-item-icon-start{-webkit-margin-end:0.75rem;margin-inline-end:0.75rem;-webkit-margin-start:0.25rem;margin-inline-start:0.25rem}.container--m .dropdown-item-icon-end{-webkit-margin-start:0.75rem;margin-inline-start:0.75rem}.container--l .dropdown-item-icon-start{-webkit-margin-end:1rem;margin-inline-end:1rem;-webkit-margin-start:0.25rem;margin-inline-start:0.25rem}.container--l .dropdown-item-icon-end{-webkit-margin-start:1rem;margin-inline-start:1rem}";
- const DropdownItem = class {
- constructor(hostRef) {
- index.registerInstance(this, hostRef);
- this.calciteDropdownItemSelect = index.createEvent(this, "calciteDropdownItemSelect", 7);
- this.calciteDropdownItemKeyEvent = index.createEvent(this, "calciteDropdownItemKeyEvent", 7);
- this.calciteDropdownCloseRequest = index.createEvent(this, "calciteDropdownCloseRequest", 7);
- //--------------------------------------------------------------------------
- //
- // Public Properties
- //
- //--------------------------------------------------------------------------
- /** Indicates whether the item is active. */
- this.active = false;
- }
- //--------------------------------------------------------------------------
- //
- // Public Methods
- //
- //--------------------------------------------------------------------------
- /** Sets focus on the component. */
- async setFocus() {
- this.el.focus();
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- componentWillLoad() {
- this.initialize();
- }
- connectedCallback() {
- 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.active) : 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(e) {
- switch (e.key) {
- case " ":
- this.emitRequestedItem();
- if (this.href) {
- e.preventDefault();
- this.childLink.click();
- }
- break;
- case "Enter":
- this.emitRequestedItem();
- if (this.href) {
- this.childLink.click();
- }
- break;
- case "Escape":
- this.calciteDropdownCloseRequest.emit();
- break;
- case "Tab":
- case "ArrowUp":
- case "ArrowDown":
- case "Home":
- case "End":
- this.calciteDropdownItemKeyEvent.emit({ keyboardEvent: e });
- break;
- }
- e.preventDefault();
- }
- updateActiveItemOnChange(event) {
- const parentEmittedChange = event.composedPath().includes(this.parentDropdownGroupEl);
- if (parentEmittedChange) {
- this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
- this.requestedDropdownItem = event.detail.requestedDropdownItem;
- this.determineActiveItem();
- }
- }
- //--------------------------------------------------------------------------
- //
- // 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.active = false;
- }
- }
- determineActiveItem() {
- switch (this.selectionMode) {
- case "multi":
- if (this.el === this.requestedDropdownItem) {
- this.active = !this.active;
- }
- break;
- case "single":
- if (this.el === this.requestedDropdownItem) {
- this.active = true;
- }
- else if (this.requestedDropdownGroup === this.parentDropdownGroupEl) {
- this.active = false;
- }
- break;
- case "none":
- this.active = false;
- break;
- }
- }
- emitRequestedItem() {
- this.calciteDropdownItemSelect.emit({
- requestedDropdownItem: this.el,
- requestedDropdownGroup: this.parentDropdownGroupEl
- });
- }
- get el() { return index.getElement(this); }
- };
- DropdownItem.style = dropdownItemCss;
- exports.calcite_dropdown = Dropdown;
- exports.calcite_dropdown_group = DropdownGroup;
- exports.calcite_dropdown_item = DropdownItem;
|