Skip to content

Commit 98efe01

Browse files
author
Jacob Logan
committed
merge template changes
2 parents aaf93da + 01da321 commit 98efe01

File tree

26 files changed

+738911
-98
lines changed

26 files changed

+738911
-98
lines changed

mdx-components.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { InternalLinkButton } from './src/components/InternalLinkButton';
2222
import { Grid, View } from '@aws-amplify/ui-react';
2323
import { Columns } from './src/components/Columns';
2424
import { Video } from './src/components/Video';
25+
import { ReferencePage } from './src/components/ApiDocs';
2526

2627
const ResponsiveImage = (props) => (
2728
<ExportedImage style={{ height: 'auto' }} {...props} />
@@ -71,6 +72,7 @@ export function useMDXComponents(components: MDXComponents): MDXComponents {
7172
Columns,
7273
Video,
7374
View,
75+
ReferencePage,
7476
...components
7577
};
7678
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Fragment } from 'react';
2+
import { View } from '@aws-amplify/ui-react';
3+
import { parseMarkdownLinks } from '@/utils/parseMdxLinks';
4+
5+
interface ApiCommentProps {
6+
apiComment?: any[];
7+
codeBlock?: boolean | undefined;
8+
}
9+
10+
export const ApiComment = ({ apiComment, codeBlock }: ApiCommentProps) => {
11+
if (!apiComment) return null;
12+
const firstItem = apiComment[0];
13+
if (!firstItem?.text?.replaceAll('-', '')?.trim()) {
14+
apiComment.shift();
15+
}
16+
const commentList = apiComment.map((snippet, idx) => {
17+
if (snippet.kind === 'code') {
18+
return <code key={idx}>{snippet.text.replaceAll('`', '')}</code>;
19+
} else {
20+
const text = snippet.text;
21+
if (idx === 0 && codeBlock) {
22+
const words = text.split(' ');
23+
return (
24+
<Fragment key={`snippet-${idx}`}>
25+
<code>{words[0]}</code>
26+
{words.slice(1).join(' ')}
27+
</Fragment>
28+
);
29+
} else {
30+
return parseMarkdownLinks(text);
31+
}
32+
}
33+
});
34+
35+
return <View>{commentList}</View>;
36+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { useState, createContext } from 'react';
2+
import { LinkDataType } from './display/TypeLink';
3+
import { ApiModal } from './display/ApiModal';
4+
5+
export const TypeContext = createContext({
6+
setModalData: (data) => data,
7+
modalOpen: () => {},
8+
addBreadCrumb: (data) => data,
9+
setBC: (data) => data
10+
});
11+
12+
export const ApiModalProvider = ({ children }) => {
13+
const [modalData, setModalData] = useState({});
14+
const [showModal, setShowModal] = useState(false);
15+
const [breadCrumbs, setBreadCrumbs] = useState<LinkDataType[]>([]);
16+
17+
const modalOpen = () => {
18+
setShowModal(true);
19+
};
20+
const closeModal = () => {
21+
setShowModal(false);
22+
};
23+
24+
const addBreadCrumb = (bc) => {
25+
breadCrumbs.push(bc);
26+
setBreadCrumbs(breadCrumbs);
27+
};
28+
29+
const setBC = (bc) => {
30+
setBreadCrumbs(bc);
31+
};
32+
33+
const clearBC = () => {
34+
setBreadCrumbs([]);
35+
};
36+
37+
const value = {
38+
setModalData,
39+
modalOpen,
40+
addBreadCrumb,
41+
setBC
42+
};
43+
44+
return (
45+
<TypeContext.Provider value={value}>
46+
<ApiModal
47+
data={modalData}
48+
showModal={showModal}
49+
close={closeModal}
50+
breadCrumbs={breadCrumbs}
51+
clearBC={clearBC}
52+
/>
53+
{children}
54+
</TypeContext.Provider>
55+
);
56+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { FunctionSignature } from './FunctionSignature';
3+
4+
export const FunctionReference = ({ func }) => {
5+
return (
6+
<View>
7+
{func.signatures.map((sig, index) => (
8+
<FunctionSignature sig={sig} key={`signature-${index}`} />
9+
))}
10+
</View>
11+
);
12+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading } from '../MDXComponents';
3+
import { Promise } from './display/Promise';
4+
import { ApiComment } from './ApiComment';
5+
import references from '@/directory/apiReferences.json';
6+
7+
export const FunctionReturn = ({ functionReturn, sigName }) => {
8+
const name = functionReturn.name;
9+
let display, description;
10+
if (name === 'Promise') {
11+
const returnType = references[functionReturn.typeArguments[0].target];
12+
display = <Promise typeObject={functionReturn} />;
13+
if (returnType?.comment?.summary) {
14+
description = <ApiComment apiComment={returnType.comment.summary} />;
15+
}
16+
} else {
17+
const returnType = references[functionReturn.target];
18+
display = name;
19+
if (returnType?.comment?.summary) {
20+
description = <ApiComment apiComment={returnType.comment.summary} />;
21+
}
22+
}
23+
return (
24+
<View>
25+
<MDXHeading level={3} id={`${sigName}-Returns`}>
26+
Returns
27+
</MDXHeading>
28+
29+
{display}
30+
31+
{description}
32+
</View>
33+
);
34+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading } from '../MDXComponents';
3+
import { ApiComment } from './ApiComment';
4+
import { Parameters } from './Parameters';
5+
import { Throws } from './Throws';
6+
import { FunctionReturn } from './FunctionReturn';
7+
import references from '@/directory/apiReferences.json';
8+
9+
export const FunctionSignature = ({ sig }) => {
10+
const sigObject = references[sig];
11+
const description = sigObject?.comment?.summary;
12+
const parameters = sigObject?.parameters;
13+
const throws = sigObject?.comment?.blockTags?.filter(
14+
(tagObject) => tagObject['tag'] === '@throws'
15+
);
16+
const returns = sigObject?.type;
17+
return (
18+
<View>
19+
<MDXHeading level={2} id={`${sigObject.name}-${sigObject.id}`}>
20+
{sigObject.name}
21+
</MDXHeading>
22+
23+
{description && <ApiComment apiComment={description} />}
24+
25+
{parameters && (
26+
<Parameters
27+
parameters={parameters}
28+
sigName={`${sigObject.name}-${sigObject.id}`}
29+
/>
30+
)}
31+
32+
{throws && throws.length > 0 && (
33+
<Throws throws={throws} sigName={`${sigObject.name}-${sigObject.id}`} />
34+
)}
35+
36+
{returns && (
37+
<FunctionReturn
38+
functionReturn={returns}
39+
sigName={`${sigObject.name}-${sigObject.id}`}
40+
/>
41+
)}
42+
</View>
43+
);
44+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading, MDXTable } from '../MDXComponents';
3+
import { ApiComment } from './ApiComment';
4+
import { ParameterType } from './display';
5+
import references from '@/directory/apiReferences.json';
6+
7+
export const Parameters = ({ parameters, sigName }) => {
8+
const paramObjects = parameters.map((id) => references[id]);
9+
return (
10+
<View>
11+
<MDXHeading level={3} id={`${sigName}-Parameters`}>
12+
Parameters
13+
</MDXHeading>
14+
<MDXTable>
15+
<thead>
16+
<tr>
17+
<th>Option</th>
18+
<th>Required</th>
19+
<th>Type</th>
20+
<th>Description</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
{paramObjects.map((option) => {
25+
return (
26+
<tr key={option.id}>
27+
<td>
28+
<code>{option.name}</code>
29+
</td>
30+
<td>{option?.flags?.isOptional ? 'false' : 'true'}</td>
31+
<td>
32+
<ParameterType typeData={option.type} />
33+
</td>
34+
<td>
35+
{option?.comment?.summary && (
36+
<ApiComment apiComment={option.comment.summary} />
37+
)}
38+
</td>
39+
</tr>
40+
);
41+
})}
42+
</tbody>
43+
</MDXTable>
44+
</View>
45+
);
46+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Fragment } from 'react';
2+
3+
import { FunctionReference } from './FunctionReference';
4+
import { Divider, View } from '@aws-amplify/ui-react';
5+
import { API_CATEGORIES, API_SUB_CATEGORIES } from '@/data/api-categories.mjs';
6+
import references from '@/directory/apiReferences.json';
7+
8+
export const ReferencePage = ({ category }) => {
9+
category = API_CATEGORIES[category] || API_SUB_CATEGORIES[category];
10+
const cat = references['categories'].find(
11+
(catObject) => catObject.name === category
12+
);
13+
return (
14+
<View className={'reference-page'}>
15+
{cat?.children?.map((child, idx) => (
16+
<Fragment key={`reference-${idx}`}>
17+
{idx !== 0 && <Divider marginTop={'medium'} />}
18+
<FunctionReference func={child} />
19+
</Fragment>
20+
))}
21+
</View>
22+
);
23+
};

src/components/ApiDocs/Throws.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { View } from '@aws-amplify/ui-react';
2+
import { MDXHeading } from '../MDXComponents';
3+
import { ApiComment } from './ApiComment';
4+
5+
export const Throws = ({ throws, sigName }) => {
6+
return (
7+
<View>
8+
<MDXHeading level={3} id={`${sigName}-Throws`}>
9+
Throws
10+
</MDXHeading>
11+
12+
<ul>
13+
{throws.map((error, i) => (
14+
<li key={i}>
15+
<ApiComment apiComment={error.content} codeBlock={true} />{' '}
16+
</li>
17+
))}
18+
</ul>
19+
</View>
20+
);
21+
};

0 commit comments

Comments
 (0)