Skip to content

Commit

Permalink
OpenAPI: Render Server Selector Only for Multiple Servers (#1065)
Browse files Browse the repository at this point in the history
* OpenAPI: Hide the server selector when there is only one server or none defined

* OpenAPI: Improve APIInfo position on smaller screens

* docs: Add changeset
  • Loading branch information
LeCarteloo authored Nov 17, 2024
1 parent 556d5dc commit c66df64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/red-owls-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'fumadocs-openapi': minor
---

OpenAPI: Display the server selector only when more than one server is defined in the OpenAPI schema
OpenAPI: Improve APIInfo position for better visibility on smaller screens
5 changes: 3 additions & 2 deletions packages/openapi/src/ui/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ export function CopyRouteButton({

export function BaseUrlSelect({ baseUrls }: { baseUrls: string[] }) {
const { baseUrl, setBaseUrl } = useApiContext();
if (baseUrls.length === 0) return null;

if (baseUrls.length <= 1) return null;

return (
<div className="flex flex-row items-center gap-1 px-1">
<div className="flex flex-row items-center gap-1 px-1 mt-2">
<span className="p-0.5 text-xs font-medium text-fd-muted-foreground">
Server
</span>
Expand Down
4 changes: 2 additions & 2 deletions packages/openapi/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function APIInfo({
return (
<div className={cn('min-w-0 flex-1', className)} {...props}>
<div className="sticky top-[var(--fd-api-info-top)] z-[4] mb-4 border-b border-fd-foreground/10 bg-fd-card/50 px-4 py-1.5 shadow-lg backdrop-blur-lg max-lg:-mx-3 max-md:-mx-4 md:rounded-xl md:border md:px-1.5">
<div className="mb-2 flex flex-row items-center gap-1.5">
<div className="flex flex-row items-center gap-1.5">
<span
className={cn(
badgeVariants({ color: getBadgeColor(method) }),
Expand All @@ -68,7 +68,7 @@ export function API({
<div
{...props}
className={cn(
'flex flex-col gap-x-6 gap-y-4 max-lg:[--fd-toc-height:46px] max-md:[--fd-toc-height:36px] xl:flex-row xl:items-start',
'flex flex-col gap-x-6 gap-y-4 max-xl:[--fd-toc-height:46px] max-md:[--fd-toc-height:36px] xl:flex-row xl:items-start',
props.className,
)}
style={
Expand Down

0 comments on commit c66df64

Please sign in to comment.