UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

336 lines (324 loc) • 21.2 kB
/*! * 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 conditionalSlot = require('./conditionalSlot-4472b3c1.js'); const dom = require('./dom-18ca68ff.js'); const locale = require('./locale-fc347462.js'); const t9n = require('./t9n-14d528c4.js'); const Heading = require('./Heading-e1a3c7e4.js'); const observers = require('./observers-83b3999d.js'); require('./guid-db20443e.js'); require('./resources-45d84c94.js'); require('./key-2ce02f02.js'); const CSS$1 = { container: "container", header: "header", heading: "heading", close: "close", imageFrame: "image-frame", content: "content", info: "info" }; const ICONS$1 = { close: "x" }; const SLOTS = { thumbnail: "thumbnail" }; const tipCss = "@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:relative;margin:1rem;box-sizing:border-box;display:flex;flex-direction:row;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-2);background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}.container{inline-size:100%;padding:1rem}:host([closed]),:host([closed]) .container{display:none}:host([selected]) .container{margin:0px;border-style:none;padding:0px}.header{margin:0px;display:flex;align-content:space-between;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{flex:1 1 auto;padding:0.5rem}.header{margin-block-end:0.5rem}.header .heading{padding:0px;font-size:var(--calcite-font-size-0);line-height:1.25rem;color:var(--calcite-ui-text-1)}.container[hidden]{display:none}.content{display:flex}.info{padding-block:0px;padding-inline:1rem;inline-size:70%}.info:only-child{inline-size:100%;padding-inline:0px}::slotted(p){margin-block-start:0px}::slotted(a){outline-color:transparent;color:var(--calcite-ui-brand)}::slotted(a:focus){outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n 2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n )}.image-frame{inline-size:25%}.image-frame img{max-inline-size:100%}::slotted(img){max-inline-size:100%}"; const Tip = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteTipDismiss = index.createEvent(this, "calciteTipDismiss", 6); // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.hideTip = () => { this.closed = true; this.calciteTipDismiss.emit(); }; this.closed = false; this.closeDisabled = false; this.heading = undefined; this.headingLevel = undefined; this.selected = false; this.messages = undefined; this.messageOverrides = undefined; this.defaultMessages = undefined; this.effectiveLocale = ""; } onMessagesChange() { /* wired up by t9n util */ } effectiveLocaleChange() { t9n.updateMessages(this, this.effectiveLocale); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { conditionalSlot.connectConditionalSlotComponent(this); locale.connectLocalized(this); t9n.connectMessages(this); } async componentWillLoad() { await t9n.setUpMessages(this); } disconnectedCallback() { conditionalSlot.disconnectConditionalSlotComponent(this); locale.disconnectLocalized(this); t9n.disconnectMessages(this); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderHeader() { const { heading, headingLevel, el } = this; const parentLevel = el.closest("calcite-tip-manager")?.headingLevel; const relativeLevel = parentLevel ? Heading.constrainHeadingLevel(parentLevel + 1) : null; const level = headingLevel || relativeLevel; return heading ? (index.h("header", { class: CSS$1.header }, index.h(Heading.Heading, { class: CSS$1.heading, level: level }, heading))) : null; } renderDismissButton() { const { closeDisabled, hideTip } = this; return !closeDisabled ? (index.h("calcite-action", { class: CSS$1.close, icon: ICONS$1.close, onClick: hideTip, scale: "l", text: this.messages.close })) : null; } renderImageFrame() { const { el } = this; return dom.getSlotted(el, SLOTS.thumbnail) ? (index.h("div", { class: CSS$1.imageFrame, key: "thumbnail" }, index.h("slot", { name: SLOTS.thumbnail }))) : null; } renderInfoNode() { return (index.h("div", { class: CSS$1.info }, index.h("slot", null))); } renderContent() { return (index.h("div", { class: CSS$1.content }, this.renderImageFrame(), this.renderInfoNode())); } render() { return (index.h(index.Fragment, null, index.h("article", { class: CSS$1.container }, this.renderHeader(), this.renderContent()), this.renderDismissButton())); } static get assetsDirs() { return ["assets"]; } get el() { return index.getElement(this); } static get watchers() { return { "messageOverrides": ["onMessagesChange"], "effectiveLocale": ["effectiveLocaleChange"] }; } }; Tip.style = tipCss; const tipGroupCss = "@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{box-sizing:border-box;display:block;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}::slotted(calcite-tip){margin:0px;border-style:none;max-inline-size:var(--calcite-tip-max-width)}"; const TipGroup = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.groupTitle = undefined; } render() { return index.h("slot", null); } }; TipGroup.style = tipGroupCss; const CSS = { 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 = { chevronLeft: "chevron-left", chevronRight: "chevron-right", close: "x" }; const tipManagerCss = "@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{box-sizing:border-box;display:block;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2);--calcite-tip-manager-height:19vh}:host *{box-sizing:border-box}:host([closed]){display:none}.header{margin:0px;display:flex;align-content:space-between;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{flex:1 1 auto;padding:0.5rem}.header{border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-block:0px;padding-inline-end:0px;padding-inline-start:1rem}.header .heading{padding:0px;font-size:var(--calcite-font-size-1);line-height:1.5rem;font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-1)}.container{position:relative;overflow:hidden;outline-color:transparent;min-block-size:150px}.container:focus{outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n 2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n )}.tip-container{margin-block-start:1px;display:flex;align-items:flex-start;justify-content:center;overflow:auto;padding:1rem;outline-color:transparent;animation-name:none;animation-duration:var(--calcite-animation-timing);block-size:var(--calcite-tip-manager-height)}.tip-container:focus{outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n 2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n )}::slotted(calcite-tip){margin:0px;border-style:none;max-inline-size:var(--calcite-tip-max-width)}.tip-container--advancing{animation-name:tip-advance}.tip-container--retreating{animation-name:tip-retreat}.pagination{display:flex;align-items:center;justify-content:center;padding-inline:0px;padding-block:0.75rem 0.5rem}.page-position{margin-block:0px;margin-inline:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem}@keyframes tip-advance{0%{opacity:0;transform:translate3d(50px, 0, 0) scale(0.99)}100%{opacity:1;transform:translate3d(0, 0, 0) scale(1)}}@keyframes tip-retreat{0%{opacity:0;transform:translate3d(-50px, 0, 0) scale(0.99)}100%{opacity:1;transform:translate3d(0, 0, 0) scale(1)}}"; const TipManager = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteTipManagerClose = index.createEvent(this, "calciteTipManagerClose", 6); this.mutationObserver = observers.createObserver("mutation", () => this.setUpTips()); this.hideTipManager = () => { this.closed = true; this.calciteTipManagerClose.emit(); }; this.previousClicked = () => { this.previousTip(); }; this.nextClicked = () => { this.nextTip(); }; this.tipManagerKeyDownHandler = (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; }; this.closed = false; this.headingLevel = undefined; this.messages = undefined; this.messageOverrides = undefined; this.selectedIndex = undefined; this.tips = undefined; this.total = undefined; this.direction = undefined; this.groupTitle = undefined; this.defaultMessages = undefined; this.effectiveLocale = ""; } closedChangeHandler() { this.direction = null; } onMessagesChange() { /* wired up by t9n util */ } selectedChangeHandler() { this.showSelectedTip(); this.updateGroupTitle(); } async effectiveLocaleChange() { await t9n.updateMessages(this, this.effectiveLocale); this.updateGroupTitle(); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { locale.connectLocalized(this); t9n.connectMessages(this); this.setUpTips(); this.mutationObserver?.observe(this.el, { childList: true, subtree: true }); } async componentWillLoad() { await t9n.setUpMessages(this); this.updateGroupTitle(); } disconnectedCallback() { this.mutationObserver?.disconnect(); locale.disconnectLocalized(this); t9n.disconnectMessages(this); } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- /** Selects the next `calcite-tip` to display. */ async nextTip() { this.direction = "advancing"; const nextIndex = this.selectedIndex + 1; this.selectedIndex = (nextIndex + this.total) % this.total; } /** Selects the previous `calcite-tip` to display. */ 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.closeDisabled = true; }); this.showSelectedTip(); } showSelectedTip() { this.tips.forEach((tip, index) => { const isSelected = this.selectedIndex === index; tip.selected = isSelected; tip.hidden = !isSelected; }); } updateGroupTitle() { if (this.tips) { const selectedTip = this.tips[this.selectedIndex]; const tipParent = selectedTip.closest("calcite-tip-group"); this.groupTitle = tipParent?.groupTitle || this.messages?.defaultGroupTitle; } } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderPagination() { const dir = dom.getElementDir(this.el); const { selectedIndex, tips, total, messages } = this; const nextLabel = messages.next; const previousLabel = messages.previous; const paginationLabel = messages.defaultPaginationLabel; return tips.length > 1 ? (index.h("footer", { class: CSS.pagination }, index.h("calcite-action", { class: CSS.pagePrevious, icon: dir === "ltr" ? ICONS.chevronLeft : ICONS.chevronRight, onClick: this.previousClicked, scale: "m", text: previousLabel }), index.h("span", { class: CSS.pagePosition }, `${paginationLabel} ${selectedIndex + 1}/${total}`), index.h("calcite-action", { class: CSS.pageNext, icon: dir === "ltr" ? ICONS.chevronRight : ICONS.chevronLeft, onClick: this.nextClicked, scale: "m", text: nextLabel }))) : null; } render() { const { closed, direction, headingLevel, groupTitle, selectedIndex, messages, total } = this; const closeLabel = messages.close; if (total === 0) { return null; } return (index.h("section", { "aria-hidden": dom.toAriaBoolean(closed), class: CSS.container, hidden: closed, onKeyDown: this.tipManagerKeyDownHandler, tabIndex: 0, // eslint-disable-next-line react/jsx-sort-props ref: this.storeContainerRef }, index.h("header", { class: CSS.header }, index.h(Heading.Heading, { class: CSS.heading, level: headingLevel }, groupTitle), index.h("calcite-action", { class: CSS.close, onClick: this.hideTipManager, scale: "m", text: closeLabel }, index.h("calcite-icon", { icon: ICONS.close, scale: "m" }))), index.h("div", { class: { [CSS.tipContainer]: true, [CSS.tipContainerAdvancing]: !closed && direction === "advancing", [CSS.tipContainerRetreating]: !closed && direction === "retreating" }, key: selectedIndex, tabIndex: 0 }, index.h("slot", null)), this.renderPagination())); } static get assetsDirs() { return ["assets"]; } get el() { return index.getElement(this); } static get watchers() { return { "closed": ["closedChangeHandler"], "messageOverrides": ["onMessagesChange"], "selectedIndex": ["selectedChangeHandler"], "effectiveLocale": ["effectiveLocaleChange"] }; } }; TipManager.style = tipManagerCss; exports.calcite_tip = Tip; exports.calcite_tip_group = TipGroup; exports.calcite_tip_manager = TipManager;