Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support falsy value from fn rule #1164

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Since you are interested in what happens next, in case, you work for a for-profi
### Bug fixes

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

---

Expand Down
12 changes: 6 additions & 6 deletions packages/css-jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dist/css-jss.js": {
"bundled": 57471,
"minified": 20270,
"gzipped": 6819
"bundled": 57601,
"minified": 20274,
"gzipped": 6822
},
"dist/css-jss.min.js": {
"bundled": 56717,
"minified": 19812,
"gzipped": 6608
"bundled": 56847,
"minified": 19816,
"gzipped": 6610
},
"dist/css-jss.cjs.js": {
"bundled": 2919,
Expand Down
24 changes: 12 additions & 12 deletions packages/jss-plugin-rule-value-function/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/jss-plugin-rule-value-function.js": {
"bundled": 2210,
"minified": 747,
"gzipped": 438
"bundled": 2340,
"minified": 751,
"gzipped": 440
},
"dist/jss-plugin-rule-value-function.min.js": {
"bundled": 2210,
"minified": 747,
"gzipped": 438
"bundled": 2340,
"minified": 751,
"gzipped": 440
},
"dist/jss-plugin-rule-value-function.cjs.js": {
"bundled": 1802,
"minified": 646,
"gzipped": 371
"bundled": 1928,
"minified": 650,
"gzipped": 373
},
"dist/jss-plugin-rule-value-function.esm.js": {
"bundled": 1724,
"minified": 582,
"gzipped": 324,
"bundled": 1850,
"minified": 586,
"gzipped": 328,
"treeshaked": {
"rollup": {
"code": 12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ describe('jss-plugin-rule-value-function: Function rules', () => {
.createStyleSheet(
{
a: data => {
if (data.removeAll) {
return null
}
if (data.noDisplay) {
return {color: data.color}
}
Expand Down Expand Up @@ -89,6 +92,18 @@ describe('jss-plugin-rule-value-function: Function rules', () => {
}
`)
})

it('should remove all props', () => {
sheet.update({color: 'red'})
expect(sheet.toString()).to.be(stripIndent`
.a-id {
color: red;
display: block;
}
`)
sheet.update({removeAll: true})
expect(sheet.toString()).to.be('.a-id {}')
})
})

describe('fallbacks inside', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/jss-plugin-rule-value-function/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export default function functionPlugin() {
// If we have a style function, the entire rule is dynamic and style object
// will be returned from that function.
if (fnRule) {
styleRule.style = fnRule(data)
// Empty object will remove all currently defined props
// in case function rule returns a falsy value.
styleRule.style = fnRule(data) || {}
}

const fnValues = styleRule[fnValuesNs]
Expand Down
12 changes: 6 additions & 6 deletions packages/jss-preset-default/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dist/jss-preset-default.js": {
"bundled": 54715,
"minified": 19504,
"gzipped": 6471
"bundled": 54845,
"minified": 19508,
"gzipped": 6474
},
"dist/jss-preset-default.min.js": {
"bundled": 53961,
"minified": 19046,
"gzipped": 6262
"bundled": 54091,
"minified": 19050,
"gzipped": 6264
},
"dist/jss-preset-default.cjs.js": {
"bundled": 1329,
Expand Down
12 changes: 6 additions & 6 deletions packages/jss-starter-kit/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dist/jss-starter-kit.js": {
"bundled": 70257,
"minified": 29544,
"gzipped": 9093
"bundled": 70387,
"minified": 29548,
"gzipped": 9100
},
"dist/jss-starter-kit.min.js": {
"bundled": 69503,
"minified": 29086,
"gzipped": 8883
"bundled": 69633,
"minified": 29090,
"gzipped": 8886
},
"dist/jss-starter-kit.cjs.js": {
"bundled": 2592,
Expand Down
12 changes: 6 additions & 6 deletions packages/react-jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dist/react-jss.js": {
"bundled": 168992,
"minified": 58283,
"gzipped": 19042
"bundled": 169122,
"minified": 58287,
"gzipped": 19043
},
"dist/react-jss.min.js": {
"bundled": 112324,
"minified": 41678,
"gzipped": 14127
"bundled": 112454,
"minified": 41682,
"gzipped": 14129
},
"dist/react-jss.cjs.js": {
"bundled": 27019,
Expand Down