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

compose shouldForwardProp #670

Merged
merged 2 commits into from
May 25, 2018
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
10 changes: 9 additions & 1 deletion packages/create-emotion-styled/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ function createEmotionStyled(emotion: Emotion, view: ReactType) {
staticClassName = options.e
identifierName = options.label
stableClassName = options.target
shouldForwardProp = options.shouldForwardProp
shouldForwardProp =
tag.__emotion_forwardProp && options.shouldForwardProp
? propName =>
tag.__emotion_forwardProp(propName) &&
// $FlowFixMe
options.shouldForwardProp(propName)
: options.shouldForwardProp
}
const isReal = tag.__emotion_real === tag
const baseTag =
Expand Down Expand Up @@ -75,6 +81,7 @@ function createEmotionStyled(emotion: Emotion, view: ReactType) {
static __emotion_styles: Interpolations
static __emotion_base: Styled
static __emotion_target: string
static __emotion_forwardProp: void | (string => boolean)
static withComponent: (ElementType, options?: StyledOptions) => any

componentWillMount() {
Expand Down Expand Up @@ -148,6 +155,7 @@ function createEmotionStyled(emotion: Emotion, view: ReactType) {
Styled.__emotion_styles = styles
Styled.__emotion_base = baseTag
Styled.__emotion_real = Styled
Styled.__emotion_forwardProp = shouldForwardProp
Object.defineProperty(Styled, 'toString', {
enumerable: false,
value() {
Expand Down
15 changes: 15 additions & 0 deletions packages/react-emotion/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,18 @@ describe('styled', () => {
expect(tree).toMatchSnapshot()
})
})

test('composes shouldForwardProp on composed styled components', () => {
const StyledDiv = styled('div', {
shouldForwardProp: prop => prop === 'forwardMe'
})()

const ComposedDiv = styled(StyledDiv, {
shouldForwardProp: () => true
})()

const tree = renderer.create(<ComposedDiv filterMe forwardMe />).toJSON()

expect(tree.props.filterMe).toBeUndefined()
expect(tree.props.forwardMe).toBeDefined()
})