This repository was archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathWrapperApiReference.js
47 lines (44 loc) · 1.78 KB
/
WrapperApiReference.js
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
42
43
44
45
46
47
import React from "react";
import PropTypes from "prop-types";
import partition from "lodash/partition";
import { Article } from "basics/Text";
import { CustomColumn } from "components/ApiReference/SharedStyles";
const RIGHT_COLUMN_COMPONENTS_NAME = {
CodeExample: "CodeExample",
EndpointsTable: "EndpointsTable",
ExampleResponse: "ExampleResponse",
MethodTable: "MethodTable",
};
// API reference has 2 columns, with certain types of content always being in one
// or the other. This component sorts through its children to separate them.
export const WrapperApiReference = ({ children, ...props }) => {
const [rightColumnContent, middleColumnContent] = React.useMemo(
() =>
partition(
React.Children.toArray(children),
(child) => RIGHT_COLUMN_COMPONENTS_NAME[child.props.mdxType],
),
[children],
);
return (
<React.Fragment>
{/* Hack to make it look appear as if we had a column-gap
4rem in between <CustomColumn/> on a large screen (min-width: 1440px)
skip the 1st column to use it as column-gap, start at the 2nd column and
span through then next 8 columns (ends at column 9) */}
<CustomColumn xs={5} xl={9} xlColumn="2 / span 8">
<Article {...props}>{middleColumnContent}</Article>
</CustomColumn>
{/* Hack to make it look appear as if we had a column-gap
4rem in between <CustomColumn/> on a large screen (min-width: 1440px)
skip the 10th column to use it as column-gap, start at the 11th column and
span through the next 8 columns (ends at column 18) */}
<CustomColumn forwardedAs="aside" xs={4} xl={9} xlColumn="11 / span 8">
{rightColumnContent}
</CustomColumn>
</React.Fragment>
);
};
WrapperApiReference.propTypes = {
children: PropTypes.node.isRequired,
};