forked from roy-jung/react.dev.ko
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeDiagram.tsx
More file actions
41 lines (38 loc) · 1.15 KB
/
Copy pathCodeDiagram.tsx
File metadata and controls
41 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
import {Children} from 'react';
import * as React from 'react';
import CodeBlock from './CodeBlock';
interface CodeDiagramProps {
children: React.ReactNode;
flip?: boolean;
}
export function CodeDiagram({children, flip = false}: CodeDiagramProps) {
const illustration = Children.toArray(children).filter((child: any) => {
return child.type === 'img';
});
const content = Children.toArray(children).map((child: any) => {
if (child.type?.mdxName === 'pre') {
return <CodeBlock {...child.props} noMargin={true} noMarkers={true} />;
} else if (child.type === 'img') {
return null;
} else {
return child;
}
});
if (flip) {
return (
<section className="my-8 grid grid-cols-1 lg:grid-cols-2 gap-x-8 gap-y-4">
{illustration}
<div className="flex flex-col justify-center">{content}</div>
</section>
);
}
return (
<section className="my-8 grid grid-cols-1 lg:grid-cols-2 gap-x-8 gap-y-4">
<div className="flex flex-col justify-center">{content}</div>
<div className="py-4">{illustration}</div>
</section>
);
}