Skip to content

Commit

Permalink
fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
James Newell committed Feb 15, 2018
1 parent d4da608 commit 9b0819c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Change log

### 2.0.2

- fixed use of multiple expressions [#11](https://github.com/jameslnewell/styled-components-breakpoint/issues/11)

### 2.0.1

- added missing `./dist` files 😬
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "styled-components-breakpoint",
"repository": "jameslnewell/styled-components-breakpoint",
"version": "2.0.1",
"version": "2.0.2",
"description": "Utility functions for creating breakpoints in `styled-components` 💅.",
"keywords": [
"react",
Expand All @@ -28,6 +28,7 @@
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.1",
"gh-pages": "^1.1.0",
"husky": "^0.14.3",
"jest-styled-components": "^4.11.0-1",
"react": "^16.2.0",
"react-create-component-from-tag-prop": "^1.3.1",
Expand All @@ -43,7 +44,8 @@
"test": "tradie test",
"deploy": "gh-pages -d \"./dist/example\"",
"prepublishOnly": "yarn run clean && yarn run build && yarn run test",
"postpublish": "yarn run deploy"
"postpublish": "yarn run deploy",
"precommit": "yarn run test"
},
"license": "MIT"
}
}
7 changes: 4 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ function withSingleCriteria(breakpoints: BreakpointMap, name: string, operator:
// special case for 0 to avoid wrapping styles in an unnecessary @media block
if (operator === 'min-width' && value === 0) {
return function (strings: string[], ...interpolations: StyledComponentsInterpolation[]) {
return css(strings, interpolations);
return css(strings, ...interpolations);
}
}


return function (strings: string[], ...interpolations: StyledComponentsInterpolation[]) {
return css`@media (${operator}: ${convertPxToEm(value + offset)}em) {
${css(strings, interpolations)}
${css(strings, ...interpolations)}
}`;
};
}
Expand All @@ -72,7 +73,7 @@ export function _between(breakpoints: BreakpointMap, gte: string, lt: string) {
const ltValue = getValueFromName(breakpoints, lt);
return function (strings: string[], ...interpolations: StyledComponentsInterpolation[]) {
return css`@media (min-width: ${convertPxToEm(gteValue)}em) and (max-width: ${convertPxToEm(ltValue - 1)}em) {
${css(strings, interpolations)}
${css(strings, ...interpolations)}
}`;
};
}
Expand Down
17 changes: 16 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const customBreakpoints = {
describe('breakpoint()', () => {

const DefaultThing = styled.h1`
${breakpoint('mobile') `
font-size: 12px;
`}
Expand Down Expand Up @@ -61,6 +61,21 @@ describe('breakpoint()', () => {
expect(element).toHaveStyleRule('font-size', '24px', { media: '(min-width:180em)' });
});

// https://github.com/jameslnewell/styled-components-breakpoint/issues/11
it('should render multiple expressions correctly #11', () => {
const Thing = styled.div`
${breakpoint('tablet') `
background: ${'grey'};
color: ${'white'};
`}
`;
const element = shallow(
<Thing />
);
expect(element).toHaveStyleRule('background', 'grey', { media: '(min-width:46.0625em)' });
expect(element).toHaveStyleRule('color', 'white', { media: '(min-width:46.0625em)' });
});

});

describe('map()', () => {
Expand Down

0 comments on commit 9b0819c

Please sign in to comment.