calcite-block_2.cjs.entry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const dom = require('./dom-2ec8c9ed.js');
  10. const Heading = require('./Heading-1e87a15f.js');
  11. const conditionalSlot = require('./conditionalSlot-ef852d9d.js');
  12. const interactive = require('./interactive-32293bca.js');
  13. const guid = require('./guid-f4f03a7a.js');
  14. const key = require('./key-6a462411.js');
  15. require('./resources-b5a5f8a7.js');
  16. require('./observers-5706326b.js');
  17. const CSS$1 = {
  18. container: "container",
  19. content: "content",
  20. contentSpaced: "content--spaced",
  21. headerContainer: "header-container",
  22. icon: "icon",
  23. statusIcon: "status-icon",
  24. toggle: "toggle",
  25. toggleIcon: "toggle-icon",
  26. title: "title",
  27. heading: "heading",
  28. header: "header",
  29. button: "button",
  30. summary: "summary",
  31. description: "description",
  32. controlContainer: "control-container",
  33. valid: "valid",
  34. invalid: "invalid",
  35. loading: "loading"
  36. };
  37. const TEXT$1 = {
  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$1 = {
  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 = "@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)}";
  57. const Block = class {
  58. constructor(hostRef) {
  59. index.registerInstance(this, hostRef);
  60. this.calciteBlockToggle = index.createEvent(this, "calciteBlockToggle", 6);
  61. // --------------------------------------------------------------------------
  62. //
  63. // Properties
  64. //
  65. // --------------------------------------------------------------------------
  66. /**
  67. * When `true`, the component is collapsible.
  68. */
  69. this.collapsible = false;
  70. /**
  71. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  72. */
  73. this.disabled = false;
  74. /**
  75. * When `true`, displays a drag handle in the header.
  76. */
  77. this.dragHandle = false;
  78. /**
  79. * Accessible name for the component's collapse button.
  80. *
  81. * @default "Collapse"
  82. */
  83. this.intlCollapse = TEXT$1.collapse;
  84. /**
  85. * Accessible name for the component's expand button.
  86. *
  87. * @default "Expand"
  88. */
  89. this.intlExpand = TEXT$1.expand;
  90. /**
  91. * Accessible name when the component is loading.
  92. *
  93. * @default "Loading"
  94. */
  95. this.intlLoading = TEXT$1.loading;
  96. /**
  97. * Accessible name for the component's options button.
  98. *
  99. * @default "Options"
  100. */
  101. this.intlOptions = TEXT$1.options;
  102. /**
  103. * When `true`, a busy indicator is displayed.
  104. */
  105. this.loading = false;
  106. /**
  107. * When `true`, expands the component and its contents.
  108. */
  109. this.open = false;
  110. /**
  111. * When `true`, removes padding for the slotted content.
  112. *
  113. * @deprecated Use `--calcite-block-padding` CSS variable instead.
  114. */
  115. this.disablePadding = false;
  116. this.guid = guid.guid();
  117. // --------------------------------------------------------------------------
  118. //
  119. // Private Methods
  120. //
  121. // --------------------------------------------------------------------------
  122. this.onHeaderClick = () => {
  123. this.open = !this.open;
  124. this.calciteBlockToggle.emit();
  125. };
  126. }
  127. //--------------------------------------------------------------------------
  128. //
  129. // Lifecycle
  130. //
  131. //--------------------------------------------------------------------------
  132. componentDidRender() {
  133. interactive.updateHostInteraction(this);
  134. }
  135. // --------------------------------------------------------------------------
  136. //
  137. // Lifecycle
  138. //
  139. // --------------------------------------------------------------------------
  140. connectedCallback() {
  141. conditionalSlot.connectConditionalSlotComponent(this);
  142. }
  143. disconnectedCallback() {
  144. conditionalSlot.disconnectConditionalSlotComponent(this);
  145. }
  146. // --------------------------------------------------------------------------
  147. //
  148. // Render Methods
  149. //
  150. // --------------------------------------------------------------------------
  151. renderScrim() {
  152. const { loading } = this;
  153. const defaultSlot = index.h("slot", null);
  154. return [loading ? index.h("calcite-scrim", { loading: loading }) : null, defaultSlot];
  155. }
  156. renderIcon() {
  157. const { el, status } = this;
  158. const showingLoadingStatus = this.loading && !this.open;
  159. const statusIcon = showingLoadingStatus ? ICONS$1.refresh : ICONS$1[status];
  160. const hasIcon = dom.getSlotted(el, SLOTS.icon) || statusIcon;
  161. const iconEl = !statusIcon ? (index.h("slot", { key: "icon-slot", name: SLOTS.icon })) : (index.h("calcite-icon", { class: {
  162. [CSS$1.statusIcon]: true,
  163. [CSS$1.valid]: status == "valid",
  164. [CSS$1.invalid]: status == "invalid",
  165. [CSS$1.loading]: showingLoadingStatus
  166. }, icon: statusIcon, scale: "m" }));
  167. return hasIcon ? index.h("div", { class: CSS$1.icon }, iconEl) : null;
  168. }
  169. renderTitle() {
  170. const { heading, headingLevel, summary, description } = this;
  171. return heading || summary || description ? (index.h("div", { class: CSS$1.title }, index.h(Heading.Heading, { class: CSS$1.heading, level: headingLevel || HEADING_LEVEL }, heading), summary || description ? (index.h("div", { class: CSS$1.description }, summary || description)) : null)) : null;
  172. }
  173. render() {
  174. const { collapsible, el, intlCollapse, intlExpand, loading, open, intlLoading } = this;
  175. const toggleLabel = open ? intlCollapse || TEXT$1.collapse : intlExpand || TEXT$1.expand;
  176. const headerContent = (index.h("header", { class: CSS$1.header }, this.renderIcon(), this.renderTitle()));
  177. const hasControl = !!dom.getSlotted(el, SLOTS.control);
  178. const hasMenuActions = !!dom.getSlotted(el, SLOTS.headerMenuActions);
  179. const collapseIcon = open ? ICONS$1.opened : ICONS$1.closed;
  180. const { guid } = this;
  181. const regionId = `${guid}-region`;
  182. const buttonId = `${guid}-button`;
  183. 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));
  184. return (index.h(index.Host, null, index.h("article", { "aria-busy": dom.toAriaBoolean(loading), class: {
  185. [CSS$1.container]: true
  186. } }, headerNode, index.h("section", { "aria-expanded": dom.toAriaBoolean(open), "aria-labelledby": buttonId, class: {
  187. [CSS$1.content]: true,
  188. [CSS$1.contentSpaced]: !this.disablePadding
  189. }, hidden: !open, id: regionId }, this.renderScrim()))));
  190. }
  191. get el() { return index.getElement(this); }
  192. };
  193. Block.style = blockCss;
  194. const CSS = {
  195. content: "content",
  196. invalid: "invalid",
  197. toggle: "toggle",
  198. toggleSwitch: "toggle--switch",
  199. toggleSwitchContent: "toggle--switch__content",
  200. toggleSwitchText: "toggle--switch__text",
  201. sectionHeader: "section-header",
  202. sectionHeaderText: "section-header__text",
  203. statusIcon: "status-icon",
  204. valid: "valid"
  205. };
  206. const TEXT = {
  207. collapse: "Collapse",
  208. expand: "Expand"
  209. };
  210. const ICONS = {
  211. menuOpen: "chevron-down",
  212. menuClosedLeft: "chevron-left",
  213. menuClosedRight: "chevron-right",
  214. valid: "check-circle",
  215. invalid: "exclamation-mark-triangle"
  216. };
  217. 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)}";
  218. const BlockSection = class {
  219. constructor(hostRef) {
  220. index.registerInstance(this, hostRef);
  221. this.calciteBlockSectionToggle = index.createEvent(this, "calciteBlockSectionToggle", 6);
  222. /**
  223. * When `true`, expands the component and its contents.
  224. */
  225. this.open = false;
  226. /**
  227. * Specifies the component's toggle display -
  228. *
  229. * `"button"` (selectable header), or
  230. *
  231. * `"switch"` (toggle switch).
  232. */
  233. this.toggleDisplay = "button";
  234. this.guid = guid.guid();
  235. // --------------------------------------------------------------------------
  236. //
  237. // Private Methods
  238. //
  239. // --------------------------------------------------------------------------
  240. this.handleHeaderKeyDown = (event) => {
  241. if (key.isActivationKey(event.key)) {
  242. this.toggleSection();
  243. event.preventDefault();
  244. event.stopPropagation();
  245. }
  246. };
  247. this.toggleSection = () => {
  248. this.open = !this.open;
  249. this.calciteBlockSectionToggle.emit();
  250. };
  251. }
  252. // --------------------------------------------------------------------------
  253. //
  254. // Render Methods
  255. //
  256. // --------------------------------------------------------------------------
  257. renderStatusIcon() {
  258. var _a;
  259. const { status } = this;
  260. const statusIcon = (_a = ICONS[status]) !== null && _a !== void 0 ? _a : false;
  261. const statusIconClasses = {
  262. [CSS.statusIcon]: true,
  263. [CSS.valid]: status == "valid",
  264. [CSS.invalid]: status == "invalid"
  265. };
  266. return !!statusIcon ? (index.h("calcite-icon", { class: statusIconClasses, icon: statusIcon, scale: "s" })) : null;
  267. }
  268. render() {
  269. const { el, intlCollapse, intlExpand, open, text, toggleDisplay } = this;
  270. const dir = dom.getElementDir(el);
  271. const arrowIcon = open
  272. ? ICONS.menuOpen
  273. : dir === "rtl"
  274. ? ICONS.menuClosedLeft
  275. : ICONS.menuClosedRight;
  276. const toggleLabel = open ? intlCollapse || TEXT.collapse : intlExpand || TEXT.expand;
  277. const { guid } = this;
  278. const regionId = `${guid}-region`;
  279. const buttonId = `${guid}-button`;
  280. const headerNode = toggleDisplay === "switch" ? (index.h("div", { "aria-controls": regionId, "aria-label": toggleLabel, class: {
  281. [CSS.toggle]: true,
  282. [CSS.toggleSwitch]: true
  283. }, 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: {
  284. [CSS.sectionHeader]: true,
  285. [CSS.toggle]: true
  286. }, id: buttonId, name: toggleLabel, onClick: this.toggleSection }, index.h("calcite-icon", { icon: arrowIcon, scale: "s" }), index.h("span", { class: CSS.sectionHeaderText }, text), this.renderStatusIcon()));
  287. 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))));
  288. }
  289. get el() { return index.getElement(this); }
  290. };
  291. BlockSection.style = blockSectionCss;
  292. exports.calcite_block = Block;
  293. exports.calcite_block_section = BlockSection;