calcite-pick-list.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client/index.js';
  7. import { I as ICON_TYPES } from './resources.js';
  8. import { m as mutationObserverCallback, d as deselectRemovedItems, a as deselectSiblingItems, s as selectSiblings, h as handleFilter, g as getItemData, k as keyDownHandler, i as initialize, b as initializeObserver, c as cleanUpObserver, r as removeItem, e as calciteListItemChangeHandler, f as calciteInternalListItemValueChangeHandler, j as calciteListFocusOutHandler, l as setUpItems, n as setFocus, L as List } from './shared-list-render.js';
  9. import { c as createObserver } from './observers.js';
  10. import { u as updateHostInteraction } from './interactive.js';
  11. import { d as defineCustomElement$7 } from './filter.js';
  12. import { d as defineCustomElement$6 } from './icon.js';
  13. import { d as defineCustomElement$5 } from './input.js';
  14. import { d as defineCustomElement$4 } from './loader.js';
  15. import { d as defineCustomElement$3 } from './progress.js';
  16. import { d as defineCustomElement$2 } from './scrim.js';
  17. const pickListCss = "@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{position:relative;box-sizing:border-box;display:flex;flex-shrink:0;flex-grow:1;flex-direction:column;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([filter-enabled]) header{margin-block-end:0.25rem;display:flex;align-items:stretch;justify-content:flex-end;background-color:var(--calcite-ui-foreground-1);--tw-shadow:0 1px 0 var(--calcite-ui-border-3);--tw-shadow-colored:0 1px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([filter-enabled]) header.sticky-pos{position:sticky;inset-block-start:0px;z-index:1}calcite-filter{margin-block-end:0px}:host([loading][disabled]){min-block-size:2rem}";
  18. const PickList = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  19. constructor() {
  20. super();
  21. this.__registerHost();
  22. this.__attachShadow();
  23. this.calciteListChange = createEvent(this, "calciteListChange", 6);
  24. // --------------------------------------------------------------------------
  25. //
  26. // Properties
  27. //
  28. // --------------------------------------------------------------------------
  29. /**
  30. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  31. */
  32. this.disabled = false;
  33. /**
  34. * When `true`, an input appears at the top of the list that can be used by end users to filter items in the list.
  35. */
  36. this.filterEnabled = false;
  37. /**
  38. * When `true`, a busy indicator is displayed.
  39. */
  40. this.loading = false;
  41. /**
  42. * Similar to standard radio buttons and checkboxes.
  43. * When `true`, a user can select multiple `calcite-pick-list-item`s at a time.
  44. * When `false`, only a single `calcite-pick-list-item` can be selected at a time,
  45. * and a new selection will deselect previous selections.
  46. */
  47. this.multiple = false;
  48. /**
  49. * When `true` and single selection is enabled, the selection changes when navigating `calcite-pick-list-item`s via keyboard.
  50. */
  51. this.selectionFollowsFocus = false;
  52. // --------------------------------------------------------------------------
  53. //
  54. // Private Properties
  55. //
  56. // --------------------------------------------------------------------------
  57. this.selectedValues = new Map();
  58. this.dataForFilter = [];
  59. this.lastSelectedItem = null;
  60. this.mutationObserver = createObserver("mutation", mutationObserverCallback.bind(this));
  61. this.setFilterEl = (el) => {
  62. this.filterEl = el;
  63. };
  64. this.deselectRemovedItems = deselectRemovedItems.bind(this);
  65. this.deselectSiblingItems = deselectSiblingItems.bind(this);
  66. this.selectSiblings = selectSiblings.bind(this);
  67. this.handleFilter = handleFilter.bind(this);
  68. this.getItemData = getItemData.bind(this);
  69. this.keyDownHandler = keyDownHandler.bind(this);
  70. }
  71. // --------------------------------------------------------------------------
  72. //
  73. // Lifecycle
  74. //
  75. // --------------------------------------------------------------------------
  76. connectedCallback() {
  77. initialize.call(this);
  78. initializeObserver.call(this);
  79. }
  80. disconnectedCallback() {
  81. cleanUpObserver.call(this);
  82. }
  83. componentDidRender() {
  84. updateHostInteraction(this);
  85. }
  86. calciteListItemRemoveHandler(event) {
  87. removeItem.call(this, event);
  88. }
  89. calciteListItemChangeHandler(event) {
  90. calciteListItemChangeHandler.call(this, event);
  91. }
  92. calciteInternalListItemPropsChangeHandler(event) {
  93. event.stopPropagation();
  94. this.setUpFilter();
  95. }
  96. calciteInternalListItemValueChangeHandler(event) {
  97. calciteInternalListItemValueChangeHandler.call(this, event);
  98. event.stopPropagation();
  99. }
  100. calciteListFocusOutHandler(event) {
  101. calciteListFocusOutHandler.call(this, event);
  102. }
  103. // --------------------------------------------------------------------------
  104. //
  105. // Private Methods
  106. //
  107. // --------------------------------------------------------------------------
  108. setUpItems() {
  109. setUpItems.call(this, "calcite-pick-list-item");
  110. }
  111. setUpFilter() {
  112. if (this.filterEnabled) {
  113. this.dataForFilter = this.getItemData();
  114. }
  115. }
  116. // --------------------------------------------------------------------------
  117. //
  118. // Public Methods
  119. //
  120. // --------------------------------------------------------------------------
  121. /** Returns the component's selected `calcite-pick-list-item`s. */
  122. async getSelectedItems() {
  123. return this.selectedValues;
  124. }
  125. /**
  126. * Sets focus on the component.
  127. *
  128. * @param focusId
  129. */
  130. async setFocus(focusId) {
  131. return setFocus.call(this, focusId);
  132. }
  133. // --------------------------------------------------------------------------
  134. //
  135. // Render Methods
  136. //
  137. // --------------------------------------------------------------------------
  138. getIconType() {
  139. return this.multiple ? ICON_TYPES.square : ICON_TYPES.circle;
  140. }
  141. render() {
  142. return h(List, { onKeyDown: this.keyDownHandler, props: this });
  143. }
  144. get el() { return this; }
  145. static get style() { return pickListCss; }
  146. }, [1, "calcite-pick-list", {
  147. "disabled": [516],
  148. "filterEnabled": [516, "filter-enabled"],
  149. "filterPlaceholder": [513, "filter-placeholder"],
  150. "headingLevel": [514, "heading-level"],
  151. "loading": [516],
  152. "multiple": [516],
  153. "selectionFollowsFocus": [516, "selection-follows-focus"],
  154. "selectedValues": [32],
  155. "dataForFilter": [32],
  156. "getSelectedItems": [64],
  157. "setFocus": [64]
  158. }, [[0, "calciteListItemRemove", "calciteListItemRemoveHandler"], [0, "calciteListItemChange", "calciteListItemChangeHandler"], [0, "calciteInternalListItemPropsChange", "calciteInternalListItemPropsChangeHandler"], [0, "calciteInternalListItemValueChange", "calciteInternalListItemValueChangeHandler"], [0, "focusout", "calciteListFocusOutHandler"]]]);
  159. function defineCustomElement$1() {
  160. if (typeof customElements === "undefined") {
  161. return;
  162. }
  163. const components = ["calcite-pick-list", "calcite-filter", "calcite-icon", "calcite-input", "calcite-loader", "calcite-progress", "calcite-scrim"];
  164. components.forEach(tagName => { switch (tagName) {
  165. case "calcite-pick-list":
  166. if (!customElements.get(tagName)) {
  167. customElements.define(tagName, PickList);
  168. }
  169. break;
  170. case "calcite-filter":
  171. if (!customElements.get(tagName)) {
  172. defineCustomElement$7();
  173. }
  174. break;
  175. case "calcite-icon":
  176. if (!customElements.get(tagName)) {
  177. defineCustomElement$6();
  178. }
  179. break;
  180. case "calcite-input":
  181. if (!customElements.get(tagName)) {
  182. defineCustomElement$5();
  183. }
  184. break;
  185. case "calcite-loader":
  186. if (!customElements.get(tagName)) {
  187. defineCustomElement$4();
  188. }
  189. break;
  190. case "calcite-progress":
  191. if (!customElements.get(tagName)) {
  192. defineCustomElement$3();
  193. }
  194. break;
  195. case "calcite-scrim":
  196. if (!customElements.get(tagName)) {
  197. defineCustomElement$2();
  198. }
  199. break;
  200. } });
  201. }
  202. defineCustomElement$1();
  203. const CalcitePickList = PickList;
  204. const defineCustomElement = defineCustomElement$1;
  205. export { CalcitePickList, defineCustomElement };