Skip to content

Commit 4f75441

Browse files
author
Eric Olkowski
committed
Resolved feedback, reverted main page changes
1 parent 1dc1e48 commit 4f75441

File tree

3 files changed

+31
-80
lines changed

3 files changed

+31
-80
lines changed

src/components/PropsTable.tsx

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,42 @@ export const PropsTable: React.FunctionComponent<PropsTableProps> = ({
3939
const SectionHeading = headingLevel
4040
const publicProps = componentProps?.filter((prop) => !prop.isHidden)
4141
const hasPropsToRender = !!publicProps?.length
42-
const betaDeprecatedProps = hasPropsToRender
43-
? publicProps.filter((prop) => prop.isBeta && prop.isDeprecated)
44-
: []
45-
46-
if (betaDeprecatedProps.length) {
47-
// eslint-disable-next-line no-console
48-
console.error(
49-
`The following ${componentName} props have both the isBeta and isDeprecated tag: ${betaDeprecatedProps.map((prop) => prop.name).join(', ')}`,
50-
)
51-
}
5242

5343
const renderTagLabel = (componentProp: ComponentProp) => {
54-
const { isBeta, isDeprecated } = componentProp
44+
const { name, isBeta, isDeprecated } = componentProp
5545
if (!isBeta && !isDeprecated) {
5646
return null
5747
}
5848

49+
if (isBeta && isDeprecated) {
50+
// eslint-disable-next-line no-console
51+
console.error(
52+
`The ${name} prop for ${componentName} has both the isBeta and isDeprecated tag.`,
53+
)
54+
}
55+
5956
return (
60-
<Label
61-
// Would need design eyes on outline vs filled
62-
variant="outline"
63-
color={`${isBeta ? 'blue' : 'orange'}`}
64-
isCompact
65-
>
57+
<Label color={`${isBeta ? 'blue' : 'grey'}`} isCompact>
6658
{isBeta ? 'Beta' : 'Deprecated'}
6759
</Label>
6860
)
6961
}
7062

63+
const renderRequiredDescription = (isRequired: boolean | undefined) => {
64+
if (!isRequired) {
65+
return null
66+
}
67+
68+
return (
69+
<>
70+
<span aria-hidden="true" className={css(textStyles.textColorRequired)}>
71+
*
72+
</span>
73+
<span className={css(accessibleStyles.screenReader)}>required</span>
74+
</>
75+
)
76+
}
77+
7178
return (
7279
<>
7380
<SectionHeading>{componentName}</SectionHeading>
@@ -108,23 +115,7 @@ export const PropsTable: React.FunctionComponent<PropsTableProps> = ({
108115
<Td>
109116
<TableText wrapModifier="breakWord">
110117
{prop.name}
111-
{prop.isRequired ? (
112-
<>
113-
<span
114-
aria-hidden="true"
115-
className={css(textStyles.textColorRequired)}
116-
>
117-
*
118-
</span>
119-
<span
120-
className={css(accessibleStyles.screenReader)}
121-
>
122-
required
123-
</span>
124-
</>
125-
) : (
126-
''
127-
)}{' '}
118+
{renderRequiredDescription(prop.isRequired)}{' '}
128119
{renderTagLabel(prop)}
129120
</TableText>
130121
</Td>

src/components/__tests__/PropsTable.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ it('Renders component description when componentDescription is passed in', () =>
4444
/>,
4545
)
4646

47-
expect(screen.getByText(componentDescription)).toBeVisible()
47+
expect(screen.getByTestId('component-description')).toHaveTextContent(
48+
componentDescription,
49+
)
4850
})
4951

5052
it('Does not render props table if componentProps is not passed in', () => {
@@ -83,7 +85,7 @@ it('Throws error if component prop has isBeta and isDeprecated both set to true'
8385

8486
expect(consoleSpy).toHaveBeenCalledTimes(1)
8587
expect(consoleSpy).toHaveBeenCalledWith(
86-
'The following TestComponent props have both the isBeta and isDeprecated tag: propWithAllTableColumns',
88+
`The ${propWithAllTableColumns.name} prop for TestComponent has both the isBeta and isDeprecated tag.`,
8789
)
8890
consoleSpy.mockRestore()
8991
})
@@ -101,7 +103,7 @@ it('Does not throw error if only one of isBeta or isDeprecated is passed', () =>
101103
consoleSpy.mockRestore()
102104
})
103105

104-
it('Does not throw error if isBeta and isDeprecated both are not passed', () => {
106+
it('Does not throw error if neither isBeta nor isDeprecated are passed', () => {
105107
const consoleSpy = jest.spyOn(console, 'error').mockImplementation()
106108
render(
107109
<PropsTable

src/pages/index.astro

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,6 @@
11
---
22
import '../styles/global.scss'
33
import MainLayout from '../layouts/Main.astro'
4-
import { PropsTable } from '../components/PropsTable'
5-
6-
const propsData = [
7-
{
8-
name: 'variant',
9-
type: "'success' | 'danger' | 'warning' | 'info' | 'custom'",
10-
defaultValue: '',
11-
description: 'Adds alert variant styles.',
12-
isBeta: true,
13-
},
14-
{
15-
name: 'children',
16-
isRequired: true,
17-
type: 'ReactNode',
18-
defaultValue: '',
19-
},
20-
{
21-
name: 'timeoutAnimation',
22-
isRequired: false,
23-
type: undefined,
24-
defaultValue: '3000',
25-
description:
26-
'If the user hovers over the alert and `timeout` expires, this is how long to wait before finally dismissing the alert.',
27-
isDeprecated: true,
28-
},
29-
{
30-
name: 'innerRef',
31-
isHidden: true,
32-
description: 'Ref to pass',
33-
},
34-
]
354
---
365

376
<html lang="en">
@@ -43,17 +12,6 @@ const propsData = [
4312
<title>PatternFly</title>
4413
</head>
4514
<body>
46-
<MainLayout title="PatternFly X Astro">
47-
<PropsTable
48-
componentName="Alert"
49-
componentDescription="The main alert component."
50-
componentProps={propsData}
51-
/>
52-
<PropsTable
53-
componentName="AlertGroup"
54-
componentDescription="The container to render a list of alerts."
55-
/>
56-
<PropsTable componentName="AlertTitle" />
57-
</MainLayout>
15+
<MainLayout title="PatternFly X Astro"> Page content </MainLayout>
5816
</body>
5917
</html>

0 commit comments

Comments
 (0)