UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

283 lines (273 loc) • 20 kB
import { r as registerInstance, c as createEvent, h, F as Fragment, g as getElement } from './index-aa8afca4.js'; import { b as getSlotted, g as getElementDir } from './dom-466af3c7.js'; import { C as CalciteHeading, c as constrainHeadingLevel } from './CalciteHeading-63c82bed.js'; import './guid-09142681.js'; const CSS$1 = { header: "header", heading: "heading", close: "close", container: "container", tipContainer: "tip-container", tipContainerAdvancing: "tip-container--advancing", tipContainerRetreating: "tip-container--retreating", pagination: "pagination", pagePosition: "page-position", pageNext: "page-next", pagePrevious: "page-previous" }; const ICONS$1 = { chevronLeft: "chevron-left", chevronRight: "chevron-right", close: "x" }; const TEXT$1 = { defaultGroupTitle: "Tips", defaultPaginationLabel: "Tip", close: "Close", previous: "Previous", next: "Next" }; const HEADING_LEVEL$1 = 2; const CSS = { container: "container", header: "header", heading: "heading", close: "close", imageFrame: "image-frame", content: "content", info: "info" }; const ICONS = { close: "x" }; const SLOTS = { thumbnail: "thumbnail" }; const TEXT = { close: "Close" }; const HEADING_LEVEL = (HEADING_LEVEL$1 + 1); const calciteTipCss = "@-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)}}: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:150ms ease-in-out}:host([hidden]){display:none}:host{position:relative;display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;margin:1rem;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-2)}.container{padding:1rem}:host([dismissed]),:host([dismissed]) .container{display:none}:host([selected]) .container{border-style:none;margin:0;padding:0}.header{margin:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;color:var(--calcite-ui-text-2);fill:var(--calcite-ui-text-2)}.heading{padding:0;margin:0;font-weight:var(--calcite-font-weight-medium);line-height:1.5}.header .heading{-ms-flex:1 0 auto;flex:1 0 auto;padding:var(--calcite-spacing-half) var(--calcite-spacing-half)}h1.heading{font-size:var(--calcite-font-size-2)}h2.heading{font-size:var(--calcite-font-size-1)}h3.heading{font-size:var(--calcite-font-size-0)}h4.heading,h5.heading{font-size:var(--calcite-font-size--1)}.header{margin-bottom:0.5rem}.header .heading{color:var(--calcite-ui-text-2);padding:0}.container[hidden]{display:none}.content{display:-ms-flexbox;display:flex}.info{padding-top:0;padding-bottom:0;padding-left:1rem;padding-right:1rem;width:70%}.info:only-child{width:100%;padding-left:0;padding-right:0}::slotted(p){margin-top:0}::slotted(a){outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;color:var(--calcite-ui-brand)}::slotted(a:focus){outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.image-frame{width:25%}.image-frame img{max-width:100%}::slotted(img){max-width:100%}"; const CalciteTip = class { constructor(hostRef) { registerInstance(this, hostRef); this.calciteTipDismiss = createEvent(this, "calciteTipDismiss", 7); // -------------------------------------------------------------------------- // // Properties // // -------------------------------------------------------------------------- /** * No longer displays the tip. */ this.dismissed = false; /** * Indicates whether the tip can be dismissed. */ this.nonDismissible = false; // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.hideTip = () => { this.dismissed = true; this.calciteTipDismiss.emit(); }; } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderHeader() { var _a; const { heading, headingLevel, el } = this; const parentLevel = (_a = el.closest("calcite-tip-manager")) === null || _a === void 0 ? void 0 : _a.headingLevel; const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null; const level = headingLevel || relativeLevel || HEADING_LEVEL; return heading ? (h("header", { class: CSS.header }, h(CalciteHeading, { class: CSS.heading, level: level }, heading))) : null; } renderDismissButton() { const { nonDismissible, hideTip, intlClose } = this; const text = intlClose || TEXT.close; return !nonDismissible ? (h("calcite-action", { class: CSS.close, icon: ICONS.close, onClick: hideTip, scale: "l", text: text })) : null; } renderImageFrame() { const { el } = this; return getSlotted(el, SLOTS.thumbnail) ? (h("div", { class: CSS.imageFrame }, h("slot", { name: SLOTS.thumbnail }))) : null; } renderInfoNode() { return (h("div", { class: CSS.info }, h("slot", null))); } renderContent() { return (h("div", { class: CSS.content }, this.renderImageFrame(), this.renderInfoNode())); } render() { return (h(Fragment, null, h("article", { class: CSS.container }, this.renderHeader(), this.renderContent()), this.renderDismissButton())); } get el() { return getElement(this); } }; CalciteTip.style = calciteTipCss; const calciteTipGroupCss = "@-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)}}: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:150ms ease-in-out}:host([hidden]){display:none}::slotted(calcite-tip){border-style:none;max-width:34rem}"; const CalciteTipGroup = class { constructor(hostRef) { registerInstance(this, hostRef); } render() { return h("slot", null); } }; CalciteTipGroup.style = calciteTipGroupCss; const calciteTipManagerCss = "@-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)}}: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:150ms ease-in-out}:host([hidden]){display:none}:host{display:block;--calcite-tip-manager-height:18vh;--calcite-tip-max-width:540px}:host([closed]){display:none}.header{margin:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;color:var(--calcite-ui-text-2);fill:var(--calcite-ui-text-2)}.heading{padding:0;margin:0;font-weight:var(--calcite-font-weight-medium);line-height:1.5}.header .heading{-ms-flex:1 0 auto;flex:1 0 auto;padding:var(--calcite-spacing-half) var(--calcite-spacing-half)}h1.heading{font-size:var(--calcite-font-size-2)}h2.heading{font-size:var(--calcite-font-size-1)}h3.heading{font-size:var(--calcite-font-size-0)}h4.heading,h5.heading{font-size:var(--calcite-font-size--1)}.header .heading{padding-left:0.5rem;padding-right:0.5rem}.container{overflow:hidden;position:relative;padding-top:0.5rem;padding-left:0.5rem;padding-right:0.5rem;padding-bottom:0;outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;min-height:150px}.container:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.tip-container{margin-top:0.25rem;overflow:auto;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:start;align-items:flex-start;outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;-webkit-animation-name:none;animation-name:none;-webkit-animation-duration:150ms;animation-duration:150ms;-webkit-animation-timing-function:cubic-bezier(0.215, 0.44, 0.42, 0.88);animation-timing-function:cubic-bezier(0.215, 0.44, 0.42, 0.88);height:var(--calcite-tip-manager-height)}.tip-container:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}::slotted(calcite-tip){border-style:none;max-width:var(--calcite-tip-max-width)}.tip-container--advancing{-webkit-animation-name:tip-advance;animation-name:tip-advance}.tip-container--retreating{-webkit-animation-name:tip-retreat;animation-name:tip-retreat}.pagination{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;padding-top:0.25rem;padding-bottom:0.25rem;padding-left:0;padding-right:0}.page-position{font-size:var(--calcite-font-size--2);line-height:1rem;margin-top:0;margin-bottom:0;margin-left:0.5rem;margin-right:0.5rem}@-webkit-keyframes tip-advance{0%{opacity:0;-webkit-transform:translate3d(50px, 0, 0) scale(0.99);transform:translate3d(50px, 0, 0) scale(0.99)}100%{opacity:1;-webkit-transform:translate3d(0, 0, 0) scale(1);transform:translate3d(0, 0, 0) scale(1)}}@keyframes tip-advance{0%{opacity:0;-webkit-transform:translate3d(50px, 0, 0) scale(0.99);transform:translate3d(50px, 0, 0) scale(0.99)}100%{opacity:1;-webkit-transform:translate3d(0, 0, 0) scale(1);transform:translate3d(0, 0, 0) scale(1)}}@-webkit-keyframes tip-retreat{0%{opacity:0;-webkit-transform:translate3d(-50px, 0, 0) scale(0.99);transform:translate3d(-50px, 0, 0) scale(0.99)}100%{opacity:1;-webkit-transform:translate3d(0, 0, 0) scale(1);transform:translate3d(0, 0, 0) scale(1)}}@keyframes tip-retreat{0%{opacity:0;-webkit-transform:translate3d(-50px, 0, 0) scale(0.99);transform:translate3d(-50px, 0, 0) scale(0.99)}100%{opacity:1;-webkit-transform:translate3d(0, 0, 0) scale(1);transform:translate3d(0, 0, 0) scale(1)}}"; const CalciteTipManager = class { constructor(hostRef) { registerInstance(this, hostRef); this.calciteTipManagerToggle = createEvent(this, "calciteTipManagerToggle", 7); // -------------------------------------------------------------------------- // // Properties // // -------------------------------------------------------------------------- /** * Alternate text for closing the `calcite-tip-manager`. */ this.closed = false; this.observer = new MutationObserver(() => this.setUpTips()); this.hideTipManager = () => { this.closed = true; this.calciteTipManagerToggle.emit(); }; this.previousClicked = () => { this.previousTip(); }; this.nextClicked = () => { this.nextTip(); }; this.tipManagerKeyUpHandler = (event) => { if (event.target !== this.container) { return; } switch (event.key) { case "ArrowRight": event.preventDefault(); this.nextTip(); break; case "ArrowLeft": event.preventDefault(); this.previousTip(); break; case "Home": event.preventDefault(); this.selectedIndex = 0; break; case "End": event.preventDefault(); this.selectedIndex = this.total - 1; break; } }; this.storeContainerRef = (el) => { this.container = el; }; } closedChangeHandler() { this.direction = null; this.calciteTipManagerToggle.emit(); } selectedChangeHandler() { this.showSelectedTip(); this.updateGroupTitle(); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { this.setUpTips(); this.observer.observe(this.el, { childList: true, subtree: true }); } disconnectedCallback() { this.observer.disconnect(); } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- async nextTip() { this.direction = "advancing"; const nextIndex = this.selectedIndex + 1; this.selectedIndex = (nextIndex + this.total) % this.total; } async previousTip() { this.direction = "retreating"; const previousIndex = this.selectedIndex - 1; this.selectedIndex = (previousIndex + this.total) % this.total; } // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- setUpTips() { const tips = Array.from(this.el.querySelectorAll("calcite-tip")); this.total = tips.length; if (this.total === 0) { return; } const selectedTip = this.el.querySelector("calcite-tip[selected]"); this.tips = tips; this.selectedIndex = selectedTip ? tips.indexOf(selectedTip) : 0; tips.forEach((tip) => { tip.nonDismissible = true; }); this.showSelectedTip(); this.updateGroupTitle(); } showSelectedTip() { this.tips.forEach((tip, index) => { const isSelected = this.selectedIndex === index; tip.selected = isSelected; tip.hidden = !isSelected; }); } updateGroupTitle() { const selectedTip = this.tips[this.selectedIndex]; const tipParent = selectedTip.closest("calcite-tip-group"); this.groupTitle = (tipParent === null || tipParent === void 0 ? void 0 : tipParent.groupTitle) || this.intlDefaultTitle || TEXT$1.defaultGroupTitle; } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderPagination() { const dir = getElementDir(this.el); const { selectedIndex, tips, total, intlNext, intlPrevious, intlPaginationLabel } = this; const nextLabel = intlNext || TEXT$1.next; const previousLabel = intlPrevious || TEXT$1.previous; const paginationLabel = intlPaginationLabel || TEXT$1.defaultPaginationLabel; return tips.length > 1 ? (h("footer", { class: CSS$1.pagination }, h("calcite-action", { class: CSS$1.pagePrevious, icon: dir === "ltr" ? ICONS$1.chevronLeft : ICONS$1.chevronRight, onClick: this.previousClicked, text: previousLabel }), h("span", { class: CSS$1.pagePosition }, `${paginationLabel} ${selectedIndex + 1}/${total}`), h("calcite-action", { class: CSS$1.pageNext, icon: dir === "ltr" ? ICONS$1.chevronRight : ICONS$1.chevronLeft, onClick: this.nextClicked, text: nextLabel }))) : null; } render() { const { closed, direction, headingLevel, groupTitle, selectedIndex, intlClose, total } = this; const closeLabel = intlClose || TEXT$1.close; if (total === 0) { return null; } return (h("section", { "aria-hidden": closed.toString(), class: CSS$1.container, hidden: closed, onKeyUp: this.tipManagerKeyUpHandler, ref: this.storeContainerRef, tabIndex: 0 }, h("header", { class: CSS$1.header }, h(CalciteHeading, { class: CSS$1.heading, level: headingLevel || HEADING_LEVEL$1 }, groupTitle), h("calcite-action", { class: CSS$1.close, icon: ICONS$1.close, onClick: this.hideTipManager, text: closeLabel })), h("div", { class: { [CSS$1.tipContainer]: true, [CSS$1.tipContainerAdvancing]: !closed && direction === "advancing", [CSS$1.tipContainerRetreating]: !closed && direction === "retreating" }, key: selectedIndex, tabIndex: 0 }, h("slot", null)), this.renderPagination())); } get el() { return getElement(this); } static get watchers() { return { "closed": ["closedChangeHandler"], "selectedIndex": ["selectedChangeHandler"] }; } }; CalciteTipManager.style = calciteTipManagerCss; export { CalciteTip as calcite_tip, CalciteTipGroup as calcite_tip_group, CalciteTipManager as calcite_tip_manager };