-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathOpenAPIDisclosure.tsx
44 lines (42 loc) · 1.42 KB
/
OpenAPIDisclosure.tsx
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
'use client';
import { useState } from 'react';
import { Button, Disclosure, DisclosurePanel, Heading } from 'react-aria-components';
import type { OpenAPIClientContext } from './types';
/**
* Display an interactive OpenAPI disclosure.
*/
export function OpenAPIDisclosure(props: {
context: OpenAPIClientContext;
children: React.ReactNode;
label: string;
}): React.JSX.Element {
const { context, children, label } = props;
const [isExpanded, setIsExpanded] = useState(false);
return (
<Disclosure
className="openapi-disclosure"
isExpanded={isExpanded}
onExpandedChange={setIsExpanded}
>
<Heading>
<Button
slot="trigger"
className="openapi-disclosure-trigger"
style={({ isFocusVisible }) => ({
outline: isFocusVisible
? '2px solid rgb(var(--primary-color-500) / 0.4)'
: 'none',
})}
>
{context.icons.plus}
<span>
{isExpanded ? 'Hide' : 'Show'} {label}
</span>
</Button>
</Heading>
<DisclosurePanel className="openapi-disclosure-panel">
{isExpanded ? children : null}
</DisclosurePanel>
</Disclosure>
);
}