calcite-value-list-item.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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, Host } from '@stencil/core/internal/client';
  7. import { I as ICON_TYPES } from './resources.js';
  8. import { g as guid } from './guid.js';
  9. import { S as SLOTS$1, C as CSS, d as defineCustomElement$2 } from './pick-list-item.js';
  10. import { b as getSlotted, t as toAriaBoolean } from './dom.js';
  11. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  12. import { u as updateHostInteraction } from './interactive.js';
  13. import { d as defineCustomElement$5 } from './action.js';
  14. import { d as defineCustomElement$4 } from './icon.js';
  15. import { d as defineCustomElement$3 } from './loader.js';
  16. const ICONS = {
  17. drag: "drag"
  18. };
  19. const SLOTS = {
  20. actionsEnd: "actions-end",
  21. actionsStart: "actions-start"
  22. };
  23. const valueListItemCss = "@-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:1px;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2);--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), -webkit-box-shadow var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing), -webkit-box-shadow var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing), box-shadow var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing), box-shadow var(--calcite-animation-timing), -webkit-box-shadow var(--calcite-animation-timing)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}calcite-pick-list-item{position:relative;margin:0px;-ms-flex-positive:1;flex-grow:1;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-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([active]),:host([selected]){--tw-shadow:0 0 0 1px var(--calcite-ui-brand);--tw-shadow-colored:0 0 0 1px 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)}.handle{display:-ms-flexbox;display:flex;cursor:move;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-style:none;background-color:transparent;padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem;color:var(--calcite-ui-text-1);color:var(--calcite-ui-border-1);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}.handle:hover{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}.handle:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.handle--activated{background-color:var(--calcite-ui-foreground-3);color:var(--calcite-ui-text-1)}.handle calcite-icon{color:inherit}: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}";
  24. const ValueListItem = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  25. constructor() {
  26. super();
  27. this.__registerHost();
  28. this.__attachShadow();
  29. this.calciteListItemRemove = createEvent(this, "calciteListItemRemove", 7);
  30. /**
  31. * When true, the list item cannot be clicked and is visually muted.
  32. */
  33. this.disabled = false;
  34. /**
  35. * @internal When false, the list item cannot be deselected by user interaction.
  36. */
  37. this.disableDeselect = false;
  38. /**
  39. * When true, prevents the content of the list item from user interaction.
  40. */
  41. this.nonInteractive = false;
  42. /**
  43. * @internal - Stores the activated state of the drag handle.
  44. */
  45. this.handleActivated = false;
  46. /**
  47. * Determines the icon SVG symbol that will be shown. Options are circle, square, grip or null.
  48. * @see [ICON_TYPES](https://github.com/Esri/calcite-components/blob/master/src/components/pick-list/resources.ts#L5)
  49. */
  50. this.icon = null;
  51. /**
  52. * When true, adds an action to remove the list item.
  53. */
  54. this.removable = false;
  55. /**
  56. * When true, preselects the list item. Toggles when an item is checked/unchecked.
  57. */
  58. this.selected = false;
  59. this.pickListItem = null;
  60. this.guid = `calcite-value-list-item-${guid()}`;
  61. // --------------------------------------------------------------------------
  62. //
  63. // Private Methods
  64. //
  65. // --------------------------------------------------------------------------
  66. this.getPickListRef = (el) => (this.pickListItem = el);
  67. this.handleKeyDown = (event) => {
  68. if (event.key === " ") {
  69. this.handleActivated = !this.handleActivated;
  70. }
  71. };
  72. this.handleBlur = () => {
  73. this.handleActivated = false;
  74. };
  75. this.handleSelectChange = (event) => {
  76. this.selected = event.detail.selected;
  77. };
  78. }
  79. // --------------------------------------------------------------------------
  80. //
  81. // Lifecycle
  82. //
  83. // --------------------------------------------------------------------------
  84. connectedCallback() {
  85. connectConditionalSlotComponent(this);
  86. }
  87. disconnectedCallback() {
  88. disconnectConditionalSlotComponent(this);
  89. }
  90. componentDidRender() {
  91. updateHostInteraction(this, this.el.closest("calcite-value-list") ? "managed" : false);
  92. }
  93. // --------------------------------------------------------------------------
  94. //
  95. // Public Methods
  96. //
  97. // --------------------------------------------------------------------------
  98. /**
  99. * Toggle the selection state. By default this won't trigger an event.
  100. * The first argument allows the value to be coerced, rather than swapping values.
  101. */
  102. async toggleSelected(coerce) {
  103. this.pickListItem.toggleSelected(coerce);
  104. }
  105. /** Set focus on the component. */
  106. async setFocus() {
  107. var _a;
  108. (_a = this.pickListItem) === null || _a === void 0 ? void 0 : _a.setFocus();
  109. }
  110. calciteListItemChangeHandler(event) {
  111. // adjust item payload from wrapped item before bubbling
  112. event.detail.item = this.el;
  113. }
  114. // --------------------------------------------------------------------------
  115. //
  116. // Render Methods
  117. //
  118. // --------------------------------------------------------------------------
  119. renderActionsEnd() {
  120. const { el } = this;
  121. const hasActionsEnd = getSlotted(el, SLOTS.actionsEnd);
  122. return hasActionsEnd ? (h("slot", { name: SLOTS.actionsEnd, slot: SLOTS$1.actionsEnd })) : null;
  123. }
  124. renderActionsStart() {
  125. const { el } = this;
  126. const hasActionsStart = getSlotted(el, SLOTS.actionsStart);
  127. return hasActionsStart ? (h("slot", { name: SLOTS.actionsStart, slot: SLOTS$1.actionsStart })) : null;
  128. }
  129. renderHandle() {
  130. const { icon } = this;
  131. if (icon === ICON_TYPES.grip) {
  132. return (h("span", { "aria-pressed": toAriaBoolean(this.handleActivated), class: {
  133. [CSS.handle]: true,
  134. [CSS.handleActivated]: this.handleActivated
  135. }, "data-js-handle": true, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, role: "button", tabindex: "0" }, h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
  136. }
  137. }
  138. render() {
  139. return (h(Host, { id: this.el.id || this.guid }, this.renderHandle(), h("calcite-pick-list-item", { description: this.description, disableDeselect: this.disableDeselect, disabled: this.disabled, label: this.label, metadata: this.metadata, nonInteractive: this.nonInteractive, onCalciteListItemChange: this.handleSelectChange, ref: this.getPickListRef, removable: this.removable, selected: this.selected, value: this.value }, this.renderActionsStart(), this.renderActionsEnd())));
  140. }
  141. get el() { return this; }
  142. static get style() { return valueListItemCss; }
  143. }, [1, "calcite-value-list-item", {
  144. "description": [513],
  145. "disabled": [516],
  146. "disableDeselect": [4, "disable-deselect"],
  147. "nonInteractive": [516, "non-interactive"],
  148. "handleActivated": [1028, "handle-activated"],
  149. "icon": [513],
  150. "label": [513],
  151. "metadata": [16],
  152. "removable": [516],
  153. "selected": [1540],
  154. "value": [8],
  155. "toggleSelected": [64],
  156. "setFocus": [64]
  157. }, [[0, "calciteListItemChange", "calciteListItemChangeHandler"]]]);
  158. function defineCustomElement$1() {
  159. if (typeof customElements === "undefined") {
  160. return;
  161. }
  162. const components = ["calcite-value-list-item", "calcite-action", "calcite-icon", "calcite-loader", "calcite-pick-list-item"];
  163. components.forEach(tagName => { switch (tagName) {
  164. case "calcite-value-list-item":
  165. if (!customElements.get(tagName)) {
  166. customElements.define(tagName, ValueListItem);
  167. }
  168. break;
  169. case "calcite-action":
  170. if (!customElements.get(tagName)) {
  171. defineCustomElement$5();
  172. }
  173. break;
  174. case "calcite-icon":
  175. if (!customElements.get(tagName)) {
  176. defineCustomElement$4();
  177. }
  178. break;
  179. case "calcite-loader":
  180. if (!customElements.get(tagName)) {
  181. defineCustomElement$3();
  182. }
  183. break;
  184. case "calcite-pick-list-item":
  185. if (!customElements.get(tagName)) {
  186. defineCustomElement$2();
  187. }
  188. break;
  189. } });
  190. }
  191. defineCustomElement$1();
  192. const CalciteValueListItem = ValueListItem;
  193. const defineCustomElement = defineCustomElement$1;
  194. export { CalciteValueListItem, defineCustomElement };