diff --git a/lib/templates/styledComponents.js b/lib/templates/styledComponents.js index 8d92deb..b8de8f5 100644 --- a/lib/templates/styledComponents.js +++ b/lib/templates/styledComponents.js @@ -4,6 +4,7 @@ module.exports = ({ styleString, propsString, systemFunctions, + systemExpressions = '', extensionImport }) => `import styled from 'styled-components' import { @@ -15,13 +16,14 @@ import { } from 'styled-system' ${extensionImport} -const ${name} = styled(${type})([], props => (${styleString}), - space, - fontSize, - width, - color, - ${systemFunctions} -) +const ${name} = styled(${type})\` + \${styleString} + \${space} + \${fontSize} + \${width} + \${color} + ${systemExpressions} +\` ${name}.defaultProps = ${propsString} diff --git a/test/snapshots/modules.js.md b/test/snapshots/modules.js.md index 6b016f6..8c9992e 100644 --- a/test/snapshots/modules.js.md +++ b/test/snapshots/modules.js.md @@ -196,6 +196,8 @@ Generated by [AVA](https://ava.li). value: true␊ });␊ ␊ + var _templateObject = _taggedTemplateLiteral(['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n \\n'], ['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n \\n']);␊ + ␊ var _styledComponents = require('styled-components');␊ ␊ var _styledComponents2 = _interopRequireDefault(_styledComponents);␊ @@ -204,9 +206,9 @@ Generated by [AVA](https://ava.li). ␊ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }␊ ␊ - var Box = (0, _styledComponents2.default)('div')([], function (props) {␊ - return {};␊ - }, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color);␊ + function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }␊ + ␊ + var Box = (0, _styledComponents2.default)('div')(_templateObject, styleString, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color);␊ ␊ Box.defaultProps = {};␊ ␊ @@ -223,6 +225,8 @@ Generated by [AVA](https://ava.li). value: true␊ });␊ ␊ + var _templateObject = _taggedTemplateLiteral(['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n \\n'], ['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n \\n']);␊ + ␊ var _styledComponents = require('styled-components');␊ ␊ var _styledComponents2 = _interopRequireDefault(_styledComponents);␊ @@ -231,9 +235,9 @@ Generated by [AVA](https://ava.li). ␊ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }␊ ␊ - var Text = (0, _styledComponents2.default)('p')([], function (props) {␊ - return {};␊ - }, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color);␊ + function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }␊ + ␊ + var Text = (0, _styledComponents2.default)('p')(_templateObject, styleString, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color);␊ ␊ Text.defaultProps = {␊ m: 0␊ @@ -287,6 +291,8 @@ Generated by [AVA](https://ava.li). value: true␊ });␊ ␊ + var _templateObject = _taggedTemplateLiteral(['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n \\n'], ['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n \\n']);␊ + ␊ var _styledComponents = require('styled-components');␊ ␊ var _styledComponents2 = _interopRequireDefault(_styledComponents);␊ @@ -299,9 +305,9 @@ Generated by [AVA](https://ava.li). ␊ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }␊ ␊ - var Beep = (0, _styledComponents2.default)(_Box2.default)([], function (props) {␊ - return {};␊ - }, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color);␊ + function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }␊ + ␊ + var Beep = (0, _styledComponents2.default)(_Box2.default)(_templateObject, styleString, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color);␊ ␊ Beep.defaultProps = {␊ p: 3,␊ @@ -321,6 +327,8 @@ Generated by [AVA](https://ava.li). value: true␊ });␊ ␊ + var _templateObject = _taggedTemplateLiteral(['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n', '\\n', '\\n', '\\n'], ['\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n ', '\\n', '\\n', '\\n', '\\n']);␊ + ␊ var _styledComponents = require('styled-components');␊ ␊ var _styledComponents2 = _interopRequireDefault(_styledComponents);␊ @@ -333,11 +341,9 @@ Generated by [AVA](https://ava.li). ␊ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }␊ ␊ - var Flex = (0, _styledComponents2.default)(_Box2.default)([], function (props) {␊ - return {␊ - display: 'flex'␊ - };␊ - }, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color, _styledSystem.alignItems, _styledSystem.justifyContent, _styledSystem.flexDirection, _styledSystem.flexWrap);␊ + function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }␊ + ␊ + var Flex = (0, _styledComponents2.default)(_Box2.default)(_templateObject, styleString, _styledSystem.space, _styledSystem.fontSize, _styledSystem.width, _styledSystem.color, _styledSystem.alignItems, _styledSystem.justifyContent, _styledSystem.flexDirection, _styledSystem.flexWrap);␊ ␊ Flex.defaultProps = {};␊ ␊ diff --git a/test/snapshots/modules.js.snap b/test/snapshots/modules.js.snap index 3fdb07d..88e3842 100644 Binary files a/test/snapshots/modules.js.snap and b/test/snapshots/modules.js.snap differ diff --git a/test/snapshots/templates.js.md b/test/snapshots/templates.js.md index d561e87..17d4958 100644 --- a/test/snapshots/templates.js.md +++ b/test/snapshots/templates.js.md @@ -315,13 +315,14 @@ Generated by [AVA](https://ava.li). } from 'styled-system'␊ import Div from './Div'␊ ␊ - const Box = styled(Div)([], props => ({}),␊ - space,␊ - fontSize,␊ - width,␊ - color,␊ + const Box = styled(Div)`␊ + ${styleString}␊ + ${space}␊ + ${fontSize}␊ + ${width}␊ + ${color}␊ ␊ - )␊ + `␊ ␊ Box.defaultProps = {}␊ ␊ @@ -341,16 +342,14 @@ Generated by [AVA](https://ava.li). } from 'styled-system'␊ ␊ ␊ - const Hello = styled(h2)([], props => ((props, theme) => ({␊ - fontFamily: 'inherit',␊ - color: props.theme('colors.blue')␊ - })),␊ - space,␊ - fontSize,␊ - width,␊ - color,␊ + const Hello = styled(h2)`␊ + ${styleString}␊ + ${space}␊ + ${fontSize}␊ + ${width}␊ + ${color}␊ ␊ - )␊ + `␊ ␊ Hello.defaultProps = {␊ p: 2␊ diff --git a/test/snapshots/templates.js.snap b/test/snapshots/templates.js.snap index 46d83e7..cd6cab9 100644 Binary files a/test/snapshots/templates.js.snap and b/test/snapshots/templates.js.snap differ