calcite-dropdown_3.entry.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-8ece2564.js';
  7. import { t as toAriaBoolean, f as focusElement, d as getElementProp } from './dom-da697a3f.js';
  8. import { d as defaultMenuPlacement, f as filterComputedPlacements, C as CSS$2, u as updatePopper, c as createPopper, p as popperMenuComputedPlacements } from './popper-0fd1fd89.js';
  9. import { c as createObserver } from './observers-b198f831.js';
  10. import { u as updateHostInteraction } from './interactive-cb5bf285.js';
  11. import './guid-b4461004.js';
  12. const SLOTS = {
  13. dropdownTrigger: "dropdown-trigger"
  14. };
  15. 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}";
  16. const Dropdown = class {
  17. constructor(hostRef) {
  18. registerInstance(this, hostRef);
  19. this.calciteDropdownSelect = createEvent(this, "calciteDropdownSelect", 7);
  20. this.calciteDropdownOpen = createEvent(this, "calciteDropdownOpen", 7);
  21. this.calciteDropdownClose = createEvent(this, "calciteDropdownClose", 7);
  22. //--------------------------------------------------------------------------
  23. //
  24. // Public Properties
  25. //
  26. //--------------------------------------------------------------------------
  27. /** Opens or closes the dropdown */
  28. this.active = false;
  29. /**
  30. allow the dropdown to remain open after a selection is made
  31. if the selection-mode of the selected item's containing group is "none", the dropdown will always close
  32. */
  33. this.disableCloseOnSelect = false;
  34. /** is the dropdown disabled */
  35. this.disabled = false;
  36. /**
  37. specify the maximum number of calcite-dropdown-items to display before showing the scroller, must be greater than 0 -
  38. this value does not include groupTitles passed to calcite-dropdown-group
  39. */
  40. this.maxItems = 0;
  41. /** Describes the type of positioning to use for the overlaid content. If your element is in a fixed container, use the 'fixed' value. */
  42. this.overlayPositioning = "absolute";
  43. /**
  44. * Determines where the dropdown will be positioned relative to the button.
  45. * @default "bottom-leading"
  46. */
  47. this.placement = defaultMenuPlacement;
  48. /** specify the scale of dropdown, defaults to m */
  49. this.scale = "m";
  50. /**
  51. * **read-only** The currently selected items
  52. *
  53. * @readonly
  54. */
  55. this.selectedItems = [];
  56. /** specify whether the dropdown is opened by hover or click of a trigger element */
  57. this.type = "click";
  58. /** specify the width of dropdown, defaults to m */
  59. this.width = "m";
  60. this.items = [];
  61. this.groups = [];
  62. this.activeTransitionProp = "visibility";
  63. this.mutationObserver = createObserver("mutation", () => this.updateItems());
  64. this.resizeObserver = createObserver("resize", () => this.setMaxScrollerHeight());
  65. //--------------------------------------------------------------------------
  66. //
  67. // Private Methods
  68. //
  69. //--------------------------------------------------------------------------
  70. this.setFilteredPlacements = () => {
  71. const { el, flipPlacements } = this;
  72. this.filteredFlipPlacements = flipPlacements
  73. ? filterComputedPlacements(flipPlacements, el)
  74. : null;
  75. };
  76. this.updateTriggers = (event) => {
  77. this.triggers = event.target.assignedElements({
  78. flatten: true
  79. });
  80. this.reposition();
  81. };
  82. this.updateItems = () => {
  83. this.items = this.groups
  84. .map((group) => Array.from(group === null || group === void 0 ? void 0 : group.querySelectorAll("calcite-dropdown-item")))
  85. .reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []);
  86. this.updateSelectedItems();
  87. this.reposition();
  88. };
  89. this.updateGroups = (event) => {
  90. const groups = event.target
  91. .assignedElements({ flatten: true })
  92. .filter((el) => el === null || el === void 0 ? void 0 : el.matches("calcite-dropdown-group"));
  93. this.groups = groups;
  94. this.updateItems();
  95. };
  96. this.setMaxScrollerHeight = () => {
  97. const { active, scrollerEl } = this;
  98. if (!scrollerEl || !active) {
  99. return;
  100. }
  101. this.reposition();
  102. const maxScrollerHeight = this.getMaxScrollerHeight();
  103. scrollerEl.style.maxHeight = maxScrollerHeight > 0 ? `${maxScrollerHeight}px` : "";
  104. this.reposition();
  105. };
  106. this.setScrollerEl = (scrollerEl) => {
  107. this.resizeObserver.observe(scrollerEl);
  108. this.scrollerEl = scrollerEl;
  109. };
  110. this.transitionEnd = (event) => {
  111. if (event.propertyName === this.activeTransitionProp) {
  112. this.active ? this.calciteDropdownOpen.emit() : this.calciteDropdownClose.emit();
  113. }
  114. };
  115. this.setReferenceEl = (el) => {
  116. this.referenceEl = el;
  117. };
  118. this.setMenuEl = (el) => {
  119. this.menuEl = el;
  120. };
  121. this.keyDownHandler = (e) => {
  122. const target = e.target;
  123. if (target !== this.referenceEl) {
  124. return;
  125. }
  126. const key = e.key;
  127. if (this.active && (key === "Escape" || (e.shiftKey && key === "Tab"))) {
  128. this.closeCalciteDropdown();
  129. return;
  130. }
  131. switch (key) {
  132. case " ":
  133. case "Enter":
  134. this.openCalciteDropdown();
  135. break;
  136. case "Escape":
  137. this.closeCalciteDropdown();
  138. break;
  139. }
  140. };
  141. this.focusOnFirstActiveOrFirstItem = () => {
  142. this.getFocusableElement(this.items.find((item) => item.active) || this.items[0]);
  143. };
  144. this.toggleOpenEnd = () => {
  145. this.focusOnFirstActiveOrFirstItem();
  146. this.el.removeEventListener("calciteDropdownOpen", this.toggleOpenEnd);
  147. };
  148. this.openCalciteDropdown = () => {
  149. this.active = !this.active;
  150. if (this.active) {
  151. this.el.addEventListener("calciteDropdownOpen", this.toggleOpenEnd);
  152. }
  153. };
  154. }
  155. activeHandler() {
  156. if (!this.disabled) {
  157. this.reposition();
  158. return;
  159. }
  160. this.active = false;
  161. }
  162. handleDisabledChange(value) {
  163. if (!value) {
  164. this.active = false;
  165. }
  166. }
  167. flipPlacementsHandler() {
  168. this.setFilteredPlacements();
  169. }
  170. maxItemsHandler() {
  171. this.setMaxScrollerHeight();
  172. }
  173. placementHandler() {
  174. this.reposition();
  175. }
  176. //--------------------------------------------------------------------------
  177. //
  178. // Lifecycle
  179. //
  180. //--------------------------------------------------------------------------
  181. connectedCallback() {
  182. var _a;
  183. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  184. this.createPopper();
  185. this.setFilteredPlacements();
  186. }
  187. componentDidLoad() {
  188. this.reposition();
  189. }
  190. componentDidRender() {
  191. updateHostInteraction(this);
  192. }
  193. disconnectedCallback() {
  194. var _a, _b;
  195. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  196. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
  197. this.destroyPopper();
  198. }
  199. render() {
  200. const { active } = this;
  201. return (h(Host, null, h("div", { class: "calcite-dropdown-trigger-container", onClick: this.openCalciteDropdown, onKeyDown: this.keyDownHandler, ref: this.setReferenceEl }, h("slot", { "aria-expanded": toAriaBoolean(active), "aria-haspopup": "true", name: SLOTS.dropdownTrigger, onSlotchange: this.updateTriggers })), h("div", { "aria-hidden": toAriaBoolean(!active), class: "calcite-dropdown-wrapper", ref: this.setMenuEl }, h("div", { class: {
  202. ["calcite-dropdown-content"]: true,
  203. [CSS$2.animation]: true,
  204. [CSS$2.animationActive]: active
  205. }, onTransitionEnd: this.transitionEnd, ref: this.setScrollerEl }, h("div", { hidden: !this.active }, h("slot", { onSlotchange: this.updateGroups }))))));
  206. }
  207. //--------------------------------------------------------------------------
  208. //
  209. // Public Methods
  210. //
  211. //--------------------------------------------------------------------------
  212. /** Updates the position of the component. */
  213. async reposition() {
  214. const { popper, menuEl, placement } = this;
  215. const modifiers = this.getModifiers();
  216. popper
  217. ? await updatePopper({
  218. el: menuEl,
  219. modifiers,
  220. placement,
  221. popper
  222. })
  223. : this.createPopper();
  224. }
  225. closeCalciteDropdownOnClick(e) {
  226. if (!this.active || e.composedPath().includes(this.el)) {
  227. return;
  228. }
  229. this.closeCalciteDropdown(false);
  230. }
  231. closeCalciteDropdownOnEvent() {
  232. this.closeCalciteDropdown();
  233. }
  234. closeCalciteDropdownOnOpenEvent(e) {
  235. if (e.composedPath().includes(this.el)) {
  236. return;
  237. }
  238. this.active = false;
  239. }
  240. mouseEnterHandler() {
  241. if (this.type === "hover") {
  242. this.openCalciteDropdown();
  243. }
  244. }
  245. mouseLeaveHandler() {
  246. if (this.type === "hover") {
  247. this.closeCalciteDropdown();
  248. }
  249. }
  250. calciteDropdownItemKeyEvent(e) {
  251. const { keyboardEvent } = e.detail;
  252. // handle edge
  253. const target = keyboardEvent.target;
  254. const itemToFocus = target.nodeName !== "A" ? target : target.parentNode;
  255. const isFirstItem = this.itemIndex(itemToFocus) === 0;
  256. const isLastItem = this.itemIndex(itemToFocus) === this.items.length - 1;
  257. switch (keyboardEvent.key) {
  258. case "Tab":
  259. if (isLastItem && !keyboardEvent.shiftKey) {
  260. this.closeCalciteDropdown();
  261. }
  262. else if (isFirstItem && keyboardEvent.shiftKey) {
  263. this.closeCalciteDropdown();
  264. }
  265. else if (keyboardEvent.shiftKey) {
  266. this.focusPrevItem(itemToFocus);
  267. }
  268. else {
  269. this.focusNextItem(itemToFocus);
  270. }
  271. break;
  272. case "ArrowDown":
  273. this.focusNextItem(itemToFocus);
  274. break;
  275. case "ArrowUp":
  276. this.focusPrevItem(itemToFocus);
  277. break;
  278. case "Home":
  279. this.focusFirstItem();
  280. break;
  281. case "End":
  282. this.focusLastItem();
  283. break;
  284. }
  285. e.stopPropagation();
  286. }
  287. handleItemSelect(event) {
  288. this.updateSelectedItems();
  289. event.stopPropagation();
  290. this.calciteDropdownSelect.emit();
  291. if (!this.disableCloseOnSelect ||
  292. event.detail.requestedDropdownGroup.selectionMode === "none") {
  293. this.closeCalciteDropdown();
  294. }
  295. }
  296. getModifiers() {
  297. const flipModifier = {
  298. name: "flip",
  299. enabled: true
  300. };
  301. flipModifier.options = {
  302. fallbackPlacements: this.filteredFlipPlacements || popperMenuComputedPlacements
  303. };
  304. const eventListenerModifier = {
  305. name: "eventListeners",
  306. enabled: this.active
  307. };
  308. return [flipModifier, eventListenerModifier];
  309. }
  310. createPopper() {
  311. this.destroyPopper();
  312. const { menuEl, referenceEl, placement, overlayPositioning } = this;
  313. const modifiers = this.getModifiers();
  314. this.popper = createPopper({
  315. el: menuEl,
  316. modifiers,
  317. overlayPositioning,
  318. placement,
  319. referenceEl
  320. });
  321. }
  322. destroyPopper() {
  323. const { popper } = this;
  324. if (popper) {
  325. popper.destroy();
  326. }
  327. this.popper = null;
  328. }
  329. updateSelectedItems() {
  330. this.selectedItems = this.items.filter((item) => item.active);
  331. }
  332. getMaxScrollerHeight() {
  333. const { maxItems } = this;
  334. let itemsToProcess = 0;
  335. let maxScrollerHeight = 0;
  336. let groupHeaderHeight;
  337. this.groups.forEach((group) => {
  338. if (maxItems > 0 && itemsToProcess < maxItems) {
  339. Array.from(group.children).forEach((item, index) => {
  340. if (index === 0) {
  341. if (isNaN(groupHeaderHeight)) {
  342. groupHeaderHeight = item.offsetTop;
  343. }
  344. maxScrollerHeight += groupHeaderHeight;
  345. }
  346. if (itemsToProcess < maxItems) {
  347. maxScrollerHeight += item.offsetHeight;
  348. itemsToProcess += 1;
  349. }
  350. });
  351. }
  352. });
  353. return maxScrollerHeight;
  354. }
  355. closeCalciteDropdown(focusTrigger = true) {
  356. this.active = false;
  357. if (focusTrigger) {
  358. focusElement(this.triggers[0]);
  359. }
  360. }
  361. focusFirstItem() {
  362. const firstItem = this.items[0];
  363. this.getFocusableElement(firstItem);
  364. }
  365. focusLastItem() {
  366. const lastItem = this.items[this.items.length - 1];
  367. this.getFocusableElement(lastItem);
  368. }
  369. focusNextItem(e) {
  370. const index = this.itemIndex(e);
  371. const nextItem = this.items[index + 1] || this.items[0];
  372. this.getFocusableElement(nextItem);
  373. }
  374. focusPrevItem(e) {
  375. const index = this.itemIndex(e);
  376. const prevItem = this.items[index - 1] || this.items[this.items.length - 1];
  377. this.getFocusableElement(prevItem);
  378. }
  379. itemIndex(e) {
  380. return this.items.indexOf(e);
  381. }
  382. getFocusableElement(item) {
  383. if (!item) {
  384. return;
  385. }
  386. const target = item.attributes.isLink
  387. ? item.shadowRoot.querySelector("a")
  388. : item;
  389. focusElement(target);
  390. }
  391. get el() { return getElement(this); }
  392. static get watchers() { return {
  393. "active": ["activeHandler"],
  394. "disabled": ["handleDisabledChange"],
  395. "flipPlacements": ["flipPlacementsHandler"],
  396. "maxItems": ["maxItemsHandler"],
  397. "placement": ["placementHandler"]
  398. }; }
  399. };
  400. Dropdown.style = dropdownCss;
  401. const CSS$1 = {
  402. containerSmall: "container--s",
  403. containerMedium: "container--m",
  404. containerLarge: "container--l"
  405. };
  406. 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)}";
  407. const DropdownGroup = class {
  408. constructor(hostRef) {
  409. registerInstance(this, hostRef);
  410. this.calciteDropdownItemChange = createEvent(this, "calciteDropdownItemChange", 7);
  411. /** specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item),
  412. none (no active items), defaults to single */
  413. this.selectionMode = "single";
  414. }
  415. //--------------------------------------------------------------------------
  416. //
  417. // Lifecycle
  418. //
  419. //--------------------------------------------------------------------------
  420. componentWillLoad() {
  421. this.groupPosition = this.getGroupPosition();
  422. }
  423. render() {
  424. const scale = this.scale || getElementProp(this.el, "scale", "m");
  425. const groupTitle = this.groupTitle ? (h("span", { "aria-hidden": "true", class: "dropdown-title" }, this.groupTitle)) : null;
  426. const dropdownSeparator = this.groupPosition > 0 ? h("div", { class: "dropdown-separator", role: "separator" }) : null;
  427. return (h(Host, { role: "menu" }, h("div", { class: {
  428. container: true,
  429. [CSS$1.containerSmall]: scale === "s",
  430. [CSS$1.containerMedium]: scale === "m",
  431. [CSS$1.containerLarge]: scale === "l"
  432. }, title: this.groupTitle }, dropdownSeparator, groupTitle, h("slot", null))));
  433. }
  434. //--------------------------------------------------------------------------
  435. //
  436. // Event Listeners
  437. //
  438. //--------------------------------------------------------------------------
  439. updateActiveItemOnChange(event) {
  440. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  441. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  442. this.calciteDropdownItemChange.emit({
  443. requestedDropdownGroup: this.requestedDropdownGroup,
  444. requestedDropdownItem: this.requestedDropdownItem
  445. });
  446. }
  447. //--------------------------------------------------------------------------
  448. //
  449. // Private Methods
  450. //
  451. //--------------------------------------------------------------------------
  452. getGroupPosition() {
  453. return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-dropdown-group"), this.el);
  454. }
  455. get el() { return getElement(this); }
  456. };
  457. DropdownGroup.style = dropdownGroupCss;
  458. const CSS = {
  459. containerLink: "container--link",
  460. containerSmall: "container--s",
  461. containerMedium: "container--m",
  462. containerLarge: "container--l",
  463. containerMulti: "container--multi-selection",
  464. containerSingle: "container--single-selection",
  465. containerNone: "container--none-selection"
  466. };
  467. 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}";
  468. const DropdownItem = class {
  469. constructor(hostRef) {
  470. registerInstance(this, hostRef);
  471. this.calciteDropdownItemSelect = createEvent(this, "calciteDropdownItemSelect", 7);
  472. this.calciteDropdownItemKeyEvent = createEvent(this, "calciteDropdownItemKeyEvent", 7);
  473. this.calciteDropdownCloseRequest = createEvent(this, "calciteDropdownCloseRequest", 7);
  474. //--------------------------------------------------------------------------
  475. //
  476. // Public Properties
  477. //
  478. //--------------------------------------------------------------------------
  479. /** Indicates whether the item is active. */
  480. this.active = false;
  481. }
  482. //--------------------------------------------------------------------------
  483. //
  484. // Public Methods
  485. //
  486. //--------------------------------------------------------------------------
  487. /** Sets focus on the component. */
  488. async setFocus() {
  489. this.el.focus();
  490. }
  491. //--------------------------------------------------------------------------
  492. //
  493. // Lifecycle
  494. //
  495. //--------------------------------------------------------------------------
  496. componentWillLoad() {
  497. this.initialize();
  498. }
  499. connectedCallback() {
  500. this.initialize();
  501. }
  502. render() {
  503. const scale = getElementProp(this.el, "scale", "m");
  504. const iconStartEl = (h("calcite-icon", { class: "dropdown-item-icon-start", flipRtl: this.iconFlipRtl === "start" || this.iconFlipRtl === "both", icon: this.iconStart, scale: "s" }));
  505. const contentNode = (h("span", { class: "dropdown-item-content" }, h("slot", null)));
  506. const iconEndEl = (h("calcite-icon", { class: "dropdown-item-icon-end", flipRtl: this.iconFlipRtl === "end" || this.iconFlipRtl === "both", icon: this.iconEnd, scale: "s" }));
  507. const slottedContent = this.iconStart && this.iconEnd
  508. ? [iconStartEl, contentNode, iconEndEl]
  509. : this.iconStart
  510. ? [iconStartEl, h("slot", null)]
  511. : this.iconEnd
  512. ? [contentNode, iconEndEl]
  513. : contentNode;
  514. const contentEl = !this.href ? (slottedContent) : (h("a", { "aria-label": this.label, class: "dropdown-link", href: this.href, ref: (el) => (this.childLink = el), rel: this.rel, target: this.target }, slottedContent));
  515. const itemRole = this.href
  516. ? null
  517. : this.selectionMode === "single"
  518. ? "menuitemradio"
  519. : this.selectionMode === "multi"
  520. ? "menuitemcheckbox"
  521. : "menuitem";
  522. const itemAria = this.selectionMode !== "none" ? toAriaBoolean(this.active) : null;
  523. return (h(Host, { "aria-checked": itemAria, role: itemRole, tabindex: "0" }, h("div", { class: {
  524. container: true,
  525. [CSS.containerLink]: !!this.href,
  526. [CSS.containerSmall]: scale === "s",
  527. [CSS.containerMedium]: scale === "m",
  528. [CSS.containerLarge]: scale === "l",
  529. [CSS.containerMulti]: this.selectionMode === "multi",
  530. [CSS.containerSingle]: this.selectionMode === "single",
  531. [CSS.containerNone]: this.selectionMode === "none"
  532. } }, this.selectionMode !== "none" ? (h("calcite-icon", { class: "dropdown-item-icon", icon: this.selectionMode === "multi" ? "check" : "bullet-point", scale: "s" })) : null, contentEl)));
  533. }
  534. //--------------------------------------------------------------------------
  535. //
  536. // Event Listeners
  537. //
  538. //--------------------------------------------------------------------------
  539. onClick() {
  540. this.emitRequestedItem();
  541. }
  542. keyDownHandler(e) {
  543. switch (e.key) {
  544. case " ":
  545. this.emitRequestedItem();
  546. if (this.href) {
  547. e.preventDefault();
  548. this.childLink.click();
  549. }
  550. break;
  551. case "Enter":
  552. this.emitRequestedItem();
  553. if (this.href) {
  554. this.childLink.click();
  555. }
  556. break;
  557. case "Escape":
  558. this.calciteDropdownCloseRequest.emit();
  559. break;
  560. case "Tab":
  561. case "ArrowUp":
  562. case "ArrowDown":
  563. case "Home":
  564. case "End":
  565. this.calciteDropdownItemKeyEvent.emit({ keyboardEvent: e });
  566. break;
  567. }
  568. e.preventDefault();
  569. }
  570. updateActiveItemOnChange(event) {
  571. const parentEmittedChange = event.composedPath().includes(this.parentDropdownGroupEl);
  572. if (parentEmittedChange) {
  573. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  574. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  575. this.determineActiveItem();
  576. }
  577. }
  578. //--------------------------------------------------------------------------
  579. //
  580. // Private Methods
  581. //
  582. //--------------------------------------------------------------------------
  583. initialize() {
  584. this.selectionMode = getElementProp(this.el, "selection-mode", "single");
  585. this.parentDropdownGroupEl = this.el.closest("calcite-dropdown-group");
  586. if (this.selectionMode === "none") {
  587. this.active = false;
  588. }
  589. }
  590. determineActiveItem() {
  591. switch (this.selectionMode) {
  592. case "multi":
  593. if (this.el === this.requestedDropdownItem) {
  594. this.active = !this.active;
  595. }
  596. break;
  597. case "single":
  598. if (this.el === this.requestedDropdownItem) {
  599. this.active = true;
  600. }
  601. else if (this.requestedDropdownGroup === this.parentDropdownGroupEl) {
  602. this.active = false;
  603. }
  604. break;
  605. case "none":
  606. this.active = false;
  607. break;
  608. }
  609. }
  610. emitRequestedItem() {
  611. this.calciteDropdownItemSelect.emit({
  612. requestedDropdownItem: this.el,
  613. requestedDropdownGroup: this.parentDropdownGroupEl
  614. });
  615. }
  616. get el() { return getElement(this); }
  617. };
  618. DropdownItem.style = dropdownItemCss;
  619. export { Dropdown as calcite_dropdown, DropdownGroup as calcite_dropdown_group, DropdownItem as calcite_dropdown_item };