Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back "passthrough" props table note #907

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading