1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-02-21 10:17:13 +00:00
Files
frontend/src/resources/css-variables.ts
renovate[bot] 6f8c366bad Update dependency prettier to v3.2.0 (#19411)
* Update dependency prettier to v3.2.0

* Reformat

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
2024-01-15 16:49:22 -05:00

31 lines
752 B
TypeScript

export function computeCssVariable(
props: string | string[]
): string | undefined {
if (Array.isArray(props)) {
return props
.reverse()
.reduce<
string | undefined
>((str, variable) => `var(${variable}${str ? `, ${str}` : ""})`, undefined);
}
return `var(${props})`;
}
export function computeCssValue(
prop: string | string[],
computedStyles: CSSStyleDeclaration
): string | undefined {
if (Array.isArray(prop)) {
for (const property of prop) {
const value = computeCssValue(property, computedStyles);
if (value) return value;
}
return undefined;
}
if (!prop.endsWith("-color")) {
return undefined;
}
return computedStyles.getPropertyValue(prop).trim() || undefined;
}