Skip to content

Commit 9b0e182

Browse files
committed
add optional argument for setting !important in Component#css()
1 parent 605e3c4 commit 9b0e182

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Component.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,24 @@ export class Component<T extends HTMLElement = HTMLElement> extends BaseComponen
8080
*/
8181
public css(name: string, value: string): typeof this;
8282

83+
/**
84+
* Set style property
85+
* @param name Property name
86+
* @param value Property value
87+
* @param priority Whether to make this rule `!important`
88+
*/
89+
public css(name: string, value: string, priority: boolean): typeof this;
90+
8391
/**
8492
* Set style properties
8593
* @param properties Object of style property name and value pairs
8694
*/
8795
public css(properties: Record<string, string>): typeof this;
8896

89-
public css(...args: [string, string] | [Record<string, string>]): typeof this {
90-
if (args.length === 2) {
91-
const [name, value] = args;
92-
this.element.style.setProperty(name, value);
97+
public css(...args: [string, string] | [string, string, boolean] | [Record<string, string>]): typeof this {
98+
if (args.length === 2 || args.length === 3) {
99+
const [name, value, priority] = args;
100+
this.element.style.setProperty(name, value, priority ? "important" : void 0);
93101
}
94102
else for (const [name, value] of Object.entries(args[0]))
95103
this.css(name, value);

0 commit comments

Comments
 (0)