Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(design-system): document shared inline code defaults (#51984)

Danny White9bd86bee934b
diff --git a/apps/design-system/components/code-fragment.tsx b/apps/design-system/components/code-fragment.tsx
index 4eeb7ee7c7c..41fb19812e1 100644
--- a/apps/design-system/components/code-fragment.tsx
+++ b/apps/design-system/components/code-fragment.tsx
@@ -50,11 +50,7 @@ export function CodeFragment({
if (!Component) {
return (
<p className="text-sm text-muted-foreground">
- Code fragment{' '}
- <code className="relative rounded-sm bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm">
- {name}
- </code>{' '}
- not found in registry.
+ Code fragment <code>{name}</code> not found in registry.
</p>
)
}
diff --git a/apps/design-system/components/component-preview.tsx b/apps/design-system/components/component-preview.tsx
index b9898033daa..a41be6d0ce1 100644
--- a/apps/design-system/components/component-preview.tsx
+++ b/apps/design-system/components/component-preview.tsx
@@ -51,11 +51,7 @@ export function ComponentPreview({
if (!Component) {
return (
<p className="text-sm text-muted-foreground">
- Component{' '}
- <code className="relative rounded-sm bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm">
- {name}
- </code>{' '}
- not found in registry.
+ Component <code>{name}</code> not found in registry.
</p>
)
}
diff --git a/apps/design-system/components/mdx-components.tsx b/apps/design-system/components/mdx-components.tsx
index 8b1469d65ad..39871b3e7f3 100644
--- a/apps/design-system/components/mdx-components.tsx
+++ b/apps/design-system/components/mdx-components.tsx
@@ -195,15 +195,6 @@ const components = {
</StyleWrapper>
)
},
- code: ({ className, ...props }: React.HTMLAttributes<HTMLElement>) => (
- <code
- className={cn(
- 'relative rounded-sm bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm',
- className
- )}
- {...props}
- />
- ),
Image,
Callout,
ComponentPreview,
diff --git a/apps/design-system/content/docs/typography.mdx b/apps/design-system/content/docs/typography.mdx
index 80b5ed96808..173cd1c858d 100644
--- a/apps/design-system/content/docs/typography.mdx
+++ b/apps/design-system/content/docs/typography.mdx
@@ -3,18 +3,48 @@ title: Typography
description: An overview of all available typography CSS variables.
---
-Some reusable patterns work better as CSS variables, or “shorthands”, than as components. Typography is one of these cases, since its usage and context vary widely.
+Use shared typography styles to keep text consistent across apps. You can find the
+heading, text, and link utilities in [`typography.css`](https://github.com/supabase/supabase/blob/master/packages/config/typography.css).
-The shorthands below are composed of core [Tailwind utility classes](../docs/tailwind-classes). You can view the full list of shorthands in [`typography.scss`](https://github.com/supabase/supabase/blob/master/apps/studio/styles/typography.scss).
+## Primary text
-## Shorthands
-
-| Value | Usage |
-| ------------------ | -------------------------------------------------------------------------- |
-| `text-code-inline` | Apply to a `code` element for inline code or similar custom inline content |
-| `text-primary` | Accessible Supabase green for readable branded text |
+Use `text-primary` for readable text in Supabase green.
`text-primary` meets WCAG AA for normal text on app surfaces: darkened in light mode,
bright in dark mode. Focus rings and selected controls derive their brighter fill from
the same primary hue. See [Primary and brand colors](../docs/color-usage#primary-and-brand-colors) for when
to use each green.
+
+## Inline code
+
+Apps that import `config/inline-code.css` get shared styles for inline `<code>`, including
+a border, background, and default foreground color. Code inherits the surrounding font weight
+and line height. Sizing keeps code readable beside small text, then stays 2px below the
+surrounding text from 16px upward, with a minimum of `0.75rem` (normally 12px).
+
+| Surrounding text | Inline code |
+| ---------------- | ----------- |
+| 13px | 12px |
+| 14px | 12.5px |
+| 15px | 13.25px |
+| 16px | 14px |
+| 20px | 18px |
+
+These sizes assume the standard 16px root font size.
+
+Long identifiers stay intact when they fit on the next line, but can break to avoid overflow.
+Tailwind utilities can override the defaults. A size class on `<code>` sets its size directly;
+put the class on a parent to keep the automatic sizing:
+
+```tsx
+<span className="text-sm">
+ <code>project_id</code>
+</span>
+```
+
+Code blocks and syntax-highlighting containers keep their own styles. For other custom
+displays, such as a command strip, add `data-code-style="plain"` to the `<code>` element
+or a parent. This removes all shared inline-code styles from that element and its descendants,
+so the display can control its own appearance.
+
+<ComponentPreview name="typography-inline-code" />
diff --git a/apps/design-system/registry/default/block/chart-palette.tsx b/apps/design-system/registry/default/block/chart-palette.tsx
index 8d44644e59d..1921b689205 100644
--- a/apps/design-system/registry/default/block/chart-palette.tsx
+++ b/apps/design-system/registry/default/block/chart-palette.tsx
@@ -50,7 +50,12 @@ function TokenCard({
<div className="border-default bg-surface-100 flex flex-col gap-4 rounded-lg border p-4">
<div className="flex flex-col gap-1">
<div className="text-foreground text-sm">{title}</div>
- <code className="text-foreground-lighter break-all font-mono text-xs">{token}</code>
+ <code
+ data-code-style="plain"
+ className="text-foreground-lighter break-all font-mono text-xs"
+ >
+ {token}
+ </code>
</div>
<div className="flex gap-3">{children}</div>
{note && <p className="text-foreground-lighter text-xs">{note}</p>}
diff --git a/apps/design-system/registry/default/example/alert-dialog-async.tsx b/apps/design-system/registry/default/example/alert-dialog-async.tsx
index 47749ce1b84..9de6ef28a8f 100644
--- a/apps/design-system/registry/default/example/alert-dialog-async.tsx
+++ b/apps/design-system/registry/default/example/alert-dialog-async.tsx
@@ -26,8 +26,8 @@ export default function AlertDialogAsync() {
<AlertDialogTitle>Create new API keys</AlertDialogTitle>
<AlertDialogDescription>
This will create a default publishable key and a default secret key both named{' '}
- <code className="text-code-inline">default</code>. These keys are required to connect
- your application to your Supabase project.
+ <code>default</code>. These keys are required to connect your application to your
+ Supabase project.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
diff --git a/apps/design-system/registry/default/example/alert-dialog-demo.tsx b/apps/design-system/registry/default/example/alert-dialog-demo.tsx
index d38011820e2..b64fd1c3c55 100644
--- a/apps/design-system/registry/default/example/alert-dialog-demo.tsx
+++ b/apps/design-system/registry/default/example/alert-dialog-demo.tsx
@@ -22,8 +22,8 @@ export default function AlertDialogDemo() {
<AlertDialogTitle>Create new API keys</AlertDialogTitle>
<AlertDialogDescription>
This will create a default publishable key and a default secret key both named{' '}
- <code className="text-code-inline">default</code>. These keys are required to connect
- your application to your Supabase project.
+ <code>default</code>. These keys are required to connect your application to your
+ Supabase project.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
diff --git a/apps/design-system/registry/default/example/alert-dialog-destructive.tsx b/apps/design-system/registry/default/example/alert-dialog-destructive.tsx
index 62446169204..4601dc58c1b 100644
--- a/apps/design-system/registry/default/example/alert-dialog-destructive.tsx
+++ b/apps/design-system/registry/default/example/alert-dialog-destructive.tsx
@@ -20,7 +20,7 @@ export default function AlertDialogDestructive() {
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
- Delete <code className="text-code-inline">hello-world</code>
+ Delete <code>hello-world</code>
</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. Ensure that you have a backup in case you want to restore
diff --git a/apps/design-system/registry/default/example/table-row-link-actions.tsx b/apps/design-system/registry/default/example/table-row-link-actions.tsx
index 8504c009db8..f227edb61d8 100644
--- a/apps/design-system/registry/default/example/table-row-link-actions.tsx
+++ b/apps/design-system/registry/default/example/table-row-link-actions.tsx
@@ -89,9 +89,7 @@ export default function TableRowLinkActions() {
</TableCell>
<TableCell>{policy.name}</TableCell>
<TableCell>
- <code className="text-foreground-muted text-code-inline uppercase">
- {policy.command}
- </code>
+ <code className="text-foreground-muted uppercase">{policy.command}</code>
</TableCell>
<TableCell className="text-foreground-lighter">{policy.appliedTo}</TableCell>
<TableCell className="flex justify-end items-center h-full gap-3">
diff --git a/apps/design-system/registry/default/example/typography-inline-code.tsx b/apps/design-system/registry/default/example/typography-inline-code.tsx
index 36e5b271396..56d2f694c67 100644
--- a/apps/design-system/registry/default/example/typography-inline-code.tsx
+++ b/apps/design-system/registry/default/example/typography-inline-code.tsx
@@ -1,7 +1,46 @@
export default function TypographyInlineCode() {
return (
- <code className="relative rounded-sm bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold">
- @radix-ui/react-alert-dialog
- </code>
+ <div className="w-full min-w-0 space-y-6 text-sm">
+ <p>
+ Install <code>@supabase/supabase-js</code> to connect to your project.
+ </p>
+ <p>
+ Read about{' '}
+ <a className="underline" href="https://supabase.com/docs/reference/javascript/select">
+ <code>select()</code>
+ </a>
+ .
+ </p>
+ <table className="w-full text-left">
+ <thead>
+ <tr>
+ <th className="pb-2 font-medium">Column</th>
+ <th className="pb-2 font-medium">Type</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>
+ <code>project_id</code>
+ </td>
+ <td>
+ <code>uuid</code>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <p>
+ Long tokens wrap:{' '}
+ <code>
+ https://your-project.supabase.co/rest/v1/project_settings?select=notification_preferences
+ </code>
+ </p>
+ <p>
+ Local size override: <code className="text-sm">project_id</code>
+ </p>
+ <div data-code-style="plain" className="rounded-md border bg-surface-100 p-4">
+ <code className="text-xs text-foreground-light">Content-Type: application/json</code>
+ </div>
+ </div>
)
}
diff --git a/apps/design-system/styles/globals.css b/apps/design-system/styles/globals.css
index e1f56ecff2f..2ea0813854f 100644
--- a/apps/design-system/styles/globals.css
+++ b/apps/design-system/styles/globals.css
@@ -1,4 +1,5 @@
@import 'config/tailwind.config.css';
+@import 'config/inline-code.css';
@import 'config/typography.css';
@source '../app/**/*.{js,ts,jsx,tsx}';
diff --git a/apps/design-system/styles/mdx.css b/apps/design-system/styles/mdx.css
index 2b3ed69ff0e..03cad5deeed 100644
--- a/apps/design-system/styles/mdx.css
+++ b/apps/design-system/styles/mdx.css
@@ -21,7 +21,7 @@
}
[data-rehype-pretty-code-figure] code {
- @apply grid min-w-full break-words rounded-none border-0 bg-transparent p-0;
+ @apply font-mono text-sm grid min-w-full break-words rounded-none border-0 bg-transparent p-0;
counter-reset: line;
box-decoration-break: clone;
}