@synergy-design-system/components
Version:
This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define
251 lines (246 loc) • 7.11 kB
JavaScript
import {
details_custom_styles_default
} from "./chunk.2DGMS4FV.js";
import {
details_styles_default
} from "./chunk.VA26EAEP.js";
import {
waitForEvent
} from "./chunk.C2ENQBPM.js";
import {
animateTo,
shimKeyframesHeightAuto,
stopAnimations
} from "./chunk.G6ITZTTW.js";
import {
getAnimation,
setDefaultAnimation
} from "./chunk.7JGKUB4A.js";
import {
SynIcon
} from "./chunk.RCBSMXQH.js";
import {
LocalizeController
} from "./chunk.OAQRCZOO.js";
import {
enableDefaultSettings
} from "./chunk.HYFCK7MM.js";
import {
watch
} from "./chunk.BVZQ6QSY.js";
import {
component_styles_default
} from "./chunk.NLYVOJGK.js";
import {
SynergyElement
} from "./chunk.3THJTCRO.js";
import {
__decorateClass
} from "./chunk.Z4XV3SMG.js";
// src/components/details/details.component.ts
import { classMap } from "lit/directives/class-map.js";
import { html } from "lit";
import { property, query } from "lit/decorators.js";
var SynDetails = class extends SynergyElement {
constructor() {
super(...arguments);
this.localize = new LocalizeController(this);
this.open = false;
this.disabled = false;
this.contained = false;
this.size = "medium";
}
firstUpdated() {
this.body.style.height = this.open ? "auto" : "0";
if (this.open) {
this.details.open = true;
}
this.detailsObserver = new MutationObserver((changes) => {
for (const change of changes) {
if (change.type === "attributes" && change.attributeName === "open") {
if (this.details.open) {
this.show();
} else {
this.hide();
}
}
}
});
this.detailsObserver.observe(this.details, { attributes: true });
}
disconnectedCallback() {
var _a;
super.disconnectedCallback();
(_a = this.detailsObserver) == null ? void 0 : _a.disconnect();
}
handleSummaryClick(event) {
event.preventDefault();
if (!this.disabled) {
if (this.open) {
this.hide();
} else {
this.show();
}
this.header.focus();
}
}
handleSummaryKeyDown(event) {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
if (this.open) {
this.hide();
} else {
this.show();
}
}
if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
event.preventDefault();
this.hide();
}
if (event.key === "ArrowDown" || event.key === "ArrowRight") {
event.preventDefault();
this.show();
}
}
async handleOpenChange() {
if (this.open) {
this.details.open = true;
const slShow = this.emit("syn-show", { cancelable: true });
if (slShow.defaultPrevented) {
this.open = false;
this.details.open = false;
return;
}
await stopAnimations(this.body);
const { keyframes, options } = getAnimation(this, "details.show", { dir: this.localize.dir() });
await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
this.body.style.height = "auto";
this.emit("syn-after-show");
} else {
const slHide = this.emit("syn-hide", { cancelable: true });
if (slHide.defaultPrevented) {
this.details.open = true;
this.open = true;
return;
}
await stopAnimations(this.body);
const { keyframes, options } = getAnimation(this, "details.hide", { dir: this.localize.dir() });
await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
this.body.style.height = "auto";
this.details.open = false;
this.emit("syn-after-hide");
}
}
/** Shows the details. */
async show() {
if (this.open || this.disabled) {
return void 0;
}
this.open = true;
return waitForEvent(this, "syn-after-show");
}
/** Hides the details */
async hide() {
if (!this.open || this.disabled) {
return void 0;
}
this.open = false;
return waitForEvent(this, "syn-after-hide");
}
render() {
return html`
<details
part="base"
class=${classMap({
details: true,
"details--size-medium": this.size === "medium",
"details--size-large": this.size === "large",
"details--open": this.open,
"details--disabled": this.disabled,
"details--contained": this.contained
})}
>
<summary
part="header"
id="header"
class="details__header"
role="button"
aria-expanded=${this.open ? "true" : "false"}
aria-controls="content"
aria-disabled=${this.disabled ? "true" : "false"}
tabindex=${this.disabled ? "-1" : "0"}
=${this.handleSummaryClick}
=${this.handleSummaryKeyDown}
>
<slot name="summary" part="summary" class="details__summary">${this.summary}</slot>
<span part="summary-icon" class="details__summary-icon">
<slot name="expand-icon">
<syn-icon library="system" name="details-open"></syn-icon>
</slot>
<slot name="collapse-icon">
<syn-icon library="system" name="details-close"></syn-icon>
</slot>
</span>
</summary>
<div class="details__body" part="body" role="region" aria-labelledby="header">
<slot part="content" id="content" class="details__content"></slot>
</div>
</details>
`;
}
};
SynDetails.styles = [component_styles_default, details_styles_default, details_custom_styles_default];
SynDetails.dependencies = {
"syn-icon": SynIcon
};
__decorateClass([
query(".details")
], SynDetails.prototype, "details", 2);
__decorateClass([
query(".details__header")
], SynDetails.prototype, "header", 2);
__decorateClass([
query(".details__body")
], SynDetails.prototype, "body", 2);
__decorateClass([
query(".details__expand-icon-slot")
], SynDetails.prototype, "expandIconSlot", 2);
__decorateClass([
property({ type: Boolean, reflect: true })
], SynDetails.prototype, "open", 2);
__decorateClass([
property()
], SynDetails.prototype, "summary", 2);
__decorateClass([
property({ type: Boolean, reflect: true })
], SynDetails.prototype, "disabled", 2);
__decorateClass([
property({ type: Boolean, reflect: true })
], SynDetails.prototype, "contained", 2);
__decorateClass([
property({ reflect: true })
], SynDetails.prototype, "size", 2);
__decorateClass([
watch("open", { waitUntilFirstUpdate: true })
], SynDetails.prototype, "handleOpenChange", 1);
SynDetails = __decorateClass([
enableDefaultSettings("SynDetails")
], SynDetails);
setDefaultAnimation("details.show", {
keyframes: [
{ height: "0", opacity: "0" },
{ height: "auto", opacity: "1" }
],
options: { duration: 250, easing: "linear" }
});
setDefaultAnimation("details.hide", {
keyframes: [
{ height: "auto", opacity: "1" },
{ height: "0", opacity: "0" }
],
options: { duration: 250, easing: "linear" }
});
export {
SynDetails
};
//# sourceMappingURL=chunk.SN4QLG4C.js.map