calcite-block_2.entry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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, H as Host, g as getElement } from './index-1f9b54dc.js';
  7. import { g as getSlotted, t as toAriaBoolean, a as getElementDir } from './dom-8f0a9ff2.js';
  8. import { H as Heading } from './Heading-e0abf8a2.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot-a3e8c63a.js';
  10. import { u as updateHostInteraction } from './interactive-5db230e8.js';
  11. import { g as guid } from './guid-9f15e57a.js';
  12. import { i as isActivationKey } from './key-acc755b7.js';
  13. import './resources-9c476cb6.js';
  14. import './observers-9f44e9b3.js';
  15. const CSS$1 = {
  16. container: "container",
  17. content: "content",
  18. contentSpaced: "content--spaced",
  19. headerContainer: "header-container",
  20. icon: "icon",
  21. statusIcon: "status-icon",
  22. toggle: "toggle",
  23. toggleIcon: "toggle-icon",
  24. title: "title",
  25. heading: "heading",
  26. header: "header",
  27. button: "button",
  28. summary: "summary",
  29. description: "description",
  30. controlContainer: "control-container",
  31. valid: "valid",
  32. invalid: "invalid",
  33. loading: "loading"
  34. };
  35. const TEXT$1 = {
  36. collapse: "Collapse",
  37. expand: "Expand",
  38. loading: "Loading",
  39. options: "Options"
  40. };
  41. const SLOTS = {
  42. icon: "icon",
  43. control: "control",
  44. headerMenuActions: "header-menu-actions"
  45. };
  46. const ICONS$1 = {
  47. opened: "chevron-up",
  48. closed: "chevron-down",
  49. valid: "check-circle",
  50. invalid: "exclamation-mark-triangle",
  51. refresh: "refresh"
  52. };
  53. const HEADING_LEVEL = 4;
  54. const blockCss = "@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}: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-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{display:flex;flex-shrink:0;flex-grow:0;flex-direction:column;border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding:0px;transition-property:margin;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-duration:150ms;transition-timing-function:cubic-bezier(0.215, 0.440, 0.420, 0.880);flex-basis:auto}: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}.header{justify-content:flex-start;padding:0px}.header,.toggle{grid-area:header}.header-container{display:grid;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:flex;cursor:pointer;flex-wrap:nowrap;align-items:center;justify-content:space-between;border-style:none;padding:0px;font-family:inherit;outline-color:transparent;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);transition-property:color;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);word-wrap:break-word;word-break:break-word}.description{margin-block-start: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{margin-inline-start:0.75rem;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{animation:spin var(--calcite-internal-animation-timing-medium) linear infinite}@keyframes spin{0%{transform:rotate(0deg)}50%{transform:rotate(180deg)}100%{transform:rotate(360deg)}}.toggle-icon{margin-block:0.75rem;align-self:center;justify-self:end;color:var(--calcite-ui-text-3);transition-property:color;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);margin-inline-end:1rem;margin-inline-start:auto}.toggle:hover .toggle-icon{color:var(--calcite-ui-text-1)}.container{display:flex;block-size:100%;flex-direction:column}.content{position:relative;flex:1 1 0%}@keyframes in{0%{opacity:0}100%{opacity:1}}.content{animation:in var(--calcite-internal-animation-timing-slow) ease-in-out}.content--spaced{padding-block:var(--calcite-block-padding, 0.5rem);padding-inline:var(--calcite-block-padding, 0.625rem)}.control-container{margin:0px;display:flex;grid-area:control}calcite-action-menu{grid-area:menu}:host([open]){margin-block:0.5rem}:host([open]) .header .title .heading{color:var(--calcite-ui-text-1)}";
  55. const Block = class {
  56. constructor(hostRef) {
  57. registerInstance(this, hostRef);
  58. this.calciteBlockToggle = createEvent(this, "calciteBlockToggle", 6);
  59. // --------------------------------------------------------------------------
  60. //
  61. // Properties
  62. //
  63. // --------------------------------------------------------------------------
  64. /**
  65. * When `true`, the component is collapsible.
  66. */
  67. this.collapsible = false;
  68. /**
  69. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  70. */
  71. this.disabled = false;
  72. /**
  73. * When `true`, displays a drag handle in the header.
  74. */
  75. this.dragHandle = false;
  76. /**
  77. * Accessible name for the component's collapse button.
  78. *
  79. * @default "Collapse"
  80. */
  81. this.intlCollapse = TEXT$1.collapse;
  82. /**
  83. * Accessible name for the component's expand button.
  84. *
  85. * @default "Expand"
  86. */
  87. this.intlExpand = TEXT$1.expand;
  88. /**
  89. * Accessible name when the component is loading.
  90. *
  91. * @default "Loading"
  92. */
  93. this.intlLoading = TEXT$1.loading;
  94. /**
  95. * Accessible name for the component's options button.
  96. *
  97. * @default "Options"
  98. */
  99. this.intlOptions = TEXT$1.options;
  100. /**
  101. * When `true`, a busy indicator is displayed.
  102. */
  103. this.loading = false;
  104. /**
  105. * When `true`, expands the component and its contents.
  106. */
  107. this.open = false;
  108. /**
  109. * When `true`, removes padding for the slotted content.
  110. *
  111. * @deprecated Use `--calcite-block-padding` CSS variable instead.
  112. */
  113. this.disablePadding = false;
  114. this.guid = guid();
  115. // --------------------------------------------------------------------------
  116. //
  117. // Private Methods
  118. //
  119. // --------------------------------------------------------------------------
  120. this.onHeaderClick = () => {
  121. this.open = !this.open;
  122. this.calciteBlockToggle.emit();
  123. };
  124. }
  125. //--------------------------------------------------------------------------
  126. //
  127. // Lifecycle
  128. //
  129. //--------------------------------------------------------------------------
  130. componentDidRender() {
  131. updateHostInteraction(this);
  132. }
  133. // --------------------------------------------------------------------------
  134. //
  135. // Lifecycle
  136. //
  137. // --------------------------------------------------------------------------
  138. connectedCallback() {
  139. connectConditionalSlotComponent(this);
  140. }
  141. disconnectedCallback() {
  142. disconnectConditionalSlotComponent(this);
  143. }
  144. // --------------------------------------------------------------------------
  145. //
  146. // Render Methods
  147. //
  148. // --------------------------------------------------------------------------
  149. renderScrim() {
  150. const { loading } = this;
  151. const defaultSlot = h("slot", null);
  152. return [loading ? h("calcite-scrim", { loading: loading }) : null, defaultSlot];
  153. }
  154. renderIcon() {
  155. const { el, status } = this;
  156. const showingLoadingStatus = this.loading && !this.open;
  157. const statusIcon = showingLoadingStatus ? ICONS$1.refresh : ICONS$1[status];
  158. const hasIcon = getSlotted(el, SLOTS.icon) || statusIcon;
  159. const iconEl = !statusIcon ? (h("slot", { key: "icon-slot", name: SLOTS.icon })) : (h("calcite-icon", { class: {
  160. [CSS$1.statusIcon]: true,
  161. [CSS$1.valid]: status == "valid",
  162. [CSS$1.invalid]: status == "invalid",
  163. [CSS$1.loading]: showingLoadingStatus
  164. }, icon: statusIcon, scale: "m" }));
  165. return hasIcon ? h("div", { class: CSS$1.icon }, iconEl) : null;
  166. }
  167. renderTitle() {
  168. const { heading, headingLevel, summary, description } = this;
  169. return heading || summary || description ? (h("div", { class: CSS$1.title }, h(Heading, { class: CSS$1.heading, level: headingLevel || HEADING_LEVEL }, heading), summary || description ? (h("div", { class: CSS$1.description }, summary || description)) : null)) : null;
  170. }
  171. render() {
  172. const { collapsible, el, intlCollapse, intlExpand, loading, open, intlLoading } = this;
  173. const toggleLabel = open ? intlCollapse || TEXT$1.collapse : intlExpand || TEXT$1.expand;
  174. const headerContent = (h("header", { class: CSS$1.header }, this.renderIcon(), this.renderTitle()));
  175. const hasControl = !!getSlotted(el, SLOTS.control);
  176. const hasMenuActions = !!getSlotted(el, SLOTS.headerMenuActions);
  177. const collapseIcon = open ? ICONS$1.opened : ICONS$1.closed;
  178. const { guid } = this;
  179. const regionId = `${guid}-region`;
  180. const buttonId = `${guid}-button`;
  181. const headerNode = (h("div", { class: CSS$1.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$1.toggle, id: buttonId, onClick: this.onHeaderClick, title: toggleLabel }, headerContent, !hasControl && !hasMenuActions ? (h("calcite-icon", { "aria-hidden": "true", class: CSS$1.toggleIcon, icon: collapseIcon, scale: "s" })) : null)) : (headerContent), loading ? (h("calcite-loader", { inline: true, "is-active": true, label: intlLoading })) : hasControl ? (h("div", { class: CSS$1.controlContainer }, h("slot", { name: SLOTS.control }))) : null, hasMenuActions ? (h("calcite-action-menu", { label: this.intlOptions || TEXT$1.options }, h("slot", { name: SLOTS.headerMenuActions }))) : null));
  182. return (h(Host, null, h("article", { "aria-busy": toAriaBoolean(loading), class: {
  183. [CSS$1.container]: true
  184. } }, headerNode, h("section", { "aria-expanded": toAriaBoolean(open), "aria-labelledby": buttonId, class: {
  185. [CSS$1.content]: true,
  186. [CSS$1.contentSpaced]: !this.disablePadding
  187. }, hidden: !open, id: regionId }, this.renderScrim()))));
  188. }
  189. get el() { return getElement(this); }
  190. };
  191. Block.style = blockCss;
  192. const CSS = {
  193. content: "content",
  194. invalid: "invalid",
  195. toggle: "toggle",
  196. toggleSwitch: "toggle--switch",
  197. toggleSwitchContent: "toggle--switch__content",
  198. toggleSwitchText: "toggle--switch__text",
  199. sectionHeader: "section-header",
  200. sectionHeaderText: "section-header__text",
  201. statusIcon: "status-icon",
  202. valid: "valid"
  203. };
  204. const TEXT = {
  205. collapse: "Collapse",
  206. expand: "Expand"
  207. };
  208. const ICONS = {
  209. menuOpen: "chevron-down",
  210. menuClosedLeft: "chevron-left",
  211. menuClosedRight: "chevron-right",
  212. valid: "check-circle",
  213. invalid: "exclamation-mark-triangle"
  214. };
  215. const blockSectionCss = "@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}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{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-block-end-width:1px;border-style:solid;border-block-end-color:var(--calcite-ui-border-3)}:host(:last-child){border-block-end-width:0px}.toggle{inline-size: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-inline:0px;margin-block:0.25rem;display:flex;cursor:pointer;-webkit-user-select:none;user-select:none;align-items:center;padding-inline:0px;padding-block:0.5rem;font-size:var(--calcite-font-size--1);outline-color:transparent}.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{align-self:flex-end}.section-header__text{margin-inline:0.75rem;margin-block:0px;flex:1 1 auto;text-align:initial;word-wrap:anywhere}.toggle--switch calcite-switch{pointer-events:none;margin-inline-start:0.25rem}.toggle--switch .status-icon{margin-inline-start:0.5rem}.toggle--switch__content{display:flex;flex:1 1 auto;align-items:center}.status-icon.valid{color:var(--calcite-ui-success)}.status-icon.invalid{color:var(--calcite-ui-danger)}";
  216. const BlockSection = class {
  217. constructor(hostRef) {
  218. registerInstance(this, hostRef);
  219. this.calciteBlockSectionToggle = createEvent(this, "calciteBlockSectionToggle", 6);
  220. /**
  221. * When `true`, expands the component and its contents.
  222. */
  223. this.open = false;
  224. /**
  225. * Specifies the component's toggle display -
  226. *
  227. * `"button"` (selectable header), or
  228. *
  229. * `"switch"` (toggle switch).
  230. */
  231. this.toggleDisplay = "button";
  232. this.guid = guid();
  233. // --------------------------------------------------------------------------
  234. //
  235. // Private Methods
  236. //
  237. // --------------------------------------------------------------------------
  238. this.handleHeaderKeyDown = (event) => {
  239. if (isActivationKey(event.key)) {
  240. this.toggleSection();
  241. event.preventDefault();
  242. event.stopPropagation();
  243. }
  244. };
  245. this.toggleSection = () => {
  246. this.open = !this.open;
  247. this.calciteBlockSectionToggle.emit();
  248. };
  249. }
  250. // --------------------------------------------------------------------------
  251. //
  252. // Render Methods
  253. //
  254. // --------------------------------------------------------------------------
  255. renderStatusIcon() {
  256. var _a;
  257. const { status } = this;
  258. const statusIcon = (_a = ICONS[status]) !== null && _a !== void 0 ? _a : false;
  259. const statusIconClasses = {
  260. [CSS.statusIcon]: true,
  261. [CSS.valid]: status == "valid",
  262. [CSS.invalid]: status == "invalid"
  263. };
  264. return !!statusIcon ? (h("calcite-icon", { class: statusIconClasses, icon: statusIcon, scale: "s" })) : null;
  265. }
  266. render() {
  267. const { el, intlCollapse, intlExpand, open, text, toggleDisplay } = this;
  268. const dir = getElementDir(el);
  269. const arrowIcon = open
  270. ? ICONS.menuOpen
  271. : dir === "rtl"
  272. ? ICONS.menuClosedLeft
  273. : ICONS.menuClosedRight;
  274. const toggleLabel = open ? intlCollapse || TEXT.collapse : intlExpand || TEXT.expand;
  275. const { guid } = this;
  276. const regionId = `${guid}-region`;
  277. const buttonId = `${guid}-button`;
  278. const headerNode = toggleDisplay === "switch" ? (h("div", { "aria-controls": regionId, "aria-label": toggleLabel, class: {
  279. [CSS.toggle]: true,
  280. [CSS.toggleSwitch]: true
  281. }, id: buttonId, onClick: this.toggleSection, onKeyDown: this.handleHeaderKeyDown, tabIndex: 0, title: toggleLabel }, h("div", { class: CSS.toggleSwitchContent }, h("span", { class: CSS.toggleSwitchText }, text)), h("calcite-switch", { checked: open, label: toggleLabel, scale: "s", tabIndex: -1 }), this.renderStatusIcon())) : (h("button", { "aria-controls": regionId, "aria-label": toggleLabel, class: {
  282. [CSS.sectionHeader]: true,
  283. [CSS.toggle]: true
  284. }, id: buttonId, name: toggleLabel, onClick: this.toggleSection }, h("calcite-icon", { icon: arrowIcon, scale: "s" }), h("span", { class: CSS.sectionHeaderText }, text), this.renderStatusIcon()));
  285. return (h(Host, null, headerNode, h("section", { "aria-expanded": toAriaBoolean(open), "aria-labelledby": buttonId, class: CSS.content, hidden: !open, id: regionId }, h("slot", null))));
  286. }
  287. get el() { return getElement(this); }
  288. };
  289. BlockSection.style = blockSectionCss;
  290. export { Block as calcite_block, BlockSection as calcite_block_section };