mirror of
https://github.com/home-assistant/frontend.git
synced 2026-11-27 23:29:16 +00:00
Compare commits
33
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4be7808510 | ||
|
|
faa275b453 | ||
|
|
f0088fe86b | ||
|
|
312c7495bb | ||
|
|
917dfbe70c | ||
|
|
d5c1860e56 | ||
|
|
0fb712a163 | ||
|
|
a426afb079 | ||
|
|
f93f330066 | ||
|
|
6e335657eb | ||
|
|
0951d6c9ab | ||
|
|
e933f82678 | ||
|
|
3fc3afb464 | ||
|
|
2a97c9a20d | ||
|
|
6c85ed4ec5 | ||
|
|
8907361d18 | ||
|
|
822582b467 | ||
|
|
9c331b16d2 | ||
|
|
157e7c36a7 | ||
|
|
a7ca2f7271 | ||
|
|
cffc46fa72 | ||
|
|
2753f014df | ||
|
|
09cd76c3a1 | ||
|
|
fb1a238a53 | ||
|
|
fe4a96568a | ||
|
|
9e9da00103 | ||
|
|
10ba469bab | ||
|
|
eed745c9a5 | ||
|
|
d285e2da5f | ||
|
|
22caf9b46b | ||
|
|
71311dcc94 | ||
|
|
694379f82f | ||
|
|
4b0d5ac5a2 |
No files matched your search
@@ -10,6 +10,7 @@ Use this skill for every loading state, following the [Loading pattern](https://
|
||||
## Pick The Indicator
|
||||
|
||||
- Use a skeleton from `src/components/skeleton/` (`ha-skeleton`, `ha-skeleton-text`, `ha-skeleton-icon`, `ha-skeleton-log`) when content loads into a layout you already know, such as table rows, tile text, or a log. It holds the layout, so nothing jumps when the content arrives.
|
||||
- Use `ha-skeleton-overlay` when the content renders before its data arrives, such as a card or badge, or when content reloads over what's already shown. See [Skeleton Overlay](#skeleton-overlay).
|
||||
- Use `ha-spinner` only when a whole area loads and its shape is unknown.
|
||||
- Use `ha-button` with `loading`, or `ha-progress-button`, for an action started from a button. Don't put a separate spinner next to it.
|
||||
|
||||
@@ -27,7 +28,7 @@ Wrap the indicator in `ha-fade-in` from `src/components/animation/ha-fade-in.ts`
|
||||
|
||||
- Fade a skeleton in straight away over about 300ms (`.duration=${300}`), as the data table does. It stands in for the content, so a delay would leave an empty gap.
|
||||
- Delay a spinner or progress bar, usually by `.delay=${500}`, so a load that finishes within that time never flashes it. Some slower areas, such as backups and updates, use `${1000}`.
|
||||
- Don't fade in the loaded content itself.
|
||||
- Content that takes a skeleton's place fades in over `--ha-animation-duration-fast`, which reduced motion makes instant. `ha-skeleton-overlay` does this for you. Elsewhere, use `skeletonOr(loading, skeleton, () => content)` from `src/components/skeleton/skeleton-arrival.ts`: it shows the skeleton while loading and fades the content in once when it replaces it, but not where no skeleton showed, such as table rows made as the table scrolls. Put text in an element of its own inside the content, as only elements fade. For content that fills in where it already is, such as a log, call `fadeInArrival(element)` once when its skeleton goes. Don't add any other fade to loaded content.
|
||||
|
||||
Give a skeleton group the `progressbar` role and a translated label, as `ha-spinner` has, rather than visible "Loading" text.
|
||||
|
||||
@@ -45,6 +46,24 @@ html`
|
||||
`;
|
||||
```
|
||||
|
||||
## Skeleton Overlay
|
||||
|
||||
`ha-skeleton-overlay` reads a skeleton from the content it wraps, so it can't drift from it: each text line, icon, image, control and drawing gets its own piece, and the real parts are hidden underneath until loading ends. Prefer it to drawing a skeleton by hand whenever the content can render before its data.
|
||||
|
||||
```ts
|
||||
html`
|
||||
<ha-skeleton-overlay .loading=${this._loading}>
|
||||
<my-content></my-content>
|
||||
</ha-skeleton-overlay>
|
||||
`;
|
||||
```
|
||||
|
||||
- Turn it on with `loading`, or fire `skeleton-loading` (`{ loading: true }`, later `{ loading: false }`) from inside the content. The event stops at the nearest overlay, so content doesn't need to know what wraps it.
|
||||
- Mark parts that shouldn't be read with `data-skeleton`: `none` leaves an element out and showing, `keep` leaves it showing but reads what's inside, and `text`, `round` or `block` force one piece of that kind. Skeletons the content draws itself are left alone.
|
||||
- Put your own skeleton in the `skeleton` slot to replace the reading altogether.
|
||||
- Call `refresh()` when the content changes without changing size.
|
||||
- It gives the skeleton the `progressbar` role and the translated label itself.
|
||||
|
||||
## Checking It
|
||||
|
||||
Check a loading state in the browser, not only by reading the code. These work on any setup: a dev server, the demo, or the gallery.
|
||||
@@ -71,5 +90,6 @@ Check a loading state in the browser, not only by reading the code. These work o
|
||||
};
|
||||
```
|
||||
|
||||
- **Compare the skeleton with the content.** It should take the same space, so nothing moves when the content arrives. Measure the wrapper's height while loading and once loaded (`element.getBoundingClientRect().height` in the console), or take a screenshot of each at the same size and flick between them. Look for pieces that are missing, extra or in the wrong place, and fix those with `data-skeleton`.
|
||||
- **Compare before and after.** Take screenshots of the same screen on `dev` and on your branch, at the same viewport size, both loading and loaded, and put them side by side. In a pull request, show both.
|
||||
- **Check every look.** Light and dark themes, a right-to-left language (the wave starts from the right), reduced motion (DevTools, Rendering, "Emulate CSS media feature prefers-reduced-motion": the wave stops), and a phone width (DevTools device toolbar).
|
||||
@@ -0,0 +1,624 @@
|
||||
/**
|
||||
* Read a skeleton from rendered content, such as a dashboard card: where its
|
||||
* text lines, icons, images, controls and drawings are, inside shadow roots
|
||||
* too. The content stays the source of truth for layout, so the skeleton
|
||||
* can't drift from it.
|
||||
*
|
||||
* Any element can say how it's read with a `data-skeleton` attribute:
|
||||
* - `text`, `round` or `block`: one piece of that kind, the size of the element
|
||||
* - `none`: left out and left showing, such as a card's own chrome
|
||||
* - `keep`: left showing, but what's inside it is still read
|
||||
*
|
||||
* Skeletons a component already draws itself (`ha-skeleton` and its
|
||||
* variants) are left out and left showing, as `none`.
|
||||
*/
|
||||
|
||||
export type SkeletonPieceKind = "text" | "round" | "block" | "shape" | "scrim";
|
||||
|
||||
type SkeletonOverride = "text" | "round" | "block" | "none" | "keep";
|
||||
|
||||
const OVERRIDES = new Set<string>(["text", "round", "block", "none", "keep"]);
|
||||
|
||||
const isOverride = (value: string | null): value is SkeletonOverride =>
|
||||
value !== null && OVERRIDES.has(value);
|
||||
|
||||
const skeletonOverride = (element: Element): SkeletonOverride | undefined => {
|
||||
if (element.localName.startsWith("ha-skeleton")) {
|
||||
return "none";
|
||||
}
|
||||
|
||||
const value = element.getAttribute("data-skeleton");
|
||||
|
||||
return isOverride(value) ? value : undefined;
|
||||
};
|
||||
|
||||
export interface SkeletonPiece {
|
||||
kind: SkeletonPieceKind;
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
radius?: string;
|
||||
/* An SVG mask for a drawing, such as a gauge arc */
|
||||
mask?: string;
|
||||
/* Where that mask sits in the piece, when something cuts the drawing short:
|
||||
still the drawing's whole size and place, with the piece only its part */
|
||||
maskBox?: { x: number; y: number; width: number; height: number };
|
||||
/* The part sits on a dark overlay, such as a picture card's name bar */
|
||||
onDark?: boolean;
|
||||
/* A see-through bar laid over a picture, kept as it is */
|
||||
background?: string;
|
||||
}
|
||||
|
||||
export interface ExtractedSkeleton {
|
||||
pieces: SkeletonPiece[];
|
||||
/* The elements the pieces stand in for, hidden while loading */
|
||||
parts: (HTMLElement | SVGElement)[];
|
||||
/* Elements holding text: hide only the text colour, as the same element
|
||||
often draws a frame, such as a badge's pill, that has to stay */
|
||||
textParts: HTMLElement[];
|
||||
}
|
||||
|
||||
const ROUND_TAGS = new Set([
|
||||
"ha-tile-icon",
|
||||
"ha-state-icon",
|
||||
"ha-svg-icon",
|
||||
"ha-icon",
|
||||
"state-badge",
|
||||
]);
|
||||
|
||||
const BLOCK_TAGS = new Set(["img", "video", "canvas", "ha-camera-stream"]);
|
||||
|
||||
/* A canvas to measure fonts with, made on first use */
|
||||
let measuringContext: CanvasRenderingContext2D | null | undefined;
|
||||
|
||||
const fontContext = (style: CSSStyleDeclaration, size: string) => {
|
||||
measuringContext ??= document.createElement("canvas").getContext("2d");
|
||||
|
||||
if (measuringContext) {
|
||||
measuringContext.font = `${style.fontStyle} ${style.fontWeight} ${size} ${style.fontFamily}`;
|
||||
}
|
||||
|
||||
return measuringContext;
|
||||
};
|
||||
|
||||
/**
|
||||
* Where a text bar goes on a line of this font: from the top of the
|
||||
* capitals down to the baseline, measured from the font itself.
|
||||
* `size` is the size as drawn, after any SVG scaling.
|
||||
*/
|
||||
const capitalBand = (style: CSSStyleDeclaration, size: number) => {
|
||||
const context = fontContext(style, `${size}px`);
|
||||
|
||||
if (!context) {
|
||||
return { top: size * 0.2, height: size * 0.7 };
|
||||
}
|
||||
|
||||
const metrics = context.measureText("H");
|
||||
|
||||
return {
|
||||
// The line box holds the font's ascent, so the baseline sits that far down
|
||||
top: metrics.fontBoundingBoxAscent - metrics.actualBoundingBoxAscent,
|
||||
height: metrics.actualBoundingBoxAscent,
|
||||
};
|
||||
};
|
||||
|
||||
/* How wide "…" is in this font, the room cut-off text leaves at its end */
|
||||
const ellipsisWidth = (style: CSSStyleDeclaration) =>
|
||||
fontContext(style, style.fontSize)?.measureText("…").width ??
|
||||
parseFloat(style.fontSize);
|
||||
|
||||
/* The icon as drawn, not its box, which a line of text can crop */
|
||||
const findGlyph = (element: Element, depth = 4): Element | undefined => {
|
||||
if (depth === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
for (const child of [
|
||||
...(element.shadowRoot?.children ?? []),
|
||||
...element.children,
|
||||
]) {
|
||||
if (child instanceof SVGSVGElement) {
|
||||
return child;
|
||||
}
|
||||
|
||||
const found = findGlyph(child, depth - 1);
|
||||
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/* Near-white text or icons, as on a picture card's dark name bar */
|
||||
const isNearWhite = (color: string): boolean => {
|
||||
const channels = color
|
||||
.match(/[\d.]+/g)
|
||||
?.slice(0, 3)
|
||||
.map(Number);
|
||||
|
||||
return channels?.length === 3 && channels.every((channel) => channel >= 200);
|
||||
};
|
||||
|
||||
const isRendered = (style: CSSStyleDeclaration) =>
|
||||
style.display !== "none" && style.visibility !== "hidden";
|
||||
|
||||
const isSeeThrough = (color: string) => {
|
||||
const alpha = Number(color.match(/rgba\(.*,\s*([\d.]+)\)/)?.[1] ?? 1);
|
||||
|
||||
return alpha > 0 && alpha < 1;
|
||||
};
|
||||
|
||||
/* The first element, inside shadow roots too, that rounds its corners */
|
||||
const findRounded = (element: Element, depth = 4): Element | undefined => {
|
||||
if (depth === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const children = [
|
||||
...(element.shadowRoot?.children ?? []),
|
||||
...element.children,
|
||||
];
|
||||
|
||||
for (const child of children) {
|
||||
if (parseFloat(getComputedStyle(child).borderTopLeftRadius) > 0) {
|
||||
return child;
|
||||
}
|
||||
|
||||
const found = findRounded(child, depth - 1);
|
||||
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/* Join the pieces of one line of text, such as "Heat", "·" and "21 °C" */
|
||||
const mergeLines = (pieces: SkeletonPiece[]): SkeletonPiece[] => {
|
||||
const merged: SkeletonPiece[] = [];
|
||||
|
||||
for (const piece of pieces) {
|
||||
const previous = merged[merged.length - 1];
|
||||
|
||||
// Either side, so right-to-left lines join too
|
||||
const gap = previous
|
||||
? Math.max(
|
||||
piece.x - (previous.x + previous.width),
|
||||
previous.x - (piece.x + piece.width)
|
||||
)
|
||||
: Infinity;
|
||||
|
||||
const sameLine =
|
||||
previous?.kind === "text" &&
|
||||
piece.kind === "text" &&
|
||||
Math.abs(previous.y - piece.y) < 2 &&
|
||||
Math.abs(previous.height - piece.height) < 2 &&
|
||||
gap < 12;
|
||||
|
||||
if (sameLine) {
|
||||
const left = Math.min(previous.x, piece.x);
|
||||
|
||||
const right = Math.max(
|
||||
previous.x + previous.width,
|
||||
piece.x + piece.width
|
||||
);
|
||||
|
||||
previous.x = left;
|
||||
previous.width = right - left;
|
||||
continue;
|
||||
}
|
||||
|
||||
merged.push({ ...piece });
|
||||
}
|
||||
|
||||
return merged;
|
||||
};
|
||||
|
||||
const svgMask = (svg: SVGSVGElement, width: number, height: number) => {
|
||||
const clone = svg.cloneNode(true);
|
||||
|
||||
if (!(clone instanceof SVGSVGElement)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const originals = [svg, ...svg.querySelectorAll("*")];
|
||||
const copies = [clone, ...clone.querySelectorAll("*")];
|
||||
let drawnPaths = 0;
|
||||
|
||||
originals.forEach((original, index) => {
|
||||
const copy = copies[index];
|
||||
const style = getComputedStyle(original);
|
||||
|
||||
if (original.localName === "text" || !isRendered(style)) {
|
||||
copy.setAttribute("display", "none");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (original !== svg && original.localName !== "g") {
|
||||
drawnPaths++;
|
||||
}
|
||||
|
||||
copy.removeAttribute("class");
|
||||
copy.removeAttribute("style");
|
||||
copy.setAttribute("fill", style.fill === "none" ? "none" : "#000");
|
||||
copy.setAttribute("stroke", style.stroke === "none" ? "none" : "#000");
|
||||
copy.setAttribute("stroke-width", style.strokeWidth);
|
||||
copy.setAttribute("stroke-linecap", style.strokeLinecap);
|
||||
|
||||
// Keep what moves or cuts a shape, such as a gauge's needle and the
|
||||
// dashes that draw its value arc
|
||||
if (style.transform !== "none") {
|
||||
copy.setAttribute(
|
||||
"style",
|
||||
`transform: ${style.transform}; transform-origin: ${style.transformOrigin}; transform-box: ${style.transformBox}`
|
||||
);
|
||||
}
|
||||
|
||||
if (style.strokeDasharray !== "none") {
|
||||
copy.setAttribute("stroke-dasharray", style.strokeDasharray);
|
||||
copy.setAttribute("stroke-dashoffset", style.strokeDashoffset);
|
||||
}
|
||||
});
|
||||
|
||||
if (drawnPaths === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
clone.setAttribute("width", String(width));
|
||||
clone.setAttribute("height", String(height));
|
||||
|
||||
const markup = new XMLSerializer().serializeToString(clone);
|
||||
|
||||
return `url("data:image/svg+xml,${encodeURIComponent(markup)}")`;
|
||||
};
|
||||
|
||||
export const extractSkeleton = (
|
||||
root: Element,
|
||||
origin: DOMRect
|
||||
): ExtractedSkeleton => {
|
||||
const pieces: SkeletonPiece[] = [];
|
||||
const parts = new Set<HTMLElement | SVGElement>();
|
||||
const textParts = new Set<HTMLElement>();
|
||||
|
||||
/* The card's own background, the first solid one found */
|
||||
let surface: string | undefined;
|
||||
|
||||
const box = (rect: DOMRect) => ({
|
||||
x: rect.left - origin.left,
|
||||
y: rect.top - origin.top,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
});
|
||||
|
||||
/* Near-white content on a light card must sit on a dark bar */
|
||||
const onDark = (style: CSSStyleDeclaration) =>
|
||||
surface !== undefined && isNearWhite(surface) && isNearWhite(style.color);
|
||||
|
||||
/* An element that cuts off its overflow, such as a scrolling list, cuts the
|
||||
pieces read inside it too, as the overlay draws them on a layer of its
|
||||
own where that clip doesn't reach */
|
||||
const clipPieces = (from: number, rect: DOMRect) => {
|
||||
const bounds = box(rect);
|
||||
|
||||
const clipped = pieces.splice(from).flatMap((piece): SkeletonPiece[] => {
|
||||
const x = Math.max(piece.x, bounds.x);
|
||||
const y = Math.max(piece.y, bounds.y);
|
||||
const right = Math.min(piece.x + piece.width, bounds.x + bounds.width);
|
||||
const bottom = Math.min(piece.y + piece.height, bounds.y + bounds.height);
|
||||
|
||||
if (right <= x || bottom <= y) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const cut = { ...piece, x, y, width: right - x, height: bottom - y };
|
||||
|
||||
// A drawing's mask is made for its whole box, so it keeps that box
|
||||
if (piece.kind === "shape") {
|
||||
const mask = piece.maskBox ?? {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: piece.width,
|
||||
height: piece.height,
|
||||
};
|
||||
|
||||
return [
|
||||
{
|
||||
...cut,
|
||||
maskBox: {
|
||||
...mask,
|
||||
x: piece.x + mask.x - x,
|
||||
y: piece.y + mask.y - y,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [cut];
|
||||
});
|
||||
|
||||
pieces.push(...clipped);
|
||||
};
|
||||
|
||||
const addText = (element: Element | ShadowRoot) => {
|
||||
const owner = element instanceof ShadowRoot ? element.host : element;
|
||||
|
||||
// Text cut short with an ellipsis reaches past its box, so clip to it.
|
||||
// An owner with no box of its own, such as one with display: contents,
|
||||
// cuts nothing off.
|
||||
const clip = owner.getBoundingClientRect();
|
||||
const clips = clip.width > 0 || clip.height > 0;
|
||||
|
||||
element.childNodes.forEach((node) => {
|
||||
if (!(node instanceof Text) || !node.textContent?.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Slotted text takes its font and colour from the slot it shows in,
|
||||
// so that's where it's measured and hidden
|
||||
const slot = node.assignedSlot;
|
||||
const hideTarget = slot ?? owner;
|
||||
const style = getComputedStyle(hideTarget);
|
||||
const band = capitalBand(style, parseFloat(style.fontSize));
|
||||
|
||||
if (hideTarget instanceof HTMLElement) {
|
||||
textParts.add(hideTarget);
|
||||
}
|
||||
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(node);
|
||||
|
||||
for (const rect of range.getClientRects()) {
|
||||
// Cut-off text ends in "…", on the right or, right to left, on the
|
||||
// left, so stop the bar where that starts
|
||||
const left =
|
||||
clips && rect.left < clip.left - 1
|
||||
? clip.left + ellipsisWidth(style)
|
||||
: rect.left;
|
||||
|
||||
const right =
|
||||
clips && rect.right > clip.right + 1
|
||||
? clip.right - ellipsisWidth(style)
|
||||
: rect.right;
|
||||
|
||||
if (right <= left) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pieces.push({
|
||||
kind: "text",
|
||||
x: left - origin.left,
|
||||
width: right - left,
|
||||
y: rect.top - origin.top + band.top,
|
||||
height: band.height,
|
||||
onDark: onDark(style),
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const walk = (node: Element | ShadowRoot) => {
|
||||
// Text straight inside a shadow root, as state-display renders its state
|
||||
if (node instanceof ShadowRoot) {
|
||||
addText(node);
|
||||
}
|
||||
|
||||
for (const child of node.children) {
|
||||
const style = getComputedStyle(child);
|
||||
|
||||
if (!isRendered(style)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rect = child.getBoundingClientRect();
|
||||
const tag = child.localName;
|
||||
// Elements such as slots take no space but their content does
|
||||
const hasSize = rect.width > 0 && rect.height > 0;
|
||||
const override = skeletonOverride(child);
|
||||
|
||||
if (override === "none") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const clipsOverflow =
|
||||
hasSize &&
|
||||
(style.overflowX !== "visible" || style.overflowY !== "visible");
|
||||
|
||||
const from = pieces.length;
|
||||
|
||||
// Read what's inside, cut to the child where it hides its overflow
|
||||
const descend = () => {
|
||||
if (child instanceof HTMLElement) {
|
||||
addText(child);
|
||||
}
|
||||
|
||||
if (child.shadowRoot) {
|
||||
walk(child.shadowRoot);
|
||||
}
|
||||
|
||||
walk(child);
|
||||
|
||||
if (clipsOverflow) {
|
||||
clipPieces(from, rect);
|
||||
}
|
||||
};
|
||||
|
||||
if (override === "keep") {
|
||||
// Its frame stays, but its own text is read like any other
|
||||
descend();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (override !== undefined) {
|
||||
if (
|
||||
hasSize &&
|
||||
(child instanceof HTMLElement || child instanceof SVGElement)
|
||||
) {
|
||||
const size = Math.min(rect.width, rect.height);
|
||||
const piece = box(rect);
|
||||
|
||||
pieces.push(
|
||||
override === "round"
|
||||
? {
|
||||
kind: "round",
|
||||
x: piece.x + (piece.width - size) / 2,
|
||||
y: piece.y + (piece.height - size) / 2,
|
||||
width: size,
|
||||
height: size,
|
||||
}
|
||||
: { kind: override, ...piece, radius: style.borderRadius }
|
||||
);
|
||||
parts.add(child);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
surface === undefined &&
|
||||
hasSize &&
|
||||
style.backgroundColor !== "rgba(0, 0, 0, 0)" &&
|
||||
!isSeeThrough(style.backgroundColor)
|
||||
) {
|
||||
surface = style.backgroundColor;
|
||||
}
|
||||
|
||||
if (child instanceof HTMLElement && ROUND_TAGS.has(tag)) {
|
||||
// Use the circle itself, such as the tile icon's 36px background
|
||||
const circle = (
|
||||
findRounded(child) ??
|
||||
findGlyph(child) ??
|
||||
child
|
||||
).getBoundingClientRect();
|
||||
|
||||
const size =
|
||||
Math.min(circle.width, circle.height) ||
|
||||
Math.max(circle.width, circle.height);
|
||||
|
||||
const piece = box(circle);
|
||||
|
||||
if (size > 0) {
|
||||
pieces.push({
|
||||
kind: "round",
|
||||
x: piece.x + (piece.width - size) / 2,
|
||||
y: piece.y + (piece.height - size) / 2,
|
||||
width: size,
|
||||
height: size,
|
||||
onDark: onDark(style),
|
||||
});
|
||||
parts.add(child);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// A see-through bar over a picture stays, so text keeps its contrast
|
||||
if (
|
||||
child instanceof HTMLElement &&
|
||||
hasSize &&
|
||||
style.position === "absolute" &&
|
||||
isSeeThrough(style.backgroundColor)
|
||||
) {
|
||||
pieces.push({
|
||||
kind: "scrim",
|
||||
...box(rect),
|
||||
radius: style.borderRadius,
|
||||
background: style.backgroundColor,
|
||||
});
|
||||
}
|
||||
|
||||
// Pictures drawn as a background, as hui-image does in a fixed ratio
|
||||
if (
|
||||
child instanceof HTMLElement &&
|
||||
hasSize &&
|
||||
style.backgroundImage.startsWith("url(")
|
||||
) {
|
||||
pieces.push({
|
||||
kind: "block",
|
||||
...box(rect),
|
||||
radius: style.borderRadius,
|
||||
});
|
||||
parts.add(child);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child instanceof HTMLElement && hasSize && BLOCK_TAGS.has(tag)) {
|
||||
pieces.push({
|
||||
kind: "block",
|
||||
...box(rect),
|
||||
radius: style.borderRadius,
|
||||
});
|
||||
parts.add(child);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
child instanceof HTMLElement &&
|
||||
hasSize &&
|
||||
tag.endsWith("-card-feature")
|
||||
) {
|
||||
const control = findRounded(child);
|
||||
|
||||
const radius = control
|
||||
? getComputedStyle(control).borderRadius
|
||||
: style.borderRadius;
|
||||
|
||||
pieces.push({ kind: "block", ...box(rect), radius });
|
||||
parts.add(child);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child instanceof SVGSVGElement && hasSize) {
|
||||
const piece = box(rect);
|
||||
const mask = svgMask(child, piece.width, piece.height);
|
||||
|
||||
if (mask) {
|
||||
pieces.push({ kind: "shape", ...piece, mask });
|
||||
}
|
||||
|
||||
child.querySelectorAll("text").forEach((text) => {
|
||||
const textRect = text.getBoundingClientRect();
|
||||
|
||||
if (textRect.width === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// SVG text is scaled with its drawing, as the gauge value is
|
||||
const scale = text.getScreenCTM()?.a ?? 1;
|
||||
const textStyle = getComputedStyle(text);
|
||||
|
||||
const band = capitalBand(
|
||||
textStyle,
|
||||
parseFloat(textStyle.fontSize) * scale
|
||||
);
|
||||
|
||||
pieces.push({
|
||||
kind: "text",
|
||||
...box(textRect),
|
||||
y: textRect.top - origin.top + band.top,
|
||||
height: band.height,
|
||||
});
|
||||
});
|
||||
|
||||
parts.add(child);
|
||||
continue;
|
||||
}
|
||||
|
||||
descend();
|
||||
}
|
||||
};
|
||||
|
||||
// Text straight inside the root, such as plain text in an overlay
|
||||
addText(root);
|
||||
walk(root);
|
||||
|
||||
return {
|
||||
pieces: mergeLines(pieces),
|
||||
parts: [...parts],
|
||||
textParts: [...textParts],
|
||||
};
|
||||
};
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
query,
|
||||
state,
|
||||
} from "lit/decorators";
|
||||
import type { DirectiveResult } from "lit/directive";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { join } from "lit/directives/join";
|
||||
@@ -45,6 +46,7 @@ import "../ha-checkbox";
|
||||
import type { HaCheckbox } from "../ha-checkbox";
|
||||
import "../skeleton/ha-skeleton-icon";
|
||||
import "../skeleton/ha-skeleton-text";
|
||||
import { skeletonOr } from "../skeleton/skeleton-arrival";
|
||||
import "../ha-svg-icon";
|
||||
import "../input/ha-input-search";
|
||||
import { filterData, sortData } from "./sort-filter";
|
||||
@@ -104,7 +106,9 @@ export interface DataTableColumnData<T = any> extends DataTableSortColumnData {
|
||||
| "overflow"
|
||||
| "overflow-menu"
|
||||
| "flex";
|
||||
template?: (row: T) => TemplateResult | string | typeof nothing;
|
||||
template?: (
|
||||
row: T
|
||||
) => TemplateResult | DirectiveResult | string | typeof nothing;
|
||||
extraTemplate?: (row: T) => TemplateResult | string | typeof nothing;
|
||||
minWidth?: string;
|
||||
maxWidth?: string;
|
||||
@@ -504,6 +508,14 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
const filteredDataLength = this._filteredData?.length || 0;
|
||||
|
||||
const showSkeleton =
|
||||
!filteredDataLength &&
|
||||
Boolean(
|
||||
this.loading ||
|
||||
!this._filteredData ||
|
||||
(this.data.length && !this._filteredDataSourceLength)
|
||||
);
|
||||
|
||||
const items = this._filteredData
|
||||
? this._groupData(
|
||||
this._filteredData,
|
||||
@@ -682,11 +694,14 @@ export class HaDataTable extends LitElement {
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
!this._filteredData?.length
|
||||
? this.loading ||
|
||||
!this._filteredData ||
|
||||
(this.data.length && !this._filteredDataSourceLength)
|
||||
? html`
|
||||
// Only what takes the skeleton rows' place fades in, not rows
|
||||
// that come back after a filter matched nothing
|
||||
skeletonOr(
|
||||
showSkeleton,
|
||||
// Only built while it shows, so loaded tables skip the work
|
||||
!showSkeleton
|
||||
? nothing
|
||||
: html`
|
||||
<div class="mdc-data-table__content" role="row">
|
||||
<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<div role="cell">
|
||||
@@ -746,73 +761,83 @@ export class HaDataTable extends LitElement {
|
||||
</div>
|
||||
</ha-fade-in>
|
||||
</div>
|
||||
`
|
||||
: this.loadError
|
||||
? nothing
|
||||
: html`
|
||||
<div class="mdc-data-table__content">
|
||||
<div class="mdc-data-table__row" role="row">
|
||||
<div
|
||||
class="mdc-data-table__cell grows center"
|
||||
role="cell"
|
||||
>
|
||||
${
|
||||
this.data.length
|
||||
? this._i18n?.localize?.(
|
||||
"ui.components.data-table.no_match_filter"
|
||||
) || "No rows matching current filters"
|
||||
: this.noDataText ||
|
||||
this._i18n?.localize?.(
|
||||
"ui.components.data-table.no-data"
|
||||
) ||
|
||||
"No data"
|
||||
}
|
||||
`,
|
||||
() =>
|
||||
!this._filteredData?.length
|
||||
? this.loadError
|
||||
? nothing
|
||||
: html`
|
||||
<div class="mdc-data-table__content">
|
||||
<div class="mdc-data-table__row" role="row">
|
||||
<div
|
||||
class="mdc-data-table__cell grows center"
|
||||
role="cell"
|
||||
>
|
||||
${
|
||||
this.data.length
|
||||
? this._i18n?.localize?.(
|
||||
"ui.components.data-table.no_match_filter"
|
||||
) || "No rows matching current filters"
|
||||
: this.noDataText ||
|
||||
this._i18n?.localize?.(
|
||||
"ui.components.data-table.no-data"
|
||||
) ||
|
||||
"No data"
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
: html`
|
||||
${
|
||||
this.groupColumn &&
|
||||
!this.autoHeight &&
|
||||
this._stickyGroup !== undefined
|
||||
? html`<div
|
||||
class="mdc-data-table__row sticky-group-header"
|
||||
role="row"
|
||||
aria-rowindex=${ifDefined(
|
||||
stickyGroupIndex === -1
|
||||
? undefined
|
||||
: stickyGroupIndex + (this.loadError ? 3 : 2)
|
||||
)}
|
||||
.group=${this._stickyGroup}
|
||||
@click=${this._collapseStickyGroup}
|
||||
>
|
||||
${keyed(
|
||||
this._stickyGroup,
|
||||
this._renderGroupHeader(
|
||||
this._stickyGroup,
|
||||
this._collapsedGroups.includes(
|
||||
this._stickyGroup
|
||||
),
|
||||
this._i18n?.localize,
|
||||
this.renderGroupActions,
|
||||
true
|
||||
)
|
||||
)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
<!-- The list fades in as a whole; rows made later as it
|
||||
scrolls show at once -->
|
||||
<lit-virtualizer
|
||||
scroller
|
||||
class="mdc-data-table__content scroller ha-scrollbar ${classMap(
|
||||
{
|
||||
grouped:
|
||||
Boolean(this.groupColumn) && !this.autoHeight,
|
||||
}
|
||||
)}"
|
||||
tabindex=${ifDefined(!this.autoHeight ? "0" : undefined)}
|
||||
@scroll=${this._saveScrollPos}
|
||||
@visibilityChanged=${this._handleVisibilityChanged}
|
||||
.items=${items}
|
||||
.keyFunction=${this._keyFunction}
|
||||
.renderItem=${renderRow}
|
||||
></lit-virtualizer>
|
||||
`
|
||||
: html`
|
||||
${
|
||||
this.groupColumn &&
|
||||
!this.autoHeight &&
|
||||
this._stickyGroup !== undefined
|
||||
? html`<div
|
||||
class="mdc-data-table__row sticky-group-header"
|
||||
role="row"
|
||||
aria-rowindex=${ifDefined(
|
||||
stickyGroupIndex === -1
|
||||
? undefined
|
||||
: stickyGroupIndex + (this.loadError ? 3 : 2)
|
||||
)}
|
||||
.group=${this._stickyGroup}
|
||||
@click=${this._collapseStickyGroup}
|
||||
>
|
||||
${keyed(
|
||||
this._stickyGroup,
|
||||
this._renderGroupHeader(
|
||||
this._stickyGroup,
|
||||
this._collapsedGroups.includes(this._stickyGroup),
|
||||
this._i18n?.localize,
|
||||
this.renderGroupActions,
|
||||
true
|
||||
)
|
||||
)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
<lit-virtualizer
|
||||
scroller
|
||||
class="mdc-data-table__content scroller ha-scrollbar ${classMap(
|
||||
{ grouped: Boolean(this.groupColumn) && !this.autoHeight }
|
||||
)}"
|
||||
tabindex=${ifDefined(!this.autoHeight ? "0" : undefined)}
|
||||
@scroll=${this._saveScrollPos}
|
||||
@visibilityChanged=${this._handleVisibilityChanged}
|
||||
.items=${items}
|
||||
.keyFunction=${this._keyFunction}
|
||||
.renderItem=${renderRow}
|
||||
></lit-virtualizer>
|
||||
`
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,652 @@
|
||||
import type { ContextType } from "@lit/context";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import type {
|
||||
ExtractedSkeleton,
|
||||
SkeletonPiece,
|
||||
} from "../../common/dom/extract-skeleton";
|
||||
import { extractSkeleton } from "../../common/dom/extract-skeleton";
|
||||
import type { HASSDomEvent } from "../../common/dom/fire_event";
|
||||
import { parseAnimationDuration } from "../../common/util/parse-animation-duration";
|
||||
import { internationalizationContext } from "../../data/context";
|
||||
import type { HaSkeleton } from "./ha-skeleton";
|
||||
import "./ha-skeleton";
|
||||
|
||||
export interface SkeletonLoadingDetail {
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
interface ArrivingParts {
|
||||
/* The whole content, when it was hidden rather than its parts */
|
||||
content: Element[];
|
||||
opacityParts: (HTMLElement | SVGElement)[];
|
||||
colorParts: HTMLElement[];
|
||||
}
|
||||
|
||||
/* Transitions are held off too, so a part hides at once rather than easing
|
||||
out from under its skeleton */
|
||||
type HiddenProperty = "opacity" | "color" | "transition";
|
||||
|
||||
interface HiddenStyle {
|
||||
/* The inline value from before anything hid it */
|
||||
value: string;
|
||||
/* The value it was hidden with */
|
||||
hidden: string;
|
||||
holders: number;
|
||||
}
|
||||
|
||||
/* Overlays nest, as a stack card's cards each have their own, so two can
|
||||
hide the same element. The first to hide one notes the value it really
|
||||
had, and only the last to let go puts that back, so neither keeps the
|
||||
other's hidden value as the one to restore. */
|
||||
const hiddenStyles: Record<
|
||||
HiddenProperty,
|
||||
Map<HTMLElement | SVGElement, HiddenStyle>
|
||||
> = { opacity: new Map(), color: new Map(), transition: new Map() };
|
||||
|
||||
const hideStyle = (
|
||||
element: HTMLElement | SVGElement,
|
||||
name: HiddenProperty,
|
||||
hidden: string
|
||||
) => {
|
||||
const held = hiddenStyles[name].get(element);
|
||||
|
||||
if (held) {
|
||||
held.holders++;
|
||||
} else {
|
||||
hiddenStyles[name].set(element, {
|
||||
value: element.style[name],
|
||||
hidden,
|
||||
holders: 1,
|
||||
});
|
||||
}
|
||||
|
||||
element.style[name] = hidden;
|
||||
};
|
||||
|
||||
const releaseStyle = (
|
||||
element: HTMLElement | SVGElement,
|
||||
name: HiddenProperty
|
||||
) => {
|
||||
const held = hiddenStyles[name].get(element);
|
||||
|
||||
if (!held) {
|
||||
return;
|
||||
}
|
||||
|
||||
held.holders--;
|
||||
|
||||
if (held.holders === 0) {
|
||||
// Content that set its own value while it was hidden keeps that one
|
||||
if (element.style[name] === held.hidden) {
|
||||
element.style[name] = held.value;
|
||||
}
|
||||
|
||||
hiddenStyles[name].delete(element);
|
||||
}
|
||||
};
|
||||
|
||||
const holdersOf = (element: HTMLElement | SVGElement, name: HiddenProperty) =>
|
||||
hiddenStyles[name].get(element)?.holders ?? 0;
|
||||
|
||||
/* What's left out with data-skeleton="none" under an element, through
|
||||
shadow roots, as the skeleton is read */
|
||||
const leftOut = (root: Element | ShadowRoot): HTMLElement[] =>
|
||||
[...root.querySelectorAll("*")].flatMap((element) => [
|
||||
...(element instanceof HTMLElement && element.dataset.skeleton === "none"
|
||||
? [element]
|
||||
: []),
|
||||
...(element.shadowRoot ? leftOut(element.shadowRoot) : []),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Shows a skeleton of its content while that content loads, read from the
|
||||
* content itself: each line of text, icon, image, control and drawing gets
|
||||
* its own piece. When loading ends, the pieces go and each part fades in.
|
||||
*
|
||||
* Loading is on while `loading` is set, or while anything inside has fired
|
||||
* a `skeleton-loading` event with `{ loading: true }` and not yet
|
||||
* `{ loading: false }`. The event stops at the nearest overlay, so content
|
||||
* doesn't need to know what wraps it.
|
||||
*
|
||||
* To take over:
|
||||
* - put your own skeleton in the `skeleton` slot, and it's used instead of
|
||||
* reading one
|
||||
* - set `data-skeleton` on any element inside, as described in
|
||||
* `extract-skeleton`, to change how that part is read or leave it out
|
||||
* - call `refresh()` when the content changes without changing size
|
||||
*
|
||||
* With nothing to read yet, such as before the content's code has loaded,
|
||||
* it fills itself with one plain wave. The skeleton follows the host's
|
||||
* corner radius.
|
||||
*
|
||||
* @slot - The content.
|
||||
* @slot skeleton - A skeleton of your own, used instead of reading one.
|
||||
*/
|
||||
@customElement("ha-skeleton-overlay")
|
||||
export class HaSkeletonOverlay extends LitElement {
|
||||
@property({ type: Boolean }) public loading = false;
|
||||
|
||||
@property() public effect: HaSkeleton["effect"] = "sheen";
|
||||
|
||||
@state()
|
||||
@consume({ context: internationalizationContext, subscribe: true })
|
||||
private _i18n?: ContextType<typeof internationalizationContext>;
|
||||
|
||||
/* What's inside that has said it's loading */
|
||||
@state() private _loadingSources = new Set<EventTarget>();
|
||||
|
||||
@state() private _pieces?: SkeletonPiece[];
|
||||
|
||||
@state() private _customSkeleton = false;
|
||||
|
||||
@state() private _onScreen = true;
|
||||
|
||||
@query("slot:not([name])") private _contentSlot?: HTMLSlotElement;
|
||||
|
||||
/* The parts this overlay hides, through hideStyle */
|
||||
private _hiddenOpacity = new Set<HTMLElement | SVGElement>();
|
||||
|
||||
private _hiddenColor = new Set<HTMLElement>();
|
||||
|
||||
private _heldTransition = new Set<HTMLElement | SVGElement>();
|
||||
|
||||
/* Inline colours of content left out inside hidden text, which keeps its
|
||||
own colour meanwhile */
|
||||
private _keptColor = new Map<HTMLElement, string>();
|
||||
|
||||
/* Whether the content was inert before loading made it so */
|
||||
private _hiddenInert = new Map<HTMLElement, boolean>();
|
||||
|
||||
private _wasLoading = false;
|
||||
|
||||
/* What to fade in once loading has ended */
|
||||
private _arriving?: ArrivingParts;
|
||||
|
||||
/* The fades still running from the last time loading ended */
|
||||
private _fades: Animation[] = [];
|
||||
|
||||
private _measureFrame?: number;
|
||||
|
||||
private _resizeObserver = new ResizeObserver(() => this._scheduleMeasure());
|
||||
|
||||
private _intersectionObserver = new IntersectionObserver((entries) => {
|
||||
this._onScreen = entries[entries.length - 1].isIntersecting;
|
||||
});
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// On the host rather than the slot, so content that says it's loading
|
||||
// as it connects, before the first render, is heard
|
||||
this.addEventListener("skeleton-loading", this._skeletonLoading);
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._resizeObserver.observe(this);
|
||||
this._intersectionObserver.observe(this);
|
||||
this._syncInert();
|
||||
this._scheduleMeasure();
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._resizeObserver.disconnect();
|
||||
this._intersectionObserver.disconnect();
|
||||
|
||||
if (this._measureFrame !== undefined) {
|
||||
cancelAnimationFrame(this._measureFrame);
|
||||
this._measureFrame = undefined;
|
||||
}
|
||||
|
||||
// Never leave the content hidden or unusable while it's away
|
||||
this._cancelFades();
|
||||
this._showParts();
|
||||
this._restoreInert();
|
||||
}
|
||||
|
||||
/** Read the skeleton again, after the content changed but not its size */
|
||||
public refresh() {
|
||||
this._scheduleMeasure();
|
||||
}
|
||||
|
||||
private get _isLoading() {
|
||||
return this.loading || this._loadingSources.size > 0;
|
||||
}
|
||||
|
||||
protected willUpdate(changedProperties: PropertyValues<this>) {
|
||||
super.willUpdate(changedProperties);
|
||||
const loading = this._isLoading;
|
||||
|
||||
if (loading && !this._wasLoading) {
|
||||
// A fade still running would show the content over the hidden style
|
||||
this._cancelFades();
|
||||
this._customSkeleton = [...this.children].some(
|
||||
(child) => child.slot === "skeleton"
|
||||
);
|
||||
}
|
||||
|
||||
if (!loading && this._wasLoading) {
|
||||
this._endLoading();
|
||||
}
|
||||
|
||||
this._wasLoading = loading;
|
||||
}
|
||||
|
||||
protected updated(changedProperties: PropertyValues<this>) {
|
||||
super.updated(changedProperties);
|
||||
|
||||
// Only when loading starts: loading events, slot changes, sizes and
|
||||
// refresh() ask for their own, and measuring after every update would
|
||||
// run each frame for content that animates, such as a spinner, as every
|
||||
// reading comes out different and updates again
|
||||
if (this._isLoading && changedProperties.has("loading")) {
|
||||
this._scheduleMeasure();
|
||||
}
|
||||
|
||||
this._syncInert();
|
||||
|
||||
if (this._arriving) {
|
||||
this._fadeIn(this._arriving);
|
||||
this._arriving = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const loading = this._isLoading;
|
||||
// Named like ha-spinner, which falls back to English before translations
|
||||
// have loaded
|
||||
const label = this._i18n?.localize("ui.common.loading") || "Loading";
|
||||
|
||||
return html`
|
||||
<slot
|
||||
class=${classMap({
|
||||
// Before the first reading, or under a skeleton of your own
|
||||
hidden:
|
||||
loading && (this._customSkeleton || this._pieces === undefined),
|
||||
})}
|
||||
@slotchange=${this._contentChanged}
|
||||
></slot>
|
||||
${
|
||||
loading
|
||||
? html`
|
||||
<div class="skeleton" role="progressbar" aria-label=${label}>
|
||||
<slot
|
||||
name="skeleton"
|
||||
@slotchange=${this._skeletonSlotChanged}
|
||||
></slot>
|
||||
${this._customSkeleton ? nothing : this._renderPieces()}
|
||||
</div>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderPieces() {
|
||||
// Nothing still animates off screen
|
||||
const effect = this._onScreen ? this.effect : "none";
|
||||
|
||||
if (!this._pieces?.length) {
|
||||
return html`<ha-skeleton class="fill" .effect=${effect}></ha-skeleton>`;
|
||||
}
|
||||
|
||||
return this._pieces.map((piece) =>
|
||||
piece.kind === "scrim"
|
||||
? html`<div class="piece" style=${pieceStyle(piece)}></div>`
|
||||
: html`<ha-skeleton
|
||||
class=${classMap({
|
||||
piece: true,
|
||||
[piece.kind]: true,
|
||||
"on-dark": Boolean(piece.onDark),
|
||||
})}
|
||||
.effect=${effect}
|
||||
style=${pieceStyle(piece)}
|
||||
></ha-skeleton>`
|
||||
);
|
||||
}
|
||||
|
||||
private _skeletonLoading = (ev: HASSDomEvent<SkeletonLoadingDetail>) => {
|
||||
// The nearest overlay owns it
|
||||
ev.stopPropagation();
|
||||
const source = ev.composedPath()[0];
|
||||
const sources = new Set(this._loadingSources);
|
||||
|
||||
if (ev.detail.loading) {
|
||||
sources.add(source);
|
||||
} else {
|
||||
sources.delete(source);
|
||||
}
|
||||
|
||||
this._loadingSources = sources;
|
||||
this._scheduleMeasure();
|
||||
};
|
||||
|
||||
private _contentChanged() {
|
||||
this._resizeObserver.disconnect();
|
||||
this._resizeObserver.observe(this);
|
||||
this._contentSlot
|
||||
?.assignedElements()
|
||||
.forEach((element) => this._resizeObserver.observe(element));
|
||||
|
||||
this._pruneSources();
|
||||
this._syncInert();
|
||||
this._scheduleMeasure();
|
||||
}
|
||||
|
||||
/* Content that went away, or moved out of this overlay, can't finish
|
||||
loading here. Removing it deep inside a card fires no slotchange, so
|
||||
this runs on every measure too, which any change of size starts. */
|
||||
private _pruneSources() {
|
||||
const sources = [...this._loadingSources].filter((source) =>
|
||||
this._holds(source)
|
||||
);
|
||||
|
||||
if (sources.length !== this._loadingSources.size) {
|
||||
this._loadingSources = new Set(sources);
|
||||
}
|
||||
}
|
||||
|
||||
/* Whether a source is still inside this overlay, the way its events
|
||||
travel: through the slots content shows in, and out of shadow roots */
|
||||
private _holds(source: EventTarget) {
|
||||
if (!(source instanceof Node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let node: Node | null = source;
|
||||
|
||||
while (node) {
|
||||
if (node === this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
node =
|
||||
node instanceof ShadowRoot
|
||||
? node.host
|
||||
: ((node instanceof Element || node instanceof Text
|
||||
? node.assignedSlot
|
||||
: null) ?? node.parentNode);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private _skeletonSlotChanged(ev: Event) {
|
||||
const slot = ev.target;
|
||||
|
||||
if (!(slot instanceof HTMLSlotElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._customSkeleton = slot.assignedNodes({ flatten: true }).length > 0;
|
||||
|
||||
if (this._customSkeleton) {
|
||||
// The whole content is hidden under it instead
|
||||
this._showParts();
|
||||
this._pieces = undefined;
|
||||
} else {
|
||||
// Read from the content again now it's gone
|
||||
this._scheduleMeasure();
|
||||
}
|
||||
}
|
||||
|
||||
private _scheduleMeasure() {
|
||||
if (this._measureFrame !== undefined || !this.isConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._measureFrame = requestAnimationFrame(() => {
|
||||
this._measureFrame = undefined;
|
||||
this._measure();
|
||||
});
|
||||
}
|
||||
|
||||
/* Read the skeleton from the content, and hide the parts it stands in for */
|
||||
private _measure() {
|
||||
this._pruneSources();
|
||||
|
||||
if (!this._isLoading || this._customSkeleton) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Read from the content as it really looks, then hide it again before
|
||||
// the next paint, so nothing flickers
|
||||
this._showParts();
|
||||
const skeleton = extractSkeleton(this, this.getBoundingClientRect());
|
||||
this._hideParts(skeleton);
|
||||
|
||||
if (JSON.stringify(skeleton.pieces) !== JSON.stringify(this._pieces)) {
|
||||
this._pieces = skeleton.pieces;
|
||||
}
|
||||
}
|
||||
|
||||
private _hideParts(skeleton: ExtractedSkeleton) {
|
||||
skeleton.parts.forEach((part) => {
|
||||
if (!this._hiddenOpacity.has(part)) {
|
||||
this._hiddenOpacity.add(part);
|
||||
hideStyle(part, "opacity", "0");
|
||||
}
|
||||
});
|
||||
|
||||
// What's left out with data-skeleton="none" inside text that's hidden
|
||||
// keeps the colour it has now, rather than taking the transparent one.
|
||||
// Read before any text is hidden.
|
||||
const kept = skeleton.textParts.flatMap((part) =>
|
||||
leftOut(part).map(
|
||||
(element) => [element, getComputedStyle(element).color] as const
|
||||
)
|
||||
);
|
||||
|
||||
// Text goes through its colour, so a frame drawn by the same element,
|
||||
// such as a badge's pill, stays
|
||||
skeleton.textParts.forEach((part) => {
|
||||
if (!this._hiddenColor.has(part)) {
|
||||
this._hiddenColor.add(part);
|
||||
hideStyle(part, "color", "transparent");
|
||||
}
|
||||
});
|
||||
|
||||
kept.forEach(([element, color]) => {
|
||||
if (!this._keptColor.has(element)) {
|
||||
this._keptColor.set(element, element.style.color);
|
||||
}
|
||||
|
||||
element.style.color = color;
|
||||
});
|
||||
|
||||
// In the same frame as the hiding, so no transition runs on it
|
||||
[...skeleton.parts, ...skeleton.textParts].forEach((part) => {
|
||||
if (!this._heldTransition.has(part)) {
|
||||
this._heldTransition.add(part);
|
||||
hideStyle(part, "transition", "none");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _showParts() {
|
||||
this._hiddenOpacity.forEach((part) => releaseStyle(part, "opacity"));
|
||||
this._hiddenColor.forEach((part) => releaseStyle(part, "color"));
|
||||
this._keptColor.forEach((color, element) => {
|
||||
element.style.color = color;
|
||||
});
|
||||
this._heldTransition.forEach((part) => releaseStyle(part, "transition"));
|
||||
this._hiddenOpacity.clear();
|
||||
this._hiddenColor.clear();
|
||||
this._keptColor.clear();
|
||||
this._heldTransition.clear();
|
||||
}
|
||||
|
||||
/* The whole content can't be focused, used or read out while it loads,
|
||||
including frames around the hidden parts, such as a card that takes
|
||||
clicks. Content that has left, or finished, gets its own state back. */
|
||||
private _syncInert() {
|
||||
const loading = this.isConnected && this._isLoading;
|
||||
|
||||
const content = new Set(
|
||||
loading ? (this._contentSlot?.assignedElements() ?? []) : []
|
||||
);
|
||||
|
||||
this._hiddenInert.forEach((inert, element) => {
|
||||
if (!content.has(element)) {
|
||||
element.inert = inert;
|
||||
this._hiddenInert.delete(element);
|
||||
}
|
||||
});
|
||||
|
||||
content.forEach((element) => {
|
||||
if (element instanceof HTMLElement && !this._hiddenInert.has(element)) {
|
||||
this._hiddenInert.set(element, element.inert);
|
||||
element.inert = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _restoreInert() {
|
||||
this._hiddenInert.forEach((inert, element) => {
|
||||
element.inert = inert;
|
||||
});
|
||||
this._hiddenInert.clear();
|
||||
}
|
||||
|
||||
/* Show the content again before the next paint, and note what to fade in */
|
||||
private _endLoading() {
|
||||
// Under a skeleton of its own, or before the first reading, the whole
|
||||
// content was hidden rather than its parts
|
||||
const wholeContent = this._customSkeleton || this._pieces === undefined;
|
||||
|
||||
this._arriving = {
|
||||
content: wholeContent
|
||||
? (this._contentSlot?.assignedElements() ?? [])
|
||||
: [],
|
||||
// Only what this overlay is the last to hide shows now; a part a
|
||||
// nested overlay still hides stays hidden, and fades in with that one
|
||||
opacityParts: [...this._hiddenOpacity].filter(
|
||||
(part) => holdersOf(part, "opacity") === 1
|
||||
),
|
||||
colorParts: [...this._hiddenColor].filter(
|
||||
(part) => holdersOf(part, "color") === 1
|
||||
),
|
||||
};
|
||||
|
||||
this._showParts();
|
||||
this._pieces = undefined;
|
||||
}
|
||||
|
||||
/* Fade each arriving part in, instantly with reduced motion */
|
||||
private _fadeIn({ content, opacityParts, colorParts }: ArrivingParts) {
|
||||
// In ms or s, as the token can be either; 150ms only when it isn't set
|
||||
const token = getComputedStyle(this)
|
||||
.getPropertyValue("--ha-animation-duration-fast")
|
||||
.trim();
|
||||
|
||||
const fade: KeyframeAnimationOptions = {
|
||||
duration: token ? parseAnimationDuration(token) : 150,
|
||||
easing: "ease-out",
|
||||
};
|
||||
|
||||
this._fades = [
|
||||
// To each part's own opacity, which isn't always 1
|
||||
...[...content, ...opacityParts].map((part) => {
|
||||
const opacity = getComputedStyle(part).opacity;
|
||||
|
||||
return part.animate([{ opacity: 0 }, { opacity }], fade);
|
||||
}),
|
||||
...colorParts.map((part) => {
|
||||
const color = getComputedStyle(part).color;
|
||||
|
||||
return part.animate([{ color: "transparent" }, { color }], fade);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
private _cancelFades() {
|
||||
this._fades.forEach((fade) => fade.cancel());
|
||||
this._fades = [];
|
||||
}
|
||||
|
||||
static readonly styles: CSSResultGroup = css`
|
||||
:host {
|
||||
display: block;
|
||||
position: relative;
|
||||
}
|
||||
slot.hidden::slotted(*) {
|
||||
opacity: 0;
|
||||
}
|
||||
.skeleton {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
overflow: hidden;
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
}
|
||||
/* Rounded by the layer it fills, which follows the host */
|
||||
.fill {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
--ha-skeleton-border-radius: 0;
|
||||
}
|
||||
.piece {
|
||||
position: absolute;
|
||||
min-height: 0;
|
||||
}
|
||||
.piece.round {
|
||||
--ha-skeleton-border-radius: var(--ha-border-radius-circle);
|
||||
}
|
||||
.piece.shape {
|
||||
--ha-skeleton-border-radius: 0;
|
||||
mask-size: 100% 100%;
|
||||
-webkit-mask-size: 100% 100%;
|
||||
mask-repeat: no-repeat;
|
||||
-webkit-mask-repeat: no-repeat;
|
||||
}
|
||||
/* Text and icons on a dark bar over a picture */
|
||||
.piece.on-dark {
|
||||
--ha-skeleton-color: rgba(255, 255, 255, 0.3);
|
||||
--ha-skeleton-sheen-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
const pieceStyle = ({ maskBox, ...piece }: SkeletonPiece) => {
|
||||
const maskPosition = maskBox ? `${maskBox.x}px ${maskBox.y}px` : undefined;
|
||||
|
||||
const maskSize = maskBox
|
||||
? `${maskBox.width}px ${maskBox.height}px`
|
||||
: undefined;
|
||||
|
||||
return styleMap({
|
||||
left: `${piece.x}px`,
|
||||
top: `${piece.y}px`,
|
||||
width: `${piece.width}px`,
|
||||
height: `${piece.height}px`,
|
||||
"--ha-skeleton-border-radius": piece.radius,
|
||||
"border-radius": piece.kind === "scrim" ? piece.radius : undefined,
|
||||
"background-color": piece.background,
|
||||
"mask-image": piece.mask,
|
||||
"-webkit-mask-image": piece.mask,
|
||||
"mask-position": maskPosition,
|
||||
"-webkit-mask-position": maskPosition,
|
||||
"mask-size": maskSize,
|
||||
"-webkit-mask-size": maskSize,
|
||||
});
|
||||
};
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-skeleton-overlay": HaSkeletonOverlay;
|
||||
}
|
||||
|
||||
interface HASSDomEvents {
|
||||
"skeleton-loading": SkeletonLoadingDetail;
|
||||
}
|
||||
|
||||
// for add event listener
|
||||
interface HTMLElementEventMap {
|
||||
"skeleton-loading": HASSDomEvent<HASSDomEvents["skeleton-loading"]>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import type { nothing, TemplateResult } from "lit";
|
||||
import { css, html } from "lit";
|
||||
import type {
|
||||
ChildPart,
|
||||
DirectiveParameters,
|
||||
DirectiveResult,
|
||||
PartInfo,
|
||||
} from "lit/directive";
|
||||
import { Directive, directive, PartType } from "lit/directive";
|
||||
import { parseAnimationDuration } from "../../common/util/parse-animation-duration";
|
||||
|
||||
/* What a skeleton or its content can be rendered as */
|
||||
type SkeletonOrValue =
|
||||
| TemplateResult
|
||||
| DirectiveResult
|
||||
| string
|
||||
| number
|
||||
| typeof nothing
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
/**
|
||||
* Content that takes a skeleton's place fades in, so it doesn't pop in. It
|
||||
* runs at the same pace as `ha-skeleton-overlay`, `--ha-animation-duration-fast`,
|
||||
* which reduced motion makes instant.
|
||||
*/
|
||||
|
||||
const ARRIVAL_KEYFRAMES: Keyframe[] = [{ opacity: 0 }, { opacity: 1 }];
|
||||
|
||||
/**
|
||||
* Fade in an element that takes a skeleton's place but was already on the
|
||||
* page, such as a log that fills in while its skeleton shows.
|
||||
*/
|
||||
export const fadeInArrival = (element: Element) => {
|
||||
// In ms or s, as the token can be either; 150ms only when it isn't set
|
||||
const token = getComputedStyle(element)
|
||||
.getPropertyValue("--ha-animation-duration-fast")
|
||||
.trim();
|
||||
|
||||
const duration = token ? parseAnimationDuration(token) : 150;
|
||||
|
||||
element.animate(ARRIVAL_KEYFRAMES, { duration, easing: "ease-out" });
|
||||
};
|
||||
|
||||
/**
|
||||
* For a whole block that replaces a skeleton: put the `arriving` class on it,
|
||||
* and it fades in once, when it first appears. Where it can appear again
|
||||
* without a skeleton before it, use `skeletonOr` instead.
|
||||
*/
|
||||
export const skeletonArrivalStyles = css`
|
||||
.arriving {
|
||||
animation: ha-skeleton-arrival var(--ha-animation-duration-fast, 150ms)
|
||||
ease-out;
|
||||
}
|
||||
@keyframes ha-skeleton-arrival {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
class SkeletonOrDirective extends Directive {
|
||||
/* What this spot showed last time */
|
||||
private _showedSkeleton = false;
|
||||
|
||||
/* Text needs an element to fade, so it's wrapped once it has arrived */
|
||||
private _wrapText = false;
|
||||
|
||||
constructor(partInfo: PartInfo) {
|
||||
super(partInfo);
|
||||
|
||||
if (partInfo.type !== PartType.CHILD) {
|
||||
throw new Error("skeletonOr can only be used in content bindings");
|
||||
}
|
||||
}
|
||||
|
||||
public render(
|
||||
loading: boolean,
|
||||
skeleton: SkeletonOrValue,
|
||||
content: () => SkeletonOrValue
|
||||
): SkeletonOrValue {
|
||||
if (loading) {
|
||||
return skeleton;
|
||||
}
|
||||
|
||||
const value = content();
|
||||
|
||||
return this._wrapText &&
|
||||
(typeof value === "string" || typeof value === "number")
|
||||
? html`<span>${value}</span>`
|
||||
: value;
|
||||
}
|
||||
|
||||
public update(
|
||||
part: ChildPart,
|
||||
[loading, skeleton, content]: DirectiveParameters<this>
|
||||
) {
|
||||
const arriving = !loading && this._showedSkeleton;
|
||||
this._showedSkeleton = loading;
|
||||
|
||||
if (arriving) {
|
||||
this._wrapText = true;
|
||||
|
||||
// Fade in what was rendered, once it's on the page
|
||||
requestAnimationFrame(() => {
|
||||
// Loading again before this frame: what's there now is a skeleton
|
||||
if (this._showedSkeleton) {
|
||||
return;
|
||||
}
|
||||
|
||||
let node = part.startNode?.nextSibling;
|
||||
|
||||
while (node && node !== part.endNode) {
|
||||
if (node instanceof Element) {
|
||||
fadeInArrival(node);
|
||||
}
|
||||
|
||||
node = node.nextSibling;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this.render(loading, skeleton, content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows `skeleton` while `loading`, then `content`. When this spot switches
|
||||
* from the skeleton to the content, the content fades in. A spot that never
|
||||
* showed a skeleton, such as a table row made as the table scrolls, shows its
|
||||
* content at once.
|
||||
*
|
||||
* Content that's only text is wrapped so it can fade. In a template, put text
|
||||
* in an element of its own, as only elements fade.
|
||||
*/
|
||||
export const skeletonOr = directive(SkeletonOrDirective);
|
||||
@@ -1,6 +1,7 @@
|
||||
import "../skeleton/ha-skeleton-text";
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { skeletonOr } from "../skeleton/skeleton-arrival";
|
||||
|
||||
/**
|
||||
* Home Assistant tile info component
|
||||
@@ -46,15 +47,16 @@ export class HaTileInfo extends LitElement {
|
||||
<slot name="primary" class="primary">
|
||||
<span part="primary">${this.primary}</span>
|
||||
</slot>
|
||||
${
|
||||
this.secondaryLoading
|
||||
? html`<div class="secondary">
|
||||
<ha-skeleton-text></ha-skeleton-text>
|
||||
</div>`
|
||||
: html`<slot name="secondary" class="secondary">
|
||||
<span>${this.secondary}</span>
|
||||
</slot>`
|
||||
}
|
||||
${skeletonOr(
|
||||
this.secondaryLoading,
|
||||
html`<div class="secondary">
|
||||
<ha-skeleton-text></ha-skeleton-text>
|
||||
</div>`,
|
||||
() =>
|
||||
html`<slot name="secondary" class="secondary">
|
||||
<span>${this.secondary}</span>
|
||||
</slot>`
|
||||
)}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import "../../../../components/skeleton/ha-skeleton-text";
|
||||
import type { HassConfig } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { skeletonOr } from "../../../../components/skeleton/skeleton-arrival";
|
||||
import { consume } from "../../../../common/decorators/consume";
|
||||
import { isComponentLoaded } from "../../../../common/config/is_component_loaded";
|
||||
import { relativeTime } from "../../../../common/datetime/relative_time";
|
||||
@@ -106,32 +107,33 @@ export class HaMoreInfoUpdateBackup extends LitElement {
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-row-item
|
||||
.headline=${createBackupTexts ? createBackupTexts.title : undefined}
|
||||
.supportingText=${
|
||||
createBackupTexts ? createBackupTexts.description : undefined
|
||||
}
|
||||
>
|
||||
${
|
||||
!createBackupTexts
|
||||
? html`<ha-fade-in slot="headline" .delay=${500}
|
||||
><ha-skeleton-text></ha-skeleton-text
|
||||
></ha-fade-in>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
this._createBackupLoading
|
||||
? html`<ha-fade-in class="skeleton-end" slot="end" .delay=${500}
|
||||
><ha-skeleton></ha-skeleton
|
||||
></ha-fade-in>`
|
||||
: html`<ha-switch
|
||||
slot="end"
|
||||
.accessibleLabel=${createBackupTexts?.title ?? ""}
|
||||
.checked=${this._createBackup}
|
||||
@change=${this._createBackupChanged}
|
||||
.disabled=${this.disabled || updateIsInstalling(this.stateObj)}
|
||||
></ha-switch>`
|
||||
}
|
||||
<ha-row-item>
|
||||
${skeletonOr(
|
||||
!createBackupTexts,
|
||||
html`<ha-fade-in slot="headline" .delay=${500}
|
||||
><ha-skeleton-text></ha-skeleton-text
|
||||
></ha-fade-in>`,
|
||||
// Only text that took the skeleton's place fades in
|
||||
() =>
|
||||
html`<span slot="headline">${createBackupTexts?.title}</span
|
||||
><span slot="supporting-text"
|
||||
>${createBackupTexts?.description}</span
|
||||
>`
|
||||
)}
|
||||
${skeletonOr(
|
||||
this._createBackupLoading,
|
||||
html`<ha-fade-in class="skeleton-end" slot="end" .delay=${500}
|
||||
><ha-skeleton></ha-skeleton
|
||||
></ha-fade-in>`,
|
||||
() =>
|
||||
html`<ha-switch
|
||||
slot="end"
|
||||
.accessibleLabel=${createBackupTexts?.title ?? ""}
|
||||
.checked=${this._createBackup}
|
||||
@change=${this._createBackupChanged}
|
||||
.disabled=${this.disabled || updateIsInstalling(this.stateObj!)}
|
||||
></ha-switch>`
|
||||
)}
|
||||
</ha-row-item>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { consume } from "../common/decorators/consume";
|
||||
import "../components/ha-card";
|
||||
import "../components/ha-ripple";
|
||||
import "../components/ha-svg-icon";
|
||||
import { skeletonOr } from "../components/skeleton/skeleton-arrival";
|
||||
import { translationsReadyContext } from "../mixins/lit-localize-lite-mixin";
|
||||
import { renderSkeleton, skeletonStyles } from "./render-skeleton";
|
||||
|
||||
@@ -29,7 +30,11 @@ class OnboardingWelcomeLink extends LitElement {
|
||||
@keydown=${this._handleKeyDown}
|
||||
>
|
||||
<ha-svg-icon .path=${this.iconPath}></ha-svg-icon>
|
||||
${this._translationsReady === false ? renderSkeleton("label") : this.label}
|
||||
${skeletonOr(
|
||||
this._translationsReady === false,
|
||||
renderSkeleton("label"),
|
||||
() => this.label
|
||||
)}
|
||||
<ha-ripple></ha-ripple>
|
||||
</ha-card>
|
||||
`;
|
||||
|
||||
@@ -10,6 +10,7 @@ import "../components/ha-button";
|
||||
import "../components/ha-icon-next";
|
||||
import "../components/item/ha-list-item-button";
|
||||
import "../components/list/ha-list-base";
|
||||
import { skeletonOr } from "../components/skeleton/skeleton-arrival";
|
||||
import { translationsReadyContext } from "../mixins/lit-localize-lite-mixin";
|
||||
import { renderSkeleton, skeletonStyles } from "./render-skeleton";
|
||||
import { onBoardingStyles } from "./styles";
|
||||
@@ -28,38 +29,36 @@ class OnboardingWelcome extends LitElement {
|
||||
const ready = this._translationsReady;
|
||||
return html`
|
||||
<h1>
|
||||
${
|
||||
ready
|
||||
? this._localize("ui.panel.page-onboarding.welcome.header")
|
||||
: renderSkeleton("title")
|
||||
}
|
||||
${skeletonOr(!ready, renderSkeleton("title"), () =>
|
||||
this._localize("ui.panel.page-onboarding.welcome.header")
|
||||
)}
|
||||
</h1>
|
||||
<p>
|
||||
${
|
||||
ready
|
||||
? this._localize("ui.panel.page-onboarding.intro")
|
||||
: renderSkeleton("line")
|
||||
}
|
||||
${skeletonOr(!ready, renderSkeleton("line"), () =>
|
||||
this._localize("ui.panel.page-onboarding.intro")
|
||||
)}
|
||||
</p>
|
||||
|
||||
<ha-button @click=${this._start} class="start" .disabled=${!ready}>
|
||||
${
|
||||
ready
|
||||
? this._localize("ui.panel.page-onboarding.welcome.start")
|
||||
: renderSkeleton("button")
|
||||
}
|
||||
${skeletonOr(!ready, renderSkeleton("button"), () =>
|
||||
this._localize("ui.panel.page-onboarding.welcome.start")
|
||||
)}
|
||||
</ha-button>
|
||||
|
||||
<div class="divider">
|
||||
<wa-divider></wa-divider>
|
||||
<div>
|
||||
<span>
|
||||
${
|
||||
ready
|
||||
? this._localize("ui.panel.page-onboarding.welcome.or_restore")
|
||||
: renderSkeleton("chip")
|
||||
}
|
||||
</span>
|
||||
${skeletonOr(
|
||||
!ready,
|
||||
html`<span>${renderSkeleton("chip")}</span>`,
|
||||
// One padded span either way, as skeletonOr would wrap bare text
|
||||
() =>
|
||||
html`<span
|
||||
>${this._localize(
|
||||
"ui.panel.page-onboarding.welcome.or_restore"
|
||||
)}</span
|
||||
>`
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -69,22 +68,16 @@ class OnboardingWelcome extends LitElement {
|
||||
.disabled=${!ready}
|
||||
>
|
||||
<div slot="headline">
|
||||
${
|
||||
ready
|
||||
? this._localize(
|
||||
"ui.panel.page-onboarding.restore.upload_backup"
|
||||
)
|
||||
: renderSkeleton("headline")
|
||||
}
|
||||
${skeletonOr(!ready, renderSkeleton("headline"), () =>
|
||||
this._localize("ui.panel.page-onboarding.restore.upload_backup")
|
||||
)}
|
||||
</div>
|
||||
<div slot="supporting-text">
|
||||
${
|
||||
ready
|
||||
? this._localize(
|
||||
"ui.panel.page-onboarding.restore.options.upload_description"
|
||||
)
|
||||
: renderSkeleton("line")
|
||||
}
|
||||
${skeletonOr(!ready, renderSkeleton("line"), () =>
|
||||
this._localize(
|
||||
"ui.panel.page-onboarding.restore.options.upload_description"
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<ha-icon-next slot="end"></ha-icon-next>
|
||||
</ha-list-item-button>
|
||||
@@ -93,16 +86,18 @@ class OnboardingWelcome extends LitElement {
|
||||
.disabled=${!ready}
|
||||
>
|
||||
<div slot="headline">
|
||||
${ready ? "Home Assistant Link" : renderSkeleton("headline")}
|
||||
${skeletonOr(
|
||||
!ready,
|
||||
renderSkeleton("headline"),
|
||||
() => "Home Assistant Link"
|
||||
)}
|
||||
</div>
|
||||
<div slot="supporting-text">
|
||||
${
|
||||
ready
|
||||
? this._localize(
|
||||
"ui.panel.page-onboarding.restore.ha-cloud.description"
|
||||
)
|
||||
: renderSkeleton("line")
|
||||
}
|
||||
${skeletonOr(!ready, renderSkeleton("line"), () =>
|
||||
this._localize(
|
||||
"ui.panel.page-onboarding.restore.ha-cloud.description"
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<ha-icon-next slot="end"></ha-icon-next>
|
||||
</ha-list-item-button>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
state,
|
||||
} from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { consume } from "../../../../common/decorators/consume";
|
||||
@@ -27,6 +28,7 @@ import "../../../../components/item/ha-list-item-button";
|
||||
import "../../../../components/list/ha-list-base";
|
||||
import "../../../../components/skeleton/ha-skeleton";
|
||||
import "../../../../components/skeleton/ha-skeleton-text";
|
||||
import { skeletonOr } from "../../../../components/skeleton/skeleton-arrival";
|
||||
import type { ConfigEntry } from "../../../../data/config_entries";
|
||||
import {
|
||||
configEntriesContext,
|
||||
@@ -135,39 +137,39 @@ export class HaAutomationAddItems extends LitElement {
|
||||
})}
|
||||
@scroll=${this._onItemsScroll}
|
||||
>
|
||||
${
|
||||
this.loadingLabel
|
||||
? html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<div
|
||||
class="skeletons"
|
||||
role="progressbar"
|
||||
aria-label=${this.loadingLabel}
|
||||
>
|
||||
<ha-skeleton-text></ha-skeleton-text>
|
||||
<ha-skeleton></ha-skeleton>
|
||||
<ha-skeleton></ha-skeleton>
|
||||
<ha-skeleton></ha-skeleton>
|
||||
</div>
|
||||
</ha-fade-in>`
|
||||
: !this.items && !this.error
|
||||
${skeletonOr(
|
||||
Boolean(this.loadingLabel),
|
||||
html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<div
|
||||
class="skeletons"
|
||||
role="progressbar"
|
||||
aria-label=${ifDefined(this.loadingLabel)}
|
||||
>
|
||||
<ha-skeleton-text></ha-skeleton-text>
|
||||
<ha-skeleton></ha-skeleton>
|
||||
<ha-skeleton></ha-skeleton>
|
||||
<ha-skeleton></ha-skeleton>
|
||||
</div>
|
||||
</ha-fade-in>`,
|
||||
() =>
|
||||
!this.items && !this.error
|
||||
? this.selectLabel
|
||||
: this.error
|
||||
? html`${this.error}
|
||||
? html`<span>${this.error}</span>
|
||||
<div>${this._renderCurrentTarget()}</div>`
|
||||
: this.items && !this.items.length
|
||||
? html`${this.emptyLabel}
|
||||
${
|
||||
this.target
|
||||
? html`<div>${this._renderCurrentTarget()}</div>`
|
||||
: nothing
|
||||
}`
|
||||
? html`<span>${this.emptyLabel}</span> ${
|
||||
this.target
|
||||
? html`<div>${this._renderCurrentTarget()}</div>`
|
||||
: nothing
|
||||
}`
|
||||
: repeat(
|
||||
this.items,
|
||||
(_, index) => `item-group-${index}`,
|
||||
(itemGroup) =>
|
||||
this._renderItemList(itemGroup.title, itemGroup.items)
|
||||
)
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
<slot></slot>`;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import "../../../../../components/ha-icon-button";
|
||||
import "../../../../../components/ha-svg-icon";
|
||||
import "../../../../../components/item/ha-list-item-base";
|
||||
import "../../../../../components/list/ha-list-base";
|
||||
import "../../../../../components/skeleton/ha-skeleton-text";
|
||||
import { skeletonOr } from "../../../../../components/skeleton/skeleton-arrival";
|
||||
import type { BackupConfig, BackupContent } from "../../../../../data/backup";
|
||||
import {
|
||||
BACKUP_OVERDUE_MARGIN_HOURS,
|
||||
@@ -67,9 +69,11 @@ class HaBackupOverviewBackups extends LitElement {
|
||||
<ha-list-base>
|
||||
<ha-list-item-base wrap-headline>
|
||||
<ha-svg-icon slot="start" .path=${mdiBackupRestore}></ha-svg-icon>
|
||||
<span slot="headline" class=${headline === null ? "skeleton" : ""}
|
||||
>${headline}</span
|
||||
>
|
||||
${skeletonOr(
|
||||
headline === null,
|
||||
html`<ha-skeleton-text slot="headline"></ha-skeleton-text>`,
|
||||
() => html`<span slot="headline">${headline}</span>`
|
||||
)}
|
||||
</ha-list-item-base>
|
||||
${
|
||||
description || description === null
|
||||
@@ -79,12 +83,13 @@ class HaBackupOverviewBackups extends LitElement {
|
||||
slot="start"
|
||||
.path=${mdiCalendar}
|
||||
></ha-svg-icon>
|
||||
<span
|
||||
slot="headline"
|
||||
class=${description === null ? "skeleton" : ""}
|
||||
>${description}</span
|
||||
>
|
||||
|
||||
${skeletonOr(
|
||||
description === null,
|
||||
html`<ha-skeleton-text
|
||||
slot="headline"
|
||||
></ha-skeleton-text>`,
|
||||
() => html`<span slot="headline">${description}</span>`
|
||||
)}
|
||||
${
|
||||
lastCompletedDate
|
||||
? html`
|
||||
@@ -370,34 +375,8 @@ class HaBackupOverviewBackups extends LitElement {
|
||||
ha-list-item-base::part(start) {
|
||||
color: var(--ha-color-text-secondary);
|
||||
}
|
||||
span.skeleton {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: 160px;
|
||||
animation-fill-mode: forwards;
|
||||
animation-iteration-count: infinite;
|
||||
animation-name: loading;
|
||||
animation-timing-function: linear;
|
||||
animation-duration: 1.2s;
|
||||
border-radius: var(--ha-border-radius-sm);
|
||||
height: 16px;
|
||||
margin: 2px 0;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
var(--card-background-color) 8%,
|
||||
var(--secondary-background-color) 18%,
|
||||
var(--card-background-color) 33%
|
||||
)
|
||||
0% 0% / 936px 104px;
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
0% {
|
||||
background-position: -468px 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 468px 0;
|
||||
}
|
||||
ha-skeleton-text {
|
||||
--ha-skeleton-text-width: 160px;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -59,6 +59,7 @@ import "../../../components/ha-filter-states";
|
||||
import "../../../components/ha-icon-button";
|
||||
import "../../../components/skeleton/ha-skeleton-icon";
|
||||
import "../../../components/skeleton/ha-skeleton-text";
|
||||
import { skeletonOr } from "../../../components/skeleton/skeleton-arrival";
|
||||
import { createAreaRegistryEntry } from "../../../data/area/area_registry";
|
||||
import type { ConfigEntry, SubEntry } from "../../../data/config_entries";
|
||||
import { getSubEntries, sortConfigEntries } from "../../../data/config_entries";
|
||||
@@ -548,23 +549,26 @@ export class HaConfigDeviceDashboard extends LitElement {
|
||||
moveable: false,
|
||||
showNarrow: true,
|
||||
template: (device) =>
|
||||
!this.entries
|
||||
? html`<ha-skeleton-icon></ha-skeleton-icon>`
|
||||
: device.domains.length
|
||||
? html`<img
|
||||
alt=""
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: device.domains[0],
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>`
|
||||
: "",
|
||||
skeletonOr(
|
||||
!this.entries,
|
||||
html`<ha-skeleton-icon></ha-skeleton-icon>`,
|
||||
() =>
|
||||
device.domains.length
|
||||
? html`<img
|
||||
alt=""
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: device.domains[0],
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>`
|
||||
: ""
|
||||
),
|
||||
},
|
||||
name: {
|
||||
title: localize("ui.panel.config.devices.data_table.device"),
|
||||
@@ -586,17 +590,20 @@ export class HaConfigDeviceDashboard extends LitElement {
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
device.label_entries.length
|
||||
? html`
|
||||
<ha-data-table-labels
|
||||
.labels=${device.label_entries}
|
||||
></ha-data-table-labels>
|
||||
`
|
||||
: device.labels.length && !this._labels
|
||||
? html`<ha-skeleton-text></ha-skeleton-text>`
|
||||
${skeletonOr(
|
||||
!device.label_entries.length &&
|
||||
device.labels.length > 0 &&
|
||||
!this._labels,
|
||||
html`<ha-skeleton-text></ha-skeleton-text>`,
|
||||
() =>
|
||||
device.label_entries.length
|
||||
? html`
|
||||
<ha-data-table-labels
|
||||
.labels=${device.label_entries}
|
||||
></ha-data-table-labels>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
)}
|
||||
`,
|
||||
},
|
||||
area: getAreaTableColumn(localize),
|
||||
@@ -609,9 +616,11 @@ export class HaConfigDeviceDashboard extends LitElement {
|
||||
urlName: "integration",
|
||||
minWidth: "120px",
|
||||
template: (device) =>
|
||||
!this.entries
|
||||
? html`<ha-skeleton-text></ha-skeleton-text>`
|
||||
: device.integration,
|
||||
skeletonOr(
|
||||
!this.entries,
|
||||
html`<ha-skeleton-text></ha-skeleton-text>`,
|
||||
() => device.integration
|
||||
),
|
||||
},
|
||||
device_family_name: {
|
||||
title: localize("ui.panel.config.devices.data_table.parent_device"),
|
||||
@@ -672,38 +681,46 @@ export class HaConfigDeviceDashboard extends LitElement {
|
||||
maxWidth: "101px",
|
||||
minWidth: "101px",
|
||||
valueColumn: "battery_level",
|
||||
template: (device) => {
|
||||
if (!this.entities) {
|
||||
return html`<ha-skeleton-text></ha-skeleton-text>`;
|
||||
}
|
||||
const batteryEntityPair = device.battery_entity;
|
||||
const battery =
|
||||
batteryEntityPair && batteryEntityPair[0]
|
||||
? this.hass.states[batteryEntityPair[0]]
|
||||
: undefined;
|
||||
const batteryDomain = battery
|
||||
? computeStateDomain(battery)
|
||||
: undefined;
|
||||
const batteryCharging =
|
||||
batteryEntityPair && batteryEntityPair[1]
|
||||
? this.hass.states[batteryEntityPair[1]]
|
||||
: undefined;
|
||||
template: (device) =>
|
||||
skeletonOr(
|
||||
!this.entities,
|
||||
html`<ha-skeleton-text></ha-skeleton-text>`,
|
||||
() => {
|
||||
const batteryEntityPair = device.battery_entity;
|
||||
|
||||
return battery &&
|
||||
(batteryDomain === "binary_sensor" || !isNaN(battery.state as any))
|
||||
? html`
|
||||
${
|
||||
batteryDomain === "sensor"
|
||||
? this.hass.formatEntityState(battery)
|
||||
: nothing
|
||||
}
|
||||
<ha-battery-icon
|
||||
.batteryStateObj=${battery}
|
||||
.batteryChargingStateObj=${batteryCharging}
|
||||
></ha-battery-icon>
|
||||
`
|
||||
: "—";
|
||||
},
|
||||
const battery =
|
||||
batteryEntityPair && batteryEntityPair[0]
|
||||
? this.hass.states[batteryEntityPair[0]]
|
||||
: undefined;
|
||||
|
||||
const batteryDomain = battery
|
||||
? computeStateDomain(battery)
|
||||
: undefined;
|
||||
|
||||
const batteryCharging =
|
||||
batteryEntityPair && batteryEntityPair[1]
|
||||
? this.hass.states[batteryEntityPair[1]]
|
||||
: undefined;
|
||||
|
||||
return battery &&
|
||||
(batteryDomain === "binary_sensor" ||
|
||||
!isNaN(Number(battery.state)))
|
||||
? html`
|
||||
${
|
||||
batteryDomain === "sensor"
|
||||
? html`<span
|
||||
>${this.hass.formatEntityState(battery)}</span
|
||||
>`
|
||||
: nothing
|
||||
}
|
||||
<ha-battery-icon
|
||||
.batteryStateObj=${battery}
|
||||
.batteryChargingStateObj=${batteryCharging}
|
||||
></ha-battery-icon>
|
||||
`
|
||||
: "—";
|
||||
}
|
||||
),
|
||||
},
|
||||
created_at: getCreatedAtTableColumn(localize, this.hass),
|
||||
modified_at: getModifiedAtTableColumn(localize, this.hass),
|
||||
@@ -888,15 +905,15 @@ export class HaConfigDeviceDashboard extends LitElement {
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.devices.filtering_by_config_entry"
|
||||
)}
|
||||
${
|
||||
!this.entries
|
||||
? html`<ha-skeleton-text></ha-skeleton-text>`
|
||||
: this.entries.find(
|
||||
(entry) =>
|
||||
entry.entry_id ===
|
||||
this._filters.config_entry!.value![0]
|
||||
)?.title || this._filters.config_entry.value[0]
|
||||
}${
|
||||
${skeletonOr(
|
||||
!this.entries,
|
||||
html`<ha-skeleton-text></ha-skeleton-text>`,
|
||||
() =>
|
||||
this.entries?.find(
|
||||
(entry) =>
|
||||
entry.entry_id === this._filters.config_entry!.value![0]
|
||||
)?.title || this._filters.config_entry!.value![0]
|
||||
)}${
|
||||
this._filters.config_entry.value.length === 1 &&
|
||||
Array.isArray(this._filters.sub_entry?.value) &&
|
||||
this._filters.sub_entry.value.length
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
ERR_CONNECTION_LOST,
|
||||
type UnsubscribeFunc,
|
||||
} from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { mdiCircle, mdiWrap, mdiWrapDisabled } from "@mdi/js";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, query, state } from "lit/decorators";
|
||||
@@ -20,6 +20,10 @@ import "../../../components/ha-svg-icon";
|
||||
import "../../../components/input/ha-input-search";
|
||||
import type { HaInputSearch } from "../../../components/input/ha-input-search";
|
||||
import "../../../components/skeleton/ha-skeleton-log";
|
||||
import {
|
||||
fadeInArrival,
|
||||
skeletonOr,
|
||||
} from "../../../components/skeleton/skeleton-arrival";
|
||||
import {
|
||||
connectionContext,
|
||||
internationalizationContext,
|
||||
@@ -65,6 +69,38 @@ class DialogLiveLog extends DialogMixin<LiveLogDialogParams>(LitElement) {
|
||||
|
||||
private _resubscribeOnReady = false;
|
||||
|
||||
// Whether the skeleton showed and no lines have come since, so the log
|
||||
// fades in once its first lines take its place, even when the waiting
|
||||
// message showed in between
|
||||
private _awaitingLines = false;
|
||||
|
||||
private _linesArriving = false;
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues<this>) {
|
||||
super.willUpdate(changedProps);
|
||||
const showSkeleton = !this._lineCount && this._loading;
|
||||
|
||||
if (showSkeleton) {
|
||||
this._awaitingLines = true;
|
||||
}
|
||||
|
||||
this._linesArriving =
|
||||
this._awaitingLines && !showSkeleton && this._lineCount > 0;
|
||||
|
||||
if (this._lineCount > 0) {
|
||||
this._awaitingLines = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues<this>) {
|
||||
super.updated(changedProps);
|
||||
|
||||
if (this._linesArriving && this._logViewer) {
|
||||
this._linesArriving = false;
|
||||
fadeInArrival(this._logViewer);
|
||||
}
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
const connection = this._connection.connection;
|
||||
@@ -217,18 +253,21 @@ class DialogLiveLog extends DialogMixin<LiveLogDialogParams>(LitElement) {
|
||||
${
|
||||
this._lineCount
|
||||
? nothing
|
||||
: this._loading
|
||||
? html`<ha-skeleton-log
|
||||
: skeletonOr(
|
||||
this._loading,
|
||||
html`<ha-skeleton-log
|
||||
.label=${this._i18n.localize(
|
||||
"ui.panel.config.logs.loading_log"
|
||||
)}
|
||||
></ha-skeleton-log>`
|
||||
: html`<div class="waiting">
|
||||
${this._i18n.localize(
|
||||
"ui.panel.config.integrations.config_entry.live_log.waiting",
|
||||
{ integration: this.params.name }
|
||||
)}
|
||||
</div>`
|
||||
></ha-skeleton-log>`,
|
||||
() =>
|
||||
html`<div class="waiting">
|
||||
${this._i18n.localize(
|
||||
"ui.panel.config.integrations.config_entry.live_log.waiting",
|
||||
{ integration: this.params!.name }
|
||||
)}
|
||||
</div>`
|
||||
)
|
||||
}
|
||||
</ha-log-viewer>
|
||||
${
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, query, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { skeletonOr } from "../../../components/skeleton/skeleton-arrival";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
@@ -190,62 +191,58 @@ class DialogSystemLogDetail extends LitElement {
|
||||
.label=${this._i18n.localize("ui.panel.config.logs.copy")}
|
||||
.path=${mdiContentCopy}
|
||||
></ha-icon-button>
|
||||
${
|
||||
integration &&
|
||||
this._manifest === undefined &&
|
||||
reportTarget !== "frontend"
|
||||
? html`<ha-alert
|
||||
alert-type=${this.isCustomIntegration ? "warning" : "info"}
|
||||
>
|
||||
<ha-skeleton-text></ha-skeleton-text>
|
||||
</ha-alert>`
|
||||
: html`<ha-alert
|
||||
alert-type=${this.isCustomIntegration ? "warning" : "info"}
|
||||
>
|
||||
<p>
|
||||
${this._i18n.localize(
|
||||
`ui.panel.config.logs.detail.report_issue.${reportMessage}.introduction`,
|
||||
{
|
||||
integration:
|
||||
this._manifest?.name ??
|
||||
(integration
|
||||
? domainToName(this._i18n.localize, integration)
|
||||
: new URL(reportUrl).hostname),
|
||||
}
|
||||
)}
|
||||
</p>
|
||||
<p>
|
||||
${this._i18n.localize(
|
||||
`ui.panel.config.logs.detail.report_issue.${reportMessage}.report`,
|
||||
{
|
||||
report_link: html`<a
|
||||
href=${reportUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>${this._i18n.localize(`ui.panel.config.logs.detail.report_issue.${reportTarget}.link_text`)}</a
|
||||
>`,
|
||||
}
|
||||
)}
|
||||
</p>
|
||||
${
|
||||
reportMessage !== "custom"
|
||||
? html`<p>
|
||||
${this._i18n.localize(
|
||||
`ui.panel.config.logs.detail.report_issue.${reportMessage}.guidance`,
|
||||
{
|
||||
guide_link: html`<a
|
||||
href=${`${DOCUMENTATION_URL}/help/reporting_issues/`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>${this._i18n.localize("ui.panel.config.logs.detail.report_issue.guide_link_text")}</a
|
||||
>`,
|
||||
}
|
||||
)}
|
||||
</p>`
|
||||
: nothing
|
||||
}
|
||||
</ha-alert>`
|
||||
}
|
||||
<ha-alert alert-type=${this.isCustomIntegration ? "warning" : "info"}>
|
||||
${skeletonOr(
|
||||
Boolean(integration) &&
|
||||
this._manifest === undefined &&
|
||||
reportTarget !== "frontend",
|
||||
html`<ha-skeleton-text></ha-skeleton-text>`,
|
||||
() => html`
|
||||
<p>
|
||||
${this._i18n.localize(
|
||||
`ui.panel.config.logs.detail.report_issue.${reportMessage}.introduction`,
|
||||
{
|
||||
integration:
|
||||
this._manifest?.name ??
|
||||
(integration
|
||||
? domainToName(this._i18n.localize, integration)
|
||||
: new URL(reportUrl).hostname),
|
||||
}
|
||||
)}
|
||||
</p>
|
||||
<p>
|
||||
${this._i18n.localize(
|
||||
`ui.panel.config.logs.detail.report_issue.${reportMessage}.report`,
|
||||
{
|
||||
report_link: html`<a
|
||||
href=${reportUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>${this._i18n.localize(`ui.panel.config.logs.detail.report_issue.${reportTarget}.link_text`)}</a
|
||||
>`,
|
||||
}
|
||||
)}
|
||||
</p>
|
||||
${
|
||||
reportMessage !== "custom"
|
||||
? html`<p>
|
||||
${this._i18n.localize(
|
||||
`ui.panel.config.logs.detail.report_issue.${reportMessage}.guidance`,
|
||||
{
|
||||
guide_link: html`<a
|
||||
href=${`${DOCUMENTATION_URL}/help/reporting_issues/`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>${this._i18n.localize("ui.panel.config.logs.detail.report_issue.guide_link_text")}</a
|
||||
>`,
|
||||
}
|
||||
)}
|
||||
</p>`
|
||||
: nothing
|
||||
}
|
||||
`
|
||||
)}
|
||||
</ha-alert>
|
||||
<div class="contents">
|
||||
<p>
|
||||
${this._i18n.localize("ui.panel.config.logs.detail.logger")}:
|
||||
|
||||
@@ -37,6 +37,10 @@ import "../../../components/ha-dropdown-item";
|
||||
import "../../../components/ha-icon-button";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import "../../../components/skeleton/ha-skeleton-log";
|
||||
import {
|
||||
fadeInArrival,
|
||||
skeletonArrivalStyles,
|
||||
} from "../../../components/skeleton/skeleton-arrival";
|
||||
|
||||
import { getSignedPath } from "../../../data/auth";
|
||||
|
||||
@@ -159,6 +163,13 @@ class ErrorLogCard extends LitElement {
|
||||
|
||||
@state() private _loadingPrevState?: "loading" | "end" | "loaded";
|
||||
|
||||
// Whether the skeleton showed and the log hasn't arrived since, so it fades
|
||||
// in once it takes the skeleton's place, even when the waiting message
|
||||
// showed in between
|
||||
private _awaitingLog = false;
|
||||
|
||||
private _logArriving = false;
|
||||
|
||||
@state() private _noSearchResults = false;
|
||||
|
||||
@state() private _numberOfLines?: number;
|
||||
@@ -359,7 +370,7 @@ class ErrorLogCard extends LitElement {
|
||||
.label=${localize("ui.panel.config.logs.loading_log")}
|
||||
></ha-skeleton-log>`
|
||||
: this._loadingState === "empty"
|
||||
? html`<div>
|
||||
? html`<div class="arriving">
|
||||
${
|
||||
integrationLog
|
||||
? localize(
|
||||
@@ -451,6 +462,25 @@ class ErrorLogCard extends LitElement {
|
||||
this._boot = 0;
|
||||
this._loadLogs();
|
||||
}
|
||||
|
||||
// As render decides: lines kept while reconnecting show instead
|
||||
const showSkeleton =
|
||||
this._loadingState === "loading" &&
|
||||
!(
|
||||
this._ansiToHtmlElement?.hasLines &&
|
||||
!(this.filter && this._noSearchResults)
|
||||
);
|
||||
|
||||
if (showSkeleton) {
|
||||
this._awaitingLog = true;
|
||||
}
|
||||
|
||||
this._logArriving =
|
||||
this._awaitingLog && !showSkeleton && this._loadingState === "loaded";
|
||||
|
||||
if (this._loadingState === "loaded") {
|
||||
this._awaitingLog = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues<this>) {
|
||||
@@ -465,6 +495,11 @@ class ErrorLogCard extends LitElement {
|
||||
protected updated(changedProps: PropertyValues) {
|
||||
super.updated(changedProps);
|
||||
|
||||
if (this._logArriving && this._ansiToHtmlElement) {
|
||||
this._logArriving = false;
|
||||
fadeInArrival(this._ansiToHtmlElement);
|
||||
}
|
||||
|
||||
if (this._newLogsIndicator && this._scrolledToBottomController.value) {
|
||||
this._newLogsIndicator = false;
|
||||
}
|
||||
@@ -683,9 +718,19 @@ class ErrorLogCard extends LitElement {
|
||||
}
|
||||
|
||||
if (lines.length) {
|
||||
const hadLines = this._ansiToHtmlElement?.hasLines;
|
||||
this._ansiToHtmlElement?.parseLinesToColoredPre(lines);
|
||||
this._numberOfLines += lines.length;
|
||||
|
||||
// A stream's first lines take the place of what showed while it
|
||||
// opened, so they fade in as they're written. Later chunks, and
|
||||
// lines kept through a reconnect, show as they are.
|
||||
if (!hadLines && this._ansiToHtmlElement) {
|
||||
fadeInArrival(this._ansiToHtmlElement);
|
||||
// Faded in here, so not again once the state says loaded
|
||||
this._awaitingLog = false;
|
||||
}
|
||||
|
||||
if (this._loadingState === "empty") {
|
||||
// delay to avoid loading older logs immediately
|
||||
setTimeout(() => {
|
||||
@@ -1041,6 +1086,7 @@ class ErrorLogCard extends LitElement {
|
||||
|
||||
static styles: CSSResultGroup = css`
|
||||
${haStyleScrollbar}
|
||||
${skeletonArrivalStyles}
|
||||
|
||||
:host {
|
||||
direction: var(--direction);
|
||||
|
||||
@@ -18,6 +18,7 @@ import "../../../components/ha-icon-button";
|
||||
import "../../../components/item/ha-list-item-button";
|
||||
import "../../../components/list/ha-list-base";
|
||||
import "../../../components/skeleton/ha-skeleton-text";
|
||||
import { skeletonOr } from "../../../components/skeleton/skeleton-arrival";
|
||||
import { getSignedPath } from "../../../data/auth";
|
||||
import {
|
||||
getCoreLogFileDownloadUnavailableReason,
|
||||
@@ -182,37 +183,38 @@ export class SystemLogCard extends LitElement {
|
||||
</ha-alert>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
this._items === undefined
|
||||
? html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<div
|
||||
class="skeleton"
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize(
|
||||
"ui.panel.config.logs.loading_log"
|
||||
)}
|
||||
>
|
||||
${SKELETON_ROW_WIDTHS.map(
|
||||
([primary, secondary]) => html`
|
||||
<div class="skeleton-row">
|
||||
<ha-skeleton-text
|
||||
class="primary"
|
||||
style=${styleMap({
|
||||
"--ha-skeleton-text-width": `${primary}%`,
|
||||
})}
|
||||
></ha-skeleton-text>
|
||||
<ha-skeleton-text
|
||||
class="secondary"
|
||||
style=${styleMap({
|
||||
"--ha-skeleton-text-width": `${secondary}%`,
|
||||
})}
|
||||
></ha-skeleton-text>
|
||||
</div>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
</ha-fade-in>`
|
||||
: this._items.length === 0
|
||||
${skeletonOr(
|
||||
this._items === undefined,
|
||||
html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<div
|
||||
class="skeleton"
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize(
|
||||
"ui.panel.config.logs.loading_log"
|
||||
)}
|
||||
>
|
||||
${SKELETON_ROW_WIDTHS.map(
|
||||
([primary, secondary]) => html`
|
||||
<div class="skeleton-row">
|
||||
<ha-skeleton-text
|
||||
class="primary"
|
||||
style=${styleMap({
|
||||
"--ha-skeleton-text-width": `${primary}%`,
|
||||
})}
|
||||
></ha-skeleton-text>
|
||||
<ha-skeleton-text
|
||||
class="secondary"
|
||||
style=${styleMap({
|
||||
"--ha-skeleton-text-width": `${secondary}%`,
|
||||
})}
|
||||
></ha-skeleton-text>
|
||||
</div>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
</ha-fade-in>`,
|
||||
() =>
|
||||
this._items!.length === 0
|
||||
? html`
|
||||
<div class="card-content empty-content">
|
||||
${this.hass.localize("ui.panel.config.logs.no_issues")}
|
||||
@@ -289,18 +291,19 @@ export class SystemLogCard extends LitElement {
|
||||
`
|
||||
)}</ha-list-base
|
||||
>`
|
||||
}
|
||||
${
|
||||
this._items === undefined
|
||||
? nothing
|
||||
: html`<div class="card-actions">
|
||||
<ha-call-service-button domain="system_log" service="clear"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.logs.clear"
|
||||
)}</ha-call-service-button
|
||||
>
|
||||
</div>`
|
||||
}
|
||||
)}
|
||||
${skeletonOr(
|
||||
this._items === undefined,
|
||||
nothing,
|
||||
() =>
|
||||
html`<div class="card-actions">
|
||||
<ha-call-service-button domain="system_log" service="clear"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.logs.clear"
|
||||
)}</ha-call-service-button
|
||||
>
|
||||
</div>`
|
||||
)}
|
||||
</ha-card>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -10,6 +10,7 @@ import "../../../components/animation/ha-fade-in";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/skeleton/ha-skeleton";
|
||||
import "../../../components/skeleton/ha-skeleton-text";
|
||||
import { skeletonOr } from "../../../components/skeleton/skeleton-arrival";
|
||||
import "../../../components/ha-yaml-editor";
|
||||
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||
import type { LovelaceConfig } from "../../../data/lovelace/config/types";
|
||||
@@ -267,15 +268,13 @@ export abstract class HuiElementEditor<
|
||||
class="gui-editor"
|
||||
@edit-sub-element=${this._editSubElement}
|
||||
>
|
||||
${
|
||||
this._loading
|
||||
? this._renderLoading()
|
||||
: cache(
|
||||
this._subElementEditorConfig
|
||||
? this._renderSubElement()
|
||||
: this.renderConfigElement()
|
||||
)
|
||||
}
|
||||
${skeletonOr(this._loading, this._renderLoading(), () =>
|
||||
cache(
|
||||
this._subElementEditorConfig
|
||||
? this._renderSubElement()
|
||||
: this.renderConfigElement()
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
: html`
|
||||
|
||||
@@ -61,6 +61,9 @@ describe("ha-data-table search", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
||||
|
||||
// jsdom has no Web Animations, which rows fade in with after a skeleton
|
||||
Element.prototype.animate = vi.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -42,6 +42,9 @@ const connection = {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
// jsdom has no Web Animations, which the log fades in with
|
||||
Element.prototype.animate = vi.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Reference in new issue
Block a user