calcite-panel.cjs.entry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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.97
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const resources = require('./resources-abee76d7.js');
  10. const dom = require('./dom-2ec8c9ed.js');
  11. const Heading = require('./Heading-1e87a15f.js');
  12. const resources$1 = require('./resources-bd2202e9.js');
  13. const interactive = require('./interactive-32293bca.js');
  14. const observers = require('./observers-5706326b.js');
  15. require('./resources-b5a5f8a7.js');
  16. require('./guid-f4f03a7a.js');
  17. const panelCss = "@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-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-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:host{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 *{box-sizing:border-box}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{position:relative;display:flex;inline-size:100%;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]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.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}.container{margin:0px;display:flex;inline-size:100%;flex:1 1 auto;flex-direction:column;align-items:stretch;background-color:var(--calcite-ui-background);padding:0px;max-block-size:var(--calcite-panel-max-height);inline-size:var(--calcite-panel-width);max-inline-size:var(--calcite-panel-max-width);min-inline-size:var(--calcite-panel-min-width);transition:max-block-size var(--calcite-animation-timing), inline-size 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}.header{border-block-end:1px solid;position:sticky;inset-block-start:0px;z-index:400;inline-size:100%;align-items:stretch;justify-content:flex-start;background-color:var(--calcite-ui-foreground-1);border-block-end-color:var(--calcite-ui-border-3);flex:0 0 auto}.header-content{display:flex;flex-direction:column;overflow:hidden;padding-inline:0.75rem;padding-block:0.875rem;margin-inline-end:auto}.header-content .heading,.header-content .description{display:block;overflow-wrap:break-word;padding:0px}.header-content .heading{margin-inline:0px;margin-block:0px 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-block-end:0px}.header-content .description{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:flex;flex-direction:row;flex-wrap:nowrap;align-items:stretch}.header-actions--end{margin-inline-start:auto}.content-wrapper{overflow:auto}.content-height{block-size:100%}.content-container{display:flex;flex:1 1 auto;flex-direction:column;flex-wrap:nowrap;align-items:stretch;background-color:var(--calcite-ui-background)}.footer{border-block-start:1px solid;position:sticky;inset-block-end:0px;display:flex;inline-size:100%;justify-content:space-evenly;background-color:var(--calcite-ui-foreground-1);border-block-start-color:var(--calcite-ui-border-3);flex:0 0 auto;min-block-size:3rem;padding:0.5rem}.fab-container{position:sticky;inset-block-end:0px;z-index:300;margin-block:0px;margin-inline:auto;display:block;padding:0.5rem;inset-inline:0;inline-size:-moz-fit-content;inline-size:fit-content}[hidden]{display:none}";
  18. const Panel = class {
  19. constructor(hostRef) {
  20. index.registerInstance(this, hostRef);
  21. this.calcitePanelClose = index.createEvent(this, "calcitePanelClose", 6);
  22. this.calcitePanelDismiss = index.createEvent(this, "calcitePanelDismiss", 6);
  23. this.calcitePanelDismissedChange = index.createEvent(this, "calcitePanelDismissedChange", 6);
  24. this.calcitePanelScroll = index.createEvent(this, "calcitePanelScroll", 6);
  25. this.calcitePanelBackClick = index.createEvent(this, "calcitePanelBackClick", 6);
  26. // --------------------------------------------------------------------------
  27. //
  28. // Properties
  29. //
  30. // --------------------------------------------------------------------------
  31. /**
  32. * When `true`, hides the component.
  33. *
  34. * @deprecated use `closed` instead.
  35. */
  36. this.dismissed = false;
  37. /** When `true`, the component will be hidden. */
  38. this.closed = false;
  39. /**
  40. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  41. */
  42. this.disabled = false;
  43. /**
  44. * When `true`, a close button is added to the component.
  45. *
  46. * @deprecated use `closable` instead
  47. */
  48. this.dismissible = false;
  49. /** When `true`, displays a close button in the trailing side of the header. */
  50. this.closable = false;
  51. /**
  52. * When `true`, displays a back button in the header.
  53. *
  54. * @deprecated use `calcite-flow-item` instead.
  55. */
  56. this.showBackButton = false;
  57. /**
  58. * When `true`, a busy indicator is displayed.
  59. */
  60. this.loading = false;
  61. /**
  62. * When `true`, the action menu items in the `header-menu-actions` slot are open.
  63. */
  64. this.menuOpen = false;
  65. this.resizeObserver = observers.createObserver("resize", () => this.resizeHandler());
  66. this.hasStartActions = false;
  67. this.hasEndActions = false;
  68. this.hasMenuItems = false;
  69. this.hasHeaderContent = false;
  70. this.hasFooterContent = false;
  71. this.hasFooterActions = false;
  72. this.hasFab = false;
  73. // --------------------------------------------------------------------------
  74. //
  75. // Private Methods
  76. //
  77. // --------------------------------------------------------------------------
  78. this.resizeHandler = () => {
  79. const { panelScrollEl } = this;
  80. if (!panelScrollEl ||
  81. typeof panelScrollEl.scrollHeight !== "number" ||
  82. typeof panelScrollEl.offsetHeight !== "number") {
  83. return;
  84. }
  85. panelScrollEl.tabIndex = panelScrollEl.scrollHeight > panelScrollEl.offsetHeight ? 0 : -1;
  86. };
  87. this.setContainerRef = (node) => {
  88. this.containerEl = node;
  89. };
  90. this.setCloseRef = (node) => {
  91. this.closeButtonEl = node;
  92. };
  93. this.setBackRef = (node) => {
  94. this.backButtonEl = node;
  95. };
  96. this.panelKeyDownHandler = (event) => {
  97. if (this.closable && event.key === "Escape" && !event.defaultPrevented) {
  98. this.close();
  99. event.preventDefault();
  100. }
  101. };
  102. this.close = () => {
  103. this.closed = true;
  104. this.calcitePanelDismiss.emit();
  105. this.calcitePanelClose.emit();
  106. };
  107. this.panelScrollHandler = () => {
  108. this.calcitePanelScroll.emit();
  109. };
  110. this.backButtonClick = () => {
  111. this.calcitePanelBackClick.emit();
  112. };
  113. this.handleHeaderActionsStartSlotChange = (event) => {
  114. const elements = event.target.assignedElements({
  115. flatten: true
  116. });
  117. this.hasStartActions = !!elements.length;
  118. };
  119. this.handleHeaderActionsEndSlotChange = (event) => {
  120. const elements = event.target.assignedElements({
  121. flatten: true
  122. });
  123. this.hasEndActions = !!elements.length;
  124. };
  125. this.handleHeaderMenuActionsSlotChange = (event) => {
  126. const elements = event.target.assignedElements({
  127. flatten: true
  128. });
  129. this.hasMenuItems = !!elements.length;
  130. };
  131. this.handleHeaderContentSlotChange = (event) => {
  132. const elements = event.target.assignedElements({
  133. flatten: true
  134. });
  135. this.hasHeaderContent = !!elements.length;
  136. };
  137. this.handleFooterSlotChange = (event) => {
  138. const elements = event.target.assignedElements({
  139. flatten: true
  140. });
  141. this.hasFooterContent = !!elements.length;
  142. };
  143. this.handleFooterActionsSlotChange = (event) => {
  144. const elements = event.target.assignedElements({
  145. flatten: true
  146. });
  147. this.hasFooterActions = !!elements.length;
  148. };
  149. this.handleFabSlotChange = (event) => {
  150. const elements = event.target.assignedElements({
  151. flatten: true
  152. });
  153. this.hasFab = !!elements.length;
  154. };
  155. this.setPanelScrollEl = (el) => {
  156. var _a, _b;
  157. this.panelScrollEl = el;
  158. (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  159. if (el) {
  160. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.observe(el);
  161. this.resizeHandler();
  162. }
  163. };
  164. }
  165. dismissedHandler(value) {
  166. this.closed = value;
  167. this.calcitePanelDismissedChange.emit();
  168. }
  169. closedHandler(value) {
  170. this.dismissed = value;
  171. }
  172. dismissibleHandler(value) {
  173. this.closable = value;
  174. }
  175. closableHandler(value) {
  176. this.dismissible = value;
  177. }
  178. //--------------------------------------------------------------------------
  179. //
  180. // Lifecycle
  181. //
  182. //--------------------------------------------------------------------------
  183. componentDidRender() {
  184. interactive.updateHostInteraction(this);
  185. }
  186. // --------------------------------------------------------------------------
  187. //
  188. // Lifecycle
  189. //
  190. // --------------------------------------------------------------------------
  191. connectedCallback() {
  192. const isClosed = this.dismissed || this.closed;
  193. const isClosable = this.dismissible || this.closable;
  194. if (isClosed) {
  195. this.dismissedHandler(isClosed);
  196. this.closedHandler(isClosed);
  197. }
  198. if (isClosable) {
  199. this.dismissibleHandler(isClosable);
  200. this.closableHandler(isClosable);
  201. }
  202. }
  203. disconnectedCallback() {
  204. var _a;
  205. (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  206. }
  207. // --------------------------------------------------------------------------
  208. //
  209. // Methods
  210. //
  211. // --------------------------------------------------------------------------
  212. /**
  213. * Sets focus on the component.
  214. *
  215. * @param focusId
  216. */
  217. async setFocus(focusId) {
  218. const { backButtonEl, closeButtonEl, containerEl } = this;
  219. if (focusId === "back-button") {
  220. backButtonEl === null || backButtonEl === void 0 ? void 0 : backButtonEl.setFocus();
  221. return;
  222. }
  223. if (focusId === "dismiss-button") {
  224. closeButtonEl === null || closeButtonEl === void 0 ? void 0 : closeButtonEl.setFocus();
  225. return;
  226. }
  227. if (backButtonEl) {
  228. backButtonEl.setFocus();
  229. return;
  230. }
  231. if (closeButtonEl) {
  232. closeButtonEl.setFocus();
  233. return;
  234. }
  235. containerEl === null || containerEl === void 0 ? void 0 : containerEl.focus();
  236. }
  237. /**
  238. * Scrolls the component's content to a specified set of coordinates.
  239. *
  240. * @example
  241. * myCalciteFlowItem.scrollContentTo({
  242. * left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.
  243. * top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element
  244. * behavior: "auto" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).
  245. * });
  246. * @param options
  247. */
  248. async scrollContentTo(options) {
  249. var _a;
  250. (_a = this.panelScrollEl) === null || _a === void 0 ? void 0 : _a.scrollTo(options);
  251. }
  252. // --------------------------------------------------------------------------
  253. //
  254. // Render Methods
  255. //
  256. // --------------------------------------------------------------------------
  257. renderBackButton() {
  258. const { el } = this;
  259. const rtl = dom.getElementDir(el) === "rtl";
  260. const { showBackButton, intlBack, backButtonClick } = this;
  261. const label = intlBack || resources.TEXT.back;
  262. const icon = rtl ? resources.ICONS.backRight : resources.ICONS.backLeft;
  263. return showBackButton ? (index.h("calcite-action", { "aria-label": label, class: resources.CSS.backButton, icon: icon, key: "back-button", onClick: backButtonClick, ref: this.setBackRef, scale: "s", slot: resources.SLOTS.headerActionsStart, text: label })) : null;
  264. }
  265. renderHeaderContent() {
  266. const { heading, headingLevel, summary, description, hasHeaderContent } = this;
  267. const headingNode = heading ? (index.h(Heading.Heading, { class: resources.CSS.heading, level: headingLevel || resources.HEADING_LEVEL }, heading)) : null;
  268. const descriptionNode = description || summary ? index.h("span", { class: resources.CSS.description }, description || summary) : null;
  269. return !hasHeaderContent && (headingNode || descriptionNode) ? (index.h("div", { class: resources.CSS.headerContent, key: "header-content" }, headingNode, descriptionNode)) : null;
  270. }
  271. /**
  272. * Allows user to override the entire header-content node.
  273. */
  274. renderHeaderSlottedContent() {
  275. return (index.h("div", { class: resources.CSS.headerContent, hidden: !this.hasHeaderContent, key: "slotted-header-content" }, index.h("slot", { name: resources.SLOTS.headerContent, onSlotchange: this.handleHeaderContentSlotChange })));
  276. }
  277. renderHeaderStartActions() {
  278. const { hasStartActions } = this;
  279. return (index.h("div", { class: { [resources.CSS.headerActionsStart]: true, [resources.CSS.headerActions]: true }, hidden: !hasStartActions, key: "header-actions-start" }, index.h("slot", { name: resources.SLOTS.headerActionsStart, onSlotchange: this.handleHeaderActionsStartSlotChange })));
  280. }
  281. renderHeaderActionsEnd() {
  282. const { close, hasEndActions, intlClose, closable } = this;
  283. const text = intlClose || resources.TEXT.close;
  284. const closableNode = closable ? (index.h("calcite-action", { "aria-label": text, icon: resources.ICONS.close, onClick: close, ref: this.setCloseRef, text: text })) : null;
  285. const slotNode = (index.h("slot", { name: resources.SLOTS.headerActionsEnd, onSlotchange: this.handleHeaderActionsEndSlotChange }));
  286. const showContainer = hasEndActions || closableNode;
  287. return (index.h("div", { class: { [resources.CSS.headerActionsEnd]: true, [resources.CSS.headerActions]: true }, hidden: !showContainer, key: "header-actions-end" }, slotNode, closableNode));
  288. }
  289. renderMenu() {
  290. const { hasMenuItems, intlOptions, menuOpen } = this;
  291. return (index.h("calcite-action-menu", { flipPlacements: ["top", "bottom"], hidden: !hasMenuItems, key: "menu", label: intlOptions || resources.TEXT.options, open: menuOpen, placement: "bottom-end" }, index.h("calcite-action", { icon: resources.ICONS.menu, slot: resources$1.SLOTS.trigger, text: intlOptions || resources.TEXT.options }), index.h("slot", { name: resources.SLOTS.headerMenuActions, onSlotchange: this.handleHeaderMenuActionsSlotChange })));
  292. }
  293. renderHeaderNode() {
  294. const { showBackButton, hasHeaderContent, hasStartActions, hasEndActions, closable, hasMenuItems } = this;
  295. const headerContentNode = this.renderHeaderContent();
  296. const showHeader = showBackButton ||
  297. hasHeaderContent ||
  298. headerContentNode ||
  299. hasStartActions ||
  300. hasEndActions ||
  301. closable ||
  302. hasMenuItems;
  303. return (index.h("header", { class: resources.CSS.header, hidden: !showHeader }, this.renderBackButton(), this.renderHeaderStartActions(), this.renderHeaderSlottedContent(), headerContentNode, this.renderHeaderActionsEnd(), this.renderMenu()));
  304. }
  305. renderFooterNode() {
  306. const { hasFooterContent, hasFooterActions } = this;
  307. const showFooter = hasFooterContent || hasFooterActions;
  308. return (index.h("footer", { class: resources.CSS.footer, hidden: !showFooter }, index.h("slot", { key: "footer-slot", name: resources.SLOTS.footer, onSlotchange: this.handleFooterSlotChange }), index.h("slot", { key: "footer-actions-slot", name: resources.SLOTS.footerActions, onSlotchange: this.handleFooterActionsSlotChange })));
  309. }
  310. renderContent() {
  311. const { hasFab } = this;
  312. const defaultSlotNode = index.h("slot", { key: "default-slot" });
  313. const containerNode = hasFab ? (index.h("section", { class: resources.CSS.contentContainer }, defaultSlotNode)) : (defaultSlotNode);
  314. return (index.h("div", { class: {
  315. [resources.CSS.contentWrapper]: true,
  316. [resources.CSS.contentContainer]: !hasFab,
  317. [resources.CSS.contentHeight]: hasFab
  318. }, onScroll: this.panelScrollHandler, ref: this.setPanelScrollEl }, containerNode, this.renderFab()));
  319. }
  320. renderFab() {
  321. return (index.h("div", { class: resources.CSS.fabContainer, hidden: !this.hasFab }, index.h("slot", { name: resources.SLOTS.fab, onSlotchange: this.handleFabSlotChange })));
  322. }
  323. render() {
  324. const { loading, panelKeyDownHandler, closed, closable } = this;
  325. const panelNode = (index.h("article", { "aria-busy": dom.toAriaBoolean(loading), class: resources.CSS.container, hidden: closed, onKeyDown: panelKeyDownHandler, ref: this.setContainerRef, tabIndex: closable ? 0 : -1 }, this.renderHeaderNode(), this.renderContent(), this.renderFooterNode()));
  326. return (index.h(index.Fragment, null, loading ? index.h("calcite-scrim", { loading: loading }) : null, panelNode));
  327. }
  328. get el() { return index.getElement(this); }
  329. static get watchers() { return {
  330. "dismissed": ["dismissedHandler"],
  331. "closed": ["closedHandler"],
  332. "dismissible": ["dismissibleHandler"],
  333. "closable": ["closableHandler"]
  334. }; }
  335. };
  336. Panel.style = panelCss;
  337. exports.calcite_panel = Panel;