Skip to content

Commit

Permalink
Readd component displayName fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Apr 22, 2017
1 parent d16997d commit 28e14e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/models/StyledComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import createWarnTooManyClasses from '../utils/createWarnTooManyClasses'
import validAttr from '../utils/validAttr'
import isTag from '../utils/isTag'
import isStyledComponent from '../utils/isStyledComponent'
import getComponentName from '../utils/getComponentName'
import type { RuleSet, Target } from '../types'

import AbstractStyledComponent from './AbstractStyledComponent'
Expand Down Expand Up @@ -172,7 +173,7 @@ export default (ComponentStyle: Function, constructWithOptions: Function) => {
rules: RuleSet,
) => {
const {
displayName = isTag(target) ? `styled.${target}` : `Styled(${target.displayName})`,
displayName = isTag(target) ? `styled.${target}` : `Styled(${getComponentName(target)})`,
componentId = generateId(options.displayName),
ParentComponent = BaseStyledComponent,
rules: extendingRules,
Expand Down
3 changes: 2 additions & 1 deletion src/models/StyledNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Theme } from './ThemeProvider'

import isTag from '../utils/isTag'
import isStyledComponent from '../utils/isStyledComponent'
import getComponentName from '../utils/getComponentName'
import type { RuleSet, Target } from '../types'

import { CHANNEL } from './ThemeProvider'
Expand Down Expand Up @@ -120,7 +121,7 @@ export default (constructWithOptions: Function) => {
rules: RuleSet,
) => {
const {
displayName = isTag(target) ? `styled.${target}` : `Styled(${target.displayName})`,
displayName = isTag(target) ? `styled.${target}` : `Styled(${getComponentName(target)})`,
ParentComponent = BaseStyledNativeComponent,
rules: extendingRules,
attrs,
Expand Down
10 changes: 10 additions & 0 deletions src/utils/getComponentName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @flow

/* eslint-disable no-undef */
export default function getComponentName(target: ReactClass<*>): string {
return (
target.displayName ||
target.name ||
'Component'
)
}

0 comments on commit 28e14e8

Please sign in to comment.