calcite-value-list-item.js 10 KB

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