Skip to content

Commit 2ec6a0e

Browse files
authored
Support falsy value from fn rule (#1164)
* support falsy value from fn rule * changelog
1 parent fc136a1 commit 2ec6a0e

File tree

8 files changed

+55
-37
lines changed

8 files changed

+55
-37
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Since you are interested in what happens next, in case, you work for a for-profi
99
### Bug fixes
1010

1111
- [react-jss] Fix nested dynamic rule updating ([1144](https://github.com/cssinjs/jss/pull/1144))
12+
- [jss] Support falsy value from fn rule ([1164](https://github.com/cssinjs/jss/pull/1164))
1213

1314
---
1415

packages/css-jss/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"dist/css-jss.js": {
3-
"bundled": 57471,
4-
"minified": 20270,
5-
"gzipped": 6819
3+
"bundled": 57601,
4+
"minified": 20274,
5+
"gzipped": 6822
66
},
77
"dist/css-jss.min.js": {
8-
"bundled": 56717,
9-
"minified": 19812,
10-
"gzipped": 6608
8+
"bundled": 56847,
9+
"minified": 19816,
10+
"gzipped": 6610
1111
},
1212
"dist/css-jss.cjs.js": {
1313
"bundled": 2919,

packages/jss-plugin-rule-value-function/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/jss-plugin-rule-value-function.js": {
3-
"bundled": 2210,
4-
"minified": 747,
5-
"gzipped": 438
3+
"bundled": 2340,
4+
"minified": 751,
5+
"gzipped": 440
66
},
77
"dist/jss-plugin-rule-value-function.min.js": {
8-
"bundled": 2210,
9-
"minified": 747,
10-
"gzipped": 438
8+
"bundled": 2340,
9+
"minified": 751,
10+
"gzipped": 440
1111
},
1212
"dist/jss-plugin-rule-value-function.cjs.js": {
13-
"bundled": 1802,
14-
"minified": 646,
15-
"gzipped": 371
13+
"bundled": 1928,
14+
"minified": 650,
15+
"gzipped": 373
1616
},
1717
"dist/jss-plugin-rule-value-function.esm.js": {
18-
"bundled": 1724,
19-
"minified": 582,
20-
"gzipped": 324,
18+
"bundled": 1850,
19+
"minified": 586,
20+
"gzipped": 328,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 12,

packages/jss-plugin-rule-value-function/src/function-rules.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ describe('jss-plugin-rule-value-function: Function rules', () => {
5252
.createStyleSheet(
5353
{
5454
a: data => {
55+
if (data.removeAll) {
56+
return null
57+
}
5558
if (data.noDisplay) {
5659
return {color: data.color}
5760
}
@@ -89,6 +92,18 @@ describe('jss-plugin-rule-value-function: Function rules', () => {
8992
}
9093
`)
9194
})
95+
96+
it('should remove all props', () => {
97+
sheet.update({color: 'red'})
98+
expect(sheet.toString()).to.be(stripIndent`
99+
.a-id {
100+
color: red;
101+
display: block;
102+
}
103+
`)
104+
sheet.update({removeAll: true})
105+
expect(sheet.toString()).to.be('.a-id {}')
106+
})
92107
})
93108

94109
describe('fallbacks inside', () => {

packages/jss-plugin-rule-value-function/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export default function functionPlugin() {
5252
// If we have a style function, the entire rule is dynamic and style object
5353
// will be returned from that function.
5454
if (fnRule) {
55-
styleRule.style = fnRule(data)
55+
// Empty object will remove all currently defined props
56+
// in case function rule returns a falsy value.
57+
styleRule.style = fnRule(data) || {}
5658
}
5759

5860
const fnValues = styleRule[fnValuesNs]

packages/jss-preset-default/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"dist/jss-preset-default.js": {
3-
"bundled": 54715,
4-
"minified": 19504,
5-
"gzipped": 6471
3+
"bundled": 54845,
4+
"minified": 19508,
5+
"gzipped": 6474
66
},
77
"dist/jss-preset-default.min.js": {
8-
"bundled": 53961,
9-
"minified": 19046,
10-
"gzipped": 6262
8+
"bundled": 54091,
9+
"minified": 19050,
10+
"gzipped": 6264
1111
},
1212
"dist/jss-preset-default.cjs.js": {
1313
"bundled": 1329,

packages/jss-starter-kit/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"dist/jss-starter-kit.js": {
3-
"bundled": 70257,
4-
"minified": 29544,
5-
"gzipped": 9093
3+
"bundled": 70387,
4+
"minified": 29548,
5+
"gzipped": 9100
66
},
77
"dist/jss-starter-kit.min.js": {
8-
"bundled": 69503,
9-
"minified": 29086,
10-
"gzipped": 8883
8+
"bundled": 69633,
9+
"minified": 29090,
10+
"gzipped": 8886
1111
},
1212
"dist/jss-starter-kit.cjs.js": {
1313
"bundled": 2592,

packages/react-jss/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"dist/react-jss.js": {
3-
"bundled": 168992,
4-
"minified": 58283,
5-
"gzipped": 19042
3+
"bundled": 169122,
4+
"minified": 58287,
5+
"gzipped": 19043
66
},
77
"dist/react-jss.min.js": {
8-
"bundled": 112324,
9-
"minified": 41678,
10-
"gzipped": 14127
8+
"bundled": 112454,
9+
"minified": 41682,
10+
"gzipped": 14129
1111
},
1212
"dist/react-jss.cjs.js": {
1313
"bundled": 27019,

0 commit comments

Comments
 (0)