@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
341 lines (335 loc) • 21.5 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.
*/
import { proxyCustomElement, HTMLElement, createEvent, h, Fragment } from '@stencil/core/internal/client';
import { a as getElementDir, b as getSlotted } from './dom.js';
import { H as Heading } from './Heading.js';
import { S as SLOTS$1, d as defineCustomElement$7 } from './action-menu.js';
import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
import { u as updateHostInteraction } from './interactive.js';
import { d as defineCustomElement$8 } from './action.js';
import { d as defineCustomElement$6 } from './icon.js';
import { d as defineCustomElement$5 } from './loader.js';
import { d as defineCustomElement$4 } from './popover.js';
import { d as defineCustomElement$3 } from './scrim.js';
import { d as defineCustomElement$2 } from './tooltip-manager.js';
const CSS = {
backButton: "back-button",
container: "container",
header: "header",
heading: "heading",
summary: "summary",
headerContent: "header-content",
headerActions: "header-actions",
headerActionsEnd: "header-actions--end",
headerActionsStart: "header-actions--start",
contentWrapper: "content-wrapper",
contentContainer: "content-container",
contentHeight: "content-height",
fabContainer: "fab-container",
footer: "footer",
menuContainer: "menu-container",
menuButton: "menu-button",
menu: "menu",
menuOpen: "menu--open"
};
const ICONS = {
close: "x",
menu: "ellipsis",
backLeft: "chevron-left",
backRight: "chevron-right"
};
const SLOTS = {
headerActionsStart: "header-actions-start",
headerActionsEnd: "header-actions-end",
headerMenuActions: "header-menu-actions",
headerContent: "header-content",
fab: "fab",
footer: "footer",
footerActions: "footer-actions"
};
const TEXT = {
back: "Back",
close: "Close",
open: "Open",
options: "Options"
};
const HEADING_LEVEL = 3;
const panelCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:host{-webkit-box-sizing:border-box;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 *{-webkit-box-sizing:border-box;box-sizing:border-box}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:-ms-flexbox;display:flex;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;overflow:hidden;--calcite-min-header-height:calc(var(--calcite-icon-size) * 3);--calcite-panel-max-height:unset;--calcite-panel-width:100%;--calcite-panel-min-width:unset;--calcite-panel-max-width:unset}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.header{margin:0px;display:-ms-flexbox;display:flex;-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;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{-ms-flex:1 1 auto;flex:1 1 auto;padding:0.5rem}h1.heading{font-size:var(--calcite-font-size-2);line-height:1.5rem}h2.heading{font-size:var(--calcite-font-size-1);line-height:1.5rem}h3.heading{font-size:var(--calcite-font-size-0);line-height:1.25rem}h4.heading,h5.heading{font-size:var(--calcite-font-size--1);line-height:1rem}.container{margin:0px;display:-ms-flexbox;display:flex;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:stretch;align-items:stretch;background-color:var(--calcite-ui-background);padding:0px;max-height:var(--calcite-panel-max-height);width:var(--calcite-panel-width);max-width:var(--calcite-panel-max-width);min-width:var(--calcite-panel-min-width);-webkit-transition:max-height var(--calcite-animation-timing), width var(--calcite-animation-timing);transition:max-height var(--calcite-animation-timing), width var(--calcite-animation-timing)}:host([height-scale=s]){--calcite-panel-max-height:40vh}:host([height-scale=m]){--calcite-panel-max-height:60vh}:host([height-scale=l]){--calcite-panel-max-height:80vh}:host([width-scale=s]){--calcite-panel-width:calc(var(--calcite-panel-width-multiplier) * 12vw);--calcite-panel-max-width:calc(var(--calcite-panel-width-multiplier) * 300px);--calcite-panel-min-width:calc(var(--calcite-panel-width-multiplier) * 150px)}:host([width-scale=m]){--calcite-panel-width:calc(var(--calcite-panel-width-multiplier) * 20vw);--calcite-panel-max-width:calc(var(--calcite-panel-width-multiplier) * 420px);--calcite-panel-min-width:calc(var(--calcite-panel-width-multiplier) * 240px)}:host([width-scale=l]){--calcite-panel-width:calc(var(--calcite-panel-width-multiplier) * 45vw);--calcite-panel-max-width:calc(var(--calcite-panel-width-multiplier) * 680px);--calcite-panel-min-width:calc(var(--calcite-panel-width-multiplier) * 340px)}.container[hidden]{display:none}:host([loading]) .container,:host([disabled]) .container{position:relative;z-index:1}.header{border-bottom:1px solid;position:-webkit-sticky;position:sticky;top:0px;width:100%;-ms-flex-align:stretch;align-items:stretch;-ms-flex-pack:start;justify-content:flex-start;background-color:var(--calcite-ui-foreground-1);border-bottom-color:var(--calcite-ui-border-3);-ms-flex:0 0 auto;flex:0 0 auto;z-index:2}.header-content{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;padding-left:0.75rem;padding-right:0.75rem;padding-top:0.875rem;padding-bottom:0.875rem;overflow:hidden;-webkit-margin-end:auto;margin-inline-end:auto}.header-content .heading,.header-content .summary{display:block;overflow-wrap:break-word;padding:0px}.header-content .heading{margin-left:0px;margin-right:0px;margin-top:0px;margin-bottom:0.25rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;font-weight:var(--calcite-font-weight-medium)}.header-content .heading:only-child{margin-bottom:0px}.header-content .summary{font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}.back-button{border-width:0px;border-style:solid;border-color:var(--calcite-ui-border-3);border-inline-end-width:1px}.header-actions{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-ms-flex-align:stretch;align-items:stretch}.header-actions--end,.menu-container:only-child{-webkit-margin-start:auto;margin-inline-start:auto}.menu-button{position:relative;height:100%;-ms-flex:0 1 auto;flex:0 1 auto;-ms-flex-item-align:stretch;align-self:stretch}.menu{min-width:10rem;-ms-flex-flow:column nowrap;flex-flow:column nowrap}.content-wrapper{overflow:auto}.content-height{height:100%}.content-container{display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-ms-flex-align:stretch;align-items:stretch;background-color:var(--calcite-ui-background)}.footer{border-top:1px solid;position:-webkit-sticky;position:sticky;bottom:0px;display:-ms-flexbox;display:flex;width:100%;-ms-flex-pack:space-evenly;justify-content:space-evenly;background-color:var(--calcite-ui-foreground-1);border-top-color:var(--calcite-ui-border-3);-ms-flex:0 0 auto;flex:0 0 auto;min-height:3rem;padding:0.5rem}.fab-container{position:-webkit-sticky;position:sticky;bottom:0px;left:0px;right:0px;margin-top:0px;margin-bottom:0px;margin-left:auto;margin-right:auto;display:block;padding:0.5rem;width:-moz-fit-content;width:-webkit-fit-content;width:fit-content;z-index:1}";
const Panel = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.__attachShadow();
this.calcitePanelDismissedChange = createEvent(this, "calcitePanelDismissedChange", 7);
this.calcitePanelScroll = createEvent(this, "calcitePanelScroll", 7);
this.calcitePanelBackClick = createEvent(this, "calcitePanelBackClick", 7);
// --------------------------------------------------------------------------
//
// Properties
//
// --------------------------------------------------------------------------
/**
* Hides the panel.
*/
this.dismissed = false;
/**
* When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
*/
this.disabled = false;
/**
* Displays a close button in the trailing side of the header.
*/
this.dismissible = false;
/**
* Shows a back button in the header.
*/
this.showBackButton = false;
/**
* When true, content is waiting to be loaded. This state shows a busy indicator.
*/
this.loading = false;
/**
* Opens the action menu.
*/
this.menuOpen = false;
// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------
this.setContainerRef = (node) => {
this.containerEl = node;
};
this.setDismissRef = (node) => {
this.dismissButtonEl = node;
};
this.setBackRef = (node) => {
this.backButtonEl = node;
};
this.panelKeyDownHandler = (event) => {
if (event.key === "Escape") {
this.dismiss();
}
};
this.dismiss = () => {
this.dismissed = true;
};
this.panelScrollHandler = () => {
this.calcitePanelScroll.emit();
};
this.backButtonClick = () => {
this.calcitePanelBackClick.emit();
};
}
dismissedHandler() {
this.calcitePanelDismissedChange.emit();
}
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
componentDidRender() {
updateHostInteraction(this);
}
// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------
connectedCallback() {
connectConditionalSlotComponent(this);
}
disconnectedCallback() {
disconnectConditionalSlotComponent(this);
}
// --------------------------------------------------------------------------
//
// Methods
//
// --------------------------------------------------------------------------
/** Sets focus on the component. */
async setFocus(focusId) {
var _a, _b, _c;
if (focusId === "dismiss-button") {
(_a = this.dismissButtonEl) === null || _a === void 0 ? void 0 : _a.setFocus();
return;
}
if (focusId === "back-button") {
(_b = this.backButtonEl) === null || _b === void 0 ? void 0 : _b.setFocus();
return;
}
(_c = this.containerEl) === null || _c === void 0 ? void 0 : _c.focus();
}
/** Scrolls panel content to a particular set of coordinates.
*
* ```
* myCalcitePanel.scrollContentTo({
* left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.
* top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element
* behavior: "auto" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).
* });
* ```
*/
async scrollContentTo(options) {
var _a;
(_a = this.panelScrollEl) === null || _a === void 0 ? void 0 : _a.scrollTo(options);
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
renderBackButton() {
const { el } = this;
const rtl = getElementDir(el) === "rtl";
const { showBackButton, intlBack, backButtonClick } = this;
const label = intlBack || TEXT.back;
const icon = rtl ? ICONS.backRight : ICONS.backLeft;
return showBackButton ? (h("calcite-action", { "aria-label": label, class: CSS.backButton, icon: icon, key: "back-button", onClick: backButtonClick, ref: this.setBackRef, scale: "s", slot: SLOTS.headerActionsStart, text: label })) : null;
}
renderHeaderContent() {
const { heading, headingLevel, summary } = this;
const headingNode = heading ? (h(Heading, { class: CSS.heading, level: headingLevel || HEADING_LEVEL }, heading)) : null;
const summaryNode = summary ? h("span", { class: CSS.summary }, summary) : null;
return headingNode || summaryNode ? (h("div", { class: CSS.headerContent, key: "header-content" }, headingNode, summaryNode)) : null;
}
/**
* Allows user to override the entire header-content node.
*/
renderHeaderSlottedContent() {
return (h("div", { class: CSS.headerContent, key: "slotted-header-content" }, h("slot", { name: SLOTS.headerContent })));
}
renderHeaderStartActions() {
const { el } = this;
const hasStartActions = getSlotted(el, SLOTS.headerActionsStart);
return hasStartActions ? (h("div", { class: { [CSS.headerActionsStart]: true, [CSS.headerActions]: true }, key: "header-actions-start" }, h("slot", { name: SLOTS.headerActionsStart }))) : null;
}
renderHeaderActionsEnd() {
const { dismiss, dismissible, el, intlClose } = this;
const text = intlClose || TEXT.close;
const dismissibleNode = dismissible ? (h("calcite-action", { "aria-label": text, icon: ICONS.close, onClick: dismiss, ref: this.setDismissRef, text: text })) : null;
const slotNode = h("slot", { name: SLOTS.headerActionsEnd });
const hasEndActions = getSlotted(el, SLOTS.headerActionsEnd);
return hasEndActions || dismissibleNode ? (h("div", { class: { [CSS.headerActionsEnd]: true, [CSS.headerActions]: true }, key: "header-actions-end" }, slotNode, dismissibleNode)) : null;
}
renderMenu() {
const { el, intlOptions, menuOpen } = this;
const hasMenuItems = getSlotted(el, SLOTS.headerMenuActions);
return hasMenuItems ? (h("calcite-action-menu", { flipPlacements: ["top", "bottom"], key: "menu", label: intlOptions || TEXT.options, open: menuOpen, placement: "bottom-end" }, h("calcite-action", { icon: ICONS.menu, slot: SLOTS$1.trigger, text: intlOptions || TEXT.options }), h("slot", { name: SLOTS.headerMenuActions }))) : null;
}
renderHeaderNode() {
const { el, showBackButton } = this;
const backButtonNode = this.renderBackButton();
const hasHeaderSlottedContent = getSlotted(el, SLOTS.headerContent);
const headerContentNode = hasHeaderSlottedContent
? this.renderHeaderSlottedContent()
: this.renderHeaderContent();
const actionsNodeStart = this.renderHeaderStartActions();
const actionsNodeEnd = this.renderHeaderActionsEnd();
const headerMenuNode = this.renderMenu();
return actionsNodeStart ||
headerContentNode ||
actionsNodeEnd ||
headerMenuNode ||
showBackButton ? (h("header", { class: CSS.header }, backButtonNode, actionsNodeStart, headerContentNode, actionsNodeEnd, headerMenuNode)) : null;
}
renderFooterNode() {
const { el } = this;
const hasFooterSlottedContent = getSlotted(el, SLOTS.footer);
const hasFooterActions = getSlotted(el, SLOTS.footerActions);
return hasFooterSlottedContent || hasFooterActions ? (h("footer", { class: CSS.footer, key: "footer" }, hasFooterSlottedContent ? h("slot", { key: "footer-slot", name: SLOTS.footer }) : null, hasFooterActions ? h("slot", { key: "footer-actions-slot", name: SLOTS.footerActions }) : null)) : null;
}
renderContent() {
const { el } = this;
const hasFab = getSlotted(el, SLOTS.fab);
const defaultSlotNode = h("slot", { key: "default-slot" });
const contentWrapperKey = "content-wrapper";
return hasFab ? (h("div", { class: { [CSS.contentWrapper]: true, [CSS.contentHeight]: true }, key: contentWrapperKey, onScroll: this.panelScrollHandler, ref: (el) => (this.panelScrollEl = el), tabIndex: 0 }, h("section", { class: CSS.contentContainer }, defaultSlotNode), this.renderFab())) : (h("section", { class: { [CSS.contentWrapper]: true, [CSS.contentContainer]: true }, key: contentWrapperKey, onScroll: this.panelScrollHandler, ref: (el) => (this.panelScrollEl = el), tabIndex: 0 }, defaultSlotNode));
}
renderFab() {
return (h("div", { class: CSS.fabContainer }, h("slot", { name: SLOTS.fab })));
}
render() {
const { dismissed, dismissible, loading, panelKeyDownHandler } = this;
const panelNode = (h("article", { "aria-busy": loading.toString(), class: CSS.container, hidden: dismissible && dismissed, onKeyDown: panelKeyDownHandler, ref: this.setContainerRef, tabIndex: dismissible ? 0 : -1 }, this.renderHeaderNode(), this.renderContent(), this.renderFooterNode()));
return (h(Fragment, null, loading ? h("calcite-scrim", { loading: loading }) : null, panelNode));
}
get el() { return this; }
static get watchers() { return {
"dismissed": ["dismissedHandler"]
}; }
static get style() { return panelCss; }
}, [1, "calcite-panel", {
"dismissed": [1540],
"beforeBack": [16],
"disabled": [516],
"dismissible": [516],
"headingLevel": [2, "heading-level"],
"showBackButton": [516, "show-back-button"],
"intlBack": [1, "intl-back"],
"heightScale": [513, "height-scale"],
"widthScale": [513, "width-scale"],
"loading": [516],
"intlClose": [1, "intl-close"],
"intlOptions": [1, "intl-options"],
"heading": [1],
"summary": [1],
"menuOpen": [516, "menu-open"],
"setFocus": [64],
"scrollContentTo": [64]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["calcite-panel", "calcite-action", "calcite-action-menu", "calcite-icon", "calcite-loader", "calcite-popover", "calcite-scrim", "calcite-tooltip-manager"];
components.forEach(tagName => { switch (tagName) {
case "calcite-panel":
if (!customElements.get(tagName)) {
customElements.define(tagName, Panel);
}
break;
case "calcite-action":
if (!customElements.get(tagName)) {
defineCustomElement$8();
}
break;
case "calcite-action-menu":
if (!customElements.get(tagName)) {
defineCustomElement$7();
}
break;
case "calcite-icon":
if (!customElements.get(tagName)) {
defineCustomElement$6();
}
break;
case "calcite-loader":
if (!customElements.get(tagName)) {
defineCustomElement$5();
}
break;
case "calcite-popover":
if (!customElements.get(tagName)) {
defineCustomElement$4();
}
break;
case "calcite-scrim":
if (!customElements.get(tagName)) {
defineCustomElement$3();
}
break;
case "calcite-tooltip-manager":
if (!customElements.get(tagName)) {
defineCustomElement$2();
}
break;
} });
}
defineCustomElement$1();
const CalcitePanel = Panel;
const defineCustomElement = defineCustomElement$1;
export { CalcitePanel, defineCustomElement };