home-assistant-styles-manager
Manage Home Assistant styles per DOM elements
Install
npm
npm install home-assistant-styles-manager
yarn
yarn add home-assistant-styles-manager
PNPM
pnpm add home-assistant-styles-manager
API
Class instantiation
The HomeAssistantStylesManager
class can be instantiated sending an optional options object.
new HomeAssistantStylesManager([options])
Options object
Parameter | Optional | Description |
---|
prefix | yes | prefix that will be used for the styles ids |
namespace | yes | namespace that will be used for the warnings |
Public methods
getStyleElement
Given an HTMLElement
or a ShadowRoot
element, returns the style element associated with it.
getStyleElement(root: HTMLElement | ShadowRoot): HTMLStyleElement | null
addStyle
Given a CSS string or a CSS object and an HTMLElement
or a ShadowRoot
element, it adds a style element containing the CSS string or replace its content with the CSS string if it already exists.
addStyle(
css: string | Record<string, Record<string, string> | false>,
root: HTMLElement | ShadowRoot
): void
removeStyle
Given an HTMLElement
or a ShadowRoot
element, it removes the style element associated to it (if it exists).
removeStyle(root: HTMLElement | ShadowRoot): void