Skip to content

Commit

Permalink
fix(docz): flow props parser integration
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed May 28, 2018
1 parent 9ba6507 commit 5a83610
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions packages/docz/src/components/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ export interface EnumValue {
computed: boolean
}

export interface FlowTypeElement {
name: string
value: string
}

export interface FlowTypeArgs {
name: string
type: {
name: string
}
}

export interface Prop {
required: boolean
description?: string
Expand All @@ -16,6 +28,18 @@ export interface Prop {
defaultValue?: {
value: string
}
flowType?: {
elements: FlowTypeElement[]
name: string
raw: string
type?: string
signature?: {
arguments: FlowTypeArgs[]
return: {
name: string
}
}
}
}

export type ComponentWithDocGenInfo = ComponentType & {
Expand All @@ -40,12 +64,17 @@ export type TooltipComponent = React.ComponentType<{
const getValue = (value: string) => value.replace(/\'/g, '')

const getPropType = (prop: Prop, Tooltip?: TooltipComponent) => {
const name = prop.type.name
const name = prop.flowType ? prop.flowType.name : prop.type.name
const value = prop.type && prop.type.value

if (!Tooltip || !prop.type.value) return name
if (!Tooltip) return name
if ((!prop.flowType && !value) || (prop.flowType && !prop.flowType.elements))
return name

return (
<Tooltip text={prop.type.value.map(val => getValue(val.value)).join(' | ')}>
return prop.flowType ? (
<Tooltip text={prop.flowType.raw}>{name}</Tooltip>
) : (
<Tooltip text={value && value.map(val => getValue(val.value)).join(' | ')}>
{name}
</Tooltip>
)
Expand Down

0 comments on commit 5a83610

Please sign in to comment.