calcite-dropdown_3.cjs.entry.js 37 KB

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