@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
113 lines (106 loc) • 5.62 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 locale = require('./locale-fc347462.js');
const t9n = require('./t9n-14d528c4.js');
const observers = require('./observers-83b3999d.js');
require('./dom-18ca68ff.js');
require('./guid-db20443e.js');
require('./resources-45d84c94.js');
require('./key-2ce02f02.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 = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.resizeObserver = observers.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() {
t9n.updateMessages(this, this.effectiveLocale);
}
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
connectedCallback() {
locale.connectLocalized(this);
t9n.connectMessages(this);
}
async componentWillLoad() {
await t9n.setUpMessages(this);
}
disconnectedCallback() {
locale.disconnectLocalized(this);
t9n.disconnectMessages(this);
}
// --------------------------------------------------------------------------
//
// Render Method
//
// --------------------------------------------------------------------------
render() {
const { el, loading, messages } = this;
const hasContent = el.innerHTML.trim().length > 0;
const loaderNode = loading ? (index.h("calcite-loader", { label: messages.loading, ref: this.storeLoaderEl, scale: this.loaderScale })) : null;
const contentNode = hasContent ? (index.h("div", { class: CSS.content }, index.h("slot", null))) : null;
return (index.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 index.getElement(this); }
static get watchers() { return {
"messageOverrides": ["onMessagesChange"],
"effectiveLocale": ["effectiveLocaleChange"]
}; }
};
Scrim.style = scrimCss;
exports.calcite_scrim = Scrim;