calcite-pick-list_3.entry.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { r as registerInstance, c as createEvent, h, g as getElement, F as Fragment } from './index-8ece2564.js';
  7. 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, c as initializeObserver, e as cleanUpObserver, r as removeItem, j as calciteListItemChangeHandler, l as calciteListItemValueChangeHandler, f as calciteListFocusOutHandler, n as setUpItems, o as setFocus, I as ICON_TYPES, L as List, p as SLOTS, q as CSS, H as HEADING_LEVEL, T as TEXT, t as ICONS, C as CSS$1, S as SLOTS$1 } from './resources-c4ee68b9.js';
  8. import { c as createObserver } from './observers-b198f831.js';
  9. import { u as updateHostInteraction } from './interactive-cb5bf285.js';
  10. import { g as getSlotted, t as toAriaBoolean } from './dom-da697a3f.js';
  11. import { H as Heading, c as constrainHeadingLevel } from './Heading-8d613e81.js';
  12. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot-203be745.js';
  13. import './array-1655bbf7.js';
  14. import './debounce-c4df98cc.js';
  15. import './guid-b4461004.js';
  16. 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}";
  17. const PickList = class {
  18. constructor(hostRef) {
  19. registerInstance(this, hostRef);
  20. this.calciteListChange = createEvent(this, "calciteListChange", 7);
  21. // --------------------------------------------------------------------------
  22. //
  23. // Properties
  24. //
  25. // --------------------------------------------------------------------------
  26. /**
  27. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  28. */
  29. this.disabled = false;
  30. /**
  31. * When true, an input appears at the top of the list that can be used by end users to filter items in the list.
  32. */
  33. this.filterEnabled = false;
  34. /**
  35. * When true, content is waiting to be loaded. This state shows a busy indicator.
  36. */
  37. this.loading = false;
  38. /**
  39. * Multiple works similar to standard radio buttons and checkboxes.
  40. * When true, a user can select multiple items at a time.
  41. * When false, only a single item can be selected at a time
  42. * and selecting a new item will deselect any other selected items.
  43. */
  44. this.multiple = false;
  45. /**
  46. * When true and single-selection is enabled, the selection will change when navigating items via the keyboard.
  47. */
  48. this.selectionFollowsFocus = false;
  49. // --------------------------------------------------------------------------
  50. //
  51. // Private Properties
  52. //
  53. // --------------------------------------------------------------------------
  54. this.selectedValues = new Map();
  55. this.dataForFilter = [];
  56. this.lastSelectedItem = null;
  57. this.mutationObserver = createObserver("mutation", mutationObserverCallback.bind(this));
  58. this.setFilterEl = (el) => {
  59. this.filterEl = el;
  60. };
  61. this.deselectRemovedItems = deselectRemovedItems.bind(this);
  62. this.deselectSiblingItems = deselectSiblingItems.bind(this);
  63. this.selectSiblings = selectSiblings.bind(this);
  64. this.handleFilter = handleFilter.bind(this);
  65. this.getItemData = getItemData.bind(this);
  66. this.keyDownHandler = keyDownHandler.bind(this);
  67. }
  68. // --------------------------------------------------------------------------
  69. //
  70. // Lifecycle
  71. //
  72. // --------------------------------------------------------------------------
  73. connectedCallback() {
  74. initialize.call(this);
  75. initializeObserver.call(this);
  76. }
  77. disconnectedCallback() {
  78. cleanUpObserver.call(this);
  79. }
  80. componentDidRender() {
  81. updateHostInteraction(this);
  82. }
  83. calciteListItemRemoveHandler(event) {
  84. removeItem.call(this, event);
  85. }
  86. calciteListItemChangeHandler(event) {
  87. calciteListItemChangeHandler.call(this, event);
  88. }
  89. calciteListItemPropsChangeHandler(event) {
  90. event.stopPropagation();
  91. this.setUpFilter();
  92. }
  93. calciteListItemValueChangeHandler(event) {
  94. calciteListItemValueChangeHandler.call(this, event);
  95. }
  96. calciteListFocusOutHandler(event) {
  97. calciteListFocusOutHandler.call(this, event);
  98. }
  99. // --------------------------------------------------------------------------
  100. //
  101. // Private Methods
  102. //
  103. // --------------------------------------------------------------------------
  104. setUpItems() {
  105. setUpItems.call(this, "calcite-pick-list-item");
  106. }
  107. setUpFilter() {
  108. if (this.filterEnabled) {
  109. this.dataForFilter = this.getItemData();
  110. }
  111. }
  112. // --------------------------------------------------------------------------
  113. //
  114. // Public Methods
  115. //
  116. // --------------------------------------------------------------------------
  117. /** Returns the currently selected items */
  118. async getSelectedItems() {
  119. return this.selectedValues;
  120. }
  121. /** Sets focus on the component. */
  122. async setFocus(focusId) {
  123. return setFocus.call(this, focusId);
  124. }
  125. // --------------------------------------------------------------------------
  126. //
  127. // Render Methods
  128. //
  129. // --------------------------------------------------------------------------
  130. getIconType() {
  131. return this.multiple ? ICON_TYPES.square : ICON_TYPES.circle;
  132. }
  133. render() {
  134. return h(List, { onKeyDown: this.keyDownHandler, props: this });
  135. }
  136. get el() { return getElement(this); }
  137. };
  138. PickList.style = pickListCss;
  139. const pickListGroupCss = "@-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{margin-bottom:0.25rem;-webkit-box-sizing:border-box;box-sizing:border-box;display:block;background-color:transparent;font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}:host(:last-child){margin-bottom:0px}.header{margin:0px;display:-ms-flexbox;display:flex;-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;align-items:center;fill:var(--calcite-ui-text-2);color:var(--calcite-ui-text-2)}.heading{margin:0px;padding:0px;font-weight:var(--calcite-font-weight-medium)}.header .heading{-ms-flex:1 1 auto;flex:1 1 auto;padding:0.5rem}h1.heading{font-size:var(--calcite-font-size-2);line-height:1.5rem}h2.heading{font-size:var(--calcite-font-size-1);line-height:1.5rem}h3.heading{font-size:var(--calcite-font-size-0);line-height:1.25rem}h4.heading,h5.heading{font-size:var(--calcite-font-size--1);line-height:1rem}h3.heading{margin-top:0.5rem;margin-bottom:0.5rem;margin-left:1rem;margin-right:1rem;font-size:var(--calcite-font-size--1);line-height:1.375;color:var(--calcite-ui-text-3)}.container--indented{-webkit-margin-start:1.5rem;margin-inline-start:1.5rem}";
  140. const PickListGroup = class {
  141. constructor(hostRef) {
  142. registerInstance(this, hostRef);
  143. }
  144. // --------------------------------------------------------------------------
  145. //
  146. // Lifecycle
  147. //
  148. // --------------------------------------------------------------------------
  149. connectedCallback() {
  150. connectConditionalSlotComponent(this);
  151. }
  152. disconnectedCallback() {
  153. disconnectConditionalSlotComponent(this);
  154. }
  155. // --------------------------------------------------------------------------
  156. //
  157. // Render Methods
  158. //
  159. // --------------------------------------------------------------------------
  160. render() {
  161. var _a;
  162. const { el, groupTitle, headingLevel } = this;
  163. const hasParentItem = getSlotted(el, SLOTS.parentItem) !== null;
  164. const sectionClasses = {
  165. [CSS.container]: true,
  166. [CSS.indented]: hasParentItem
  167. };
  168. const title = groupTitle;
  169. const parentLevel = (_a = el.closest("calcite-pick-list")) === null || _a === void 0 ? void 0 : _a.headingLevel;
  170. const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
  171. const level = headingLevel || relativeLevel || HEADING_LEVEL;
  172. return (h(Fragment, null, title ? (h(Heading, { class: CSS.heading, level: level }, title)) : null, h("slot", { name: SLOTS.parentItem }), h("section", { class: sectionClasses }, h("slot", null))));
  173. }
  174. get el() { return getElement(this); }
  175. };
  176. PickListGroup.style = pickListGroupCss;
  177. const pickListItemCss = "@charset \"UTF-8\";@-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{margin:0px;margin-bottom:1px;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex-align:stretch;align-items:stretch;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-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);-webkit-transition:background-color var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing);-webkit-animation:calcite-fade-in var(--calcite-animation-timing);animation:calcite-fade-in var(--calcite-animation-timing)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}.label{display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;cursor:pointer;-ms-flex-align:center;align-items:center;background-color:transparent;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}.label:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.label:hover{background-color:var(--calcite-ui-foreground-2)}:host([non-interactive]:hover){background-color:var(--calcite-ui-foreground-1)}:host([non-interactive]) .label,:host([non-interactive]) .icon{pointer-events:none}.icon{margin-top:0px;margin-bottom:0px;display:-ms-flexbox;display:flex;cursor:pointer;-ms-flex-align:center;align-items:center;padding:0.25rem;color:var(--calcite-ui-brand);-ms-flex:0 0 auto;flex:0 0 auto;line-height:0}.icon:hover{background-color:var(--calcite-ui-foreground-2)}.icon-dot{display:-ms-flexbox;display:flex;width:1.5rem;-ms-flex-align:center;align-items:center;padding:0.5rem}.icon-dot:before{opacity:0;content:\"•\"}.icon calcite-icon{opacity:0}:host([selected]) .icon-dot:before,:host([selected]) .icon calcite-icon{-webkit-transition:opacity var(--calcite-animation-timing);transition:opacity var(--calcite-animation-timing);opacity:1}.text-container{pointer-events:none;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-wrap:nowrap;flex-wrap:nowrap;overflow:hidden;padding-top:0.5rem;padding-bottom:0.5rem;padding-left:0.75rem;padding-right:0.75rem;font-size:var(--calcite-font-size--2);line-height:1.375;word-wrap:break-word;word-break:break-word}.title{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-1)}.description{margin-top:0.125rem;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}.actions{margin:0px;display:-ms-flexbox;display:flex;-ms-flex:0 1 auto;flex:0 1 auto;-ms-flex-align:stretch;align-items:stretch;-ms-flex-pack:end;justify-content:flex-end}.actions--start~.label{-webkit-padding-start:0.25rem;padding-inline-start:0.25rem}: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}";
  178. const PickListItem = class {
  179. constructor(hostRef) {
  180. registerInstance(this, hostRef);
  181. this.calciteListItemChange = createEvent(this, "calciteListItemChange", 7);
  182. this.calciteListItemRemove = createEvent(this, "calciteListItemRemove", 7);
  183. this.calciteListItemPropsChange = createEvent(this, "calciteListItemPropsChange", 7);
  184. this.calciteListItemValueChange = createEvent(this, "calciteListItemValueChange", 7);
  185. /**
  186. * When true, the item cannot be clicked and is visually muted.
  187. */
  188. this.disabled = false;
  189. /**
  190. * When false, the item cannot be deselected by user interaction.
  191. */
  192. this.disableDeselect = false;
  193. /**
  194. * @internal When true, the item cannot be selected by user interaction.
  195. */
  196. this.nonInteractive = false;
  197. /**
  198. * Determines the icon SVG symbol that will be shown. Options are circle, square, grip or null.
  199. * @see [ICON_TYPES](https://github.com/Esri/calcite-components/blob/master/src/components/pick-list/resources.ts#L5)
  200. */
  201. this.icon = null;
  202. /**
  203. * Set this to true to display a remove action that removes the item from the list.
  204. */
  205. this.removable = false;
  206. /**
  207. * Set this to true to pre-select an item. Toggles when an item is checked/unchecked.
  208. */
  209. this.selected = false;
  210. /**
  211. * Used as an accessible label (aria-label) for the "remove item" action. Only applicable if removable is true.
  212. * @default "Remove"
  213. */
  214. this.intlRemove = TEXT.remove;
  215. // --------------------------------------------------------------------------
  216. //
  217. // Private Methods
  218. //
  219. // --------------------------------------------------------------------------
  220. this.pickListClickHandler = (event) => {
  221. if (this.disabled || (this.disableDeselect && this.selected) || this.nonInteractive) {
  222. return;
  223. }
  224. this.shiftPressed = event.shiftKey;
  225. this.selected = !this.selected;
  226. };
  227. this.pickListKeyDownHandler = (event) => {
  228. if (event.key === " ") {
  229. event.preventDefault();
  230. if ((this.disableDeselect && this.selected) || this.nonInteractive) {
  231. return;
  232. }
  233. this.selected = !this.selected;
  234. }
  235. };
  236. this.removeClickHandler = () => {
  237. this.calciteListItemRemove.emit();
  238. };
  239. }
  240. descriptionWatchHandler() {
  241. this.calciteListItemPropsChange.emit();
  242. }
  243. labelWatchHandler() {
  244. this.calciteListItemPropsChange.emit();
  245. }
  246. metadataWatchHandler() {
  247. this.calciteListItemPropsChange.emit();
  248. }
  249. selectedWatchHandler() {
  250. this.calciteListItemChange.emit({
  251. item: this.el,
  252. value: this.value,
  253. selected: this.selected,
  254. shiftPressed: this.shiftPressed
  255. });
  256. this.shiftPressed = false;
  257. }
  258. valueWatchHandler(newValue, oldValue) {
  259. this.calciteListItemValueChange.emit({ oldValue, newValue });
  260. }
  261. // --------------------------------------------------------------------------
  262. //
  263. // Lifecycle
  264. //
  265. // --------------------------------------------------------------------------
  266. connectedCallback() {
  267. connectConditionalSlotComponent(this);
  268. }
  269. disconnectedCallback() {
  270. disconnectConditionalSlotComponent(this);
  271. }
  272. componentDidRender() {
  273. updateHostInteraction(this, this.el.closest("calcite-pick-list") ? "managed" : false);
  274. }
  275. // --------------------------------------------------------------------------
  276. //
  277. // Public Methods
  278. //
  279. // --------------------------------------------------------------------------
  280. /**
  281. * Used to toggle the selection state. By default this won't trigger an event.
  282. * The first argument allows the value to be coerced, rather than swapping values.
  283. */
  284. async toggleSelected(coerce) {
  285. this.selected = typeof coerce === "boolean" ? coerce : !this.selected;
  286. }
  287. /** Sets focus on the component. */
  288. async setFocus() {
  289. var _a;
  290. (_a = this.focusEl) === null || _a === void 0 ? void 0 : _a.focus();
  291. }
  292. // --------------------------------------------------------------------------
  293. //
  294. // Render Methods
  295. //
  296. // --------------------------------------------------------------------------
  297. renderIcon() {
  298. const { icon } = this;
  299. if (!icon) {
  300. return null;
  301. }
  302. return (h("span", { class: {
  303. [CSS$1.icon]: true,
  304. [CSS$1.iconDot]: icon === ICON_TYPES.circle
  305. }, onClick: this.pickListClickHandler }, icon === ICON_TYPES.square ? h("calcite-icon", { icon: ICONS.checked, scale: "s" }) : null));
  306. }
  307. renderRemoveAction() {
  308. return this.removable ? (h("calcite-action", { class: CSS$1.remove, icon: ICONS.remove, onCalciteActionClick: this.removeClickHandler, slot: SLOTS$1.actionsEnd, text: this.intlRemove })) : null;
  309. }
  310. renderActionsStart() {
  311. const { el } = this;
  312. const hasActionsStart = getSlotted(el, SLOTS$1.actionsStart);
  313. return hasActionsStart ? (h("div", { class: { [CSS$1.actions]: true, [CSS$1.actionsStart]: true } }, h("slot", { name: SLOTS$1.actionsStart }))) : null;
  314. }
  315. renderActionsEnd() {
  316. const { el, removable } = this;
  317. const hasActionsEnd = getSlotted(el, SLOTS$1.actionsEnd);
  318. return hasActionsEnd || removable ? (h("div", { class: { [CSS$1.actions]: true, [CSS$1.actionsEnd]: true } }, h("slot", { name: SLOTS$1.actionsEnd }), this.renderRemoveAction())) : null;
  319. }
  320. render() {
  321. const { description, label } = this;
  322. return (h(Fragment, null, this.renderIcon(), this.renderActionsStart(), h("label", { "aria-label": label, class: CSS$1.label, onClick: this.pickListClickHandler, onKeyDown: this.pickListKeyDownHandler, ref: (focusEl) => (this.focusEl = focusEl), tabIndex: 0 }, h("div", { "aria-checked": toAriaBoolean(this.selected), class: CSS$1.textContainer, role: "menuitemcheckbox" }, h("span", { class: CSS$1.title }, label), description ? h("span", { class: CSS$1.description }, description) : null)), this.renderActionsEnd()));
  323. }
  324. get el() { return getElement(this); }
  325. static get watchers() { return {
  326. "description": ["descriptionWatchHandler"],
  327. "label": ["labelWatchHandler"],
  328. "metadata": ["metadataWatchHandler"],
  329. "selected": ["selectedWatchHandler"],
  330. "value": ["valueWatchHandler"]
  331. }; }
  332. };
  333. PickListItem.style = pickListItemCss;
  334. export { PickList as calcite_pick_list, PickListGroup as calcite_pick_list_group, PickListItem as calcite_pick_list_item };