* mvp done * wip * fix ts errors and other code improvements * fix ts errors * ensure mobile layout support * Make skeleton responsive on screen resize * refactor * Add test for EmbedElement * make skeleton closer to pixel perfect * Address PR feedback * Remove PR_TODO --------- Co-authored-by: Benny Joo <sldisek783@gmail.com> Co-authored-by: amrit <iamamrit27@gmail.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { EmbedElement } from "../EmbedElement";
|
|
import loaderCss from "../loader.css?inline";
|
|
import { getErrorString } from "../utils";
|
|
import inlineHtml, { getSkeletonData } from "./inlineHtml";
|
|
|
|
export class Inline extends EmbedElement {
|
|
static get observedAttributes() {
|
|
return ["loading"];
|
|
}
|
|
|
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
this.assertHasShadowRoot();
|
|
const errorEl = this.shadowRoot.querySelector<HTMLElement>("#error");
|
|
const slotEl = this.shadowRoot.querySelector<HTMLElement>("slot");
|
|
if (!slotEl || !errorEl) {
|
|
throw new Error("One of loaderEl, slotEl or errorEl is missing");
|
|
}
|
|
if (name === "loading") {
|
|
if (newValue == "done") {
|
|
this.toggleLoader(false);
|
|
} else if (newValue === "failed") {
|
|
this.toggleLoader(false);
|
|
slotEl.style.visibility = "hidden";
|
|
errorEl.style.display = "block";
|
|
const errorString = getErrorString(this.dataset.errorCode);
|
|
errorEl.innerText = errorString;
|
|
}
|
|
}
|
|
}
|
|
|
|
constructor() {
|
|
super({ isModal: false, getSkeletonData });
|
|
this.attachShadow({ mode: "open" });
|
|
this.assertHasShadowRoot();
|
|
this.shadowRoot.innerHTML = `<style>${window.Cal.__css}</style><style>${loaderCss}</style>${inlineHtml({
|
|
layout: this.layout,
|
|
pageType: this.getPageType() ?? null,
|
|
})}`;
|
|
}
|
|
}
|