@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
134 lines (129 loc) • 6.33 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 { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { c as connectLocalized, d as disconnectLocalized } from './locale.js';
import { u as updateMessages, c as connectMessages, s as setUpMessages, d as disconnectMessages } from './t9n.js';
import { c as createObserver } from './observers.js';
import { d as defineCustomElement$1 } from './loader.js';
const CSS = {
scrim: "scrim",
content: "content"
};
const BREAKPOINTS = {
s: 72,
// medium is assumed default.
l: 480 // Greater than or equal to 480px.
};
const scrimCss = "@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{position:absolute;inset:0px;z-index:var(--calcite-app-z-index-overlay);display:flex;block-size:100%;inline-size:100%;flex-direction:column;align-items:stretch}@keyframes calcite-scrim-fade-in{0%{--tw-bg-opacity:0}100%{--tw-text-opacity:1}}.scrim{position:absolute;inset:0px;display:flex;flex-direction:column;align-content:center;align-items:center;justify-content:center;overflow:hidden;animation:calcite-scrim-fade-in var(--calcite-internal-animation-timing-medium) ease-in-out;background-color:var(--calcite-scrim-background, var(--calcite-scrim-background-internal))}.content{padding:1rem}";
const Scrim = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.__attachShadow();
this.resizeObserver = createObserver("resize", () => this.handleResize());
// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------
this.storeLoaderEl = (el) => {
this.loaderEl = el;
this.handleResize();
};
this.loading = false;
this.messages = undefined;
this.messageOverrides = undefined;
this.loaderScale = undefined;
this.defaultMessages = undefined;
this.effectiveLocale = "";
}
onMessagesChange() {
/* wired up by t9n util */
}
effectiveLocaleChange() {
updateMessages(this, this.effectiveLocale);
}
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
connectedCallback() {
connectLocalized(this);
connectMessages(this);
}
async componentWillLoad() {
await setUpMessages(this);
}
disconnectedCallback() {
disconnectLocalized(this);
disconnectMessages(this);
}
// --------------------------------------------------------------------------
//
// Render Method
//
// --------------------------------------------------------------------------
render() {
const { el, loading, messages } = this;
const hasContent = el.innerHTML.trim().length > 0;
const loaderNode = loading ? (h("calcite-loader", { label: messages.loading, ref: this.storeLoaderEl, scale: this.loaderScale })) : null;
const contentNode = hasContent ? (h("div", { class: CSS.content }, h("slot", null))) : null;
return (h("div", { class: CSS.scrim }, loaderNode, contentNode));
}
getScale(size) {
if (size < BREAKPOINTS.s) {
return "s";
}
else if (size >= BREAKPOINTS.l) {
return "l";
}
else {
return "m";
}
}
handleResize() {
const { loaderEl, el } = this;
if (!loaderEl) {
return;
}
this.loaderScale = this.getScale(Math.min(el.clientHeight, el.clientWidth) ?? 0);
}
static get assetsDirs() { return ["assets"]; }
get el() { return this; }
static get watchers() { return {
"messageOverrides": ["onMessagesChange"],
"effectiveLocale": ["effectiveLocaleChange"]
}; }
static get style() { return scrimCss; }
}, [1, "calcite-scrim", {
"loading": [516],
"messages": [1040],
"messageOverrides": [1040],
"loaderScale": [32],
"defaultMessages": [32],
"effectiveLocale": [32]
}]);
function defineCustomElement() {
if (typeof customElements === "undefined") {
return;
}
const components = ["calcite-scrim", "calcite-loader"];
components.forEach(tagName => { switch (tagName) {
case "calcite-scrim":
if (!customElements.get(tagName)) {
customElements.define(tagName, Scrim);
}
break;
case "calcite-loader":
if (!customElements.get(tagName)) {
defineCustomElement$1();
}
break;
} });
}
defineCustomElement();
export { Scrim as S, defineCustomElement as d };