Skip to content

Commit 027e2c0

Browse files
heiskrCopilot
andauthored
🕸️ Tidy GraphqlItem markup; render Enum values as a table (#61435)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 51f2444 commit 027e2c0

2 files changed

Lines changed: 37 additions & 29 deletions

File tree

src/graphql/components/Enum.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import React from 'react'
2-
31
import { useTranslation } from '@/languages/components/useTranslation'
42
import { GraphqlItem } from './GraphqlItem'
53
import type { EnumT } from './types'
@@ -14,18 +12,28 @@ export function Enum({ item }: Props) {
1412

1513
return (
1614
<GraphqlItem item={item} heading={heading}>
17-
{item.values.map((value) => (
18-
<React.Fragment key={`${value.name}-${value.description}`}>
19-
<p>
20-
<strong>{value.name}</strong>
21-
</p>
22-
<div
23-
dangerouslySetInnerHTML={{
24-
__html: value.description,
25-
}}
26-
/>
27-
</React.Fragment>
28-
))}
15+
<table className="fields width-full table-fixed">
16+
<thead>
17+
<tr>
18+
<th>{t('reference.name')}</th>
19+
<th>{t('reference.description')}</th>
20+
</tr>
21+
</thead>
22+
<tbody>
23+
{item.values.map((value) => (
24+
<tr key={`${value.name}-${value.description}`}>
25+
<td>
26+
<code>{value.name}</code>
27+
</td>
28+
<td
29+
dangerouslySetInnerHTML={{
30+
__html: value.description,
31+
}}
32+
/>
33+
</tr>
34+
))}
35+
</tbody>
36+
</table>
2937
</GraphqlItem>
3038
)
3139
}

src/graphql/components/GraphqlItem.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ type Props = {
1111
}
1212

1313
export function GraphqlItem({ item, heading, children, headingLevel = 2 }: Props) {
14-
const lowerCaseName = item.name.toLowerCase()
14+
const slug = item.name.toLowerCase()
15+
const hasNotice = Boolean(item.preview || item.isDeprecated)
16+
1517
return (
16-
<div>
17-
<HeadingLink
18-
as={headingLevel === 2 ? 'h2' : headingLevel === 3 ? 'h3' : 'h6'}
19-
slug={lowerCaseName}
20-
>
18+
<>
19+
<HeadingLink as={headingLevel === 2 ? 'h2' : headingLevel === 3 ? 'h3' : 'h6'} slug={slug}>
2120
{item.name}
2221
</HeadingLink>
2322
<div
23+
className="graphql-item-description"
2424
dangerouslySetInnerHTML={{
2525
__html: item.description,
2626
}}
2727
/>
28-
<div>
29-
{item.preview && <Notice item={item} variant="preview" />}
30-
{item.isDeprecated && <Notice item={item} variant="deprecation" />}
31-
</div>
32-
<div>
33-
{heading && <h4 dangerouslySetInnerHTML={{ __html: heading }} />}
34-
{children}
35-
</div>
36-
</div>
28+
{hasNotice && (
29+
<div>
30+
{item.preview && <Notice item={item} variant="preview" />}
31+
{item.isDeprecated && <Notice item={item} variant="deprecation" />}
32+
</div>
33+
)}
34+
{heading && <h4 dangerouslySetInnerHTML={{ __html: heading }} />}
35+
{children}
36+
</>
3737
)
3838
}

0 commit comments

Comments
 (0)