Files
supabase/apps/design-system/components/mdx-components.tsx
Danny White 9bd86bee93 feat(design-system): document shared inline code defaults (#51984)
## Problem

The design system repeats inline-code styles and does not document the
new shared defaults.

## Solution

Import the shared styles from #51980 and document how sizing, colour,
weight and wrapping work. Add examples of bare and linked code, tables,
long values, Tailwind overrides and `data-code-style="plain"`. Remove
repeated styles from existing examples.

Highlighted code blocks keep an explicit `text-sm` size so removing
inline-code classes does not enlarge them.

## Review instructions

This PR changes the design-system app only.

1. Open the [Layout
page](https://design-system-git-dnywh-depr-707-code-design-system-supabase.vercel.app/design-system/docs/ui-patterns/layout).
Check the inline-code examples at narrow and desktop widths in both
themes.
2. Check code in headings, long values, explicit size overrides and the
plain display example. Code should use the default foreground colour and
follow the surrounding weight unless a class overrides it.
3. Check the [chart palette
example](https://design-system-git-dnywh-depr-707-code-design-system-supabase.vercel.app/design-system/docs/ui-patterns/charts).
CSS variable names should remain `<code>` elements with their own
display styles.

| Before | After |
| --- | --- |
| <img width="1666" height="770" alt="CleanShot 2026-10-20 at 16 37
20@2x"
src="https://github.com/user-attachments/assets/2ac87442-12a9-49ab-8e4f-f82436308567"
/> | <img width="1680" height="782" alt="CleanShot 2026-10-20 at 16 36
12@2x"
src="https://github.com/user-attachments/assets/b0074844-3431-4fb9-827b-c6fd0de889fe"
/> |
| _Layout
([live](https://supabase.com/design-system/docs/ui-patterns/layout))_ |
_Layout
([preview](https://design-system-git-dnywh-depr-707-code-design-system-supabase.vercel.app/design-system/docs/ui-patterns/layout))_
|
| <img width="1072" height="476" alt="CleanShot 2026-10-20 at 16 35
14@2x"
src="https://github.com/user-attachments/assets/242bf850-58fa-4b29-a978-bd0e296c2e8b"
/> | <img width="1072" height="484" alt="CleanShot 2026-10-20 at 16 34
47@2x"
src="https://github.com/user-attachments/assets/962adef0-05b7-47ed-8fdc-5229a3a332e1"
/> |
| _Charts
([live](https://supabase.com/design-system/docs/ui-patterns/charts))_ |
_Charts
([preview](https://design-system-git-dnywh-depr-707-code-design-system-supabase.vercel.app/design-system/docs/ui-patterns/charts)):
no visual changes as `data-code-style="plain"` has been used_ |
2026-10-22 00:48:57 +00:00

296 lines
9.4 KiB
TypeScript

'use client'
import Image from 'next/image'
import Link from 'next/link'
import * as React from 'react'
// import { NpmCommands } from 'types/unist'
// import { Event } from '@/lib/events'
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
Alert,
AlertDescription,
AlertTitle,
AspectRatio,
cn,
Tabs,
TabsContent,
TabsIndicator,
TabsList,
TabsTrigger,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { ComponentProps } from './component-props'
import { SonnerExpandConfig } from './sonner-expand-config'
import { SonnerPositionConfig } from './sonner-expand-position'
// import { FrameworkDocs } from '@/components/framework-docs'
import { StyleWrapper } from './style-wrapper'
import { Callout } from '@/components/callout'
import { CodeBlockWrapper } from '@/components/code-block-wrapper'
import { CodeFragment } from '@/components/code-fragment'
import { ColorPalette } from '@/components/color-palette'
import { Colors } from '@/components/colors'
import { ComponentExample } from '@/components/component-example'
import { ComponentPreview } from '@/components/component-preview'
import { ComponentSource } from '@/components/component-source'
import {
CopyButton,
// CopyNpmCommandButton
} from '@/components/copy-button'
import { Icons } from '@/components/icons'
import { ThemeSettings } from '@/components/theme-settings'
import { useConfig } from '@/hooks/use-config'
import { useMDXComponent } from '@/lib/use-mdx-component'
import { Style } from '@/registry/styles'
const components = {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
Alert,
AlertTitle,
AlertDescription,
h1: ({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
<h1 className={cn('font-heading mt-2 scroll-m-20 text-4xl font-bold', className)} {...props} />
),
h2: ({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
<h2
className={cn(
'font-heading mt-12 scroll-m-20 border-b pb-2 text-2xl tracking-tight first:mt-0',
className
)}
{...props}
/>
),
h3: ({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
<h3
className={cn('font-heading mt-8 scroll-m-20 text-xl tracking-tight', className)}
{...props}
/>
),
h4: ({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
<h4
className={cn('font-heading mt-8 scroll-m-20 text-lg tracking-tight', className)}
{...props}
/>
),
h5: ({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
<h5 className={cn('mt-8 scroll-m-20 text-lg tracking-tight', className)} {...props} />
),
h6: ({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
<h6 className={cn('mt-8 scroll-m-20 text-base tracking-tight', className)} {...props} />
),
a: ({ className, ...props }: React.HTMLAttributes<HTMLAnchorElement>) => (
<a
className={cn(
'text-foreground underline decoration-1 decoration-foreground-muted underline-offset-4 transition-colors hover:decoration-primary hover:decoration-2',
className
)}
{...props}
/>
),
p: ({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) => (
<p className={cn('leading-7 not-first:mt-6 text-foreground-light', className)} {...props} />
),
ul: ({ className, ...props }: React.HTMLAttributes<HTMLUListElement>) => (
<ul className={cn('my-6 ml-6 list-disc', className)} {...props} />
),
ol: ({ className, ...props }: React.HTMLAttributes<HTMLOListElement>) => (
<ol className={cn('my-6 ml-6 list-decimal', className)} {...props} />
),
li: ({ className, ...props }: React.HTMLAttributes<HTMLElement>) => (
<li className={cn('mt-2', className)} {...props} />
),
blockquote: ({ className, ...props }: React.HTMLAttributes<HTMLElement>) => (
<blockquote className={cn('mt-6 border-l-2 pl-6 italic', className)} {...props} />
),
img: ({ className, alt, ...props }: React.ImgHTMLAttributes<HTMLImageElement>) => (
// eslint-disable-next-line @next/next/no-img-element
<img className={cn('rounded-md', className)} alt={alt} {...props} />
),
hr: ({ ...props }: React.HTMLAttributes<HTMLHRElement>) => (
<hr className="my-4 md:my-8" {...props} />
),
table: ({ className, ...props }: React.HTMLAttributes<HTMLTableElement>) => (
<div className="my-6 w-full overflow-y-auto">
<table className={cn('w-full', className)} {...props} />
</div>
),
tr: ({ className, ...props }: React.HTMLAttributes<HTMLTableRowElement>) => (
<tr className={cn('m-0 border-t p-0 even:bg-surface-75/75', className)} {...props} />
),
th: ({ className, ...props }: React.HTMLAttributes<HTMLTableCellElement>) => (
<th
className={cn(
'border px-4 py-2 text-left font-normal [[align=center]]:text-center [[align=right]]:text-right',
className
)}
{...props}
/>
),
td: ({ className, ...props }: React.HTMLAttributes<HTMLTableCellElement>) => (
<td
className={cn(
'border text-foreground-light px-4 py-2 text-left [[align=center]]:text-center [[align=right]]:text-right',
className
)}
{...props}
/>
),
pre: (
{
className,
__rawString__,
// __npmCommand__,
// __yarnCommand__,
// __pnpmCommand__,
// __bunCommand__,
__withMeta__,
__src__,
// __event__,
__style__,
...props
}: React.HTMLAttributes<HTMLPreElement> & {
__style__?: Style['name']
__rawString__?: string
__withMeta__?: boolean
__src__?: string
// __event__?: Event['name']
}
// & NpmCommands
) => {
return (
<StyleWrapper styleName={__style__}>
<pre
className={cn(
'mb-4 mt-6 max-h-[650px] overflow-x-auto rounded-lg border bg-surface-75/75 py-4',
className
)}
{...props}
/>
{__rawString__ && (
// !__npmCommand__ &&
<CopyButton
value={__rawString__}
src={__src__}
// event={__event__}
className={cn('absolute right-4 top-4', __withMeta__ && 'top-16')}
/>
)}
{/* {__npmCommand__ && __yarnCommand__ && __pnpmCommand__ && __bunCommand__ && (
<CopyNpmCommandButton
commands={{
__npmCommand__,
__yarnCommand__,
__pnpmCommand__,
__bunCommand__,
}}
className={cn('absolute right-4 top-4', __withMeta__ && 'top-16')}
/>
)} */}
</StyleWrapper>
)
},
Image,
Callout,
ComponentPreview,
ComponentExample,
ComponentSource,
ComponentProps,
AspectRatio,
CodeBlockWrapper: ({ ...props }) => <CodeBlockWrapper className="rounded-md border" {...props} />,
Step: ({ className, ...props }: React.ComponentProps<'h3'>) => (
<h3
className={cn(
'font-heading mt-8 scroll-m-20 text-xl font-semibold tracking-tight',
className
)}
{...props}
/>
),
Steps: ({ ...props }) => (
<div className="[&>h3]:step steps mb-12 ml-4 border-l pl-8 [counter-reset:step]" {...props} />
),
Tabs: ({ className, ...props }: React.ComponentProps<typeof Tabs>) => (
<Tabs className={cn('relative mt-6 w-full', className)} {...props} />
),
TabsList: ({ className, children, ...props }: React.ComponentProps<typeof TabsList>) => (
<TabsList
className={cn(
'w-full justify-start rounded-none bg-transparent p-0',
'ps-4 -ms-4 [--tab-track-inset:--spacing(4)]',
className
)}
{...props}
>
{children}
<TabsIndicator />
</TabsList>
),
TabsTrigger: ({ className, ...props }: React.ComponentProps<typeof TabsTrigger>) => (
<TabsTrigger
className={cn(
'relative h-9 rounded-none bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:text-foreground data-[state=active]:shadow-none',
// The first label lines up with the surrounding content, keeping its
// padding so the focus ring sits off the glyphs
'first:-ms-4',
className
)}
{...props}
/>
),
TabsContent: ({ className, ...props }: React.ComponentProps<typeof TabsContent>) => (
<TabsContent
className={cn(
'relative [&_h3.font-heading]:text-base [&_h3.font-heading]:font-semibold',
className
)}
{...props}
/>
),
// FrameworkDocs: ({ className, ...props }: React.ComponentProps<typeof FrameworkDocs>) => (
// <FrameworkDocs className={cn(className)} {...props} />
// ),
Link: ({ className, ...props }: React.ComponentProps<typeof Link>) => (
<Link className={cn('font-medium underline underline-offset-4', className)} {...props} />
),
LinkedCard: ({ className, ...props }: React.ComponentProps<typeof Link>) => (
<Link
className={cn(
'flex w-full flex-col items-center rounded-xl border bg-card p-6 text-card-foreground shadow-sm transition-colors hover:bg-muted/50 sm:p-10',
className
)}
{...props}
/>
),
Colors,
ColorPalette,
Icons,
ThemeSettings,
CodeFragment,
Admonition,
SonnerExpandConfig,
SonnerPositionConfig,
}
interface MdxProps {
code: string
}
export function Mdx({ code }: MdxProps) {
const [config] = useConfig()
const Component = useMDXComponent(code, {
style: config.style,
})
return (
<div className="mdx">
<Component components={components} />
</div>
)
}