Skip to content

Commit

Permalink
Supply MDX rendering components via a DRY approach
Browse files Browse the repository at this point in the history
  • Loading branch information
btalb committed Mar 20, 2022
1 parent f1e6c76 commit 58cb8f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
6 changes: 3 additions & 3 deletions demo_assets/component_demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import {
TableRow,
} from '@mui/material';

interface DemoComponentProps {
interface DemoRobotTableProps {
name: string;
description: string;
image: string;
features: string[];
}

export default function DemoComponent({
export default function DemoRobotTable({
name,
description,
image,
features,
}: DemoComponentProps) {
}: DemoRobotTableProps) {
return (
<TableContainer>
<Table sx={{width: '100% !important', display: 'table !important'}}>
Expand Down
4 changes: 2 additions & 2 deletions demo_assets/custom_components.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {ComponentDeclarations} from 'lib/loaders/handlebars-helpers';

import DemoComponent from './component_demo';
import DemoRobotTable from './component_demo';

const components: ComponentDeclarations = {
DemoRobotTable: (ctx: any) => <DemoComponent {...ctx} />,
DemoRobotTable: (ctx: any) => <DemoRobotTable {...ctx} />,
};

export default components;
20 changes: 4 additions & 16 deletions pages/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ import {MDXProvider} from '@mdx-js/react';

import {TABS} from './index';

import Md from 'demo_assets/markdown_demo.md?full';
import customComponents from 'demo_assets/custom_components';
import {components} from 'qcr-sites-shared/loaders/handlebars-helpers';

import DemoComponent from 'demo_assets/component_demo';

import {Button} from '@mui/material';

const cs = {
DemoComponent: (props) => (
<DemoComponent
name={props.name}
description={props.description}
image={props.image}
features={props.features}
/>
),
};
import Mdx from 'demo_assets/markdown_demo.md?full';

export default function MarkdownPage() {
return (
Expand All @@ -37,7 +25,7 @@ export default function MarkdownPage() {
<QcrText>
<QcrTitle>Demonstration of markdown capabilities</QcrTitle>
<QcrMarkdown>
<Md components={cs} />
<Mdx components={{...components, ...customComponents}} />
</QcrMarkdown>
</QcrText>
</QcrBody>
Expand Down

0 comments on commit 58cb8f9

Please sign in to comment.