@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
358 lines (350 loc) • 23.3 kB
JavaScript
/*!
* 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
*/
import { r as registerInstance, c as createEvent, h, a as getElement, F as Fragment } from './index-c8875db5.js';
import { c as connectInteractive, d as disconnectInteractive, u as updateHostInteraction } from './interactive-cff0a7ea.js';
import { s as setUpLoadableComponent, a as setComponentLoaded, c as componentLoaded } from './loadable-8d606217.js';
import { c as createObserver } from './observers-d19b0d93.js';
import { m as mutationObserverCallback, d as deselectRemovedItems, a as deselectSiblingItems, s as selectSiblings, h as handleFilter, b as handleFilterEvent, c as getItemData, k as keyDownHandler, i as initialize, f as initializeObserver, l as cleanUpObserver, j as handleInitialFilter, r as removeItem, o as calciteListItemChangeHandler, p as calciteInternalListItemValueChangeHandler, n as calciteListFocusOutHandler, q as setUpItems, t as setFocus, I as ICON_TYPES, L as List, u as SLOTS, v as CSS, w as ICONS, C as CSS$1, S as SLOTS$1 } from './resources-f20dbf1c.js';
import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot-ed85dd9d.js';
import { g as getSlotted, t as toAriaBoolean } from './dom-4f5d1224.js';
import { H as Heading, c as constrainHeadingLevel } from './Heading-4ce5f5c4.js';
import { c as connectLocalized, d as disconnectLocalized } from './locale-0c018cdb.js';
import { u as updateMessages, c as connectMessages, s as setUpMessages, d as disconnectMessages } from './t9n-f819e5a2.js';
import './browser-4be2add2.js';
import './array-c45ef254.js';
import './debounce-ca1bd093.js';
import './guid-bdb80778.js';
import './resources-35f23920.js';
import './key-582cee8f.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) {
registerInstance(this, hostRef);
this.calciteListChange = createEvent(this, "calciteListChange", 6);
this.calciteListFilter = createEvent(this, "calciteListFilter", 6);
this.lastSelectedItem = null;
this.mutationObserver = createObserver("mutation", mutationObserverCallback.bind(this));
this.setFilterEl = (el) => {
this.filterEl = el;
};
this.setFilteredItems = (filteredItems) => {
this.filteredItems = filteredItems;
};
this.deselectRemovedItems = deselectRemovedItems.bind(this);
this.deselectSiblingItems = deselectSiblingItems.bind(this);
this.selectSiblings = selectSiblings.bind(this);
this.handleFilter = handleFilter.bind(this);
this.handleFilterEvent = handleFilterEvent.bind(this);
this.getItemData = getItemData.bind(this);
this.keyDownHandler = 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() {
initialize.call(this);
initializeObserver.call(this);
connectInteractive(this);
}
disconnectedCallback() {
cleanUpObserver.call(this);
disconnectInteractive(this);
}
componentWillLoad() {
setUpLoadableComponent(this);
}
componentDidLoad() {
setComponentLoaded(this);
handleInitialFilter.call(this);
}
componentDidRender() {
updateHostInteraction(this);
}
calciteListItemRemoveHandler(event) {
removeItem.call(this, event);
}
calciteListItemChangeHandler(event) {
calciteListItemChangeHandler.call(this, event);
}
calciteInternalListItemPropsChangeHandler(event) {
event.stopPropagation();
this.setUpFilter();
}
calciteInternalListItemValueChangeHandler(event) {
calciteInternalListItemValueChangeHandler.call(this, event);
event.stopPropagation();
}
calciteListFocusOutHandler(event) {
calciteListFocusOutHandler.call(this, event);
}
// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------
setUpItems() {
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 componentLoaded(this);
return setFocus.call(this, focusId);
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
getIconType() {
return this.multiple ? ICON_TYPES.square : ICON_TYPES.circle;
}
render() {
return h(List, { onKeyDown: this.keyDownHandler, props: this });
}
get el() { return 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) {
registerInstance(this, hostRef);
this.groupTitle = undefined;
this.headingLevel = undefined;
}
// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------
connectedCallback() {
connectConditionalSlotComponent(this);
}
disconnectedCallback() {
disconnectConditionalSlotComponent(this);
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
render() {
const { el, groupTitle, headingLevel } = this;
const hasParentItem = getSlotted(el, SLOTS.parentItem) !== null;
const sectionClasses = {
[CSS.container]: true,
[CSS.indented]: hasParentItem
};
const title = groupTitle;
const parentLevel = el.closest("calcite-pick-list")?.headingLevel;
const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
const level = headingLevel || relativeLevel;
return (h(Fragment, null, title ? (h(Heading, { class: CSS.heading, level: level }, title)) : null, h("slot", { name: SLOTS.parentItem }), h("section", { class: sectionClasses }, h("slot", null))));
}
get el() { return 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) {
registerInstance(this, hostRef);
this.calciteListItemChange = createEvent(this, "calciteListItemChange", 6);
this.calciteListItemRemove = createEvent(this, "calciteListItemRemove", 7);
this.calciteInternalListItemPropsChange = createEvent(this, "calciteInternalListItemPropsChange", 6);
this.calciteInternalListItemValueChange = 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() {
updateMessages(this, this.effectiveLocale);
}
// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------
connectedCallback() {
connectInteractive(this);
connectLocalized(this);
connectMessages(this);
connectConditionalSlotComponent(this);
}
async componentWillLoad() {
await setUpMessages(this);
setUpLoadableComponent(this);
}
componentDidLoad() {
setComponentLoaded(this);
}
disconnectedCallback() {
disconnectInteractive(this);
disconnectLocalized(this);
disconnectMessages(this);
disconnectConditionalSlotComponent(this);
}
componentDidRender() {
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 componentLoaded(this);
this.focusEl?.focus();
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
renderIcon() {
const { icon, iconFlipRtl } = this;
if (!icon) {
return null;
}
return (h("span", { class: {
[CSS$1.icon]: true,
[CSS$1.iconDot]: icon === ICON_TYPES.circle
}, onClick: this.pickListClickHandler }, icon === ICON_TYPES.square ? (h("calcite-icon", { flipRtl: iconFlipRtl, icon: ICONS.checked, scale: "s" })) : null));
}
renderRemoveAction() {
return this.removable ? (h("calcite-action", { class: CSS$1.remove, icon: ICONS.remove, onClick: this.removeClickHandler, slot: SLOTS$1.actionsEnd, text: this.messages.remove })) : null;
}
renderActionsStart() {
const { el } = this;
const hasActionsStart = getSlotted(el, SLOTS$1.actionsStart);
return hasActionsStart ? (h("div", { class: { [CSS$1.actions]: true, [CSS$1.actionsStart]: true } }, h("slot", { name: SLOTS$1.actionsStart }))) : null;
}
renderActionsEnd() {
const { el, removable } = this;
const hasActionsEnd = getSlotted(el, SLOTS$1.actionsEnd);
return hasActionsEnd || removable ? (h("div", { class: { [CSS$1.actions]: true, [CSS$1.actionsEnd]: true } }, h("slot", { name: SLOTS$1.actionsEnd }), this.renderRemoveAction())) : null;
}
render() {
const { description, label } = this;
return (h(Fragment, null, this.renderIcon(), this.renderActionsStart(), h("label", { "aria-label": label, class: CSS$1.label, onClick: this.pickListClickHandler, onKeyDown: this.pickListKeyDownHandler, tabIndex: 0,
// eslint-disable-next-line react/jsx-sort-props
ref: (focusEl) => (this.focusEl = focusEl) }, h("div", { "aria-checked": toAriaBoolean(this.selected), class: CSS$1.textContainer, role: "menuitemcheckbox" }, h("span", { class: CSS$1.title }, label), description ? h("span", { class: CSS$1.description }, description) : null)), this.renderActionsEnd()));
}
static get assetsDirs() { return ["assets"]; }
get el() { return 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;
export { PickList as calcite_pick_list, PickListGroup as calcite_pick_list_group, PickListItem as calcite_pick_list_item };