Skip to content

Commit

Permalink
Add "passthrough" note back to docs props table
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJDev committed Dec 20, 2024
1 parent 8913a83 commit bbcfc17
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/layouts/react-component-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const query = graphql`
required
deprecated
}
passthrough {
element
url
}
subcomponents {
name
props {
Expand All @@ -67,6 +71,10 @@ export const query = graphql`
required
deprecated
}
passthrough {
element
url
}
}
}
Expand All @@ -77,7 +85,7 @@ export const query = graphql`
`

export default function ReactComponentLayout({data}) {
const {name, status, a11yReviewed, importPath, props: componentProps, subcomponents, stories} = data.reactComponent
const {name, status, a11yReviewed, importPath, passthrough, props: componentProps, subcomponents, stories} = data.reactComponent
// This is a temporary and very hacky fix to make sure TooltipV2 has the correct component name in the import path.
// We will remove this once https://github.com/primer/react/pull/4483 is merged and release.
let componentName = name
Expand Down Expand Up @@ -252,11 +260,11 @@ export default function ReactComponentLayout({data}) {

<H2>Props</H2>
<H3>{name}</H3>
<ReactPropsTable props={componentProps} />
<ReactPropsTable passthrough={passthrough} props={componentProps} />
{subcomponents?.map(subcomponent => (
<>
<H3>{subcomponent.name}</H3>
<ReactPropsTable props={subcomponent.props} />
<ReactPropsTable passthrough={subcomponent.passthrough} props={subcomponent.props} />
</>
))}
</Box>
Expand All @@ -276,6 +284,7 @@ function sentenceCase(str: string) {
// TODO: Make table responsive
function ReactPropsTable({
props,
passthrough,
}: {
props: Array<{
name: string
Expand All @@ -285,13 +294,19 @@ function ReactPropsTable({
deprecated: boolean
description: string
}>
passthrough: {
url: string
element: string
}
}) {
if (props.length === 0) {
return (
<Box sx={{padding: 3, bg: 'canvas.inset', textAlign: 'center', color: 'fg.muted', borderRadius: 2}}>No props</Box>
)
}

const isPolymorphic = props.find(({name}) => name === 'as');

return (
<Box sx={{overflow: 'auto'}}>
<Table>
Expand Down Expand Up @@ -340,6 +355,21 @@ function ReactPropsTable({
</td>
</tr>
))}
{passthrough && (
<tr>
<Box as="td" colSpan={3} fontSize={1} verticalAlign="top">
Additional props are passed to the <InlineCode>&lt;{passthrough?.element}&gt;</InlineCode> element. See{' '}
the <Link href={passthrough.url}>docs for {passthrough?.element}</Link> for a list of props/attributes accepted by the <InlineCode>&lt;{passthrough.element}&gt;</InlineCode>{' '}
element.
{isPolymorphic && (
<>
{' '}
If an <InlineCode>as</InlineCode> prop is specified, the accepted props will change accordingly.
</>
)}
</Box>
</tr>
)}
</tbody>
</Table>
</Box>
Expand Down

0 comments on commit bbcfc17

Please sign in to comment.