Files
Danny White a31ca2bad0 fix(ui): make brand text readable across themes (#49871)
## What kind of change does this PR introduce?

Bug fix and design-system update. Resolves DEPR-316.

Follow-up rename (`text-brand` → `text-primary`) is in a dedicated PR
(https://github.com/supabase/supabase/pull/50564) stacked on this one.

## What is the current behavior?

`text-brand` resolves to the canonical bright brand green in places that
need readable text, which fails WCAG AA on light surfaces. A separate
`text-brand-display` token adds another green for large type.

## What is the new behavior?

- `text-brand` maps to accessible `--primary` (light mode darkened to
meet ~4.5:1 AA)
- `--hue` / `--primary-hue` aligned to 157.5
- `text-brand-display` removed; former display callsites use
`text-brand`
- Bright fills/borders stay on `brand-default`
- Design-system colour and typography docs updated

| Before | After |
| --- | --- |
| <img width="514" height="112" alt="CleanShot 2026-09-02 at 11 13
09@2x"
src="https://github.com/user-attachments/assets/4e0138a9-a32d-4e4c-a426-90736706e1e7"
/> | <img width="512" height="138" alt="CleanShot 2026-09-21 at 11 42
05@2x"
src="https://github.com/user-attachments/assets/164cc5b1-a0c5-4e93-95f1-80016641a114"
/> |
| <img width="864" height="266" alt="CleanShot 2026-09-02 at 11 13
53@2x"
src="https://github.com/user-attachments/assets/3c1ca53f-bf9e-431e-bc15-816b4a275b8e"
/> | <img width="882" height="248" alt="CleanShot 2026-09-21 at 11 41
37@2x"
src="https://github.com/user-attachments/assets/24828e7b-ed6b-44cb-b9dc-becc3398bdfc"
/> |
| <img width="782" height="692" alt="CleanShot 2026-09-02 at 11 16
30@2x"
src="https://github.com/user-attachments/assets/fc871977-77bc-47fb-9e0e-9284e0ecd5cc"
/> | <img width="730" height="690" alt="CleanShot 2026-09-21 at 11 42
52@2x"
src="https://github.com/user-attachments/assets/bf479515-d5f9-471e-b82d-f097c0f4b56c"
/> |
| <img width="480" height="306" alt="CleanShot 2026-09-02 at 11 18
53@2x"
src="https://github.com/user-attachments/assets/03f341f4-f02e-44f8-a2b2-8c31670d0427"
/> | <img width="470" height="300" alt="CleanShot 2026-09-21 at 11 43
19@2x"
src="https://github.com/user-attachments/assets/9df18217-d5e6-48b8-ba0b-579d2664b94b"
/> |
| <img width="960" height="300" alt="CleanShot 2026-09-02 at 11 32
04@2x"
src="https://github.com/user-attachments/assets/6b1d9373-7a71-4247-81ff-26441604b09d"
/> | <img width="980" height="306" alt="CleanShot 2026-09-21 at 11 44
13@2x"
src="https://github.com/user-attachments/assets/41ad4784-02ec-4b29-b860-32af9fa79aa8"
/> |
| <img width="924" height="214" alt="CleanShot 2026-09-02 at 11 34
44@2x"
src="https://github.com/user-attachments/assets/1de661fe-c7b6-499b-a94f-e4737436ec79"
/> | <img width="752" height="162" alt="CleanShot 2026-09-21 at 11 44
56@2x"
src="https://github.com/user-attachments/assets/1811890f-0660-4445-84e9-447720954fa1"
/> |

## To test

Test each callsite **in light mode** (dark mode is largely unchanged).

### WWW

-
[Homepage](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/):
“Scale to millions” uses readable brand text (display token is gone)
-
[Careers](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/careers):
small “Careers” eyebrow readable; green dividers stay bright
`brand-default`
-
[Contact](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/contact-us):
email / policy links use readable brand text
-
[Regions](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/regions):
“Ask about early access to BYOC” readable

### Docs

- [Docs
homepage](https://docs-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs):
“DOCS” wordmark and resource links readable
- [Database
overview](https://docs-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/guides/database/overview):
nav / footer brand links readable
- [JavaScript
reference](https://docs-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/reference/javascript/introduction):
active sidebar treatment readable

### Design system

-
[Typography](https://design-system-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/typography):
documents `text-brand` only (no display)
- [Colour
usage](https://design-system-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/color-usage):
`text-brand` vs `bg-brand-default`
- [Design-system
homepage](https://design-system-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/):
brand text examples across themes

### Studio

- [Auth
providers](https://studio-staging-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/dashboard/project/_/auth/providers):
enabled provider badge text readable; status dot stays bright
- [Database
policies](https://studio-staging-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/dashboard/project/_/database/policies?new=true):
template hover text more legible
- [Database
connections](https://studio-staging-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/dashboard/project/_/observability/connections):
“Live” status readable; animated dot stays bright green

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-22 10:07:28 +10:00

370 lines
14 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Handle, Node, NodeProps } from '@xyflow/react'
import { TableEditor } from 'icons'
import {
Copy,
DiamondIcon,
Edit,
Fingerprint,
Hash,
InfoIcon,
Key,
MoreVertical,
Table2,
} from 'lucide-react'
import { useRouter } from 'next/router'
import { memo } from 'react'
import { toast } from 'sonner'
import {
Button,
cn,
copyToClipboard,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
Tooltip,
TooltipContent,
TooltipTrigger,
} from 'ui'
import { useSchemaGraphContext } from './SchemaGraphContext'
import { TableNodeData } from './Schemas.constants'
import { getTableDefinitionAsMarkdown } from './Schemas.utils'
import { buildTableEditorUrl } from '@/components/grid/SupabaseGrid.utils'
import { getTableDefinition } from '@/data/database/table-definition-query'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { formatSql } from '@/lib/formatSql'
// ReactFlow is scaling everything by the factor of 2
export const TABLE_NODE_WIDTH = 320
export const TABLE_NODE_ROW_HEIGHT = 40
type TableNodeOwnProps = NodeProps<Node<TableNodeData>> & { placeholder?: boolean }
const TableNodeComponent = ({
id,
data,
targetPosition,
sourcePosition,
placeholder,
}: TableNodeOwnProps) => {
// Important styles is a nasty hack to use Handles (required for edges calculations), but do not show them in the UI.
// ref: https://github.com/wbkd/react-flow/discussions/2698
const hiddenNodeConnector = 'h-px! w-px! min-w-0! min-h-0! cursor-grab! border-0! opacity-0!'
const schemaGraphContext = useSchemaGraphContext()
const { data: project } = useSelectedProjectQuery()
const { can: canUpdateColumns } = useAsyncCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'columns'
)
const router = useRouter()
const itemHeight = 'h-[22px]'
const hasEdgesSelected =
schemaGraphContext.selectedEdge?.source === id || schemaGraphContext.selectedEdge?.target === id
return (
<article>
{data.isForeign ? (
<header
className={cn(
'text-[0.55rem] px-2 py-1 border-[0.5px] rounded-[4px] bg-alternative flex gap-1 items-center',
hasEdgesSelected ? 'outline outline-1 outline-brand-default' : undefined
)}
>
{data.name}
{targetPosition && (
<Handle
type="target"
id={data.name}
position={targetPosition}
className={cn(hiddenNodeConnector)}
/>
)}
</header>
) : (
<div
className={cn(
'border-[0.5px] overflow-hidden rounded-[4px] shadow-xs',
hasEdgesSelected ? 'outline outline-1 outline-brand-default' : undefined
)}
style={{ width: TABLE_NODE_WIDTH / 2 }}
>
<header
className={cn(
'text-[0.55rem] pl-2 pr-1 bg-alternative flex gap-2 items-center justify-between',
itemHeight
)}
>
<div className="min-w-0 flex shrink gap-x-1 items-center">
<Table2 strokeWidth={1} size={12} className="text-light" />
<span className="whitespace-nowrap overflow-hidden text-ellipsis" title={data.name}>
{data.name}
</span>
</div>
{
// Hide the actions while downloading the schema as png/svg
!schemaGraphContext.isDownloading ? (
<div className="flex shrink-0 items-center gap-2">
{data.description && (
<Tooltip>
<TooltipTrigger asChild className="cursor-default ">
<InfoIcon size={10} className="text-light" />
</TooltipTrigger>
<TooltipContent side="top">{data.description}</TooltipContent>
</Tooltip>
)}
{!placeholder && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="text"
className="px-0 w-[16px] h-[16px] rounded-sm nodrag nopan"
>
<MoreVertical size={10} />
<span className="sr-only">{data.name} actions</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" className="w-40">
<DropdownMenuItem
className="flex items-center space-x-2 whitespace-nowrap"
onClick={() => schemaGraphContext.onEditTable(data.id)}
>
<Edit size={12} />
<p>Edit table</p>
</DropdownMenuItem>
<DropdownMenuItem
className="flex items-center space-x-2 whitespace-nowrap"
onClick={() =>
router.push(
buildTableEditorUrl({
projectRef: project?.ref,
tableId: data.id,
schema: data.schema,
})
)
}
>
<TableEditor size={12} />
<p>View in Table Editor</p>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
className="flex items-center space-x-2 whitespace-nowrap"
onClick={(e) => {
e.stopPropagation()
copyToClipboard(data.name)
}}
>
<Copy size={12} />
<span>Copy name</span>
</DropdownMenuItem>
<DropdownMenuItem
key="copy-schema-sql"
className="space-x-2"
onClick={async (e) => {
e.stopPropagation()
const toastId = toast.loading('Getting table schema...')
const formattedSchema = getTableDefinition({
id: data.id,
projectRef: project?.ref,
connectionString: project?.connectionString,
}).then((tableDefinition) => {
if (!tableDefinition) {
throw new Error('Failed to get table schema')
}
return formatSql(tableDefinition)
})
try {
await copyToClipboard(formattedSchema, () => {
toast.success('Table schema copied to clipboard', { id: toastId })
})
} catch (err) {
toast.error(
'Failed to copy schema: ' + ((err as Error).message || err),
{
id: toastId,
}
)
}
}}
>
<Copy size={12} />
<span>Copy as SQL</span>
</DropdownMenuItem>
<DropdownMenuItem
key="copy-schema-markdown"
className="space-x-2"
onClick={async (e) => {
e.stopPropagation()
const markdown = getTableDefinitionAsMarkdown(data)
try {
await copyToClipboard(markdown, () => {
toast.success('Table schema copied to clipboard')
})
} catch (err) {
toast.error(
'Failed to copy schema: ' + ((err as Error).message || err)
)
}
}}
>
<Copy size={12} />
<span>Copy as Markdown</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
) : null
}
</header>
{data.columns.map((column) => (
<div
className={cn(
'text-[8px] leading-5 relative flex flex-row justify-items-start',
'bg-surface-100',
'border-t',
'border-t-[0.5px]',
'hover:bg-scale-500 transition cursor-default',
'group',
'pr-1',
itemHeight
)}
data-testid={`${data.name}/${column.name}`}
key={column.id}
>
<div
className={cn(
'gap-[0.24rem] flex mx-2 align-middle items-center justify-start',
column.isPrimary && 'basis-1/5'
)}
>
{column.isPrimary && (
<Key size={8} strokeWidth={1} className={cn('shrink-0', 'text-light')} />
)}
{column.isNullable && (
<DiamondIcon size={8} strokeWidth={1} className="shrink-0 text-light" />
)}
{!column.isNullable && (
<DiamondIcon
size={8}
strokeWidth={1}
fill="currentColor"
className="shrink-0 text-light"
/>
)}
{column.isUnique && (
<Fingerprint size={8} strokeWidth={1} className="shrink-0 text-light" />
)}
{column.isIdentity && (
<Hash size={8} strokeWidth={1} className="shrink-0 text-light" />
)}
</div>
<div className="flex w-full justify-between min-w-0">
<span
className={cn(
'text-ellipsis overflow-hidden whitespace-nowrap min-w-0 max-w-[80%]',
schemaGraphContext.selectedEdge?.sourceHandle === column.id ||
schemaGraphContext.selectedEdge?.targetHandle === column.id
? 'text-brand'
: undefined
)}
title={column.name}
>
{column.name}
</span>
<span className="shrink-0 pl-2 pr-1 inline-flex justify-end font-mono text-lighter text-[0.4rem] group-hover:hidden">
{column.format}
</span>
</div>
{targetPosition && (
<Handle
type="target"
id={column.id}
position={targetPosition}
className={cn(hiddenNodeConnector)}
/>
)}
{sourcePosition && (
<Handle
type="source"
id={column.id}
position={sourcePosition}
className={cn(hiddenNodeConnector)}
/>
)}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="text"
// Use opacity to hide the button so that it remains accessible (users can tab to it)
className="opacity-0 focus:opacity-100 group-hover:opacity-100 data-open:opacity-100 absolute right-0 top-1/2 -translate-y-1/2 px-0 mr-1 w-[16px] h-[16px] rounded-sm"
>
<MoreVertical size={10} />
<span className="sr-only">
{data.name} {column.name} actions
</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" className="w-32">
<Tooltip>
<TooltipTrigger asChild>
<DropdownMenuItem
disabled={!canUpdateColumns}
onClick={() => schemaGraphContext.onEditColumn(data.id, column.id)}
className="space-x-2"
>
<Edit size={12} />
<p>Edit column</p>
</DropdownMenuItem>
</TooltipTrigger>
{!canUpdateColumns && (
<TooltipContent side="bottom">
Additional permissions required to edit column
</TooltipContent>
)}
</Tooltip>
<DropdownMenuItem
className="space-x-2"
onClick={(e) => {
e.stopPropagation()
copyToClipboard(column.name)
}}
>
<Copy size={12} />
<span>Copy name</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
))}
</div>
)}
</article>
)
}
// Custom comparator: xyflow re-renders nodes on selection/drag with new prop
// objects; only the listed props affect rendered output. Selection-driven styling
// (highlighted edges) is read from context inside the component, so we can safely
// ignore xyflow's `selected`/`dragging`/etc. here.
export const TableNode = memo(
TableNodeComponent,
(prev, next) =>
prev.id === next.id &&
prev.data === next.data &&
prev.targetPosition === next.targetPosition &&
prev.sourcePosition === next.sourcePosition &&
prev.placeholder === next.placeholder
)