From 9e10e50a475f68e78015f0de9da802ecbf15b9b6 Mon Sep 17 00:00:00 2001 From: Wellington Guimaraes Date: Tue, 30 May 2017 16:10:43 -0700 Subject: [PATCH 1/5] fixed issue while updating dynamic props for conditional rules --- src/styled.js | 7 +++++- .../__snapshots__/functional.spec.jsx.snap | 22 +++++++++++++++++++ src/tests/functional.spec.jsx | 18 +++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/styled.js b/src/styled.js index 556f2fc..265bb89 100644 --- a/src/styled.js +++ b/src/styled.js @@ -71,10 +71,15 @@ const styled = ({tagName, elementStyle, mountSheet}: StyledArgs) => { updateSheet(props: StyledElementPropsType) { let rule let ruleIndex = 0 + // nested styles become to flatten rules, so we need to update each nested rule for (ruleIndex; ruleIndex < classMap[this.dynamicTagName].length; ruleIndex++) { rule = classMap[this.dynamicTagName][ruleIndex] - this.sheet.update(rule.name, props) + + if (rule.name) + this.sheet.update(rule.name, props) + else + this.sheet.update(props) } } diff --git a/src/tests/__snapshots__/functional.spec.jsx.snap b/src/tests/__snapshots__/functional.spec.jsx.snap index 2bb3b0e..10cbe14 100644 --- a/src/tests/__snapshots__/functional.spec.jsx.snap +++ b/src/tests/__snapshots__/functional.spec.jsx.snap @@ -1,3 +1,25 @@ +exports[`functional tests should update all dynamic props 1`] = ` +".button-1-id { + padding: 10px; +} +@media screen { + .button-1-id { + margin: 10px; + } +}" +`; + +exports[`functional tests should update all dynamic props 2`] = ` +".button-1-id { + padding: 0; +} +@media screen { + .button-1-id { + margin: 0; + } +}" +`; + exports[`functional tests should update nested props 1`] = ` ".button-id { font-size: 12px; diff --git a/src/tests/functional.spec.jsx b/src/tests/functional.spec.jsx index 7b28cae..25f3ecd 100644 --- a/src/tests/functional.spec.jsx +++ b/src/tests/functional.spec.jsx @@ -110,4 +110,22 @@ describe('functional tests', () => { assertSheet(sheet) wrapper.unmount() }) + + it('should update all dynamic props', () => { + const Button = styled('button')({ + padding: props => props.spaced ? 10 : 0, + + '@media screen': { + margin: props => props.spaced ? 10 : 0 + } + }) + + const wrapper = mount(