calcite-pick-list.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
  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 calciteListItemValueChangeHandler, 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 = "@-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{position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex-negative:0;flex-shrink:0;-ms-flex-positive:1;flex-grow:1;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:stretch;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}: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([filter-enabled]) header{margin-bottom:0.25rem;display:-ms-flexbox;display:flex;-ms-flex-align:stretch;align-items:stretch;-ms-flex-pack:end;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);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);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:-webkit-sticky;position:sticky;top:0px;z-index:1}calcite-filter{margin-bottom:0px}:host([loading][disabled]){min-height: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", 7);
  24. // --------------------------------------------------------------------------
  25. //
  26. // Properties
  27. //
  28. // --------------------------------------------------------------------------
  29. /**
  30. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  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, content is waiting to be loaded. This state shows a busy indicator.
  39. */
  40. this.loading = false;
  41. /**
  42. * Multiple works similar to standard radio buttons and checkboxes.
  43. * When true, a user can select multiple items at a time.
  44. * When false, only a single item can be selected at a time
  45. * and selecting a new item will deselect any other selected items.
  46. */
  47. this.multiple = false;
  48. /**
  49. * When true and single-selection is enabled, the selection will change when navigating items via the 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. calciteListItemPropsChangeHandler(event) {
  93. event.stopPropagation();
  94. this.setUpFilter();
  95. }
  96. calciteListItemValueChangeHandler(event) {
  97. calciteListItemValueChangeHandler.call(this, event);
  98. }
  99. calciteListFocusOutHandler(event) {
  100. calciteListFocusOutHandler.call(this, event);
  101. }
  102. // --------------------------------------------------------------------------
  103. //
  104. // Private Methods
  105. //
  106. // --------------------------------------------------------------------------
  107. setUpItems() {
  108. setUpItems.call(this, "calcite-pick-list-item");
  109. }
  110. setUpFilter() {
  111. if (this.filterEnabled) {
  112. this.dataForFilter = this.getItemData();
  113. }
  114. }
  115. // --------------------------------------------------------------------------
  116. //
  117. // Public Methods
  118. //
  119. // --------------------------------------------------------------------------
  120. /** Returns the currently selected items */
  121. async getSelectedItems() {
  122. return this.selectedValues;
  123. }
  124. /** Sets focus on the component. */
  125. async setFocus(focusId) {
  126. return setFocus.call(this, focusId);
  127. }
  128. // --------------------------------------------------------------------------
  129. //
  130. // Render Methods
  131. //
  132. // --------------------------------------------------------------------------
  133. getIconType() {
  134. return this.multiple ? ICON_TYPES.square : ICON_TYPES.circle;
  135. }
  136. render() {
  137. return h(List, { onKeyDown: this.keyDownHandler, props: this });
  138. }
  139. get el() { return this; }
  140. static get style() { return pickListCss; }
  141. }, [1, "calcite-pick-list", {
  142. "disabled": [516],
  143. "filterEnabled": [516, "filter-enabled"],
  144. "filterPlaceholder": [513, "filter-placeholder"],
  145. "headingLevel": [2, "heading-level"],
  146. "loading": [516],
  147. "multiple": [516],
  148. "selectionFollowsFocus": [4, "selection-follows-focus"],
  149. "selectedValues": [32],
  150. "dataForFilter": [32],
  151. "getSelectedItems": [64],
  152. "setFocus": [64]
  153. }, [[0, "calciteListItemRemove", "calciteListItemRemoveHandler"], [0, "calciteListItemChange", "calciteListItemChangeHandler"], [0, "calciteListItemPropsChange", "calciteListItemPropsChangeHandler"], [0, "calciteListItemValueChange", "calciteListItemValueChangeHandler"], [0, "focusout", "calciteListFocusOutHandler"]]]);
  154. function defineCustomElement$1() {
  155. if (typeof customElements === "undefined") {
  156. return;
  157. }
  158. const components = ["calcite-pick-list", "calcite-filter", "calcite-icon", "calcite-input", "calcite-loader", "calcite-progress", "calcite-scrim"];
  159. components.forEach(tagName => { switch (tagName) {
  160. case "calcite-pick-list":
  161. if (!customElements.get(tagName)) {
  162. customElements.define(tagName, PickList);
  163. }
  164. break;
  165. case "calcite-filter":
  166. if (!customElements.get(tagName)) {
  167. defineCustomElement$7();
  168. }
  169. break;
  170. case "calcite-icon":
  171. if (!customElements.get(tagName)) {
  172. defineCustomElement$6();
  173. }
  174. break;
  175. case "calcite-input":
  176. if (!customElements.get(tagName)) {
  177. defineCustomElement$5();
  178. }
  179. break;
  180. case "calcite-loader":
  181. if (!customElements.get(tagName)) {
  182. defineCustomElement$4();
  183. }
  184. break;
  185. case "calcite-progress":
  186. if (!customElements.get(tagName)) {
  187. defineCustomElement$3();
  188. }
  189. break;
  190. case "calcite-scrim":
  191. if (!customElements.get(tagName)) {
  192. defineCustomElement$2();
  193. }
  194. break;
  195. } });
  196. }
  197. defineCustomElement$1();
  198. const CalcitePickList = PickList;
  199. const defineCustomElement = defineCustomElement$1;
  200. export { CalcitePickList, defineCustomElement };