Skip to content

Commit ce3bea5

Browse files
fix(tables): only render props/css tables when needed (#102)
1 parent 364dbc0 commit ce3bea5

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

src/components/DocsTables.astro

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
import { Stack, StackItem } from '@patternfly/react-core'
3+
import PropsTables from './PropsTables.astro'
4+
import CSSTable from './CSSTable.astro'
5+
6+
const { propComponents, cssPrefix } = Astro.props
7+
8+
const hasTables = !!propComponents || !!cssPrefix
9+
---
10+
11+
<>
12+
{
13+
hasTables && (
14+
<Stack hasGutter>
15+
{propComponents && (
16+
<StackItem>
17+
<PropsTables propComponents={propComponents} server:defer />
18+
</StackItem>
19+
)}
20+
{cssPrefix && (
21+
<StackItem>
22+
<CSSTable cssPrefix={cssPrefix} server:defer />
23+
</StackItem>
24+
)}
25+
</Stack>
26+
)
27+
}
28+
</>

src/pages/[section]/[...page].astro

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
---
22
import { getCollection, render } from 'astro:content'
3-
import { Title, PageSection, Stack, StackItem } from '@patternfly/react-core'
3+
import { Title, PageSection } from '@patternfly/react-core'
44
import MainLayout from '../../layouts/Main.astro'
55
import { content } from '../../content'
66
import { kebabCase } from '../../utils/case'
77
import { componentTabs } from '../../globals'
8-
import PropsTables from '../../components/PropsTables.astro'
9-
import CSSTable from '../../components/CSSTable.astro'
108
import SectionGallery from '../../components/section-gallery/SectionGallery.astro'
119
import LiveExample from '../../components/LiveExample.astro'
1210
import {
@@ -29,6 +27,7 @@ import {
2927
dt,
3028
dd,
3129
} from '../../components/Content'
30+
import DocsTables from '../../components/DocsTables.astro'
3231
3332
export async function getStaticPaths() {
3433
const collections = await Promise.all(
@@ -91,13 +90,10 @@ if (section === 'components' && componentTabs[id]) {
9190
LiveExample,
9291
}}
9392
/>
94-
<Stack hasGutter>
95-
<StackItem>
96-
<PropsTables propComponents={propComponents} server:defer />
97-
</StackItem>
98-
<StackItem>
99-
<CSSTable cssPrefix={cssPrefix} server:defer />
100-
</StackItem>
101-
</Stack>
93+
<DocsTables
94+
propComponents={propComponents}
95+
cssPrefix={cssPrefix}
96+
server:defer
97+
/>
10298
</PageSection>
10399
</MainLayout>

src/pages/[section]/[page]/[...tab].astro

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
---
22
import { getCollection, render } from 'astro:content'
3-
import { Title, PageSection, Stack, StackItem } from '@patternfly/react-core'
3+
import { Title, PageSection } from '@patternfly/react-core'
44
import MainLayout from '../../../layouts/Main.astro'
55
import { content } from '../../../content'
66
import { kebabCase } from '../../../utils/case'
77
import { componentTabs, tabNames, buildTab, sortTabs } from '../../../globals'
8-
import PropsTables from '../../../components/PropsTables.astro'
98
import {
109
h1,
1110
h2,
@@ -27,7 +26,7 @@ import {
2726
dd,
2827
} from '../../../components/Content'
2928
import LiveExample from '../../../components/LiveExample.astro'
30-
import CSSTable from '../../../components/CSSTable.astro'
29+
import DocsTables from '../../../components/DocsTables.astro'
3130
3231
export async function getStaticPaths() {
3332
const collections = await Promise.all(
@@ -126,13 +125,6 @@ const currentPath = Astro.url.pathname
126125
LiveExample,
127126
}}
128127
/>
129-
<Stack hasGutter>
130-
<StackItem>
131-
<PropsTables propComponents={propComponents} server:defer />
132-
</StackItem>
133-
<StackItem>
134-
<CSSTable cssPrefix={cssPrefix} server:defer />
135-
</StackItem>
136-
</Stack>
128+
<DocsTables propComponents={propComponents} cssPrefix={cssPrefix} server:defer />
137129
</PageSection>
138130
</MainLayout>

0 commit comments

Comments
 (0)