import React from 'react'; import { error as errorComponent } from './error'; import { useDocgenInfo } from './docgen'; import type { ComponentWithDocGenInfo, Prop } from './types'; type PropsProps = { /** Component with documentation info for which to list the props details. */ of: ComponentWithDocGenInfo; filter: (prop: Prop) => boolean; }; const getType = (prop: Prop) => { const type = prop.type || prop.tsType; if (!type) return 'undefined'; switch (type.name) { case 'union': case 'intersection': return type.raw; case 'enum': return type.value.map((v) => v.value).join(' | '); default: return type.name; } }; /** Used for listing the props details of a React component. */ export const Props = ({ of, filter = (p) => true }: PropsProps) => { const [docgenInfo, error] = useDocgenInfo(of); if (error) { return errorComponent(error.message); } const props = docgenInfo?.props; if (!props) { return 'Loading...'; } return (
| Name | Description | Type(s) | Default | Required |
|---|---|---|---|---|
| {name} | {prop.description} |
{getType(prop)}
|
{prop.defaultValue?.value} | {prop.required.toString()} |