diff --git a/api/js/etemplate/Layout/Et2Details/Et2Details.ts b/api/js/etemplate/Layout/Et2Details/Et2Details.ts index aa9d764a50..d3d9c7d930 100644 --- a/api/js/etemplate/Layout/Et2Details/Et2Details.ts +++ b/api/js/etemplate/Layout/Et2Details/Et2Details.ts @@ -8,11 +8,12 @@ */ import {Et2Widget} from "../../Et2Widget/Et2Widget"; -import {css} from "lit"; +import {css, html} from "lit"; import {SlDetails} from "@shoelace-style/shoelace"; import shoelace from "../../Styles/shoelace"; import {property} from "lit/decorators/property.js"; import {customElement} from "lit/decorators/custom-element.js"; +import {classMap} from "lit/directives/class-map.js"; @customElement("et2-details") export class Et2Details extends Et2Widget(SlDetails) @@ -23,61 +24,83 @@ export class Et2Details extends Et2Widget(SlDetails) ...super.styles, shoelace, css` - :host { - display: block; - } - - :host([align="right"]) > div { - justify-content: flex-end; - } - :host([align="left"]) > div { - justify-content: flex-start; - } - /* CSS for child elements */ - ::slotted(*) { - flex: 1 1 auto; - } - ::slotted(img),::slotted(et2-image) { - /* Stop images from growing. In general we want them to stay */ - flex-grow: 0; - } - ::slotted([align="left"]) { - margin-right: auto; - order: -1; - } - ::slotted([align="right"]) { - margin-left: auto; - order: 1; - } + :host { + display: block; + } + + :host([align="right"]) > div { + justify-content: flex-end; + } - .details { - border: var(--sl-panel-border-width) solid var(--sl-panel-border-color); - margin: 0px; - } - .details.hoist { - position: relative; - } + :host([align="left"]) > div { + justify-content: flex-start; + } - .details.hoist .details__body { - position: absolute; - z-index: var(--sl-z-index-drawer); - background: var(--sl-color-neutral-0); - box-shadow: var(--sl-shadow-large); - width: 100%; - min-width: fit-content; - border-radius: var(--sl-border-radius-small); - border: var(--sl-panel-border-width) solid var(--sl-panel-border-color); - max-height: 15em; - overflow-y: auto; - } - .details.hoist .details__body.overlaySummaryLeftAligned { - top: 0; - left: 2em; - width: calc(100% - 2em); - } - .details.hoist .details__body.overlaySummaryRightAligned { - top: 0; - } + /* CSS for child elements */ + + ::slotted(*) { + flex: 1 1 auto; + } + + ::slotted(img), ::slotted(et2-image) { + /* Stop images from growing. In general we want them to stay */ + flex-grow: 0; + } + + ::slotted([align="left"]) { + margin-right: auto; + order: -1; + } + + ::slotted([align="right"]) { + margin-left: auto; + order: 1; + } + + .details { + border: var(--sl-panel-border-width) solid var(--sl-panel-border-color); + margin: 0px; + overflow: hidden; + } + + .details.hoist { + position: relative; + } + + .details__body { + display: none; + } + + .details--open .details__body { + display: block; + } + + .details.hoist .details__body { + position: absolute; + z-index: var(--sl-z-index-drawer); + background: var(--sl-color-neutral-0); + box-shadow: var(--sl-shadow-large); + width: 100%; + min-width: fit-content; + border-radius: var(--sl-border-radius-small); + border: var(--sl-panel-border-width) solid var(--sl-panel-border-color); + max-height: 15em; + overflow-y: auto; + } + + .details.hoist .details__body.overlaySummaryLeftAligned { + top: 0; + left: 2em; + width: calc(100% - 2em); + } + + .details.hoist .details__body.overlaySummaryRightAligned { + top: 0; + } + + .details__summary-icon--left-aligned { + order: -1; + } `, ]; } @@ -128,19 +151,6 @@ export class Et2Details extends Et2Widget(SlDetails) this.addEventListener("mouseover", this.show); window.document.addEventListener('mouseout', this._mouseOutEvent.bind(this)); } - if (this.hoist) - { - this.shadowRoot.querySelector('.details').classList.add('hoist'); - } - if (this.toggleAlign === 'left') - { - this.shadowRoot.querySelector('.details__summary-icon').style.order = -1; - } - if (this.overlaySummaryOnOpen) - { - this.shadowRoot.querySelector('.details__body').classList.add(this.toggleAlign === 'left' ? - 'overlaySummaryLeftAligend' : 'overlaySummaryRightAligned'); - } }); } @@ -158,4 +168,57 @@ export class Et2Details extends Et2Widget(SlDetails) { if (!this.getDOMNode().contains(event.relatedTarget)) this.hide(); } + + render() + { + const isRtl = this.matches(':dir(rtl)'); + + return html` +