Skip to content

Commit

Permalink
Merge pull request #23 from gravity-ui/fix-update-css
Browse files Browse the repository at this point in the history
fix: update css after call setEntities
  • Loading branch information
itwillwork authored Nov 26, 2024
2 parents 61a7f25 + a38b363 commit bcba26c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/utils/functions/cssProp.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
type CssVar = `--${string}`;

export function setCssProp(target: HTMLElement, name: CssVar, value: string) {
export function setCssProp(target: HTMLElement | null, name: CssVar, value: string) {
if (!target) {
return;
}
target.style.setProperty(name, value);
}

export function setCssProps(target: HTMLElement, vars: { [k in CssVar]: string }) {
export function setCssProps(target: HTMLElement | null, vars: { [k in CssVar]: string }) {
if (!target) {
return;
}

Object.entries(vars).forEach(([name, value]) => {
setCssProp(target, name as CssVar, value);
});
}

export function removeCssProps(target: HTMLElement, names: CssVar[]) {
export function removeCssProps(target: HTMLElement | null, names: CssVar[]) {
if (!target) {
return;
}

names.forEach((name) => {
target.style.removeProperty(name);
});
Expand Down

0 comments on commit bcba26c

Please sign in to comment.