calcite-shell-panel.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 { proxyCustomElement, HTMLElement, createEvent, h, forceUpdate } from '@stencil/core/internal/client';
  7. import { a as getElementDir, b as getSlotted } from './dom.js';
  8. import { c as clamp } from './math.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  10. const CSS = {
  11. container: "container",
  12. content: "content",
  13. contentHeader: "content__header",
  14. contentBody: "content__body",
  15. contentDetached: "content--detached",
  16. separator: "separator"
  17. };
  18. const SLOTS = {
  19. actionBar: "action-bar",
  20. header: "header"
  21. };
  22. const TEXT = {
  23. resize: "Resize"
  24. };
  25. const shellPanelCss = "@-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}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{pointer-events:none;display:-ms-flexbox;display:flex;-ms-flex:0 1 auto;flex:0 1 auto;-ms-flex-align:stretch;align-items:stretch;--calcite-shell-panel-detached-max-height:unset}.container{pointer-events:none;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-align:stretch;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}.container *{-webkit-box-sizing:border-box;box-sizing:border-box}:host(:hover) .separator:not(:hover):not(:focus),:host(:focus-within) .separator:not(:hover):not(:focus){opacity:1;background-color:var(--calcite-ui-border-3)}.separator{pointer-events:auto;position:absolute;bottom:0px;top:0px;z-index:10;display:-ms-flexbox;display:flex;height:100%;width:0.125rem;background-color:transparent;opacity:0;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s;cursor:col-resize;outline:none}.separator:hover{opacity:1;background-color:var(--calcite-ui-border-2)}.separator:focus{background-color:var(--calcite-ui-brand);opacity:1}:host([position=start]) .separator{inset-inline-end:-2px}:host([position=end]) .separator{inset-inline-start:-2px}::slotted(calcite-panel),::slotted(calcite-flow){height:100%;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;max-height:unset;max-width:unset}::slotted(.calcite-match-height){display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;overflow:hidden}.content{pointer-events:auto;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-ms-flex-align:stretch;align-items:stretch;-ms-flex-item-align:stretch;align-self:stretch;background-color:var(--calcite-ui-background);padding:0px;width:var(--calcite-shell-panel-width);max-width:var(--calcite-shell-panel-max-width);min-width:var(--calcite-shell-panel-min-width);-webkit-transition:max-height var(--calcite-animation-timing), max-width var(--calcite-animation-timing);transition:max-height var(--calcite-animation-timing), max-width var(--calcite-animation-timing)}.content__header{display:-ms-flexbox;display:flex;-ms-flex:0 1 auto;flex:0 1 auto;-ms-flex-direction:column;flex-direction:column;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-ms-flex-align:stretch;align-items:stretch}.content__body{display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column;overflow:hidden}:host([width-scale=s]) .content{--calcite-shell-panel-width:calc(var(--calcite-panel-width-multiplier) * 12vw);--calcite-shell-panel-max-width:calc(var(--calcite-panel-width-multiplier) * 300px);--calcite-shell-panel-min-width:calc(var(--calcite-panel-width-multiplier) * 150px)}:host([width-scale=m]) .content{--calcite-shell-panel-width:calc(var(--calcite-panel-width-multiplier) * 20vw);--calcite-shell-panel-max-width:calc(var(--calcite-panel-width-multiplier) * 420px);--calcite-shell-panel-min-width:calc(var(--calcite-panel-width-multiplier) * 240px)}:host([width-scale=l]) .content{--calcite-shell-panel-width:calc(var(--calcite-panel-width-multiplier) * 45vw);--calcite-shell-panel-max-width:calc(var(--calcite-panel-width-multiplier) * 680px);--calcite-shell-panel-min-width:calc(var(--calcite-panel-width-multiplier) * 340px)}:host([detached-height-scale=s]) .content--detached{--calcite-shell-panel-detached-max-height:40vh}:host([detached-height-scale=m]) .content--detached{--calcite-shell-panel-detached-max-height:60vh}:host([detached-height-scale=l]) .content--detached{--calcite-shell-panel-detached-max-height:80vh}.content--detached{margin-left:0.5rem;margin-right:0.5rem;margin-top:0.5rem;margin-bottom:auto;height:auto;overflow:hidden;border-radius:0.25rem;--tw-shadow:0 4px 8px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);--tw-shadow-colored:0 4px 8px -1px var(--tw-shadow-color), 0 2px 4px -1px var(--tw-shadow-color);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);max-height:var(--calcite-shell-panel-detached-max-height)}.content--detached ::slotted(calcite-panel),.content--detached ::slotted(calcite-flow){max-height:unset}:host([position=start]) .content--detached ::slotted(calcite-panel),:host([position=start]) .content--detached ::slotted(calcite-flow),:host([position=end]) .content--detached ::slotted(calcite-panel),:host([position=end]) .content--detached ::slotted(calcite-flow){border-style:none}.content[hidden]{display:none}slot[name=action-bar]::slotted(calcite-action-bar),.content ::slotted(calcite-flow),.content ::slotted(calcite-panel:not([dismissed])){border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3)}:host([position=start]) slot[name=action-bar]::slotted(calcite-action-bar),:host([position=start]) .content ::slotted(calcite-flow),:host([position=start]) .content ::slotted(calcite-panel){-webkit-border-start:none;border-inline-start:none}:host([position=end]) slot[name=action-bar]::slotted(calcite-action-bar),:host([position=end]) .content ::slotted(calcite-flow),:host([position=end]) .content ::slotted(calcite-panel){-webkit-border-end:none;border-inline-end:none}";
  26. const ShellPanel = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  27. constructor() {
  28. super();
  29. this.__registerHost();
  30. this.__attachShadow();
  31. this.calciteShellPanelToggle = createEvent(this, "calciteShellPanelToggle", 7);
  32. // --------------------------------------------------------------------------
  33. //
  34. // Properties
  35. //
  36. // --------------------------------------------------------------------------
  37. /**
  38. * Hide the content panel.
  39. */
  40. this.collapsed = false;
  41. /**
  42. * This property makes the content area appear like a "floating" panel.
  43. */
  44. this.detached = false;
  45. /**
  46. * Specifies the maximum height of the contents when detached.
  47. */
  48. this.detachedHeightScale = "l";
  49. /**
  50. * This sets width of the content area.
  51. */
  52. this.widthScale = "m";
  53. /**
  54. * Accessible label for resize separator.
  55. * @default "Resize"
  56. */
  57. this.intlResize = TEXT.resize;
  58. /**
  59. * This property makes the content area resizable if the calcite-shell-panel is not 'detached'.
  60. */
  61. this.resizable = false;
  62. this.contentWidth = null;
  63. this.initialContentWidth = null;
  64. this.initialClientX = null;
  65. this.contentWidthMax = null;
  66. this.contentWidthMin = null;
  67. this.step = 1;
  68. this.stepMultiplier = 10;
  69. this.storeContentEl = (contentEl) => {
  70. this.contentEl = contentEl;
  71. };
  72. this.getKeyAdjustedWidth = (event) => {
  73. const { key } = event;
  74. const { el, step, stepMultiplier, contentWidthMin, contentWidthMax, initialContentWidth, position } = this;
  75. const multipliedStep = step * stepMultiplier;
  76. const MOVEMENT_KEYS = [
  77. "ArrowUp",
  78. "ArrowDown",
  79. "ArrowLeft",
  80. "ArrowRight",
  81. "Home",
  82. "End",
  83. "PageUp",
  84. "PageDown"
  85. ];
  86. if (MOVEMENT_KEYS.indexOf(key) > -1) {
  87. event.preventDefault();
  88. }
  89. const dir = getElementDir(el);
  90. const directionKeys = ["ArrowLeft", "ArrowRight"];
  91. const directionFactor = dir === "rtl" && directionKeys.includes(key) ? -1 : 1;
  92. const increaseKeys = key === "ArrowUp" ||
  93. (position === "end" ? key === directionKeys[0] : key === directionKeys[1]);
  94. if (increaseKeys) {
  95. const stepValue = event.shiftKey ? multipliedStep : step;
  96. return initialContentWidth + directionFactor * stepValue;
  97. }
  98. const decreaseKeys = key === "ArrowDown" ||
  99. (position === "end" ? key === directionKeys[1] : key === directionKeys[0]);
  100. if (decreaseKeys) {
  101. const stepValue = event.shiftKey ? multipliedStep : step;
  102. return initialContentWidth - directionFactor * stepValue;
  103. }
  104. if (typeof contentWidthMin === "number" && key === "Home") {
  105. return contentWidthMin;
  106. }
  107. if (typeof contentWidthMax === "number" && key === "End") {
  108. return contentWidthMax;
  109. }
  110. if (key === "PageDown") {
  111. return initialContentWidth - multipliedStep;
  112. }
  113. if (key === "PageUp") {
  114. return initialContentWidth + multipliedStep;
  115. }
  116. return null;
  117. };
  118. this.separatorKeyDown = (event) => {
  119. this.setInitialContentWidth();
  120. const width = this.getKeyAdjustedWidth(event);
  121. if (typeof width === "number") {
  122. this.setContentWidth(width);
  123. }
  124. };
  125. this.separatorPointerMove = (event) => {
  126. event.preventDefault();
  127. const { el, initialContentWidth, position, initialClientX } = this;
  128. const offset = event.clientX - initialClientX;
  129. const dir = getElementDir(el);
  130. const adjustmentDirection = dir === "rtl" ? -1 : 1;
  131. const adjustedOffset = position === "end" ? -adjustmentDirection * offset : adjustmentDirection * offset;
  132. const width = initialContentWidth + adjustedOffset;
  133. this.setContentWidth(width);
  134. };
  135. this.separatorPointerUp = (event) => {
  136. event.preventDefault();
  137. document.removeEventListener("pointerup", this.separatorPointerUp);
  138. document.removeEventListener("pointermove", this.separatorPointerMove);
  139. };
  140. this.setInitialContentWidth = () => {
  141. var _a;
  142. this.initialContentWidth = (_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width;
  143. };
  144. this.separatorPointerDown = (event) => {
  145. event.preventDefault();
  146. const { separatorEl } = this;
  147. separatorEl && document.activeElement !== separatorEl && separatorEl.focus();
  148. this.setInitialContentWidth();
  149. this.initialClientX = event.clientX;
  150. document.addEventListener("pointerup", this.separatorPointerUp);
  151. document.addEventListener("pointermove", this.separatorPointerMove);
  152. };
  153. this.connectSeparator = (separatorEl) => {
  154. this.disconnectSeparator();
  155. this.separatorEl = separatorEl;
  156. separatorEl.addEventListener("pointerdown", this.separatorPointerDown);
  157. };
  158. this.disconnectSeparator = () => {
  159. var _a;
  160. (_a = this.separatorEl) === null || _a === void 0 ? void 0 : _a.removeEventListener("pointerdown", this.separatorPointerDown);
  161. };
  162. }
  163. watchHandler() {
  164. this.calciteShellPanelToggle.emit();
  165. }
  166. //--------------------------------------------------------------------------
  167. //
  168. // Lifecycle
  169. //
  170. //--------------------------------------------------------------------------
  171. connectedCallback() {
  172. connectConditionalSlotComponent(this);
  173. }
  174. disconnectedCallback() {
  175. disconnectConditionalSlotComponent(this);
  176. this.disconnectSeparator();
  177. }
  178. componentDidLoad() {
  179. this.updateAriaValues();
  180. }
  181. // --------------------------------------------------------------------------
  182. //
  183. // Render Methods
  184. //
  185. // --------------------------------------------------------------------------
  186. renderHeader() {
  187. const { el } = this;
  188. const hasHeader = getSlotted(el, SLOTS.header);
  189. return hasHeader ? (h("div", { class: CSS.contentHeader, key: "header" }, h("slot", { name: SLOTS.header }))) : null;
  190. }
  191. render() {
  192. const { collapsed, detached, position, initialContentWidth, contentWidth, contentWidthMax, contentWidthMin, intlResize, resizable } = this;
  193. const allowResizing = !detached && resizable;
  194. const contentNode = (h("div", { class: { [CSS.content]: true, [CSS.contentDetached]: detached }, hidden: collapsed, key: "content", ref: this.storeContentEl, style: allowResizing && contentWidth ? { width: `${contentWidth}px` } : null }, this.renderHeader(), h("div", { class: CSS.contentBody }, h("slot", null))));
  195. const separatorNode = allowResizing ? (h("div", { "aria-label": intlResize, "aria-orientation": "horizontal", "aria-valuemax": contentWidthMax, "aria-valuemin": contentWidthMin, "aria-valuenow": contentWidth !== null && contentWidth !== void 0 ? contentWidth : initialContentWidth, class: CSS.separator, key: "separator", onKeyDown: this.separatorKeyDown, ref: this.connectSeparator, role: "separator", tabIndex: 0, "touch-action": "none" })) : null;
  196. const actionBarNode = h("slot", { key: "action-bar", name: SLOTS.actionBar });
  197. const mainNodes = [actionBarNode, contentNode, separatorNode];
  198. if (position === "end") {
  199. mainNodes.reverse();
  200. }
  201. return h("div", { class: { [CSS.container]: true } }, mainNodes);
  202. }
  203. // --------------------------------------------------------------------------
  204. //
  205. // private Methods
  206. //
  207. // --------------------------------------------------------------------------
  208. setContentWidth(width) {
  209. const { contentWidthMax, contentWidthMin } = this;
  210. const roundedWidth = Math.round(width);
  211. this.contentWidth =
  212. typeof contentWidthMax === "number" && typeof contentWidthMin === "number"
  213. ? clamp(roundedWidth, contentWidthMin, contentWidthMax)
  214. : roundedWidth;
  215. }
  216. updateAriaValues() {
  217. const { contentEl } = this;
  218. const computedStyle = contentEl && getComputedStyle(contentEl);
  219. if (!computedStyle) {
  220. return;
  221. }
  222. const max = parseInt(computedStyle.getPropertyValue("max-width"), 10);
  223. const min = parseInt(computedStyle.getPropertyValue("min-width"), 10);
  224. const valueNow = parseInt(computedStyle.getPropertyValue("width"), 10);
  225. if (typeof valueNow === "number" && !isNaN(valueNow)) {
  226. this.initialContentWidth = valueNow;
  227. }
  228. if (typeof max === "number" && !isNaN(max)) {
  229. this.contentWidthMax = max;
  230. }
  231. if (typeof min === "number" && !isNaN(min)) {
  232. this.contentWidthMin = min;
  233. }
  234. forceUpdate(this);
  235. }
  236. get el() { return this; }
  237. static get watchers() { return {
  238. "collapsed": ["watchHandler"]
  239. }; }
  240. static get style() { return shellPanelCss; }
  241. }, [1, "calcite-shell-panel", {
  242. "collapsed": [516],
  243. "detached": [516],
  244. "detachedHeightScale": [513, "detached-height-scale"],
  245. "widthScale": [513, "width-scale"],
  246. "position": [513],
  247. "intlResize": [1, "intl-resize"],
  248. "resizable": [516],
  249. "contentWidth": [32]
  250. }]);
  251. function defineCustomElement$1() {
  252. if (typeof customElements === "undefined") {
  253. return;
  254. }
  255. const components = ["calcite-shell-panel"];
  256. components.forEach(tagName => { switch (tagName) {
  257. case "calcite-shell-panel":
  258. if (!customElements.get(tagName)) {
  259. customElements.define(tagName, ShellPanel);
  260. }
  261. break;
  262. } });
  263. }
  264. defineCustomElement$1();
  265. const CalciteShellPanel = ShellPanel;
  266. const defineCustomElement = defineCustomElement$1;
  267. export { CalciteShellPanel, defineCustomElement };