calcite-block.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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, Host } from '@stencil/core/internal/client';
  7. import { b as getSlotted, t as toAriaBoolean } from './dom.js';
  8. import { H as Heading } from './Heading.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  10. import { u as updateHostInteraction } from './interactive.js';
  11. import { g as guid } from './guid.js';
  12. import { d as defineCustomElement$8 } from './action.js';
  13. import { d as defineCustomElement$7 } from './action-menu.js';
  14. import { d as defineCustomElement$6 } from './handle.js';
  15. import { d as defineCustomElement$5 } from './icon.js';
  16. import { d as defineCustomElement$4 } from './loader.js';
  17. import { d as defineCustomElement$3 } from './popover.js';
  18. import { d as defineCustomElement$2 } from './scrim.js';
  19. const CSS = {
  20. article: "article",
  21. content: "content",
  22. headerContainer: "header-container",
  23. icon: "icon",
  24. statusIcon: "status-icon",
  25. toggle: "toggle",
  26. toggleIcon: "toggle-icon",
  27. title: "title",
  28. heading: "heading",
  29. header: "header",
  30. button: "button",
  31. summary: "summary",
  32. controlContainer: "control-container",
  33. valid: "valid",
  34. invalid: "invalid",
  35. loading: "loading"
  36. };
  37. const TEXT = {
  38. collapse: "Collapse",
  39. expand: "Expand",
  40. loading: "Loading",
  41. options: "Options"
  42. };
  43. const SLOTS = {
  44. icon: "icon",
  45. control: "control",
  46. headerMenuActions: "header-menu-actions"
  47. };
  48. const ICONS = {
  49. opened: "chevron-up",
  50. closed: "chevron-down",
  51. valid: "check-circle",
  52. invalid: "exclamation-mark-triangle",
  53. refresh: "refresh"
  54. };
  55. const HEADING_LEVEL = 4;
  56. const blockCss = "@-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}:host{--calcite-icon-size:1rem;--calcite-spacing-eighth:0.125rem;--calcite-spacing-quarter:0.25rem;--calcite-spacing-half:0.5rem;--calcite-spacing-three-quarters:0.75rem;--calcite-spacing:1rem;--calcite-spacing-plus-quarter:1.25rem;--calcite-spacing-plus-half:1.5rem;--calcite-spacing-double:2rem;--calcite-menu-min-width:10rem;--calcite-header-min-height:3rem;--calcite-footer-min-height:3rem}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:-ms-flexbox;display:flex;-ms-flex-negative:0;flex-shrink:0;-ms-flex-positive:0;flex-grow:0;-ms-flex-direction:column;flex-direction:column;border-width:0px;border-bottom-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding:0px;-webkit-transition-property:margin;transition-property:margin;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.215, 0.440, 0.420, 0.880);transition-timing-function:cubic-bezier(0.215, 0.440, 0.420, 0.880);-ms-flex-preferred-size:auto;flex-basis:auto}: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}.header{-ms-flex-pack:start;justify-content:flex-start;padding:0px}.header,.toggle{grid-area:header}.header-container{display:grid;-ms-flex-align:stretch;align-items:stretch;grid-template:auto/auto 1fr auto auto;grid-template-areas:\"handle header control menu\";grid-column:header-start/menu-end;grid-row:1/2}.toggle{margin:0px;display:-ms-flexbox;display:flex;cursor:pointer;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;border-style:none;padding:0px;font-family:inherit;outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;text-align:initial;background-color:transparent}.toggle:hover{background-color:var(--calcite-ui-foreground-2)}.toggle:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}calcite-loader[inline]{grid-area:control;align-self:center}calcite-handle{grid-area:handle}.title{margin:0px;padding:0.75rem}.header .title .heading{padding:0px;font-size:var(--calcite-font-size--1);font-weight:var(--calcite-font-weight-medium);line-height:1.25;color:var(--calcite-ui-text-2);-webkit-transition-property:color;transition-property:color;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);word-wrap:break-word;word-break:break-word}.summary{margin-top:0.125rem;padding:0px;font-size:var(--calcite-font-size--2);color:var(--calcite-ui-text-3);word-wrap:break-word;word-break:break-word}.icon{-webkit-margin-start:0.75rem;margin-inline-start:0.75rem;-webkit-margin-end:0px;margin-inline-end:0px;margin-block:0.75rem}.status-icon.valid{color:var(--calcite-ui-success)}.status-icon.invalid{color:var(--calcite-ui-danger)}.status-icon.loading{-webkit-animation:spin 2s linear infinite;animation:spin 2s linear infinite}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}50%{-webkit-transform:rotate(180deg);transform:rotate(180deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}50%{-webkit-transform:rotate(180deg);transform:rotate(180deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}.toggle-icon{margin-top:0.75rem;margin-bottom:0.75rem;-ms-flex-item-align:center;align-self:center;justify-self:end;color:var(--calcite-ui-text-3);-webkit-transition-property:color;transition-property:color;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-margin-end:1rem;margin-inline-end:1rem;-webkit-margin-start:auto;margin-inline-start:auto}.toggle:hover .toggle-icon{color:var(--calcite-ui-text-1)}.content{position:relative}@keyframes in{0%{opacity:0}100%{opacity:1}}.content{-webkit-animation:in var(--calcite-internal-animation-timing-slow) ease-in-out;animation:in var(--calcite-internal-animation-timing-slow) ease-in-out;padding-left:0.75rem;padding-right:0.75rem;padding-top:0.5rem;padding-bottom:0.5rem}.control-container{margin:0px;display:-ms-flexbox;display:flex;grid-area:control}calcite-action-menu{grid-area:menu}:host([open]){margin-top:0.5rem;margin-bottom:0.5rem}:host([open]) .header .title .heading{color:var(--calcite-ui-text-1)}";
  57. const Block = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  58. constructor() {
  59. super();
  60. this.__registerHost();
  61. this.__attachShadow();
  62. this.calciteBlockToggle = createEvent(this, "calciteBlockToggle", 7);
  63. // --------------------------------------------------------------------------
  64. //
  65. // Properties
  66. //
  67. // --------------------------------------------------------------------------
  68. /**
  69. * When true, this block will be collapsible.
  70. */
  71. this.collapsible = false;
  72. /**
  73. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  74. */
  75. this.disabled = false;
  76. /**
  77. * When true, displays a drag handle in the header.
  78. */
  79. this.dragHandle = false;
  80. /**
  81. * Aria-label for collapsing the toggle and tooltip used for the toggle when expanded.
  82. */
  83. this.intlCollapse = TEXT.collapse;
  84. /**
  85. * Aria-label for expanding the toggle and tooltip used for the toggle when collapsed.
  86. */
  87. this.intlExpand = TEXT.expand;
  88. /** string to override English loading text
  89. * @default "Loading"
  90. */
  91. this.intlLoading = TEXT.loading;
  92. /** Text string used for the actions menu
  93. * @default "Options"
  94. */
  95. this.intlOptions = TEXT.options;
  96. /**
  97. * When true, content is waiting to be loaded. This state shows a busy indicator.
  98. */
  99. this.loading = false;
  100. /**
  101. * When true, the block's content will be displayed.
  102. */
  103. this.open = false;
  104. this.guid = guid();
  105. // --------------------------------------------------------------------------
  106. //
  107. // Private Methods
  108. //
  109. // --------------------------------------------------------------------------
  110. this.onHeaderClick = () => {
  111. this.open = !this.open;
  112. this.calciteBlockToggle.emit();
  113. };
  114. }
  115. //--------------------------------------------------------------------------
  116. //
  117. // Lifecycle
  118. //
  119. //--------------------------------------------------------------------------
  120. componentDidRender() {
  121. updateHostInteraction(this);
  122. }
  123. // --------------------------------------------------------------------------
  124. //
  125. // Lifecycle
  126. //
  127. // --------------------------------------------------------------------------
  128. connectedCallback() {
  129. connectConditionalSlotComponent(this);
  130. }
  131. disconnectedCallback() {
  132. disconnectConditionalSlotComponent(this);
  133. }
  134. // --------------------------------------------------------------------------
  135. //
  136. // Render Methods
  137. //
  138. // --------------------------------------------------------------------------
  139. renderScrim() {
  140. const { loading } = this;
  141. const defaultSlot = h("slot", null);
  142. return [loading ? h("calcite-scrim", { loading: loading }) : null, defaultSlot];
  143. }
  144. renderIcon() {
  145. const { el, status } = this;
  146. const showingLoadingStatus = this.loading && !this.open;
  147. const statusIcon = showingLoadingStatus ? ICONS.refresh : ICONS[status];
  148. const hasIcon = getSlotted(el, SLOTS.icon) || statusIcon;
  149. const iconEl = !statusIcon ? (h("slot", { key: "icon-slot", name: SLOTS.icon })) : (h("calcite-icon", { class: {
  150. [CSS.statusIcon]: true,
  151. [CSS.valid]: status == "valid",
  152. [CSS.invalid]: status == "invalid",
  153. [CSS.loading]: showingLoadingStatus
  154. }, icon: statusIcon, scale: "m" }));
  155. return hasIcon ? h("div", { class: CSS.icon }, iconEl) : null;
  156. }
  157. renderTitle() {
  158. const { heading, headingLevel, summary } = this;
  159. return heading || summary ? (h("div", { class: CSS.title }, h(Heading, { class: CSS.heading, level: headingLevel || HEADING_LEVEL }, heading), summary ? h("div", { class: CSS.summary }, summary) : null)) : null;
  160. }
  161. render() {
  162. const { collapsible, el, intlCollapse, intlExpand, loading, open, intlLoading } = this;
  163. const toggleLabel = open ? intlCollapse || TEXT.collapse : intlExpand || TEXT.expand;
  164. const headerContent = (h("header", { class: CSS.header }, this.renderIcon(), this.renderTitle()));
  165. const hasControl = !!getSlotted(el, SLOTS.control);
  166. const hasMenuActions = !!getSlotted(el, SLOTS.headerMenuActions);
  167. const collapseIcon = open ? ICONS.opened : ICONS.closed;
  168. const { guid } = this;
  169. const regionId = `${guid}-region`;
  170. const buttonId = `${guid}-button`;
  171. const headerNode = (h("div", { class: CSS.headerContainer }, this.dragHandle ? h("calcite-handle", null) : null, collapsible ? (h("button", { "aria-controls": regionId, "aria-expanded": collapsible ? toAriaBoolean(open) : null, "aria-label": toggleLabel, class: CSS.toggle, id: buttonId, onClick: this.onHeaderClick, title: toggleLabel }, headerContent, !hasControl && !hasMenuActions ? (h("calcite-icon", { "aria-hidden": "true", class: CSS.toggleIcon, icon: collapseIcon, scale: "s" })) : null)) : (headerContent), loading ? (h("calcite-loader", { inline: true, "is-active": true, label: intlLoading })) : hasControl ? (h("div", { class: CSS.controlContainer }, h("slot", { name: SLOTS.control }))) : null, hasMenuActions ? (h("calcite-action-menu", { label: this.intlOptions || TEXT.options }, h("slot", { name: SLOTS.headerMenuActions }))) : null));
  172. return (h(Host, null, h("article", { "aria-busy": toAriaBoolean(loading), class: {
  173. [CSS.article]: true
  174. } }, headerNode, h("section", { "aria-expanded": toAriaBoolean(open), "aria-labelledby": buttonId, class: CSS.content, hidden: !open, id: regionId }, this.renderScrim()))));
  175. }
  176. get el() { return this; }
  177. static get style() { return blockCss; }
  178. }, [1, "calcite-block", {
  179. "collapsible": [4],
  180. "disabled": [516],
  181. "dragHandle": [516, "drag-handle"],
  182. "heading": [1],
  183. "headingLevel": [2, "heading-level"],
  184. "intlCollapse": [1, "intl-collapse"],
  185. "intlExpand": [1, "intl-expand"],
  186. "intlLoading": [1, "intl-loading"],
  187. "intlOptions": [1, "intl-options"],
  188. "loading": [516],
  189. "open": [1540],
  190. "status": [513],
  191. "summary": [1]
  192. }]);
  193. function defineCustomElement$1() {
  194. if (typeof customElements === "undefined") {
  195. return;
  196. }
  197. const components = ["calcite-block", "calcite-action", "calcite-action-menu", "calcite-handle", "calcite-icon", "calcite-loader", "calcite-popover", "calcite-scrim"];
  198. components.forEach(tagName => { switch (tagName) {
  199. case "calcite-block":
  200. if (!customElements.get(tagName)) {
  201. customElements.define(tagName, Block);
  202. }
  203. break;
  204. case "calcite-action":
  205. if (!customElements.get(tagName)) {
  206. defineCustomElement$8();
  207. }
  208. break;
  209. case "calcite-action-menu":
  210. if (!customElements.get(tagName)) {
  211. defineCustomElement$7();
  212. }
  213. break;
  214. case "calcite-handle":
  215. if (!customElements.get(tagName)) {
  216. defineCustomElement$6();
  217. }
  218. break;
  219. case "calcite-icon":
  220. if (!customElements.get(tagName)) {
  221. defineCustomElement$5();
  222. }
  223. break;
  224. case "calcite-loader":
  225. if (!customElements.get(tagName)) {
  226. defineCustomElement$4();
  227. }
  228. break;
  229. case "calcite-popover":
  230. if (!customElements.get(tagName)) {
  231. defineCustomElement$3();
  232. }
  233. break;
  234. case "calcite-scrim":
  235. if (!customElements.get(tagName)) {
  236. defineCustomElement$2();
  237. }
  238. break;
  239. } });
  240. }
  241. defineCustomElement$1();
  242. const CalciteBlock = Block;
  243. const defineCustomElement = defineCustomElement$1;
  244. export { CalciteBlock, defineCustomElement };