-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/2419-sibling-examples-ref
- Loading branch information
Showing
11 changed files
with
244 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/elements-core/src/components/Docs/HttpOperation/Callbacks.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Box, Flex, NodeAnnotation, Select, VStack } from '@stoplight/mosaic'; | ||
import { IHttpCallbackOperation } from '@stoplight/types'; | ||
import * as React from 'react'; | ||
|
||
import { useOptionsCtx } from '../../../context/Options'; | ||
import { MarkdownViewer } from '../../MarkdownViewer'; | ||
import { SectionSubtitle, SectionTitle } from '../Sections'; | ||
import { OperationHeader } from './HttpOperation'; | ||
import { Request } from './Request'; | ||
import { Responses } from './Responses'; | ||
|
||
export interface CallbacksProps { | ||
callbacks: IHttpCallbackOperation[]; | ||
isCompact?: boolean; | ||
} | ||
|
||
export interface CallbackProps { | ||
data: IHttpCallbackOperation; | ||
isCompact?: boolean; | ||
} | ||
|
||
export const Callbacks = ({ callbacks, isCompact }: CallbacksProps) => { | ||
const [selectedCallbackIndex, setSelectedCallbackIndex] = React.useState(0); | ||
|
||
const callback = React.useMemo(() => callbacks[selectedCallbackIndex], [callbacks, selectedCallbackIndex]); | ||
|
||
return ( | ||
<VStack spacing={8}> | ||
<SectionTitle title="Callbacks" isCompact={isCompact}> | ||
{callbacks.length > 0 && ( | ||
<Flex flex={1} justify="end"> | ||
<Select | ||
aria-label="Callback" | ||
value={String(selectedCallbackIndex)} | ||
onChange={value => setSelectedCallbackIndex(parseInt(String(value), 10))} | ||
options={callbacks.map((c, index) => ({ | ||
label: `${c.key} - ${c.path} - ${c.method}`, | ||
value: index, | ||
}))} | ||
size="sm" | ||
/> | ||
</Flex> | ||
)} | ||
</SectionTitle> | ||
|
||
{callback && <Callback data={callback} isCompact={isCompact} />} | ||
</VStack> | ||
); | ||
}; | ||
|
||
Callbacks.displayName = 'HttpOperation.Callbacks'; | ||
|
||
export const Callback = ({ data, isCompact }: CallbackProps) => { | ||
const { nodeHasChanged } = useOptionsCtx(); | ||
|
||
const isDeprecated = !!data.deprecated; | ||
const isInternal = !!data.internal; | ||
|
||
const descriptionChanged = nodeHasChanged?.({ nodeId: data.id, attr: 'description' }); | ||
|
||
return ( | ||
<VStack spacing={10}> | ||
<Box> | ||
<SectionSubtitle title={data.key} id="callback-key"></SectionSubtitle> | ||
<OperationHeader | ||
id={data.id} | ||
method={data.method} | ||
path={`/${data.path}`} | ||
isDeprecated={isDeprecated} | ||
isInternal={isInternal} | ||
/> | ||
</Box> | ||
{data.description && ( | ||
<Box pos="relative"> | ||
<MarkdownViewer className="HttpOperation__Description" markdown={data.description} /> | ||
<NodeAnnotation change={descriptionChanged} /> | ||
</Box> | ||
)} | ||
|
||
<Request operation={data} /> | ||
|
||
{data.responses && <Responses responses={data.responses} isCompact={isCompact} />} | ||
</VStack> | ||
); | ||
}; | ||
Callbacks.displayName = 'HttpOperation.Callback'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.