@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
157 lines (150 loc) • 8.56 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
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-55f8a3b7.js');
const filter = require('./filter-84a21188.js');
const interactive = require('./interactive-26294f2c.js');
const loadable = require('./loadable-53f729bb.js');
const locale = require('./locale-fc347462.js');
const t9n = require('./t9n-14d528c4.js');
const debounce = require('./debounce-492319d0.js');
require('./browser-28ea2ce1.js');
require('./dom-18ca68ff.js');
require('./guid-db20443e.js');
require('./resources-45d84c94.js');
require('./key-2ce02f02.js');
require('./observers-83b3999d.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 = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.calciteFilterChange = index.createEvent(this, "calciteFilterChange", 6);
// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------
this.filter = debounce.debounce((value, emit = false) => this.updateFiltered(filter.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() {
t9n.updateMessages(this, this.effectiveLocale);
}
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
async componentWillLoad() {
loadable.setUpLoadableComponent(this);
this.updateFiltered(filter.filter(this.items, this.value));
await t9n.setUpMessages(this);
}
connectedCallback() {
interactive.connectInteractive(this);
locale.connectLocalized(this);
t9n.connectMessages(this);
}
componentDidRender() {
interactive.updateHostInteraction(this);
}
disconnectedCallback() {
interactive.disconnectInteractive(this);
locale.disconnectLocalized(this);
t9n.disconnectMessages(this);
}
componentDidLoad() {
loadable.setComponentLoaded(this);
}
// --------------------------------------------------------------------------
//
// Public Methods
//
// --------------------------------------------------------------------------
/** Sets focus on the component. */
async setFocus() {
await loadable.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 (index.h(index.Fragment, null, index.h("div", { class: CSS.container }, index.h("label", null, index.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 index.getElement(this); }
static get watchers() { return {
"items": ["watchItemsHandler"],
"messageOverrides": ["onMessagesChange"],
"value": ["valueHandler"],
"effectiveLocale": ["effectiveLocaleChange"]
}; }
};
Filter.style = filterCss;
exports.calcite_filter = Filter;