calcite-panel.entry.js 19 KB

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