Skip to content

Commit

Permalink
fix(docz): prevent crash when use imported props
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Sep 11, 2018
1 parent a28ab79 commit ef6de9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/docz/src/components/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export interface PropType {
name: string
value?: any
raw?: any
computed?: boolean
}

export interface FlowType extends PropType {
elements: FlowTypeElement[]
name: string
raw: string
type?: string
computed?: boolean
signature?: {
arguments: FlowTypeArgs[]
return: {
Expand Down Expand Up @@ -73,12 +75,13 @@ export type TooltipComponent = React.ComponentType<{

const getPropType = (prop: Prop, Tooltip?: TooltipComponent) => {
const propName = prop.flowType ? prop.flowType.name : prop.type.name
const isEnum = propName.startsWith('"')
const isEnum = propName.startsWith('"') || propName === 'enum'
const name = capitalize(isEnum ? 'enum' : propName)
const value = prop.type && prop.type.value

if (!name) return null
if (!Tooltip) return name
if (isEnum && typeof value === 'string') return name
if (!prop.flowType && !isEnum && !value) return name
if (prop.flowType && !prop.flowType.elements) return name

Expand Down
1 change: 1 addition & 0 deletions packages/docz/src/utils/humanize-prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getTypeStr = (type: PropType | FlowType): any => {
case 'instanceof':
return `Class(${type.value})`
case 'enum':
if (type.computed) return type.value
return type.value
? type.value.map((v: any) => `${v.value}`).join(' │ ')
: type.raw
Expand Down

0 comments on commit ef6de9d

Please sign in to comment.