UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

364 lines (354 loc) 23.3 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-55f8a3b7.js'); const interactive = require('./interactive-26294f2c.js'); const loadable = require('./loadable-53f729bb.js'); const observers = require('./observers-83b3999d.js'); const resources = require('./resources-2e69630c.js'); const conditionalSlot = require('./conditionalSlot-4472b3c1.js'); const dom = require('./dom-18ca68ff.js'); const Heading = require('./Heading-e1a3c7e4.js'); const locale = require('./locale-fc347462.js'); const t9n = require('./t9n-14d528c4.js'); require('./browser-28ea2ce1.js'); require('./array-056ac2a2.js'); require('./debounce-492319d0.js'); require('./guid-db20443e.js'); require('./resources-45d84c94.js'); require('./key-2ce02f02.js'); const pickListCss = "@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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{position:relative;box-sizing:border-box;display:flex;flex-shrink:0;flex-grow:1;flex-direction:column;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([filter-enabled]) header{margin-block-end:0.25rem;display:flex;align-items:stretch;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);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:sticky;inset-block-start:0px;z-index:var(--calcite-app-z-index)}calcite-filter{margin-block-end:0px}:host([loading][disabled]){min-block-size:2rem}"; const PickList = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteListChange = index.createEvent(this, "calciteListChange", 6); this.calciteListFilter = index.createEvent(this, "calciteListFilter", 6); this.lastSelectedItem = null; this.mutationObserver = observers.createObserver("mutation", resources.mutationObserverCallback.bind(this)); this.setFilterEl = (el) => { this.filterEl = el; }; this.setFilteredItems = (filteredItems) => { this.filteredItems = filteredItems; }; this.deselectRemovedItems = resources.deselectRemovedItems.bind(this); this.deselectSiblingItems = resources.deselectSiblingItems.bind(this); this.selectSiblings = resources.selectSiblings.bind(this); this.handleFilter = resources.handleFilter.bind(this); this.handleFilterEvent = resources.handleFilterEvent.bind(this); this.getItemData = resources.getItemData.bind(this); this.keyDownHandler = resources.keyDownHandler.bind(this); this.disabled = false; this.filteredItems = []; this.filteredData = []; this.filterEnabled = false; this.filterPlaceholder = undefined; this.filterText = undefined; this.headingLevel = undefined; this.loading = false; this.multiple = false; this.selectionFollowsFocus = false; this.selectedValues = new Map(); this.dataForFilter = []; } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { resources.initialize.call(this); resources.initializeObserver.call(this); interactive.connectInteractive(this); } disconnectedCallback() { resources.cleanUpObserver.call(this); interactive.disconnectInteractive(this); } componentWillLoad() { loadable.setUpLoadableComponent(this); } componentDidLoad() { loadable.setComponentLoaded(this); resources.handleInitialFilter.call(this); } componentDidRender() { interactive.updateHostInteraction(this); } calciteListItemRemoveHandler(event) { resources.removeItem.call(this, event); } calciteListItemChangeHandler(event) { resources.calciteListItemChangeHandler.call(this, event); } calciteInternalListItemPropsChangeHandler(event) { event.stopPropagation(); this.setUpFilter(); } calciteInternalListItemValueChangeHandler(event) { resources.calciteInternalListItemValueChangeHandler.call(this, event); event.stopPropagation(); } calciteListFocusOutHandler(event) { resources.calciteListFocusOutHandler.call(this, event); } // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- setUpItems() { resources.setUpItems.call(this, "calcite-pick-list-item"); } setUpFilter() { if (this.filterEnabled) { this.dataForFilter = this.getItemData(); } } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- /** Returns the component's selected `calcite-pick-list-item`s. */ async getSelectedItems() { return this.selectedValues; } /** * Sets focus on the component's first focusable element. * * @param focusId */ async setFocus(focusId) { await loadable.componentLoaded(this); return resources.setFocus.call(this, focusId); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- getIconType() { return this.multiple ? resources.ICON_TYPES.square : resources.ICON_TYPES.circle; } render() { return index.h(resources.List, { onKeyDown: this.keyDownHandler, props: this }); } get el() { return index.getElement(this); } }; PickList.style = pickListCss; const pickListGroupCss = "@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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host{margin-block-end:0.25rem;box-sizing:border-box;display:block;background-color:transparent;font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}:host(:last-child){margin-block-end:0px}.header{margin:0px;display:flex;align-content:space-between;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{flex:1 1 auto;padding:0.5rem}.heading{margin-block:0.5rem;margin-inline:1rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;font-size:var(--calcite-font-size--1);line-height:1.375;color:var(--calcite-ui-text-3)}.container--indented{margin-inline-start:1.5rem}"; const PickListGroup = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.groupTitle = undefined; this.headingLevel = undefined; } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { conditionalSlot.connectConditionalSlotComponent(this); } disconnectedCallback() { conditionalSlot.disconnectConditionalSlotComponent(this); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- render() { const { el, groupTitle, headingLevel } = this; const hasParentItem = dom.getSlotted(el, resources.SLOTS$1.parentItem) !== null; const sectionClasses = { [resources.CSS$1.container]: true, [resources.CSS$1.indented]: hasParentItem }; const title = groupTitle; const parentLevel = el.closest("calcite-pick-list")?.headingLevel; const relativeLevel = parentLevel ? Heading.constrainHeadingLevel(parentLevel + 1) : null; const level = headingLevel || relativeLevel; 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)))); } get el() { return index.getElement(this); } }; PickListGroup.style = pickListGroupCss; const pickListItemCss = "@charset \"UTF-8\";@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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{margin:0px;margin-block-end:1px;box-sizing:border-box;display:flex;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);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);animation:calcite-fade-in var(--calcite-animation-timing)}:host *{box-sizing:border-box}.label{display:flex;flex:1 1 auto;cursor:pointer;align-items:center;background-color:transparent;outline-color:transparent}.label:focus{outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n -2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n )}.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-block:0px;display:flex;cursor:pointer;align-items:center;padding:0.25rem;color:var(--calcite-ui-brand);flex:0 0 auto;line-height:0}.icon:hover{background-color:var(--calcite-ui-foreground-2)}.icon-dot{display:flex;inline-size:1.5rem;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{transition:opacity var(--calcite-animation-timing);opacity:1}.text-container{pointer-events:none;display:flex;flex-direction:column;flex-wrap:nowrap;overflow:hidden;padding-block:0.5rem;padding-inline: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-block-start:0.125rem;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}.actions{margin:0px;display:flex;flex:0 1 auto;align-items:stretch;justify-content:flex-end}.actions--start~.label{padding-inline-start:0.25rem}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}"; const PickListItem = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteListItemChange = index.createEvent(this, "calciteListItemChange", 6); this.calciteListItemRemove = index.createEvent(this, "calciteListItemRemove", 7); this.calciteInternalListItemPropsChange = index.createEvent(this, "calciteInternalListItemPropsChange", 6); this.calciteInternalListItemValueChange = index.createEvent(this, "calciteInternalListItemValueChange", 6); // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.pickListClickHandler = (event) => { if (this.disabled || (this.deselectDisabled && this.selected) || this.nonInteractive) { return; } this.shiftPressed = event.shiftKey; this.selected = !this.selected; }; this.pickListKeyDownHandler = (event) => { if (event.key === " ") { event.preventDefault(); if ((this.deselectDisabled && this.selected) || this.nonInteractive) { return; } this.selected = !this.selected; } }; this.removeClickHandler = () => { this.calciteListItemRemove.emit(); }; this.description = undefined; this.disabled = false; this.deselectDisabled = false; this.nonInteractive = false; this.icon = null; this.iconFlipRtl = false; this.label = undefined; this.messageOverrides = undefined; this.messages = undefined; this.metadata = undefined; this.removable = false; this.selected = false; this.value = undefined; this.defaultMessages = undefined; this.effectiveLocale = ""; } descriptionWatchHandler() { this.calciteInternalListItemPropsChange.emit(); } labelWatchHandler() { this.calciteInternalListItemPropsChange.emit(); } onMessagesChange() { /* wired up by t9n util */ } metadataWatchHandler() { this.calciteInternalListItemPropsChange.emit(); } selectedWatchHandler() { this.calciteListItemChange.emit({ item: this.el, value: this.value, selected: this.selected, shiftPressed: this.shiftPressed }); this.shiftPressed = false; } valueWatchHandler(newValue, oldValue) { this.calciteInternalListItemValueChange.emit({ oldValue, newValue }); } effectiveLocaleChange() { t9n.updateMessages(this, this.effectiveLocale); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { interactive.connectInteractive(this); locale.connectLocalized(this); t9n.connectMessages(this); conditionalSlot.connectConditionalSlotComponent(this); } async componentWillLoad() { await t9n.setUpMessages(this); loadable.setUpLoadableComponent(this); } componentDidLoad() { loadable.setComponentLoaded(this); } disconnectedCallback() { interactive.disconnectInteractive(this); locale.disconnectLocalized(this); t9n.disconnectMessages(this); conditionalSlot.disconnectConditionalSlotComponent(this); } componentDidRender() { interactive.updateHostInteraction(this, this.el.closest("calcite-pick-list") ? "managed" : false); } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- /** * Toggles the selection state. By default this won't trigger an event. * The first argument allows the value to be coerced, rather than swapping values. * * @param coerce */ async toggleSelected(coerce) { this.selected = typeof coerce === "boolean" ? coerce : !this.selected; } /** Sets focus on the component. */ async setFocus() { await loadable.componentLoaded(this); this.focusEl?.focus(); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderIcon() { const { icon, iconFlipRtl } = this; if (!icon) { return null; } return (index.h("span", { class: { [resources.CSS.icon]: true, [resources.CSS.iconDot]: icon === resources.ICON_TYPES.circle }, onClick: this.pickListClickHandler }, icon === resources.ICON_TYPES.square ? (index.h("calcite-icon", { flipRtl: iconFlipRtl, icon: resources.ICONS.checked, scale: "s" })) : null)); } renderRemoveAction() { return this.removable ? (index.h("calcite-action", { class: resources.CSS.remove, icon: resources.ICONS.remove, onClick: this.removeClickHandler, slot: resources.SLOTS.actionsEnd, text: this.messages.remove })) : null; } renderActionsStart() { const { el } = this; const hasActionsStart = dom.getSlotted(el, resources.SLOTS.actionsStart); return hasActionsStart ? (index.h("div", { class: { [resources.CSS.actions]: true, [resources.CSS.actionsStart]: true } }, index.h("slot", { name: resources.SLOTS.actionsStart }))) : null; } renderActionsEnd() { const { el, removable } = this; const hasActionsEnd = dom.getSlotted(el, resources.SLOTS.actionsEnd); 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; } render() { const { description, label } = this; 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, tabIndex: 0, // eslint-disable-next-line react/jsx-sort-props ref: (focusEl) => (this.focusEl = focusEl) }, 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())); } static get assetsDirs() { return ["assets"]; } get el() { return index.getElement(this); } static get watchers() { return { "description": ["descriptionWatchHandler"], "label": ["labelWatchHandler"], "defaultMessages": ["onMessagesChange"], "messageOverrides": ["onMessagesChange"], "metadata": ["metadataWatchHandler"], "selected": ["selectedWatchHandler"], "value": ["valueWatchHandler"], "effectiveLocale": ["effectiveLocaleChange"] }; } }; PickListItem.style = pickListItemCss; exports.calcite_pick_list = PickList; exports.calcite_pick_list_group = PickListGroup; exports.calcite_pick_list_item = PickListItem;