diff --git a/docs/src/app/new/(content)/layout.tsx b/docs/src/app/new/(content)/layout.tsx index d4396436eb..cd7084c8ab 100644 --- a/docs/src/app/new/(content)/layout.tsx +++ b/docs/src/app/new/(content)/layout.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import type { Metadata } from 'next/types'; import * as SideNav from 'docs/src/components/SideNav'; import * as QuickNav from 'docs/src/components/quick-nav/QuickNav'; import './layout.css'; @@ -161,3 +162,8 @@ const nav = [ ], }, ]; +// Title and description are pulled from

and in the MDX. +export const metadata: Metadata = { + title: null, + description: null, +}; diff --git a/docs/src/components/TableCode.tsx b/docs/src/components/TableCode.tsx index 2bccc630fa..66c4b8958a 100644 --- a/docs/src/components/TableCode.tsx +++ b/docs/src/components/TableCode.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { Code } from './Code'; +import { getChildrenText } from '../getChildrenText'; interface TableCodeProps extends React.ComponentProps<'code'> { printWidth?: number; @@ -7,7 +8,7 @@ interface TableCodeProps extends React.ComponentProps<'code'> { /** An inline code component that breaks long union types into multiple lines */ export function TableCode({ children, printWidth = 40, ...props }: TableCodeProps) { - const text = getTextContents(children); + const text = getChildrenText(children); if (text.includes('|') && text.length > printWidth) { const unionGroups: React.ReactNode[][] = []; @@ -21,17 +22,17 @@ export function TableCode({ children, printWidth = 40, ...props }: TableCodeProp return; } - if (getTextContents(child).trim() === '|' && depth < 1) { + if (getChildrenText(child).trim() === '|' && depth < 1) { groupIndex += 1; unionGroups.push([]); return; } - if (getTextContents(child).trim() === '(') { + if (getChildrenText(child).trim() === '(') { depth += 1; } - if (getTextContents(child).trim() === ')') { + if (getChildrenText(child).trim() === ')') { depth -= 1; } @@ -58,31 +59,3 @@ export function TableCode({ children, printWidth = 40, ...props }: TableCodeProp return {children}; } - -function getTextContents(node?: React.ReactNode): string { - if (hasChildren(node)) { - return getTextContents(node.props?.children); - } - - if (Array.isArray(node)) { - return node.map(getTextContents).flat().filter(Boolean).join(''); - } - - if (typeof node === 'string') { - return node; - } - - return ''; -} - -function hasChildren( - element?: React.ReactNode, -): element is React.ReactElement { - return ( - React.isValidElement(element) && - typeof element.props === 'object' && - !!element.props && - 'children' in element.props && - Boolean(element.props.children) - ); -} diff --git a/docs/src/getChildrenText.ts b/docs/src/getChildrenText.ts new file mode 100644 index 0000000000..735a98f09b --- /dev/null +++ b/docs/src/getChildrenText.ts @@ -0,0 +1,29 @@ +import * as React from 'react'; + +export function getChildrenText(children?: React.ReactNode): string { + if (hasChildren(children)) { + return getChildrenText(children.props?.children); + } + + if (Array.isArray(children)) { + return children.map(getChildrenText).flat().filter(Boolean).join(''); + } + + if (typeof children === 'string') { + return children; + } + + return ''; +} + +function hasChildren( + element?: React.ReactNode, +): element is React.ReactElement { + return ( + React.isValidElement(element) && + typeof element.props === 'object' && + !!element.props && + 'children' in element.props && + Boolean(element.props.children) + ); +} diff --git a/docs/src/mdx-components.tsx b/docs/src/mdx-components.tsx index 0464c813ab..b1161ea2e3 100644 --- a/docs/src/mdx-components.tsx +++ b/docs/src/mdx-components.tsx @@ -8,6 +8,7 @@ import { PropsTable } from './components/reference/PropsTable'; import { AttributesTable } from './components/reference/AttributesTable'; import { CssVariablesTable } from './components/reference/CssVariablesTable'; import { TableCode } from './components/TableCode'; +import { getChildrenText } from './getChildrenText'; interface MDXComponents { [key: string]: React.FC | MDXComponents; @@ -15,7 +16,12 @@ interface MDXComponents { export const mdxComponents: MDXComponents = { code: (props) => , - h1: (props) =>

, + h1: (props) => ( + +

+ {`${getChildrenText(props.children)} ยท Base UI`} + + ), h2: (props) => (

@@ -58,7 +64,12 @@ export const mdxComponents: MDXComponents = { AttributesTable: (props) => , CssVariablesTable: (props) => , PropsTable: (props) => , - Subtitle: (props) =>

, + Subtitle: (props) => ( + +

+ + + ), }; export const inlineMdxComponents: MDXComponents = {