calcite-panel.entry.js 20 KB

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