MCPcopy Create free account
hub / github.com/github/docs / RestReferencePage

Function RestReferencePage

components/rest/RestReferencePage.tsx:21–75  ·  view source on GitHub ↗
({ restOperations }: StructuredContentT)

Source from the content-addressed store, hash-verified

19}
20
21export const RestReferencePage = ({ restOperations }: StructuredContentT) => {
22 const { title, intro, renderedPage, permissions } = useAutomatedPageContext()
23
24 // Scrollable code blocks in our REST API docs and elsewhere aren't accessible
25 // via keyboard navigation without setting tabindex="0". But we don't want to set
26 // this attribute on every `<pre>` code block, only the ones where there are scroll
27 // bars because the content isn't all visible.
28 useEffect(() => {
29 const codeBlocks = document.querySelectorAll<HTMLPreElement>('pre')
30
31 codeBlocks.forEach((codeBlock) => {
32 if (
33 codeBlock.scrollWidth > codeBlock.clientWidth ||
34 codeBlock.scrollHeight > codeBlock.clientHeight
35 ) {
36 codeBlock.setAttribute('tabindex', '0')
37 }
38 })
39 }, [])
40
41 return (
42 <DefaultLayout>
43 {/* Doesn't matter *where* this is included because it will
44 never render anything. It always just return null. */}
45 <ClientSideRedirects />
46 <ClientSideHighlight />
47 <RestRedirect />
48 <div
49 className={cx(styles.restOperation, 'px-3 px-md-6 my-4 container-xl')}
50 data-search="article-body"
51 >
52 <h1 className="mb-3">{title}</h1>
53 {intro && (
54 <Lead data-testid="lead" data-search="lead" className="markdown-body">
55 {intro}
56 </Lead>
57 )}
58
59 {permissions && <PermissionsStatement permissions={permissions} />}
60
61 {renderedPage && <MarkdownContent className="pt-3 pb-4">{renderedPage}</MarkdownContent>}
62 {restOperations.length > 0 && (
63 <MarkdownContent className="pt-3 pb-4">
64 {restOperations.map((operation) => (
65 <RestOperation
66 key={`${operation.title}-${operation.category}-${operation.subcategory}`}
67 operation={operation}
68 />
69 ))}
70 </MarkdownContent>
71 )}
72 </div>
73 </DefaultLayout>
74 )
75}

Callers

nothing calls this directly

Calls 1

useAutomatedPageContextFunction · 0.90

Tested by

no test coverage detected