Files
supabase/apps/docs/components/ApiSchemaOption.tsx
Hieu c5a88a9fc4 feat: render mgmt api body params (#26319)
* feat: render body parameters

* feat: api parameters render

* fix: update mgmt api spec to latest

* fix: body param format and support content type selection

* fix: prettier errors

* fix: use Options to render accepted enum values

* fix: prettier again

* fix: merge conflict

* fix: expose new api routes

* fix: prettier again

* refactor: ApiBodyParam

* fix: add missing apis

* chore: tidy up

* feat: improve api response with sample + schema tabs

* fix: support show/hide object param schema

* fix: show no content text

* refactor: use collapsible for hidden content

* Update apps/docs/components/reference/ApiOperationSection.tsx

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* Update apps/docs/components/ApiSchemaOption.tsx

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* fix: resolve comments

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2024-05-21 13:30:34 +07:00

48 lines
1.3 KiB
TypeScript

import { type FC, type PropsWithChildren, useState } from 'react'
import {
CollapsibleContent_Shadcn_,
CollapsibleTrigger_Shadcn_,
Collapsible_Shadcn_,
IconXCircle,
cn,
} from 'ui'
import ApiSchema from '~/components/ApiSchema'
interface IOptions {
name?: string
}
type IOption = any
type OptionsSubComponents = {
Option: IOption
}
const ApiSchemaOptions: FC<PropsWithChildren<IOptions>> & OptionsSubComponents = (props) => {
const [open, setOpen] = useState(false)
return (
<Collapsible_Shadcn_ open={open} onOpenChange={setOpen} className="mt-0">
<CollapsibleTrigger_Shadcn_ asChild>
<button
className={cn(
'px-5',
'border-t border-l border-r border-default',
'text-left text-sm text-foreground-light',
'hover:bg-surface-100 transition-all',
'flex items-center gap-2',
open ? 'w-full py-1.5 rounded-tl-lg rounded-tr-lg' : 'py-1 border-b rounded-full'
)}
>
<IconXCircle size={14} className={open ? '' : 'rotate-45'} />
{`${!open ? `Open` : `Close`} ${props.name ?? 'object schema'}`}
</button>
</CollapsibleTrigger_Shadcn_>
<CollapsibleContent_Shadcn_>{props.children}</CollapsibleContent_Shadcn_>
</Collapsible_Shadcn_>
)
}
ApiSchemaOptions.Option = ApiSchema
export default ApiSchemaOptions