Skip to content

Commit 619f55f

Browse files
committed
Use generated component examples texts
1 parent 6af02d5 commit 619f55f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+615
-774
lines changed

packages/react-renderer-demo/src/app/src/components/component-example-text.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,35 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import ComponentExample from '@docs/components/component-example';
44
import { Heading } from './mdx/mdx-components';
5+
import avalableMappers from '../helpers/available-mappers';
56

6-
const ComponentExampleText = ({ component, activeMapper, baseStructure }) => {
7-
return (
8-
<React.Fragment>
9-
<Heading level="4" component="h1">
10-
{baseStructure.linkText}
11-
</Heading>
12-
<ComponentExample activeMapper={activeMapper} baseStructure={baseStructure} component={component} />
13-
<div hidden={activeMapper !== 'mui'} className="mui">
14-
<Heading level="5" component="h2">{`MUI ${baseStructure.linkText}`}</Heading>
15-
<baseStructure.ContentText activeMapper={activeMapper} component={component} />
7+
const ComponentExampleText = ({ linkText, schema, variants, component, activeMapper, ContentText }) => (
8+
<React.Fragment>
9+
<Heading level="4" component="h1">
10+
{linkText}
11+
</Heading>
12+
<ComponentExample variants={variants} schema={schema} activeMapper={activeMapper} component={component} />
13+
{avalableMappers.map(({ mapper, title }) => (
14+
<div key={mapper} hidden={activeMapper !== mapper}>
15+
<Heading level="5" component="h2">{`${title} ${linkText}`}</Heading>
16+
<ContentText activeMapper={activeMapper} component={component} />
1617
</div>
17-
<div hidden={activeMapper !== 'pf3'}>
18-
<Heading level="5" component="h2">{`PF3 ${baseStructure.linkText}`}</Heading>
19-
<baseStructure.ContentText activeMapper={'pf3'} component={component} />
20-
</div>
21-
<div hidden={activeMapper !== 'pf4'}>
22-
<Heading level="5" component="h2">{`PF4 ${baseStructure.linkText}`}</Heading>
23-
<baseStructure.ContentText activeMapper={'pf4'} component={component} />
24-
</div>
25-
<div hidden={activeMapper !== 'blueprint'}>
26-
<Heading level="5" component="h2">{`Blueprint ${baseStructure.linkText}`}</Heading>
27-
<baseStructure.ContentText activeMapper={'blueprint'} component={component} />
28-
</div>
29-
</React.Fragment>
30-
);
31-
};
18+
))}
19+
</React.Fragment>
20+
);
3221

3322
ComponentExampleText.propTypes = {
3423
component: PropTypes.string.isRequired,
35-
activeMapper: PropTypes.oneOf(['mui', 'pf4', 'pf3']),
36-
baseStructure: PropTypes.shape({ linkText: PropTypes.string.isRequired }).isRequired
24+
activeMapper: PropTypes.oneOf(avalableMappers.map(({ mapper }) => mapper)),
25+
linkText: PropTypes.string.isRequired,
26+
ContentText: PropTypes.elementType,
27+
schema: PropTypes.object.isRequired,
28+
variants: PropTypes.arrayOf(PropTypes.object)
29+
};
30+
31+
ComponentExampleText.defaultProps = {
32+
variants: [],
33+
ContentText: () => null
3734
};
3835

3936
export default ComponentExampleText;

packages/react-renderer-demo/src/app/src/components/component-example.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { pf4Code, pf4WizardCode, pf4Html, pf4Dependencies } from '../stackblitz-
2424
import { pf3Code, pf3WizardCode, pf3Html, pf3Dependencies } from '../stackblitz-templates/pf3-templates';
2525
import { blueprintCode, blueprintWizardCode, blueprintHtml, blueprintDependencies } from '../stackblitz-templates/blueprint-templates';
2626
import { suirCode, suirWizardCode, suirHtml, suirDependencies } from '../stackblitz-templates/suir-template';
27+
import avalableMappers from '../helpers/available-mappers';
2728

2829
const project = {
2930
settings: {
@@ -146,15 +147,7 @@ const mapperTab = {
146147
suir: 4
147148
};
148149

149-
const tabs = [
150-
{ title: 'MUI', mapper: 'mui' },
151-
{ title: 'PF4', mapper: 'pf4' },
152-
{ title: 'PF3', mapper: 'pf3' },
153-
{ title: 'BJS', mapper: 'blueprint' },
154-
{ title: 'SUIR', mapper: 'suir' }
155-
];
156-
157-
const ComponentExample = ({ baseStructure, activeMapper, component }) => {
150+
const ComponentExample = ({ variants, schema, activeMapper, component }) => {
158151
const activeTab = mapperTab[activeMapper];
159152
const { pathname, push } = useRouter();
160153
const classes = useStyles();
@@ -167,15 +160,15 @@ const ComponentExample = ({ baseStructure, activeMapper, component }) => {
167160
files: {
168161
...blitzFiles[activeMapper],
169162
...(component === 'wizard' && { 'index.js': blitzWizards[activeMapper] }),
170-
'schema.js': `export default ${JSON.stringify(baseStructure.value, null, 2)};`
163+
'schema.js': `export default ${JSON.stringify(schema, null, 2)};`
171164
}
172165
},
173166
{ height: '100%', hideNavigation: true, forceEmbedLayout: true, openFile: 'schema.js' }
174167
);
175-
}, [activeMapper, baseStructure.value]);
168+
}, [activeMapper, schema]);
176169

177170
const renderMapperTabs = () =>
178-
tabs.map(({ title, mapper }, index) => (
171+
avalableMappers.map(({ title, mapper }, index) => (
179172
<Tab
180173
key={mapper}
181174
value={index}
@@ -205,7 +198,7 @@ const ComponentExample = ({ baseStructure, activeMapper, component }) => {
205198
</TableRow>
206199
</TableHead>
207200
<TableBody>
208-
{baseStructure.variants.map(({ name, type, required }) => (
201+
{variants.map(({ name, type, required }) => (
209202
<TableRow key={name}>
210203
<TableCell>{name}</TableCell>
211204
<TableCell>{`${type}`}</TableCell>
@@ -255,10 +248,14 @@ const ComponentExample = ({ baseStructure, activeMapper, component }) => {
255248
ComponentExample.propTypes = {
256249
component: PropTypes.string.isRequired,
257250
activeMapper: PropTypes.string.isRequired,
258-
baseStructure: PropTypes.shape({
259-
variants: PropTypes.array.isRequired,
260-
value: PropTypes.object.isRequired
261-
}).isRequired
251+
schema: PropTypes.object.isRequired,
252+
variants: PropTypes.arrayOf(
253+
PropTypes.shape({
254+
name: PropTypes.string.isRequired,
255+
type: PropTypes.string.isRequired,
256+
required: PropTypes.bool
257+
})
258+
).isRequired
262259
};
263260

264261
export default ComponentExample;

0 commit comments

Comments
 (0)