Skip to content

Commit 94773bc

Browse files
committed
Support styled-components@4.0.2
1 parent ca7911f commit 94773bc

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

dist/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React from 'react';
88
import styled from 'styled-components';
99
import { ContainerQuery } from 'react-container-query';
1010
import classNames from 'classnames';
11+
import hoistStatics from 'hoist-non-react-statics';
1112
import domElements from './dom-elements';
1213
import newClassName from './utils/new-class-name';
1314
import kebabToCamel from './utils/kebab-to-camel';
@@ -55,8 +56,7 @@ function removeUnit(value) {
5556
const constructWithOptions = Component => (strings, ...expressions) => {
5657
const [cssStrings, query] = parseCss(strings);
5758
const StyledComponent = styled(Component)(cssStrings, ...expressions);
58-
59-
const StyledContainerQuery = (_ref) => {
59+
const StyledContainerQuery = React.forwardRef((_ref, ref) => {
6060
let {
6161
className
6262
} = _ref,
@@ -65,11 +65,11 @@ const constructWithOptions = Component => (strings, ...expressions) => {
6565
return React.createElement(ContainerQuery, {
6666
query: query
6767
}, params => React.createElement(StyledComponent, _extends({
68+
ref: ref,
6869
className: classNames(params, className)
6970
}, f)));
70-
};
71-
72-
return Object.assign(StyledContainerQuery, StyledComponent);
71+
});
72+
return hoistStatics(StyledContainerQuery, StyledComponent);
7373
};
7474

7575
const styledContainerQuery = (() => {

package-lock.json

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"dependencies": {
3131
"classnames": "^2.2.6",
32+
"hoist-non-react-statics": "^3.0.1",
3233
"react-container-query": "^0.11.0",
3334
"shorthash": "0.0.2"
3435
},

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import styled from 'styled-components'
33
import { ContainerQuery } from 'react-container-query'
44
import classNames from 'classnames'
5+
import hoistStatics from 'hoist-non-react-statics'
56
import domElements from './dom-elements'
67
import newClassName from './utils/new-class-name'
78
import kebabToCamel from './utils/kebab-to-camel'
@@ -51,12 +52,12 @@ function removeUnit(value) {
5152
const constructWithOptions = Component => (strings, ...expressions) => {
5253
const [cssStrings, query] = parseCss(strings)
5354
const StyledComponent = styled(Component)(cssStrings, ...expressions)
54-
const StyledContainerQuery = ({ className, ...f }) => (
55+
const StyledContainerQuery = React.forwardRef(({ className, ...f }, ref) => (
5556
<ContainerQuery query={query}>
56-
{params => <StyledComponent className={classNames(params, className)} {...f} />}
57+
{params => <StyledComponent ref={ref} className={classNames(params, className)} {...f} />}
5758
</ContainerQuery>
58-
)
59-
return Object.assign(StyledContainerQuery, StyledComponent)
59+
))
60+
return hoistStatics(StyledContainerQuery, StyledComponent)
6061
}
6162

6263
const styledContainerQuery = (() => {

0 commit comments

Comments
 (0)