UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

193 lines (188 loc) • 9.74 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 */ import { proxyCustomElement, HTMLElement, createEvent, h, Fragment } from '@stencil/core/internal/client'; import { f as filter } from './filter2.js'; import { c as connectInteractive, u as updateHostInteraction, d as disconnectInteractive } from './interactive.js'; import { a as setUpLoadableComponent, s as setComponentLoaded, c as componentLoaded } from './loadable.js'; import { c as connectLocalized, d as disconnectLocalized } from './locale.js'; import { u as updateMessages, s as setUpMessages, c as connectMessages, d as disconnectMessages } from './t9n.js'; import { d as defineCustomElement$3 } from './icon.js'; import { d as defineCustomElement$2 } from './input.js'; import { d as defineCustomElement$1 } from './progress.js'; import { d as debounce } from './debounce.js'; const CSS = { container: "container", searchIcon: "search-icon" }; const ICONS = { search: "search", close: "x" }; const DEBOUNCE_TIMEOUT = 250; const filterCss = "@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}}:host{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 *{box-sizing:border-box}: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{display:flex;inline-size:100%}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.container{display:flex;inline-size:100%;padding:0.5rem}label{position:relative;margin-inline:0.25rem;margin-block:0px;display:flex;inline-size:100%;align-items:center;overflow:hidden}input[type=text]{margin-block-end:0.25rem;inline-size:100%;border-style:none;background-color:transparent;padding-block:0.25rem;font-family:inherit;font-size:var(--calcite-font-size--2);line-height:1rem;color:var(--calcite-ui-text-1);padding-inline-end:0.25rem;padding-inline-start:1.5rem;transition:padding var(--calcite-animation-timing), box-shadow var(--calcite-animation-timing)}input[type=text]::-ms-clear{display:none}calcite-input{inline-size:100%}.search-icon{position:absolute;display:flex;color:var(--calcite-ui-text-2);inset-inline-start:0;transition:inset-inline-start var(--calcite-animation-timing), inset-inline-end var(--calcite-animation-timing), opacity var(--calcite-animation-timing)}input[type=text]:focus{border-color:var(--calcite-ui-brand);outline:2px solid transparent;outline-offset:2px;padding-inline:0.25rem}input[type=text]:focus~.search-icon{inset-inline-start:calc(1rem * -1);opacity:0}.clear-button{display:flex;cursor:pointer;align-items:center;border-width:0px;background-color:transparent;color:var(--calcite-ui-text-2)}.clear-button:hover,.clear-button:focus{color:var(--calcite-ui-text-1)}"; const Filter = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteFilterChange = createEvent(this, "calciteFilterChange", 6); // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.filter = debounce((value, emit = false) => this.updateFiltered(filter(this.items, value), emit), DEBOUNCE_TIMEOUT); this.inputHandler = (event) => { const target = event.target; this.value = target.value; this.filter(target.value, true); }; this.keyDownHandler = (event) => { if (event.key === "Escape") { this.clear(); event.preventDefault(); } if (event.key === "Enter") { event.preventDefault(); } }; this.clear = () => { this.value = ""; this.filter("", true); this.setFocus(); }; this.items = []; this.disabled = false; this.filteredItems = []; this.placeholder = undefined; this.scale = "m"; this.value = ""; this.messages = undefined; this.messageOverrides = undefined; this.effectiveLocale = undefined; this.defaultMessages = undefined; } watchItemsHandler() { this.filter(this.value); } onMessagesChange() { /* wired up by t9n util */ } valueHandler(value) { this.filter(value); } effectiveLocaleChange() { updateMessages(this, this.effectiveLocale); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- async componentWillLoad() { setUpLoadableComponent(this); this.updateFiltered(filter(this.items, this.value)); await setUpMessages(this); } connectedCallback() { connectInteractive(this); connectLocalized(this); connectMessages(this); } componentDidRender() { updateHostInteraction(this); } disconnectedCallback() { disconnectInteractive(this); disconnectLocalized(this); disconnectMessages(this); } componentDidLoad() { setComponentLoaded(this); } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- /** Sets focus on the component. */ async setFocus() { await componentLoaded(this); this.el?.focus(); } updateFiltered(filtered, emit = false) { this.filteredItems.length = 0; this.filteredItems = this.filteredItems.concat(filtered); if (emit) { this.calciteFilterChange.emit(); } } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- render() { const { disabled, scale } = this; return (h(Fragment, null, h("div", { class: CSS.container }, h("label", null, h("calcite-input", { "aria-label": this.messages.label, clearable: true, disabled: disabled, icon: ICONS.search, messageOverrides: { clear: this.messages.clear }, onCalciteInputInput: this.inputHandler, onKeyDown: this.keyDownHandler, placeholder: this.placeholder, scale: scale, type: "text", value: this.value, // eslint-disable-next-line react/jsx-sort-props ref: (el) => { this.textInput = el; } }))))); } static get delegatesFocus() { return true; } static get assetsDirs() { return ["assets"]; } get el() { return this; } static get watchers() { return { "items": ["watchItemsHandler"], "messageOverrides": ["onMessagesChange"], "value": ["valueHandler"], "effectiveLocale": ["effectiveLocaleChange"] }; } static get style() { return filterCss; } }, [17, "calcite-filter", { "items": [16], "disabled": [516], "filteredItems": [1040], "placeholder": [1], "scale": [513], "value": [1025], "messages": [1040], "messageOverrides": [1040], "effectiveLocale": [32], "defaultMessages": [32], "setFocus": [64] }]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["calcite-filter", "calcite-icon", "calcite-input", "calcite-progress"]; components.forEach(tagName => { switch (tagName) { case "calcite-filter": if (!customElements.get(tagName)) { customElements.define(tagName, Filter); } break; case "calcite-icon": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "calcite-input": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; case "calcite-progress": if (!customElements.get(tagName)) { defineCustomElement$1(); } break; } }); } defineCustomElement(); export { Filter as F, defineCustomElement as d };