UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

113 lines (108 loc) 7.74 kB
import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-8fd57462.js'; import { c as getSlotted } from './dom-d9ba1da4.js'; import { g as guid } from './guid-09142681.js'; import { I as ICON_TYPES } from './resources-e06851d2.js'; import { C as CSS, S as SLOTS$1 } from './resources-c89a74dc.js'; const ICONS = { drag: "drag" }; const SLOTS = { actionsEnd: "actions-end", actionsStart: "actions-start" }; const calciteValueListItemCss = "@-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)}}:host{-webkit-box-sizing:border-box;box-sizing:border-box;background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-2);font-size:var(--calcite-font-size--1)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}:host{--calcite-icon-size:1rem;--calcite-spacing-quarter:0.25rem;--calcite-spacing-half:0.5rem;--calcite-spacing-three-quarters:0.75rem;--calcite-spacing:1rem;--calcite-spacing-plus-quarter:1.25rem;--calcite-spacing-plus-half:1.5rem;--calcite-spacing-double:2rem;--calcite-menu-min-width:10rem;--calcite-header-min-height:3rem;--calcite-footer-min-height:3rem}:root{--calcite-popper-transition:150ms ease-in-out}:host([hidden]){display:none}:host{margin-bottom:1px;display:-ms-flexbox;display:flex;-webkit-transition:background-color 150ms ease-in-out, -webkit-box-shadow 150ms ease-in-out;transition:background-color 150ms ease-in-out, -webkit-box-shadow 150ms ease-in-out;transition:background-color 150ms ease-in-out, box-shadow 150ms ease-in-out;transition:background-color 150ms ease-in-out, box-shadow 150ms ease-in-out, -webkit-box-shadow 150ms ease-in-out;-webkit-box-shadow:0 1px 0 var(--calcite-ui-border-3);box-shadow:0 1px 0 var(--calcite-ui-border-3)}calcite-pick-list-item{-webkit-box-shadow:none;box-shadow:none;-ms-flex-positive:1;flex-grow:1;position:relative;margin:0}:host([active]),:host([selected]){-webkit-box-shadow:0 0 0 1px var(--calcite-ui-brand);box-shadow:0 0 0 1px var(--calcite-ui-brand)}.handle{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;padding:0 var(--calcite-spacing-quarter);background-color:transparent;border:none;color:var(--calcite-ui-border-1);line-height:0;cursor:move;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-blue-1);outline-offset:-2px}.handle--activated{background-color:var(--calcite-ui-foreground-3);color:var(--calcite-ui-text-1)}"; const CalciteValueListItem = class { constructor(hostRef) { registerInstance(this, hostRef); this.calciteListItemRemove = createEvent(this, "calciteListItemRemove", 7); /** * When true, the item cannot be clicked and is visually muted */ this.disabled = false; /** * @internal When false, the item cannot be deselected by user interaction. */ this.disableDeselect = false; /** * @internal - stores the activated state of the drag handle. */ this.handleActivated = false; /** * Determines the icon SVG symbol that will be shown. Options are circle, square, grid or null. */ this.icon = null; /** * Set this to true to display a remove action that removes the item from the list. */ this.removable = false; /** * Set this to true to pre-select an item. Toggles when an item is checked/unchecked. */ this.selected = false; this.pickListItem = null; this.guid = `calcite-value-list-item-${guid()}`; // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.getPickListRef = (el) => (this.pickListItem = el); this.handleKeyDown = (event) => { if (event.key === " ") { this.handleActivated = !this.handleActivated; } }; this.handleBlur = () => { this.handleActivated = false; }; this.handleSelectChange = (event) => { this.selected = event.detail.selected; }; } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- async toggleSelected(coerce) { this.pickListItem.toggleSelected(coerce); } async setFocus() { var _a; (_a = this.pickListItem) === null || _a === void 0 ? void 0 : _a.setFocus(); } calciteListItemChangeHandler(event) { // adjust item payload from wrapped item before bubbling event.detail.item = this.el; } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderActionsEnd() { const { el } = this; const hasActionsEnd = getSlotted(el, SLOTS.actionsEnd); return hasActionsEnd ? (h("slot", { name: SLOTS.actionsEnd, slot: SLOTS$1.actionsEnd })) : null; } renderActionsStart() { const { el } = this; const hasActionsStart = getSlotted(el, SLOTS.actionsStart); return hasActionsStart ? (h("slot", { name: SLOTS.actionsStart, slot: SLOTS$1.actionsStart })) : null; } renderHandle() { const { icon } = this; if (icon === ICON_TYPES.grip) { return (h("span", { "aria-pressed": this.handleActivated.toString(), class: { [CSS.handle]: true, [CSS.handleActivated]: this.handleActivated }, "data-js-handle": true, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, role: "button", tabindex: "0" }, h("calcite-icon", { icon: ICONS.drag, scale: "s" }))); } } render() { return (h(Host, { "data-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, onCalciteListItemChange: this.handleSelectChange, ref: this.getPickListRef, removable: this.removable, selected: this.selected, value: this.value }, this.renderActionsStart(), this.renderActionsEnd()))); } get el() { return getElement(this); } }; CalciteValueListItem.style = calciteValueListItemCss; export { CalciteValueListItem as calcite_value_list_item };