refactor folk-space to lit
This commit is contained in:
parent
50c07fcf81
commit
ebe6c71c08
|
|
@ -1,4 +1,6 @@
|
||||||
import { html, css } from './common/tags';
|
import { css, PropertyValues } from '@lit/reactive-element';
|
||||||
|
import { FolkElement } from './common/folk-element';
|
||||||
|
import { html } from './common/tags';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
|
|
@ -6,60 +8,53 @@ declare global {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = css`
|
export class FolkSpace extends FolkElement {
|
||||||
:host {
|
|
||||||
display: block;
|
|
||||||
perspective: 1000px;
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.space {
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
transform-style: preserve-3d;
|
|
||||||
transform-origin: center;
|
|
||||||
transition: transform 0.6s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.space.rotate {
|
|
||||||
transform: rotateX(-90deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.face {
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
backface-visibility: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.front {
|
|
||||||
transform: rotateX(0deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.back {
|
|
||||||
transform: rotateX(90deg);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export class FolkSpace extends HTMLElement {
|
|
||||||
static tagName = 'folk-space';
|
static tagName = 'folk-space';
|
||||||
|
|
||||||
static define() {
|
static styles = css`
|
||||||
if (customElements.get(this.tagName)) return;
|
:host {
|
||||||
customElements.define(this.tagName, this);
|
display: block;
|
||||||
}
|
perspective: 1000px;
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
#shadow = this.attachShadow({ mode: 'open' });
|
.space {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
transform-style: preserve-3d;
|
||||||
|
transform-origin: center;
|
||||||
|
transition: transform 0.6s;
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
.space.rotate {
|
||||||
super();
|
transform: rotateX(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
this.#shadow.adoptedStyleSheets.push(styles);
|
.face {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
backface-visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
this.#shadow.setHTMLUnsafe(html`
|
.front {
|
||||||
|
transform: rotateX(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.back {
|
||||||
|
transform: rotateX(90deg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
override firstUpdated(changedProperties: PropertyValues): void {
|
||||||
|
super.firstUpdated(changedProperties);
|
||||||
|
|
||||||
|
if (!(this.renderRoot instanceof ShadowRoot)) return;
|
||||||
|
|
||||||
|
this.renderRoot.setHTMLUnsafe(html`
|
||||||
<div class="space">
|
<div class="space">
|
||||||
<div class="face front">
|
<div class="face front">
|
||||||
<slot name="front"></slot>
|
<slot name="front"></slot>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue