UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

173 lines (167 loc) • 9.66 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client'; import { c as getElementDir, t as toAriaBoolean } from './dom.js'; import { g as guid } from './guid.js'; import { i as isActivationKey } from './key.js'; import { c as connectLocalized, d as disconnectLocalized } from './locale.js'; import { u as updateMessages, c as connectMessages, d as disconnectMessages, s as setUpMessages } from './t9n.js'; import { d as defineCustomElement$3 } from './icon.js'; import { d as defineCustomElement$2 } from './switch.js'; const CSS = { content: "content", invalid: "invalid", toggle: "toggle", toggleSwitch: "toggle--switch", toggleSwitchContent: "toggle--switch__content", toggleSwitchText: "toggle--switch__text", sectionHeader: "section-header", sectionHeaderText: "section-header__text", statusIcon: "status-icon", valid: "valid" }; const ICONS = { menuOpen: "chevron-down", menuClosedLeft: "chevron-left", menuClosedRight: "chevron-right", valid: "check-circle", invalid: "exclamation-mark-triangle" }; 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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}: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-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n 2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n )}.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)}"; const BlockSection = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteBlockSectionToggle = createEvent(this, "calciteBlockSectionToggle", 6); this.guid = guid(); // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.handleHeaderKeyDown = (event) => { if (isActivationKey(event.key)) { this.toggleSection(); event.preventDefault(); event.stopPropagation(); } }; this.toggleSection = () => { this.open = !this.open; this.calciteBlockSectionToggle.emit(); }; this.open = false; this.status = undefined; this.text = undefined; this.toggleDisplay = "button"; this.messages = undefined; this.messageOverrides = undefined; this.effectiveLocale = undefined; this.defaultMessages = undefined; } onMessagesChange() { /* wired up by t9n util */ } effectiveLocaleChange() { updateMessages(this, this.effectiveLocale); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { connectLocalized(this); connectMessages(this); } disconnectedCallback() { disconnectLocalized(this); disconnectMessages(this); } async componentWillLoad() { await setUpMessages(this); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderStatusIcon() { const { status } = this; const statusIcon = ICONS[status] ?? false; const statusIconClasses = { [CSS.statusIcon]: true, [CSS.valid]: status == "valid", [CSS.invalid]: status == "invalid" }; return !!statusIcon ? (h("calcite-icon", { class: statusIconClasses, icon: statusIcon, scale: "s" })) : null; } render() { const { el, messages, open, text, toggleDisplay } = this; const dir = getElementDir(el); const arrowIcon = open ? ICONS.menuOpen : dir === "rtl" ? ICONS.menuClosedLeft : ICONS.menuClosedRight; const toggleLabel = open ? messages.collapse : messages.expand; const { guid } = this; const regionId = `${guid}-region`; const buttonId = `${guid}-button`; const headerNode = toggleDisplay === "switch" ? (h("div", { "aria-controls": regionId, "aria-label": toggleLabel, class: { [CSS.toggle]: true, [CSS.toggleSwitch]: true }, 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: { [CSS.sectionHeader]: true, [CSS.toggle]: true }, id: buttonId, name: toggleLabel, onClick: this.toggleSection }, h("calcite-icon", { icon: arrowIcon, scale: "s" }), h("span", { class: CSS.sectionHeaderText }, text), this.renderStatusIcon())); return (h(Host, null, headerNode, h("section", { "aria-expanded": toAriaBoolean(open), "aria-labelledby": buttonId, class: CSS.content, hidden: !open, id: regionId }, h("slot", null)))); } static get assetsDirs() { return ["assets"]; } get el() { return this; } static get watchers() { return { "messageOverrides": ["onMessagesChange"], "effectiveLocale": ["effectiveLocaleChange"] }; } static get style() { return blockSectionCss; } }, [1, "calcite-block-section", { "open": [1540], "status": [513], "text": [1], "toggleDisplay": [513, "toggle-display"], "messages": [1040], "messageOverrides": [1040], "effectiveLocale": [32], "defaultMessages": [32] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["calcite-block-section", "calcite-icon", "calcite-switch"]; components.forEach(tagName => { switch (tagName) { case "calcite-block-section": if (!customElements.get(tagName)) { customElements.define(tagName, BlockSection); } break; case "calcite-icon": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "calcite-switch": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } defineCustomElement$1(); const CalciteBlockSection = BlockSection; const defineCustomElement = defineCustomElement$1; export { CalciteBlockSection, defineCustomElement };