calcite-dropdown_3.cjs.entry.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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.97
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const dom = require('./dom-2ec8c9ed.js');
  10. const floatingUi = require('./floating-ui-b48c8256.js');
  11. const observers = require('./observers-5706326b.js');
  12. const interactive = require('./interactive-32293bca.js');
  13. const openCloseComponent = require('./openCloseComponent-178191c0.js');
  14. const guid = require('./guid-f4f03a7a.js');
  15. const key = require('./key-6a462411.js');
  16. require('./resources-b5a5f8a7.js');
  17. require('./debounce-2c8b61fb.js');
  18. const SLOTS = {
  19. dropdownTrigger: "dropdown-trigger"
  20. };
  21. const dropdownCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:inline-flex;flex:0 1 auto}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host .calcite-dropdown-wrapper{display:block;position:absolute;z-index:900;visibility:hidden;pointer-events:none;inline-size:0;block-size:0;overflow:hidden}.calcite-dropdown-wrapper .calcite-floating-ui-anim{position:relative;transition:var(--calcite-floating-ui-transition);visibility:hidden;transition-property:transform, visibility, opacity;opacity:0;box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);z-index:1;border-radius:0.25rem}.calcite-dropdown-wrapper[data-placement^=bottom] .calcite-floating-ui-anim{transform:translateY(-5px)}.calcite-dropdown-wrapper[data-placement^=top] .calcite-floating-ui-anim{transform:translateY(5px)}.calcite-dropdown-wrapper[data-placement^=left] .calcite-floating-ui-anim{transform:translateX(5px)}.calcite-dropdown-wrapper[data-placement^=right] .calcite-floating-ui-anim{transform:translateX(-5px)}.calcite-dropdown-wrapper[data-placement] .calcite-floating-ui-anim--active{opacity:1;visibility:visible;transform:translate(0)}:host([open]) .calcite-dropdown-wrapper{pointer-events:initial;visibility:visible;inline-size:unset;block-size:unset;overflow:unset}:host .calcite-dropdown-content{max-block-size:45vh;inline-size:auto;overflow-y:auto;overflow-x:hidden;background-color:var(--calcite-ui-foreground-1);inline-size:var(--calcite-dropdown-width)}.calcite-dropdown-trigger-container{position:relative;display:flex;flex:1 1 auto}@media (forced-colors: active){:host([open]) .calcite-dropdown-wrapper{border:1px solid canvasText}}:host([width=s]){--calcite-dropdown-width:12rem}:host([width=m]){--calcite-dropdown-width:14rem}:host([width=l]){--calcite-dropdown-width:16rem}";
  22. const Dropdown = class {
  23. constructor(hostRef) {
  24. index.registerInstance(this, hostRef);
  25. this.calciteDropdownSelect = index.createEvent(this, "calciteDropdownSelect", 6);
  26. this.calciteDropdownBeforeClose = index.createEvent(this, "calciteDropdownBeforeClose", 6);
  27. this.calciteDropdownClose = index.createEvent(this, "calciteDropdownClose", 6);
  28. this.calciteDropdownBeforeOpen = index.createEvent(this, "calciteDropdownBeforeOpen", 6);
  29. this.calciteDropdownOpen = index.createEvent(this, "calciteDropdownOpen", 6);
  30. //--------------------------------------------------------------------------
  31. //
  32. // Public Properties
  33. //
  34. //--------------------------------------------------------------------------
  35. /**
  36. * Opens or closes the dropdown
  37. *
  38. * @deprecated use open instead.
  39. */
  40. this.active = false;
  41. /** When true, opens the dropdown */
  42. this.open = false;
  43. /**
  44. allow the dropdown to remain open after a selection is made
  45. if the selection-mode of the selected item's containing group is "none", the dropdown will always close
  46. */
  47. this.disableCloseOnSelect = false;
  48. /** is the dropdown disabled */
  49. this.disabled = false;
  50. /**
  51. specify the maximum number of calcite-dropdown-items to display before showing the scroller, must be greater than 0 -
  52. this value does not include groupTitles passed to calcite-dropdown-group
  53. */
  54. this.maxItems = 0;
  55. /**
  56. * Determines the type of positioning to use for the overlaid content.
  57. *
  58. * Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.
  59. *
  60. * `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
  61. *
  62. */
  63. this.overlayPositioning = "absolute";
  64. /**
  65. * Determines where the dropdown will be positioned relative to the button.
  66. *
  67. * @default "bottom-start"
  68. */
  69. this.placement = floatingUi.defaultMenuPlacement;
  70. /** specify the scale of dropdown, defaults to m */
  71. this.scale = "m";
  72. /**
  73. * **read-only** The currently selected items
  74. *
  75. * @readonly
  76. */
  77. this.selectedItems = [];
  78. /** specify whether the dropdown is opened by hover or click of a trigger element */
  79. this.type = "click";
  80. this.items = [];
  81. this.groups = [];
  82. this.mutationObserver = observers.createObserver("mutation", () => this.updateItems());
  83. this.resizeObserver = observers.createObserver("resize", (entries) => this.resizeObserverCallback(entries));
  84. this.openTransitionProp = "visibility";
  85. this.guid = `calcite-dropdown-${guid.guid()}`;
  86. this.defaultAssignedElements = [];
  87. //--------------------------------------------------------------------------
  88. //
  89. // Private Methods
  90. //
  91. //--------------------------------------------------------------------------
  92. this.slotChangeHandler = (event) => {
  93. this.defaultAssignedElements = event.target.assignedElements({
  94. flatten: true
  95. });
  96. this.updateItems();
  97. };
  98. this.setFilteredPlacements = () => {
  99. const { el, flipPlacements } = this;
  100. this.filteredFlipPlacements = flipPlacements
  101. ? floatingUi.filterComputedPlacements(flipPlacements, el)
  102. : null;
  103. };
  104. this.updateTriggers = (event) => {
  105. this.triggers = event.target.assignedElements({
  106. flatten: true
  107. });
  108. this.reposition(true);
  109. };
  110. this.updateItems = () => {
  111. this.items = this.groups
  112. .map((group) => Array.from(group === null || group === void 0 ? void 0 : group.querySelectorAll("calcite-dropdown-item")))
  113. .reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []);
  114. this.updateSelectedItems();
  115. this.reposition(true);
  116. };
  117. this.updateGroups = (event) => {
  118. const groups = event.target
  119. .assignedElements({ flatten: true })
  120. .filter((el) => el === null || el === void 0 ? void 0 : el.matches("calcite-dropdown-group"));
  121. this.groups = groups;
  122. this.updateItems();
  123. };
  124. this.resizeObserverCallback = (entries) => {
  125. entries.forEach((entry) => {
  126. const { target } = entry;
  127. if (target === this.referenceEl) {
  128. this.setDropdownWidth();
  129. }
  130. else if (target === this.scrollerEl) {
  131. this.setMaxScrollerHeight();
  132. }
  133. });
  134. };
  135. this.setDropdownWidth = () => {
  136. const { referenceEl, scrollerEl } = this;
  137. const referenceElWidth = referenceEl === null || referenceEl === void 0 ? void 0 : referenceEl.clientWidth;
  138. if (!referenceElWidth || !scrollerEl) {
  139. return;
  140. }
  141. scrollerEl.style.minWidth = `${referenceElWidth}px`;
  142. };
  143. this.setMaxScrollerHeight = () => {
  144. const { scrollerEl } = this;
  145. if (!scrollerEl) {
  146. return;
  147. }
  148. this.reposition(true);
  149. const maxScrollerHeight = this.getMaxScrollerHeight();
  150. scrollerEl.style.maxHeight = maxScrollerHeight > 0 ? `${maxScrollerHeight}px` : "";
  151. this.reposition(true);
  152. };
  153. this.setScrollerAndTransitionEl = (el) => {
  154. this.resizeObserver.observe(el);
  155. this.scrollerEl = el;
  156. this.transitionEl = el;
  157. openCloseComponent.connectOpenCloseComponent(this);
  158. };
  159. this.setReferenceEl = (el) => {
  160. this.referenceEl = el;
  161. floatingUi.connectFloatingUI(this, this.referenceEl, this.floatingEl);
  162. this.resizeObserver.observe(el);
  163. };
  164. this.setFloatingEl = (el) => {
  165. this.floatingEl = el;
  166. floatingUi.connectFloatingUI(this, this.referenceEl, this.floatingEl);
  167. };
  168. this.keyDownHandler = (event) => {
  169. const target = event.target;
  170. if (target !== this.referenceEl) {
  171. return;
  172. }
  173. const { defaultPrevented, key: key$1 } = event;
  174. if (defaultPrevented) {
  175. return;
  176. }
  177. if (this.open) {
  178. if (key$1 === "Escape") {
  179. this.closeCalciteDropdown();
  180. event.preventDefault();
  181. return;
  182. }
  183. else if (event.shiftKey && key$1 === "Tab") {
  184. this.closeCalciteDropdown();
  185. event.preventDefault();
  186. return;
  187. }
  188. }
  189. if (key.isActivationKey(key$1)) {
  190. this.openCalciteDropdown();
  191. event.preventDefault();
  192. }
  193. else if (key$1 === "Escape") {
  194. this.closeCalciteDropdown();
  195. event.preventDefault();
  196. }
  197. };
  198. this.focusOnFirstActiveOrFirstItem = () => {
  199. this.getFocusableElement(this.items.find((item) => item.selected) || this.items[0]);
  200. };
  201. this.toggleOpenEnd = () => {
  202. this.focusOnFirstActiveOrFirstItem();
  203. this.el.removeEventListener("calciteDropdownOpen", this.toggleOpenEnd);
  204. };
  205. this.openCalciteDropdown = () => {
  206. this.open = !this.open;
  207. if (this.open) {
  208. this.el.addEventListener("calciteDropdownOpen", this.toggleOpenEnd);
  209. }
  210. };
  211. }
  212. activeHandler(value) {
  213. this.open = value;
  214. }
  215. openHandler(value) {
  216. if (!this.disabled) {
  217. if (value) {
  218. this.reposition(true);
  219. }
  220. else {
  221. floatingUi.updateAfterClose(this.floatingEl);
  222. }
  223. this.active = value;
  224. return;
  225. }
  226. if (!value) {
  227. floatingUi.updateAfterClose(this.floatingEl);
  228. }
  229. this.open = false;
  230. }
  231. handleDisabledChange(value) {
  232. if (!value) {
  233. this.open = false;
  234. }
  235. }
  236. flipPlacementsHandler() {
  237. this.setFilteredPlacements();
  238. this.reposition(true);
  239. }
  240. maxItemsHandler() {
  241. this.setMaxScrollerHeight();
  242. }
  243. overlayPositioningHandler() {
  244. this.reposition(true);
  245. }
  246. placementHandler() {
  247. this.reposition(true);
  248. }
  249. //--------------------------------------------------------------------------
  250. //
  251. // Lifecycle
  252. //
  253. //--------------------------------------------------------------------------
  254. connectedCallback() {
  255. var _a;
  256. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  257. this.setFilteredPlacements();
  258. this.reposition(true);
  259. if (this.open) {
  260. this.openHandler(this.open);
  261. }
  262. if (this.active) {
  263. this.activeHandler(this.active);
  264. }
  265. openCloseComponent.connectOpenCloseComponent(this);
  266. }
  267. componentDidLoad() {
  268. this.reposition(true);
  269. }
  270. componentDidRender() {
  271. interactive.updateHostInteraction(this);
  272. }
  273. disconnectedCallback() {
  274. var _a, _b;
  275. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  276. floatingUi.disconnectFloatingUI(this, this.referenceEl, this.floatingEl);
  277. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
  278. openCloseComponent.disconnectOpenCloseComponent(this);
  279. }
  280. render() {
  281. const { open, guid } = this;
  282. return (index.h(index.Host, null, index.h("div", { class: "calcite-dropdown-trigger-container", id: `${guid}-menubutton`, onClick: this.openCalciteDropdown, onKeyDown: this.keyDownHandler, ref: this.setReferenceEl }, index.h("slot", { "aria-controls": `${guid}-menu`, "aria-expanded": dom.toAriaBoolean(open), "aria-haspopup": "menu", name: SLOTS.dropdownTrigger, onSlotchange: this.updateTriggers })), index.h("div", { "aria-hidden": dom.toAriaBoolean(!open), class: "calcite-dropdown-wrapper", ref: this.setFloatingEl }, index.h("div", { "aria-labelledby": `${guid}-menubutton`, class: {
  283. ["calcite-dropdown-content"]: true,
  284. [floatingUi.FloatingCSS.animation]: true,
  285. [floatingUi.FloatingCSS.animationActive]: open
  286. }, id: `${guid}-menu`, ref: this.setScrollerAndTransitionEl, role: "menu" }, index.h("slot", { onSlotchange: this.updateGroups })))));
  287. }
  288. //--------------------------------------------------------------------------
  289. //
  290. // Public Methods
  291. //
  292. //--------------------------------------------------------------------------
  293. /**
  294. * Updates the position of the component.
  295. *
  296. * @param delayed
  297. */
  298. async reposition(delayed = false) {
  299. const { floatingEl, referenceEl, placement, overlayPositioning, filteredFlipPlacements } = this;
  300. return floatingUi.reposition(this, {
  301. floatingEl,
  302. referenceEl,
  303. overlayPositioning,
  304. placement,
  305. flipPlacements: filteredFlipPlacements,
  306. type: "menu"
  307. }, delayed);
  308. }
  309. closeCalciteDropdownOnClick(event) {
  310. if (!dom.isPrimaryPointerButton(event) || !this.open || event.composedPath().includes(this.el)) {
  311. return;
  312. }
  313. this.closeCalciteDropdown(false);
  314. }
  315. closeCalciteDropdownOnEvent(event) {
  316. this.closeCalciteDropdown();
  317. event.stopPropagation();
  318. }
  319. closeCalciteDropdownOnOpenEvent(event) {
  320. if (event.composedPath().includes(this.el)) {
  321. return;
  322. }
  323. this.open = false;
  324. }
  325. mouseEnterHandler() {
  326. if (this.type === "hover") {
  327. this.openCalciteDropdown();
  328. }
  329. }
  330. mouseLeaveHandler() {
  331. if (this.type === "hover") {
  332. this.closeCalciteDropdown();
  333. }
  334. }
  335. calciteInternalDropdownItemKeyEvent(event) {
  336. const { keyboardEvent } = event.detail;
  337. // handle edge
  338. const target = keyboardEvent.target;
  339. const itemToFocus = target.nodeName !== "A" ? target : target.parentNode;
  340. const isFirstItem = this.itemIndex(itemToFocus) === 0;
  341. const isLastItem = this.itemIndex(itemToFocus) === this.items.length - 1;
  342. switch (keyboardEvent.key) {
  343. case "Tab":
  344. if (isLastItem && !keyboardEvent.shiftKey) {
  345. this.closeCalciteDropdown();
  346. }
  347. else if (isFirstItem && keyboardEvent.shiftKey) {
  348. this.closeCalciteDropdown();
  349. }
  350. else if (keyboardEvent.shiftKey) {
  351. this.focusPrevItem(itemToFocus);
  352. }
  353. else {
  354. this.focusNextItem(itemToFocus);
  355. }
  356. break;
  357. case "ArrowDown":
  358. this.focusNextItem(itemToFocus);
  359. break;
  360. case "ArrowUp":
  361. this.focusPrevItem(itemToFocus);
  362. break;
  363. case "Home":
  364. this.focusFirstItem();
  365. break;
  366. case "End":
  367. this.focusLastItem();
  368. break;
  369. }
  370. event.stopPropagation();
  371. }
  372. handleItemSelect(event) {
  373. this.updateSelectedItems();
  374. event.stopPropagation();
  375. this.calciteDropdownSelect.emit({
  376. item: event.detail.requestedDropdownItem
  377. });
  378. if (!this.disableCloseOnSelect ||
  379. event.detail.requestedDropdownGroup.selectionMode === "none") {
  380. this.closeCalciteDropdown();
  381. }
  382. event.stopPropagation();
  383. }
  384. onBeforeOpen() {
  385. this.calciteDropdownBeforeOpen.emit();
  386. }
  387. onOpen() {
  388. this.calciteDropdownOpen.emit();
  389. }
  390. onBeforeClose() {
  391. this.calciteDropdownBeforeClose.emit();
  392. }
  393. onClose() {
  394. this.calciteDropdownClose.emit();
  395. }
  396. updateSelectedItems() {
  397. this.selectedItems = this.items.filter((item) => item.selected);
  398. }
  399. getMaxScrollerHeight() {
  400. const { maxItems, items } = this;
  401. let itemsToProcess = 0;
  402. let maxScrollerHeight = 0;
  403. let groupHeaderHeight;
  404. this.groups.forEach((group) => {
  405. if (maxItems > 0 && itemsToProcess < maxItems) {
  406. Array.from(group.children).forEach((item, index) => {
  407. if (index === 0) {
  408. if (isNaN(groupHeaderHeight)) {
  409. groupHeaderHeight = item.offsetTop;
  410. }
  411. maxScrollerHeight += groupHeaderHeight;
  412. }
  413. if (itemsToProcess < maxItems) {
  414. maxScrollerHeight += item.offsetHeight;
  415. itemsToProcess += 1;
  416. }
  417. });
  418. }
  419. });
  420. return items.length > maxItems ? maxScrollerHeight : 0;
  421. }
  422. closeCalciteDropdown(focusTrigger = true) {
  423. this.open = false;
  424. if (focusTrigger) {
  425. dom.focusElement(this.triggers[0]);
  426. }
  427. }
  428. focusFirstItem() {
  429. const firstItem = this.items[0];
  430. this.getFocusableElement(firstItem);
  431. }
  432. focusLastItem() {
  433. const lastItem = this.items[this.items.length - 1];
  434. this.getFocusableElement(lastItem);
  435. }
  436. focusNextItem(el) {
  437. const index = this.itemIndex(el);
  438. const nextItem = this.items[index + 1] || this.items[0];
  439. this.getFocusableElement(nextItem);
  440. }
  441. focusPrevItem(el) {
  442. const index = this.itemIndex(el);
  443. const prevItem = this.items[index - 1] || this.items[this.items.length - 1];
  444. this.getFocusableElement(prevItem);
  445. }
  446. itemIndex(el) {
  447. return this.items.indexOf(el);
  448. }
  449. getFocusableElement(item) {
  450. if (!item) {
  451. return;
  452. }
  453. const target = item.attributes.isLink
  454. ? item.shadowRoot.querySelector("a")
  455. : item;
  456. dom.focusElement(target);
  457. }
  458. get el() { return index.getElement(this); }
  459. static get watchers() { return {
  460. "active": ["activeHandler"],
  461. "open": ["openHandler"],
  462. "disabled": ["handleDisabledChange"],
  463. "flipPlacements": ["flipPlacementsHandler"],
  464. "maxItems": ["maxItemsHandler"],
  465. "overlayPositioning": ["overlayPositioningHandler"],
  466. "placement": ["placementHandler"]
  467. }; }
  468. };
  469. Dropdown.style = dropdownCss;
  470. const CSS$1 = {
  471. containerSmall: "container--s",
  472. containerMedium: "container--m",
  473. containerLarge: "container--l"
  474. };
  475. const dropdownGroupCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}.container{text-align:start}.container--s{font-size:var(--calcite-font-size--2);line-height:1rem}.container--s .dropdown-title{padding:0.5rem}.container--m{font-size:var(--calcite-font-size--1);line-height:1rem}.container--m .dropdown-title{padding:0.75rem}.container--l{font-size:var(--calcite-font-size-0);line-height:1.25rem}.container--l .dropdown-title{padding:1rem}.dropdown-title{margin-block-end:-1px;display:block;cursor:default;overflow-wrap:break-word;border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-2)}.dropdown-separator{display:block;block-size:1px;background-color:var(--calcite-ui-border-3)}";
  476. const DropdownGroup = class {
  477. constructor(hostRef) {
  478. index.registerInstance(this, hostRef);
  479. this.calciteInternalDropdownItemChange = index.createEvent(this, "calciteInternalDropdownItemChange", 6);
  480. /**
  481. specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item),
  482. none (no active items), defaults to single
  483. */
  484. this.selectionMode = "single";
  485. }
  486. //--------------------------------------------------------------------------
  487. //
  488. // Lifecycle
  489. //
  490. //--------------------------------------------------------------------------
  491. componentWillLoad() {
  492. this.groupPosition = this.getGroupPosition();
  493. }
  494. render() {
  495. const scale = this.scale || dom.getElementProp(this.el, "scale", "m");
  496. const groupTitle = this.groupTitle ? (index.h("span", { "aria-hidden": "true", class: "dropdown-title" }, this.groupTitle)) : null;
  497. const dropdownSeparator = this.groupPosition > 0 ? index.h("div", { class: "dropdown-separator", role: "separator" }) : null;
  498. return (index.h(index.Host, { "aria-label": this.groupTitle, role: "group" }, index.h("div", { class: {
  499. container: true,
  500. [CSS$1.containerSmall]: scale === "s",
  501. [CSS$1.containerMedium]: scale === "m",
  502. [CSS$1.containerLarge]: scale === "l"
  503. }, title: this.groupTitle }, dropdownSeparator, groupTitle, index.h("slot", null))));
  504. }
  505. //--------------------------------------------------------------------------
  506. //
  507. // Event Listeners
  508. //
  509. //--------------------------------------------------------------------------
  510. updateActiveItemOnChange(event) {
  511. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  512. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  513. this.calciteInternalDropdownItemChange.emit({
  514. requestedDropdownGroup: this.requestedDropdownGroup,
  515. requestedDropdownItem: this.requestedDropdownItem
  516. });
  517. }
  518. //--------------------------------------------------------------------------
  519. //
  520. // Private Methods
  521. //
  522. //--------------------------------------------------------------------------
  523. getGroupPosition() {
  524. return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-dropdown-group"), this.el);
  525. }
  526. get el() { return index.getElement(this); }
  527. };
  528. DropdownGroup.style = dropdownGroupCss;
  529. const CSS = {
  530. containerLink: "container--link",
  531. containerSmall: "container--s",
  532. containerMedium: "container--m",
  533. containerLarge: "container--l",
  534. containerMulti: "container--multi-selection",
  535. containerSingle: "container--single-selection",
  536. containerNone: "container--none-selection"
  537. };
  538. const dropdownItemCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}.container--s{padding-block:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;padding-inline-end:0.5rem;padding-inline-start:1.5rem}.container--m{padding-block:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;padding-inline-end:0.75rem;padding-inline-start:2rem}.container--l{padding-block:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;padding-inline-end:1rem;padding-inline-start:2.5rem}.container--s.container--none-selection{padding-inline-start:0.25rem}.container--s.container--none-selection .dropdown-link{padding-inline-start:0px}.container--m.container--none-selection{padding-inline-start:0.5rem}.container--m.container--none-selection .dropdown-link{padding-inline-start:0px}.container--l.container--none-selection{padding-inline-start:0.75rem}.container--l.container--none-selection .dropdown-link{padding-inline-start:0px}:host{position:relative;display:flex;flex-grow:1;align-items:center}.container{position:relative;display:flex;flex-grow:1;cursor:pointer;align-items:center;color:var(--calcite-ui-text-3);text-decoration-line:none;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);text-align:start}.dropdown-item-content{flex:1 1 auto;padding-inline-end:auto;padding-inline-start:0.25rem}:host,.container--link a{outline-color:transparent}:host(:focus){outline:2px solid transparent;outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.container--link{padding:0px}.container--link a{position:relative;display:flex;flex-grow:1;cursor:pointer;align-items:center;color:var(--calcite-ui-text-3);text-decoration-line:none;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}.container--s .dropdown-link{padding-block:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;padding-inline-end:0.5rem;padding-inline-start:1.5rem}.container--m .dropdown-link{padding-block:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;padding-inline-end:0.75rem;padding-inline-start:2rem}.container--l .dropdown-link{padding-block:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;padding-inline-end:1rem;padding-inline-start:2.5rem}:host(:hover) .container,:host(:active) .container{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1);text-decoration-line:none}:host(:hover) .container--link .dropdown-link,:host(:active) .container--link .dropdown-link{color:var(--calcite-ui-text-1)}:host(:focus) .container{color:var(--calcite-ui-text-1);text-decoration-line:none}:host(:active) .container{background-color:var(--calcite-ui-foreground-3)}:host(:hover) .container:before,:host(:active) .container:before,:host(:focus) .container:before{opacity:1}:host([selected]) .container:not(.container--none-selection),:host([selected]) .container--link .dropdown-link{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}:host([selected]) .container:not(.container--none-selection):before,:host([selected]) .container--link .dropdown-link:before{opacity:1;color:var(--calcite-ui-brand)}:host([selected]) .container:not(.container--none-selection) calcite-icon,:host([selected]) .container--link .dropdown-link calcite-icon{color:var(--calcite-ui-brand)}.container--multi-selection:before,.container--none-selection:before{display:none}.container--s:before{inset-inline-start:0.5rem}.container--m:before{inset-inline-start:0.75rem}.container--l:before{inset-inline-start:1rem}.dropdown-item-icon{position:absolute;opacity:0;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:scale(0.9)}.container--s .dropdown-item-icon{inset-inline-start:0.25rem}.container--m .dropdown-item-icon{inset-inline-start:0.5rem}.container--l .dropdown-item-icon{inset-inline-start:0.75rem}:host(:hover) .dropdown-item-icon{color:var(--calcite-ui-border-1);opacity:1}:host([active]) .dropdown-item-icon{color:var(--calcite-ui-brand);opacity:1}.container--s .dropdown-item-icon-start{margin-inline-end:0.5rem;margin-inline-start:0.25rem}.container--s .dropdown-item-icon-end{margin-inline-start:0.5rem}.container--m .dropdown-item-icon-start{margin-inline-end:0.75rem;margin-inline-start:0.25rem}.container--m .dropdown-item-icon-end{margin-inline-start:0.75rem}.container--l .dropdown-item-icon-start{margin-inline-end:1rem;margin-inline-start:0.25rem}.container--l .dropdown-item-icon-end{margin-inline-start:1rem}";
  539. const DropdownItem = class {
  540. constructor(hostRef) {
  541. index.registerInstance(this, hostRef);
  542. this.calciteInternalDropdownItemSelect = index.createEvent(this, "calciteInternalDropdownItemSelect", 6);
  543. this.calciteInternalDropdownItemKeyEvent = index.createEvent(this, "calciteInternalDropdownItemKeyEvent", 6);
  544. this.calciteInternalDropdownCloseRequest = index.createEvent(this, "calciteInternalDropdownCloseRequest", 6);
  545. //--------------------------------------------------------------------------
  546. //
  547. // Public Properties
  548. //
  549. //--------------------------------------------------------------------------
  550. /**
  551. * Indicates whether the item is active.
  552. *
  553. * @deprecated Use selected instead.
  554. */
  555. this.active = false;
  556. /** When true, item is selected */
  557. this.selected = false;
  558. }
  559. activeHandler(value) {
  560. this.selected = value;
  561. }
  562. selectedHandler(value) {
  563. this.active = value;
  564. }
  565. //--------------------------------------------------------------------------
  566. //
  567. // Public Methods
  568. //
  569. //--------------------------------------------------------------------------
  570. /** Sets focus on the component. */
  571. async setFocus() {
  572. var _a;
  573. (_a = this.el) === null || _a === void 0 ? void 0 : _a.focus();
  574. }
  575. //--------------------------------------------------------------------------
  576. //
  577. // Lifecycle
  578. //
  579. //--------------------------------------------------------------------------
  580. componentWillLoad() {
  581. this.initialize();
  582. }
  583. connectedCallback() {
  584. const isSelected = this.selected || this.active;
  585. if (isSelected) {
  586. this.activeHandler(isSelected);
  587. this.selectedHandler(isSelected);
  588. }
  589. this.initialize();
  590. }
  591. render() {
  592. const scale = dom.getElementProp(this.el, "scale", "m");
  593. const iconStartEl = (index.h("calcite-icon", { class: "dropdown-item-icon-start", flipRtl: this.iconFlipRtl === "start" || this.iconFlipRtl === "both", icon: this.iconStart, scale: "s" }));
  594. const contentNode = (index.h("span", { class: "dropdown-item-content" }, index.h("slot", null)));
  595. const iconEndEl = (index.h("calcite-icon", { class: "dropdown-item-icon-end", flipRtl: this.iconFlipRtl === "end" || this.iconFlipRtl === "both", icon: this.iconEnd, scale: "s" }));
  596. const slottedContent = this.iconStart && this.iconEnd
  597. ? [iconStartEl, contentNode, iconEndEl]
  598. : this.iconStart
  599. ? [iconStartEl, index.h("slot", null)]
  600. : this.iconEnd
  601. ? [contentNode, iconEndEl]
  602. : contentNode;
  603. 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));
  604. const itemRole = this.href
  605. ? null
  606. : this.selectionMode === "single"
  607. ? "menuitemradio"
  608. : this.selectionMode === "multi"
  609. ? "menuitemcheckbox"
  610. : "menuitem";
  611. const itemAria = this.selectionMode !== "none" ? dom.toAriaBoolean(this.selected) : null;
  612. return (index.h(index.Host, { "aria-checked": itemAria, role: itemRole, tabindex: "0" }, index.h("div", { class: {
  613. container: true,
  614. [CSS.containerLink]: !!this.href,
  615. [CSS.containerSmall]: scale === "s",
  616. [CSS.containerMedium]: scale === "m",
  617. [CSS.containerLarge]: scale === "l",
  618. [CSS.containerMulti]: this.selectionMode === "multi",
  619. [CSS.containerSingle]: this.selectionMode === "single",
  620. [CSS.containerNone]: this.selectionMode === "none"
  621. } }, this.selectionMode !== "none" ? (index.h("calcite-icon", { class: "dropdown-item-icon", icon: this.selectionMode === "multi" ? "check" : "bullet-point", scale: "s" })) : null, contentEl)));
  622. }
  623. //--------------------------------------------------------------------------
  624. //
  625. // Event Listeners
  626. //
  627. //--------------------------------------------------------------------------
  628. onClick() {
  629. this.emitRequestedItem();
  630. }
  631. keyDownHandler(event) {
  632. switch (event.key) {
  633. case " ":
  634. case "Enter":
  635. this.emitRequestedItem();
  636. if (this.href) {
  637. this.childLink.click();
  638. }
  639. event.preventDefault();
  640. break;
  641. case "Escape":
  642. this.calciteInternalDropdownCloseRequest.emit();
  643. event.preventDefault();
  644. break;
  645. case "Tab":
  646. this.calciteInternalDropdownItemKeyEvent.emit({ keyboardEvent: event });
  647. break;
  648. case "ArrowUp":
  649. case "ArrowDown":
  650. case "Home":
  651. case "End":
  652. event.preventDefault();
  653. this.calciteInternalDropdownItemKeyEvent.emit({ keyboardEvent: event });
  654. break;
  655. }
  656. }
  657. updateActiveItemOnChange(event) {
  658. const parentEmittedChange = event.composedPath().includes(this.parentDropdownGroupEl);
  659. if (parentEmittedChange) {
  660. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  661. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  662. this.determineActiveItem();
  663. }
  664. event.stopPropagation();
  665. }
  666. //--------------------------------------------------------------------------
  667. //
  668. // Private Methods
  669. //
  670. //--------------------------------------------------------------------------
  671. initialize() {
  672. this.selectionMode = dom.getElementProp(this.el, "selection-mode", "single");
  673. this.parentDropdownGroupEl = this.el.closest("calcite-dropdown-group");
  674. if (this.selectionMode === "none") {
  675. this.selected = false;
  676. }
  677. }
  678. determineActiveItem() {
  679. switch (this.selectionMode) {
  680. case "multi":
  681. if (this.el === this.requestedDropdownItem) {
  682. this.selected = !this.selected;
  683. }
  684. break;
  685. case "single":
  686. if (this.el === this.requestedDropdownItem) {
  687. this.selected = true;
  688. }
  689. else if (this.requestedDropdownGroup === this.parentDropdownGroupEl) {
  690. this.selected = false;
  691. }
  692. break;
  693. case "none":
  694. this.selected = false;
  695. break;
  696. }
  697. }
  698. emitRequestedItem() {
  699. this.calciteInternalDropdownItemSelect.emit({
  700. requestedDropdownItem: this.el,
  701. requestedDropdownGroup: this.parentDropdownGroupEl
  702. });
  703. }
  704. get el() { return index.getElement(this); }
  705. static get watchers() { return {
  706. "active": ["activeHandler"],
  707. "selected": ["selectedHandler"]
  708. }; }
  709. };
  710. DropdownItem.style = dropdownItemCss;
  711. exports.calcite_dropdown = Dropdown;
  712. exports.calcite_dropdown_group = DropdownGroup;
  713. exports.calcite_dropdown_item = DropdownItem;