Files
Anthony Lio e6bd407e88 fix(docs): collapsible details component (#50065)
## What kind of change does this PR introduce?

nitpick ui bug fix in docs of the collapsible details component +
commentary

## What is the current behavior?

1. data / response / notes collapsibles on reference pages grow taller
when you expand them + also get double padding: the panel pads the
content, and the code block pads itself again inside it

2. commentary that follows a snippet in the example column renders
unstyled, since that column has no prose context. it comes out larger
than the description column and inline code stays as plain text

## What is the new behavior?

├ adds `CodeBlock` a `compact` variant that get appropriate styling when
used within collapsible

| state | preview |
| -------|------|
| before | <video
src="https://github.com/user-attachments/assets/8b70e1c6-9e0e-4371-a2b2-eb4a3d580247"
/> |
| after | <video
src="https://github.com/user-attachments/assets/1e5cdd46-ce7d-4d2d-ac6a-6da680df37e5"
/> |

├ wraps example column in prose so trailing commentary matches the
description font size + inline code styling

| state | preview |
| -------|------|
| before | <img width="1142" height="404" alt="image"
src="https://github.com/user-attachments/assets/8d0f1ac0-087d-47f7-b35d-b8798d589fdb"
/> |
| after | <img width="1142" height="404" alt="image"
src="https://github.com/user-attachments/assets/b9ba4202-a8dd-407d-b535-f34d83f5b24b"
/> |

## Test
- visits `/docs/reference/javascript/using-filters-gt`
- visits `/docs/reference/server/middleware-withsupabaseadminclient`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Documentation code blocks can now be displayed in a compact format
without borders or extra spacing.
- Reference documentation supports customizing code block presentation.
- **Style**
- Improved formatting for example content, including prose wrapping,
spacing, and code block margins.
- Refined collapsible documentation sections with clearer spacing, hover
and focus states, and open/close animations.
- Code-only collapsible content now uses a more compact layout, while
text content receives consistent typography and padding.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-10 10:54:21 +03:00

64 lines
2.3 KiB
TypeScript

import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import CliGlobalFlagsHandler from '~/components/reference/enrichments/cli/CliGlobalFlagsHandler'
import { MDXRemoteBase } from '~/features/docs/MdxBase'
import { components } from '~/features/docs/MdxBase.shared'
import { RefSubLayout } from '~/features/docs/Reference.ui'
import { cache_fullProcess_withDevCacheBust } from '~/features/helpers.fs'
import { REF_DOCS_DIRECTORY } from '~/lib/docs'
import matter from 'gray-matter'
import { type ComponentProps } from 'react'
import { CodeBlock } from '../ui/CodeBlock/CodeBlock'
async function getRefMarkdownInternal(relPath: string) {
const fullPath = join(REF_DOCS_DIRECTORY, relPath + '.mdx')
try {
if (!fullPath.startsWith(REF_DOCS_DIRECTORY)) {
throw Error(`Accessing forbidden path outside of REF_DOCS_DIRECTORY: ${fullPath}`)
}
const mdx = await readFile(fullPath, 'utf-8')
const { content } = matter(mdx)
return content
} catch (err) {
console.error(`Error fetching reference markdown from file: ${fullPath}:\n\n${err}`)
return ''
}
}
/**
* Caching this for the entire process is fine because the Markdown content is
* baked into each deployment and cannot change. There's also nothing sensitive
* here: this is just reading the public MDX files from the codebase.
*/
const getRefMarkdown = cache_fullProcess_withDevCacheBust(
getRefMarkdownInternal,
REF_DOCS_DIRECTORY,
(filename: string) => JSON.stringify([filename.replace(/\.mdx$/, '')])
)
interface MDXRemoteRefsProps {
source: string
codeBlockProps?: Partial<ComponentProps<typeof CodeBlock>>
}
function MDXRemoteRefs({ source, codeBlockProps }: MDXRemoteRefsProps) {
const refComponents = {
...components,
// Override the CodeBlock used for normal guides to skip type generation
// because it is too resource-intensive
pre: (props: ComponentProps<typeof CodeBlock>) => (
<CodeBlock {...props} {...codeBlockProps} skipTypeGeneration />
),
RefSubLayout,
CliGlobalFlagsHandler,
}
// @ts-expect-error: Gildas - This is because RefSubLayout is a namespace containing multiple components. It works but the MDXClient types are stricter
return <MDXRemoteBase source={source} components={refComponents} />
}
export { getRefMarkdown, MDXRemoteRefs }