calcite-panel.cjs.entry.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-5c65e149.js');
  9. const dom = require('./dom-9ac0341c.js');
  10. const Heading = require('./Heading-0cb5902d.js');
  11. const resources = require('./resources-1a214670.js');
  12. const conditionalSlot = require('./conditionalSlot-ba5cd797.js');
  13. const interactive = require('./interactive-e294111f.js');
  14. const observers = require('./observers-d9fdf006.js');
  15. require('./guid-8b6d6cb4.js');
  16. const CSS = {
  17. backButton: "back-button",
  18. container: "container",
  19. header: "header",
  20. heading: "heading",
  21. summary: "summary",
  22. headerContent: "header-content",
  23. headerActions: "header-actions",
  24. headerActionsEnd: "header-actions--end",
  25. headerActionsStart: "header-actions--start",
  26. contentWrapper: "content-wrapper",
  27. contentContainer: "content-container",
  28. contentHeight: "content-height",
  29. fabContainer: "fab-container",
  30. footer: "footer",
  31. menuContainer: "menu-container",
  32. menuButton: "menu-button",
  33. menu: "menu",
  34. menuOpen: "menu--open"
  35. };
  36. const ICONS = {
  37. close: "x",
  38. menu: "ellipsis",
  39. backLeft: "chevron-left",
  40. backRight: "chevron-right"
  41. };
  42. const SLOTS = {
  43. headerActionsStart: "header-actions-start",
  44. headerActionsEnd: "header-actions-end",
  45. headerMenuActions: "header-menu-actions",
  46. headerContent: "header-content",
  47. fab: "fab",
  48. footer: "footer",
  49. footerActions: "footer-actions"
  50. };
  51. const TEXT = {
  52. back: "Back",
  53. close: "Close",
  54. open: "Open",
  55. options: "Options"
  56. };
  57. const HEADING_LEVEL = 3;
  58. 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}.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}.header-content{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;overflow:hidden;padding-left:0.75rem;padding-right:0.75rem;padding-top:0.875rem;padding-bottom:0.875rem;-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}";
  59. const Panel = class {
  60. constructor(hostRef) {
  61. index.registerInstance(this, hostRef);
  62. this.calcitePanelDismiss = index.createEvent(this, "calcitePanelDismiss", 7);
  63. this.calcitePanelDismissedChange = index.createEvent(this, "calcitePanelDismissedChange", 7);
  64. this.calcitePanelScroll = index.createEvent(this, "calcitePanelScroll", 7);
  65. this.calcitePanelBackClick = index.createEvent(this, "calcitePanelBackClick", 7);
  66. // --------------------------------------------------------------------------
  67. //
  68. // Properties
  69. //
  70. // --------------------------------------------------------------------------
  71. /**
  72. * Hides the panel.
  73. */
  74. this.dismissed = false;
  75. /**
  76. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  77. */
  78. this.disabled = false;
  79. /**
  80. * Displays a close button in the trailing side of the header.
  81. */
  82. this.dismissible = false;
  83. /**
  84. * Shows a back button in the header.
  85. */
  86. this.showBackButton = false;
  87. /**
  88. * When true, content is waiting to be loaded. This state shows a busy indicator.
  89. */
  90. this.loading = false;
  91. /**
  92. * Opens the action menu.
  93. */
  94. this.menuOpen = false;
  95. this.resizeObserver = observers.createObserver("resize", () => this.resizeHandler());
  96. // --------------------------------------------------------------------------
  97. //
  98. // Private Methods
  99. //
  100. // --------------------------------------------------------------------------
  101. this.resizeHandler = () => {
  102. const { panelScrollEl } = this;
  103. if (!panelScrollEl ||
  104. typeof panelScrollEl.scrollHeight !== "number" ||
  105. typeof panelScrollEl.offsetHeight !== "number") {
  106. return;
  107. }
  108. panelScrollEl.tabIndex = panelScrollEl.scrollHeight > panelScrollEl.offsetHeight ? 0 : -1;
  109. };
  110. this.setContainerRef = (node) => {
  111. this.containerEl = node;
  112. };
  113. this.setDismissRef = (node) => {
  114. this.dismissButtonEl = node;
  115. };
  116. this.setBackRef = (node) => {
  117. this.backButtonEl = node;
  118. };
  119. this.panelKeyDownHandler = (event) => {
  120. if (event.key === "Escape") {
  121. this.dismiss();
  122. }
  123. };
  124. this.dismiss = () => {
  125. this.dismissed = true;
  126. this.calcitePanelDismiss.emit();
  127. };
  128. this.panelScrollHandler = () => {
  129. this.calcitePanelScroll.emit();
  130. };
  131. this.backButtonClick = () => {
  132. this.calcitePanelBackClick.emit();
  133. };
  134. this.setPanelScrollEl = (el) => {
  135. var _a, _b;
  136. this.panelScrollEl = el;
  137. (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  138. if (el) {
  139. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.observe(el);
  140. this.resizeHandler();
  141. }
  142. };
  143. }
  144. dismissedHandler() {
  145. this.calcitePanelDismissedChange.emit();
  146. }
  147. //--------------------------------------------------------------------------
  148. //
  149. // Lifecycle
  150. //
  151. //--------------------------------------------------------------------------
  152. componentDidRender() {
  153. interactive.updateHostInteraction(this);
  154. }
  155. // --------------------------------------------------------------------------
  156. //
  157. // Lifecycle
  158. //
  159. // --------------------------------------------------------------------------
  160. connectedCallback() {
  161. conditionalSlot.connectConditionalSlotComponent(this);
  162. }
  163. disconnectedCallback() {
  164. var _a;
  165. conditionalSlot.disconnectConditionalSlotComponent(this);
  166. (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  167. }
  168. // --------------------------------------------------------------------------
  169. //
  170. // Methods
  171. //
  172. // --------------------------------------------------------------------------
  173. /** Sets focus on the component. */
  174. async setFocus(focusId) {
  175. var _a, _b, _c;
  176. if (focusId === "dismiss-button") {
  177. (_a = this.dismissButtonEl) === null || _a === void 0 ? void 0 : _a.setFocus();
  178. return;
  179. }
  180. if (focusId === "back-button") {
  181. (_b = this.backButtonEl) === null || _b === void 0 ? void 0 : _b.setFocus();
  182. return;
  183. }
  184. (_c = this.containerEl) === null || _c === void 0 ? void 0 : _c.focus();
  185. }
  186. /** Scrolls panel content to a particular set of coordinates.
  187. *
  188. * ```
  189. * myCalcitePanel.scrollContentTo({
  190. * left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.
  191. * top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element
  192. * behavior: "auto" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).
  193. * });
  194. * ```
  195. */
  196. async scrollContentTo(options) {
  197. var _a;
  198. (_a = this.panelScrollEl) === null || _a === void 0 ? void 0 : _a.scrollTo(options);
  199. }
  200. // --------------------------------------------------------------------------
  201. //
  202. // Render Methods
  203. //
  204. // --------------------------------------------------------------------------
  205. renderBackButton() {
  206. const { el } = this;
  207. const rtl = dom.getElementDir(el) === "rtl";
  208. const { showBackButton, intlBack, backButtonClick } = this;
  209. const label = intlBack || TEXT.back;
  210. const icon = rtl ? ICONS.backRight : ICONS.backLeft;
  211. return showBackButton ? (index.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;
  212. }
  213. renderHeaderContent() {
  214. const { heading, headingLevel, summary } = this;
  215. const headingNode = heading ? (index.h(Heading.Heading, { class: CSS.heading, level: headingLevel || HEADING_LEVEL }, heading)) : null;
  216. const summaryNode = summary ? index.h("span", { class: CSS.summary }, summary) : null;
  217. return headingNode || summaryNode ? (index.h("div", { class: CSS.headerContent, key: "header-content" }, headingNode, summaryNode)) : null;
  218. }
  219. /**
  220. * Allows user to override the entire header-content node.
  221. */
  222. renderHeaderSlottedContent() {
  223. return (index.h("div", { class: CSS.headerContent, key: "slotted-header-content" }, index.h("slot", { name: SLOTS.headerContent })));
  224. }
  225. renderHeaderStartActions() {
  226. const { el } = this;
  227. const hasStartActions = dom.getSlotted(el, SLOTS.headerActionsStart);
  228. return hasStartActions ? (index.h("div", { class: { [CSS.headerActionsStart]: true, [CSS.headerActions]: true }, key: "header-actions-start" }, index.h("slot", { name: SLOTS.headerActionsStart }))) : null;
  229. }
  230. renderHeaderActionsEnd() {
  231. const { dismiss, dismissible, el, intlClose } = this;
  232. const text = intlClose || TEXT.close;
  233. const dismissibleNode = dismissible ? (index.h("calcite-action", { "aria-label": text, icon: ICONS.close, onClick: dismiss, ref: this.setDismissRef, text: text })) : null;
  234. const slotNode = index.h("slot", { name: SLOTS.headerActionsEnd });
  235. const hasEndActions = dom.getSlotted(el, SLOTS.headerActionsEnd);
  236. return hasEndActions || dismissibleNode ? (index.h("div", { class: { [CSS.headerActionsEnd]: true, [CSS.headerActions]: true }, key: "header-actions-end" }, slotNode, dismissibleNode)) : null;
  237. }
  238. renderMenu() {
  239. const { el, intlOptions, menuOpen } = this;
  240. const hasMenuItems = dom.getSlotted(el, SLOTS.headerMenuActions);
  241. return hasMenuItems ? (index.h("calcite-action-menu", { flipPlacements: ["top", "bottom"], key: "menu", label: intlOptions || TEXT.options, open: menuOpen, placement: "bottom-end" }, index.h("calcite-action", { icon: ICONS.menu, slot: resources.SLOTS.trigger, text: intlOptions || TEXT.options }), index.h("slot", { name: SLOTS.headerMenuActions }))) : null;
  242. }
  243. renderHeaderNode() {
  244. const { el, showBackButton } = this;
  245. const backButtonNode = this.renderBackButton();
  246. const hasHeaderSlottedContent = dom.getSlotted(el, SLOTS.headerContent);
  247. const headerContentNode = hasHeaderSlottedContent
  248. ? this.renderHeaderSlottedContent()
  249. : this.renderHeaderContent();
  250. const actionsNodeStart = this.renderHeaderStartActions();
  251. const actionsNodeEnd = this.renderHeaderActionsEnd();
  252. const headerMenuNode = this.renderMenu();
  253. return actionsNodeStart ||
  254. headerContentNode ||
  255. actionsNodeEnd ||
  256. headerMenuNode ||
  257. showBackButton ? (index.h("header", { class: CSS.header }, backButtonNode, actionsNodeStart, headerContentNode, actionsNodeEnd, headerMenuNode)) : null;
  258. }
  259. renderFooterNode() {
  260. const { el } = this;
  261. const hasFooterSlottedContent = dom.getSlotted(el, SLOTS.footer);
  262. const hasFooterActions = dom.getSlotted(el, SLOTS.footerActions);
  263. return hasFooterSlottedContent || hasFooterActions ? (index.h("footer", { class: CSS.footer, key: "footer" }, hasFooterSlottedContent ? index.h("slot", { key: "footer-slot", name: SLOTS.footer }) : null, hasFooterActions ? index.h("slot", { key: "footer-actions-slot", name: SLOTS.footerActions }) : null)) : null;
  264. }
  265. renderContent() {
  266. const { el } = this;
  267. const hasFab = dom.getSlotted(el, SLOTS.fab);
  268. const defaultSlotNode = index.h("slot", { key: "default-slot" });
  269. const contentWrapperKey = "content-wrapper";
  270. return hasFab ? (index.h("div", { class: { [CSS.contentWrapper]: true, [CSS.contentHeight]: true }, key: contentWrapperKey, onScroll: this.panelScrollHandler, ref: this.setPanelScrollEl }, index.h("section", { class: CSS.contentContainer }, defaultSlotNode), this.renderFab())) : (index.h("section", { class: { [CSS.contentWrapper]: true, [CSS.contentContainer]: true }, key: contentWrapperKey, onScroll: this.panelScrollHandler, ref: this.setPanelScrollEl }, defaultSlotNode));
  271. }
  272. renderFab() {
  273. return (index.h("div", { class: CSS.fabContainer }, index.h("slot", { name: SLOTS.fab })));
  274. }
  275. render() {
  276. const { dismissed, dismissible, loading, panelKeyDownHandler } = this;
  277. const panelNode = (index.h("article", { "aria-busy": dom.toAriaBoolean(loading), class: CSS.container, hidden: dismissible && dismissed, onKeyDown: panelKeyDownHandler, ref: this.setContainerRef, tabIndex: dismissible ? 0 : -1 }, this.renderHeaderNode(), this.renderContent(), this.renderFooterNode()));
  278. return (index.h(index.Fragment, null, loading ? index.h("calcite-scrim", { loading: loading }) : null, panelNode));
  279. }
  280. get el() { return index.getElement(this); }
  281. static get watchers() { return {
  282. "dismissed": ["dismissedHandler"]
  283. }; }
  284. };
  285. Panel.style = panelCss;
  286. exports.calcite_panel = Panel;