123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.82
- */
- import { Component, Element, Event, Method, Prop, Watch, h, Fragment } from "@stencil/core";
- import { CSS, HEADING_LEVEL, ICONS, SLOTS, TEXT } from "./resources";
- import { getElementDir, getSlotted, toAriaBoolean } from "../../utils/dom";
- import { Heading } from "../functional/Heading";
- import { SLOTS as ACTION_MENU_SLOTS } from "../action-menu/resources";
- import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
- import { updateHostInteraction } from "../../utils/interactive";
- import { createObserver } from "../../utils/observers";
- /**
- * @slot - A slot for adding custom content.
- * @slot header-actions-start - A slot for adding actions or content to the start side of the panel header.
- * @slot header-actions-end - A slot for adding actions or content to the end side of the panel header.
- * @slot header-content - A slot for adding custom content to the header.
- * @slot header-menu-actions - A slot for adding an overflow menu with actions inside a dropdown.
- * @slot fab - A slot for adding a `calcite-fab` (floating action button) to perform an action.
- * @slot footer-actions - A slot for adding buttons to the footer.
- * @slot footer - A slot for adding custom content to the footer.
- */
- export class Panel {
- constructor() {
- // --------------------------------------------------------------------------
- //
- // 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;
- this.resizeObserver = createObserver("resize", () => this.resizeHandler());
- // --------------------------------------------------------------------------
- //
- // Private Methods
- //
- // --------------------------------------------------------------------------
- this.resizeHandler = () => {
- const { panelScrollEl } = this;
- if (!panelScrollEl ||
- typeof panelScrollEl.scrollHeight !== "number" ||
- typeof panelScrollEl.offsetHeight !== "number") {
- return;
- }
- panelScrollEl.tabIndex = panelScrollEl.scrollHeight > panelScrollEl.offsetHeight ? 0 : -1;
- };
- 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.calcitePanelDismiss.emit();
- };
- this.panelScrollHandler = () => {
- this.calcitePanelScroll.emit();
- };
- this.backButtonClick = () => {
- this.calcitePanelBackClick.emit();
- };
- this.setPanelScrollEl = (el) => {
- var _a, _b;
- this.panelScrollEl = el;
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
- if (el) {
- (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.observe(el);
- this.resizeHandler();
- }
- };
- }
- dismissedHandler() {
- this.calcitePanelDismissedChange.emit();
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- componentDidRender() {
- updateHostInteraction(this);
- }
- // --------------------------------------------------------------------------
- //
- // Lifecycle
- //
- // --------------------------------------------------------------------------
- connectedCallback() {
- connectConditionalSlotComponent(this);
- }
- disconnectedCallback() {
- var _a;
- disconnectConditionalSlotComponent(this);
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
- }
- // --------------------------------------------------------------------------
- //
- // 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: ACTION_MENU_SLOTS.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: this.setPanelScrollEl },
- h("section", { class: CSS.contentContainer }, defaultSlotNode),
- this.renderFab())) : (h("section", { class: { [CSS.contentWrapper]: true, [CSS.contentContainer]: true }, key: contentWrapperKey, onScroll: this.panelScrollHandler, ref: this.setPanelScrollEl }, 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": toAriaBoolean(loading), 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));
- }
- static get is() { return "calcite-panel"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() { return {
- "$": ["panel.scss"]
- }; }
- static get styleUrls() { return {
- "$": ["panel.css"]
- }; }
- static get properties() { return {
- "dismissed": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Hides the panel."
- },
- "attribute": "dismissed",
- "reflect": true,
- "defaultValue": "false"
- },
- "beforeBack": {
- "type": "unknown",
- "mutable": false,
- "complexType": {
- "original": "() => Promise<void>",
- "resolved": "() => Promise<void>",
- "references": {
- "Promise": {
- "location": "global"
- }
- }
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "When provided, this method will be called before it is removed from the parent flow."
- }
- },
- "disabled": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When true, disabled prevents interaction. This state shows items with lower opacity/grayed."
- },
- "attribute": "disabled",
- "reflect": true,
- "defaultValue": "false"
- },
- "dismissible": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Displays a close button in the trailing side of the header."
- },
- "attribute": "dismissible",
- "reflect": true,
- "defaultValue": "false"
- },
- "headingLevel": {
- "type": "number",
- "mutable": false,
- "complexType": {
- "original": "HeadingLevel",
- "resolved": "1 | 2 | 3 | 4 | 5 | 6",
- "references": {
- "HeadingLevel": {
- "location": "import",
- "path": "../functional/Heading"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Number at which section headings should start for this component."
- },
- "attribute": "heading-level",
- "reflect": false
- },
- "showBackButton": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Shows a back button in the header."
- },
- "attribute": "show-back-button",
- "reflect": true,
- "defaultValue": "false"
- },
- "intlBack": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "'Back' text string."
- },
- "attribute": "intl-back",
- "reflect": false
- },
- "heightScale": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Scale",
- "resolved": "\"l\" | \"m\" | \"s\"",
- "references": {
- "Scale": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "Specifies the maximum height of the panel."
- },
- "attribute": "height-scale",
- "reflect": true
- },
- "widthScale": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Scale",
- "resolved": "\"l\" | \"m\" | \"s\"",
- "references": {
- "Scale": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "This sets width of the panel."
- },
- "attribute": "width-scale",
- "reflect": true
- },
- "loading": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When true, content is waiting to be loaded. This state shows a busy indicator."
- },
- "attribute": "loading",
- "reflect": true,
- "defaultValue": "false"
- },
- "intlClose": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "'Close' text string for the close button. The close button will only be shown when 'dismissible' is true."
- },
- "attribute": "intl-close",
- "reflect": false
- },
- "intlOptions": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "'Options' text string for the actions menu."
- },
- "attribute": "intl-options",
- "reflect": false
- },
- "heading": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "Heading text."
- },
- "attribute": "heading",
- "reflect": false
- },
- "summary": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "Summary text. A description displayed underneath the heading."
- },
- "attribute": "summary",
- "reflect": false
- },
- "menuOpen": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Opens the action menu."
- },
- "attribute": "menu-open",
- "reflect": true,
- "defaultValue": "false"
- }
- }; }
- static get events() { return [{
- "method": "calcitePanelDismiss",
- "name": "calcitePanelDismiss",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Emitted when the close button has been clicked."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }, {
- "method": "calcitePanelDismissedChange",
- "name": "calcitePanelDismissedChange",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "use calcitePanelDismiss instead."
- }],
- "text": "Emitted when the close button has been clicked."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }, {
- "method": "calcitePanelScroll",
- "name": "calcitePanelScroll",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Emitted when the content has been scrolled."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }, {
- "method": "calcitePanelBackClick",
- "name": "calcitePanelBackClick",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Emitted when the back button has been clicked."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }]; }
- static get methods() { return {
- "setFocus": {
- "complexType": {
- "signature": "(focusId?: \"dismiss-button\" | \"back-button\") => Promise<void>",
- "parameters": [{
- "tags": [],
- "text": ""
- }],
- "references": {
- "Promise": {
- "location": "global"
- }
- },
- "return": "Promise<void>"
- },
- "docs": {
- "text": "Sets focus on the component.",
- "tags": []
- }
- },
- "scrollContentTo": {
- "complexType": {
- "signature": "(options?: ScrollToOptions) => Promise<void>",
- "parameters": [{
- "tags": [],
- "text": ""
- }],
- "references": {
- "Promise": {
- "location": "global"
- },
- "ScrollToOptions": {
- "location": "global"
- }
- },
- "return": "Promise<void>"
- },
- "docs": {
- "text": "Scrolls panel content to a particular set of coordinates.\n\n```\n myCalcitePanel.scrollContentTo({\n left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.\n top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element\n behavior: \"auto\" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).\n });\n```",
- "tags": []
- }
- }
- }; }
- static get elementRef() { return "el"; }
- static get watchers() { return [{
- "propName": "dismissed",
- "methodName": "dismissedHandler"
- }]; }
- }
|