calcite-pick-list_3.cjs.entry.js 26 KB

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