calcite-block_2.cjs.entry.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-5c65e149.js');
  9. const dom = require('./dom-9ac0341c.js');
  10. const Heading = require('./Heading-0cb5902d.js');
  11. const conditionalSlot = require('./conditionalSlot-ba5cd797.js');
  12. const interactive = require('./interactive-e294111f.js');
  13. const guid = require('./guid-8b6d6cb4.js');
  14. require('./observers-d9fdf006.js');
  15. const CSS$1 = {
  16. article: "article",
  17. content: "content",
  18. headerContainer: "header-container",
  19. icon: "icon",
  20. statusIcon: "status-icon",
  21. toggle: "toggle",
  22. toggleIcon: "toggle-icon",
  23. title: "title",
  24. heading: "heading",
  25. header: "header",
  26. button: "button",
  27. summary: "summary",
  28. controlContainer: "control-container",
  29. valid: "valid",
  30. invalid: "invalid",
  31. loading: "loading"
  32. };
  33. const TEXT$1 = {
  34. collapse: "Collapse",
  35. expand: "Expand",
  36. loading: "Loading",
  37. options: "Options"
  38. };
  39. const SLOTS = {
  40. icon: "icon",
  41. control: "control",
  42. headerMenuActions: "header-menu-actions"
  43. };
  44. const ICONS$1 = {
  45. opened: "chevron-up",
  46. closed: "chevron-down",
  47. valid: "check-circle",
  48. invalid: "exclamation-mark-triangle",
  49. refresh: "refresh"
  50. };
  51. const HEADING_LEVEL = 4;
  52. 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)}";
  53. const Block = class {
  54. constructor(hostRef) {
  55. index.registerInstance(this, hostRef);
  56. this.calciteBlockToggle = index.createEvent(this, "calciteBlockToggle", 7);
  57. // --------------------------------------------------------------------------
  58. //
  59. // Properties
  60. //
  61. // --------------------------------------------------------------------------
  62. /**
  63. * When true, this block will be collapsible.
  64. */
  65. this.collapsible = false;
  66. /**
  67. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  68. */
  69. this.disabled = false;
  70. /**
  71. * When true, displays a drag handle in the header.
  72. */
  73. this.dragHandle = false;
  74. /**
  75. * Aria-label for collapsing the toggle and tooltip used for the toggle when expanded.
  76. */
  77. this.intlCollapse = TEXT$1.collapse;
  78. /**
  79. * Aria-label for expanding the toggle and tooltip used for the toggle when collapsed.
  80. */
  81. this.intlExpand = TEXT$1.expand;
  82. /** string to override English loading text
  83. * @default "Loading"
  84. */
  85. this.intlLoading = TEXT$1.loading;
  86. /** Text string used for the actions menu
  87. * @default "Options"
  88. */
  89. this.intlOptions = TEXT$1.options;
  90. /**
  91. * When true, content is waiting to be loaded. This state shows a busy indicator.
  92. */
  93. this.loading = false;
  94. /**
  95. * When true, the block's content will be displayed.
  96. */
  97. this.open = false;
  98. this.guid = guid.guid();
  99. // --------------------------------------------------------------------------
  100. //
  101. // Private Methods
  102. //
  103. // --------------------------------------------------------------------------
  104. this.onHeaderClick = () => {
  105. this.open = !this.open;
  106. this.calciteBlockToggle.emit();
  107. };
  108. }
  109. //--------------------------------------------------------------------------
  110. //
  111. // Lifecycle
  112. //
  113. //--------------------------------------------------------------------------
  114. componentDidRender() {
  115. interactive.updateHostInteraction(this);
  116. }
  117. // --------------------------------------------------------------------------
  118. //
  119. // Lifecycle
  120. //
  121. // --------------------------------------------------------------------------
  122. connectedCallback() {
  123. conditionalSlot.connectConditionalSlotComponent(this);
  124. }
  125. disconnectedCallback() {
  126. conditionalSlot.disconnectConditionalSlotComponent(this);
  127. }
  128. // --------------------------------------------------------------------------
  129. //
  130. // Render Methods
  131. //
  132. // --------------------------------------------------------------------------
  133. renderScrim() {
  134. const { loading } = this;
  135. const defaultSlot = index.h("slot", null);
  136. return [loading ? index.h("calcite-scrim", { loading: loading }) : null, defaultSlot];
  137. }
  138. renderIcon() {
  139. const { el, status } = this;
  140. const showingLoadingStatus = this.loading && !this.open;
  141. const statusIcon = showingLoadingStatus ? ICONS$1.refresh : ICONS$1[status];
  142. const hasIcon = dom.getSlotted(el, SLOTS.icon) || statusIcon;
  143. const iconEl = !statusIcon ? (index.h("slot", { key: "icon-slot", name: SLOTS.icon })) : (index.h("calcite-icon", { class: {
  144. [CSS$1.statusIcon]: true,
  145. [CSS$1.valid]: status == "valid",
  146. [CSS$1.invalid]: status == "invalid",
  147. [CSS$1.loading]: showingLoadingStatus
  148. }, icon: statusIcon, scale: "m" }));
  149. return hasIcon ? index.h("div", { class: CSS$1.icon }, iconEl) : null;
  150. }
  151. renderTitle() {
  152. const { heading, headingLevel, summary } = this;
  153. return heading || summary ? (index.h("div", { class: CSS$1.title }, index.h(Heading.Heading, { class: CSS$1.heading, level: headingLevel || HEADING_LEVEL }, heading), summary ? index.h("div", { class: CSS$1.summary }, summary) : null)) : null;
  154. }
  155. render() {
  156. const { collapsible, el, intlCollapse, intlExpand, loading, open, intlLoading } = this;
  157. const toggleLabel = open ? intlCollapse || TEXT$1.collapse : intlExpand || TEXT$1.expand;
  158. const headerContent = (index.h("header", { class: CSS$1.header }, this.renderIcon(), this.renderTitle()));
  159. const hasControl = !!dom.getSlotted(el, SLOTS.control);
  160. const hasMenuActions = !!dom.getSlotted(el, SLOTS.headerMenuActions);
  161. const collapseIcon = open ? ICONS$1.opened : ICONS$1.closed;
  162. const { guid } = this;
  163. const regionId = `${guid}-region`;
  164. const buttonId = `${guid}-button`;
  165. const headerNode = (index.h("div", { class: CSS$1.headerContainer }, this.dragHandle ? index.h("calcite-handle", null) : null, collapsible ? (index.h("button", { "aria-controls": regionId, "aria-expanded": collapsible ? dom.toAriaBoolean(open) : null, "aria-label": toggleLabel, class: CSS$1.toggle, id: buttonId, onClick: this.onHeaderClick, title: toggleLabel }, headerContent, !hasControl && !hasMenuActions ? (index.h("calcite-icon", { "aria-hidden": "true", class: CSS$1.toggleIcon, icon: collapseIcon, scale: "s" })) : null)) : (headerContent), loading ? (index.h("calcite-loader", { inline: true, "is-active": true, label: intlLoading })) : hasControl ? (index.h("div", { class: CSS$1.controlContainer }, index.h("slot", { name: SLOTS.control }))) : null, hasMenuActions ? (index.h("calcite-action-menu", { label: this.intlOptions || TEXT$1.options }, index.h("slot", { name: SLOTS.headerMenuActions }))) : null));
  166. return (index.h(index.Host, null, index.h("article", { "aria-busy": dom.toAriaBoolean(loading), class: {
  167. [CSS$1.article]: true
  168. } }, headerNode, index.h("section", { "aria-expanded": dom.toAriaBoolean(open), "aria-labelledby": buttonId, class: CSS$1.content, hidden: !open, id: regionId }, this.renderScrim()))));
  169. }
  170. get el() { return index.getElement(this); }
  171. };
  172. Block.style = blockCss;
  173. const CSS = {
  174. content: "content",
  175. invalid: "invalid",
  176. toggle: "toggle",
  177. toggleSwitch: "toggle--switch",
  178. toggleSwitchContent: "toggle--switch__content",
  179. toggleSwitchText: "toggle--switch__text",
  180. sectionHeader: "section-header",
  181. sectionHeaderText: "section-header__text",
  182. statusIcon: "status-icon",
  183. valid: "valid"
  184. };
  185. const TEXT = {
  186. collapse: "Collapse",
  187. expand: "Expand"
  188. };
  189. const ICONS = {
  190. menuOpen: "chevron-down",
  191. menuClosedLeft: "chevron-left",
  192. menuClosedRight: "chevron-right",
  193. valid: "check-circle",
  194. invalid: "exclamation-mark-triangle"
  195. };
  196. const blockSectionCss = "@-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{-webkit-box-sizing:border-box;box-sizing:border-box;display:block;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}:host([open]){border-width:0px;border-bottom-width:1px;border-style:solid;border-bottom-color:var(--calcite-ui-border-3)}:host(:last-child){border-bottom-width:0px}.toggle{width:100%;border-width:0px;background-color:transparent;font-family:var(--calcite-sans-family);font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-2)}.toggle--switch,.section-header{margin-left:0px;margin-right:0px;margin-top:0.25rem;margin-bottom:0.25rem;display:-ms-flexbox;display:flex;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-ms-flex-align:center;align-items:center;padding-left:0px;padding-right:0px;padding-top:0.5rem;padding-bottom:0.5rem;font-size:var(--calcite-font-size--1);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}.toggle--switch:focus,.section-header:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.toggle--switch:hover,.section-header:hover{color:var(--calcite-ui-text-1)}.section-header .status-icon{-ms-flex-item-align:end;align-self:flex-end}.section-header__text{margin-left:0.75rem;margin-right:0.75rem;margin-top:0px;margin-bottom:0px;-ms-flex:1 1 auto;flex:1 1 auto;text-align:initial;word-wrap:anywhere}.toggle--switch calcite-switch{pointer-events:none;-webkit-margin-start:0.25rem;margin-inline-start:0.25rem}.toggle--switch .status-icon{-webkit-margin-start:0.5rem;margin-inline-start:0.5rem}.toggle--switch__content{display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-align:center;align-items:center}.status-icon.valid{color:var(--calcite-ui-success)}.status-icon.invalid{color:var(--calcite-ui-danger)}";
  197. const BlockSection = class {
  198. constructor(hostRef) {
  199. index.registerInstance(this, hostRef);
  200. this.calciteBlockSectionToggle = index.createEvent(this, "calciteBlockSectionToggle", 7);
  201. /**
  202. * When true, the block's section content will be displayed.
  203. */
  204. this.open = false;
  205. /**
  206. * This property determines the look of the section toggle.
  207. * If the value is "switch", a toggle-switch will be displayed.
  208. * If the value is "button", a clickable header is displayed.
  209. */
  210. this.toggleDisplay = "button";
  211. this.guid = guid.guid();
  212. // --------------------------------------------------------------------------
  213. //
  214. // Private Methods
  215. //
  216. // --------------------------------------------------------------------------
  217. this.handleHeaderKeyDown = (event) => {
  218. if (event.key === " " || event.key === "Enter") {
  219. this.toggleSection();
  220. event.preventDefault();
  221. event.stopPropagation();
  222. }
  223. };
  224. this.toggleSection = () => {
  225. this.open = !this.open;
  226. this.calciteBlockSectionToggle.emit();
  227. };
  228. }
  229. // --------------------------------------------------------------------------
  230. //
  231. // Render Methods
  232. //
  233. // --------------------------------------------------------------------------
  234. renderStatusIcon() {
  235. var _a;
  236. const { status } = this;
  237. const statusIcon = (_a = ICONS[status]) !== null && _a !== void 0 ? _a : false;
  238. const statusIconClasses = {
  239. [CSS.statusIcon]: true,
  240. [CSS.valid]: status == "valid",
  241. [CSS.invalid]: status == "invalid"
  242. };
  243. return !!statusIcon ? (index.h("calcite-icon", { class: statusIconClasses, icon: statusIcon, scale: "s" })) : null;
  244. }
  245. render() {
  246. const { el, intlCollapse, intlExpand, open, text, toggleDisplay } = this;
  247. const dir = dom.getElementDir(el);
  248. const arrowIcon = open
  249. ? ICONS.menuOpen
  250. : dir === "rtl"
  251. ? ICONS.menuClosedLeft
  252. : ICONS.menuClosedRight;
  253. const toggleLabel = open ? intlCollapse || TEXT.collapse : intlExpand || TEXT.expand;
  254. const { guid } = this;
  255. const regionId = `${guid}-region`;
  256. const buttonId = `${guid}-button`;
  257. const headerNode = toggleDisplay === "switch" ? (index.h("div", { "aria-controls": regionId, "aria-label": toggleLabel, class: {
  258. [CSS.toggle]: true,
  259. [CSS.toggleSwitch]: true
  260. }, id: buttonId, onClick: this.toggleSection, onKeyDown: this.handleHeaderKeyDown, tabIndex: 0, title: toggleLabel }, index.h("div", { class: CSS.toggleSwitchContent }, index.h("span", { class: CSS.toggleSwitchText }, text)), index.h("calcite-switch", { checked: open, label: toggleLabel, scale: "s", tabIndex: -1 }), this.renderStatusIcon())) : (index.h("button", { "aria-controls": regionId, "aria-label": toggleLabel, class: {
  261. [CSS.sectionHeader]: true,
  262. [CSS.toggle]: true
  263. }, id: buttonId, name: toggleLabel, onClick: this.toggleSection }, index.h("calcite-icon", { icon: arrowIcon, scale: "s" }), index.h("span", { class: CSS.sectionHeaderText }, text), this.renderStatusIcon()));
  264. return (index.h(index.Host, null, headerNode, index.h("section", { "aria-expanded": dom.toAriaBoolean(open), "aria-labelledby": buttonId, class: CSS.content, hidden: !open, id: regionId }, index.h("slot", null))));
  265. }
  266. get el() { return index.getElement(this); }
  267. };
  268. BlockSection.style = blockSectionCss;
  269. exports.calcite_block = Block;
  270. exports.calcite_block_section = BlockSection;