Skip to content

Commit ddb243d

Browse files
committed
minor tweaks and docs for sheet.replaceRule
1 parent 87952b4 commit ddb243d

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

docs/jss-api.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,18 @@ const sheet2 = jss.createStyleSheet({}, {index: 1, meta: 'sheet-2'}).attach()
196196

197197
## Add a rule to an existing Style Sheet
198198

199-
`sheet.addRule([name], style, [options])`
199+
`sheet.addRule(nameOrSelector, style, [options])`
200200

201201
This function will use [insertRule](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule) API if your Style Sheet is already attached to the DOM. In this case **you will not see this CSS Rule in the "Elements" view of the dev tools**. You can always verify correct rendering by using the selector on some DOM Node and watch styles applied as well as in the "Styles" inspector.
202202

203203
If you use `addRule()` before you call `attach()`, styles will be rendered in one batch using `textContent` API which will not have the above-described side effect.
204204

205+
## Replace a rule in an existing Style Sheet
206+
207+
`sheet.replaceRule(nameOrSelector, style, [options])`
208+
209+
Same as `sheet.addRule(...)` but replaces a rule with the same name if found.
210+
205211
### Options
206212

207213
- `index` - index where the rule should be added, by default, rules get pushed at the end.

packages/jss/.size-snapshot.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
22
"jss.js": {
3-
"bundled": 64878,
4-
"minified": 23187,
5-
"gzipped": 7185
3+
"bundled": 64920,
4+
"minified": 23189,
5+
"gzipped": 7183
66
},
77
"jss.min.js": {
8-
"bundled": 63482,
9-
"minified": 22418,
10-
"gzipped": 6844
8+
"bundled": 63524,
9+
"minified": 22420,
10+
"gzipped": 6842
1111
},
1212
"jss.cjs.js": {
13-
"bundled": 60556,
14-
"minified": 26215,
15-
"gzipped": 7305
13+
"bundled": 60598,
14+
"minified": 26217,
15+
"gzipped": 7301
1616
},
1717
"jss.esm.js": {
18-
"bundled": 58928,
19-
"minified": 24909,
20-
"gzipped": 7138,
18+
"bundled": 58970,
19+
"minified": 24911,
20+
"gzipped": 7135,
2121
"treeshaked": {
2222
"rollup": {
23-
"code": 20173,
23+
"code": 20175,
2424
"import_statements": 345
2525
},
2626
"webpack": {
27-
"code": 21663
27+
"code": 21665
2828
}
2929
}
3030
}

packages/jss/src/StyleSheet.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ export default class StyleSheet {
9090
/**
9191
* Replace a rule in the current stylesheet.
9292
*/
93-
replaceRule(name, decl, options) {
94-
const oldRule = this.getRule(name)
95-
if (!oldRule) return this.addRule(name, decl, options)
93+
replaceRule(nameOrSelector, decl, options) {
94+
const oldRule = this.rules.get(nameOrSelector)
95+
if (!oldRule) return this.addRule(nameOrSelector, decl, options)
9696

97-
const newRule = this.rules.replace(name, decl, options)
97+
const newRule = this.rules.replace(nameOrSelector, decl, options)
9898

9999
if (newRule) {
100100
this.options.jss.plugins.onProcessRule(newRule)

0 commit comments

Comments
 (0)