Files
supabase/apps/studio/components/interfaces/Connect/OrganizationSelector.tsx
Danny White d067e81a69 fix(ui): align primary colours across text, buttons, and controls (#50697)
## Problem

Primary colour serves readable text and selected controls, but those
uses need different shades. Light mode needs darker text, while dark
mode needs a deeper button fill. Fixed brand green on interactive chrome
also prevents a custom primary hue from carrying through the interface.
Some slider tracks and selected text are hard to read.

## Solution

- Keep `--primary` for accessible text and small selected indicators.
Use `--primary-solid` for button fills, which need a deeper shade in
dark mode.
- Add `--primary-bright` for focus rings, selected control chrome, chart
accents, and other interactive highlights. It follows `--primary-hue`;
`brand-*` stays fixed for Supabase identity.
- Make slider troughs clearer and text selection translucent with theme
foreground text.
- Document the split in the design-system colour guide.

| Before | After |
| --- | --- |
| <img width="980" height="244" alt="Before: light mode primary
controls"
src="https://github.com/user-attachments/assets/dfae325d-0dfe-4231-8bcd-3f89c4b9d793"
/> | <img width="982" height="204" alt="After: light mode primary
controls"
src="https://github.com/user-attachments/assets/5fdcb531-a6e3-4549-8a13-9d9a5ebe6e20"
/> |
| <img width="610" height="120" alt="Before: slider track"
src="https://github.com/user-attachments/assets/04f768e0-51e8-4d06-9b97-c52f4a34f122"
/> | <img width="622" height="126" alt="After: slider track"
src="https://github.com/user-attachments/assets/95127f4e-13dc-4f0f-b63c-cf5d70a28b42"
/> |
| <img width="652" height="512" alt="Before: dark mode controls"
src="https://github.com/user-attachments/assets/3f88de66-90cc-40ee-8cf1-b5f4eb87b09a"
/> | <img width="658" height="498" alt="After: dark mode controls"
src="https://github.com/user-attachments/assets/906bec30-6ca1-4614-9fb3-6cf5e5feec22"
/> |

## Review instructions

1. Compare light and dark mode in the [colour usage
guide](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/color-usage#primary-and-brand-colors).
Check primary ink, primary-solid, primary-bright, and fixed brand
swatches.
2. In Studio, open the ‘new table’ sheet in [Table
Editor](https://studio-staging-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/dashboard/project/_/editor).
Tab through the new table sheet's fields and toggles. Check the focus
rings, selected controls, and the sheet's edges in both themes. You do
not need to save a table.
3. Select text in Studio in both themes, including a link or
primary-coloured label. The selection and text should remain legible.
4. Check the
[Field](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/field)
Price Range slider: the unused track should remain visible in both
themes. The selected field card border should follow primary-bright.
5. Check the
[Button](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/button)
and [Radio
Group](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/radio-group)
previews. In dark mode, `primary` button fill should be deeper than
primary
[text](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/color-usage#text);
selected radios should remain readable.
2026-09-24 09:56:31 +10:00

221 lines
7.9 KiB
TypeScript

import { ChevronDown } from 'lucide-react'
import { useMemo, useState, type ReactNode } from 'react'
import { cn, Collapsible, CollapsibleContent, CollapsibleTrigger, SuccessCheck } from 'ui'
import {
CreateOrganizationCard,
OrganizationCard,
} from '@/components/interfaces/Organization/OrganizationCard'
import { useLastVisitedOrganization } from '@/hooks/misc/useLastVisitedOrganization'
import type { Organization } from '@/types'
const VISIBLE_ORGANIZATIONS_LIMIT = 3
const CONNECT_DISCLOSURE_TRIGGER_CLASSNAME = cn(
'mx-auto flex h-7 cursor-pointer items-center justify-center gap-1.5 rounded-md px-2',
'text-xs text-foreground-lighter transition-colors',
'hover:bg-surface-200 hover:text-foreground',
'[&[data-state=open]>svg]:-rotate-180!'
)
export const OrganizationSelector = ({
organizations,
unavailableOrganizations = [],
selectedSlug,
disabled = false,
description,
createLabel,
createHrefParams,
onCreate,
onSelect,
getOrganizationDescription,
getUnavailableOrganizationDescription,
unavailableReason,
}: {
organizations: Organization[]
unavailableOrganizations?: Organization[]
selectedSlug?: string | null
disabled?: boolean
description?: ReactNode
createLabel?: string
createHrefParams?: { [key: string]: string }
onCreate?: () => void
onSelect: (slug: string) => void
getOrganizationDescription?: (organization: Organization) => ReactNode
getUnavailableOrganizationDescription?: (organization: Organization) => ReactNode
unavailableReason?: ReactNode
}) => {
const [showMore, setShowMore] = useState(false)
const { lastVisitedOrganization } = useLastVisitedOrganization()
const { visibleOrganizations, overflowOrganizations } = useMemo(() => {
const lastVisitedOrg = organizations.find(({ slug }) => slug === lastVisitedOrganization)
const selectedIndex = organizations.findIndex(({ slug }) => slug === selectedSlug)
const selectedInOverflow = selectedIndex >= VISIBLE_ORGANIZATIONS_LIMIT
if (!!lastVisitedOrg) {
const withoutLastVisited = organizations.filter(
({ slug }) => slug !== lastVisitedOrganization
)
return {
visibleOrganizations: [
lastVisitedOrg,
...withoutLastVisited.slice(0, VISIBLE_ORGANIZATIONS_LIMIT - 1),
],
overflowOrganizations: withoutLastVisited.slice(VISIBLE_ORGANIZATIONS_LIMIT - 1),
}
}
if (!selectedInOverflow || !selectedSlug) {
return {
visibleOrganizations: organizations.slice(0, VISIBLE_ORGANIZATIONS_LIMIT),
overflowOrganizations: organizations.slice(VISIBLE_ORGANIZATIONS_LIMIT),
}
}
const selected = organizations[selectedIndex]
const withoutSelected = organizations.filter(({ slug }) => slug !== selectedSlug)
return {
visibleOrganizations: [
...withoutSelected.slice(0, VISIBLE_ORGANIZATIONS_LIMIT - 1),
selected,
],
overflowOrganizations: withoutSelected.slice(VISIBLE_ORGANIZATIONS_LIMIT - 1),
}
}, [lastVisitedOrganization, organizations, selectedSlug])
const hasOverflow = overflowOrganizations.length > 0
const hasUnavailableOrganizations = unavailableOrganizations.length > 0
return (
<section className="space-y-2" aria-label="Organizations">
<div className="space-y-1">
<p className="text-xs font-medium uppercase tracking-wider text-foreground-light">
Organization
</p>
{description && <p className="text-xs text-foreground-lighter pr-4">{description}</p>}
</div>
<div className="space-y-2">
{visibleOrganizations.map((organization) => (
<ConnectOrganizationButton
key={organization.slug}
organization={organization}
selected={selectedSlug === organization.slug}
disabled={disabled}
onClick={() => onSelect(organization.slug)}
description={
getOrganizationDescription?.(organization) ?? getPlanDescription(organization)
}
/>
))}
{!!createLabel && (!!createHrefParams || !!onCreate) && (
<CreateOrganizationCard
params={createHrefParams}
label={createLabel}
disabled={disabled}
onClick={onCreate}
/>
)}
{hasOverflow && (
<Collapsible open={showMore} onOpenChange={setShowMore}>
<CollapsibleTrigger className={CONNECT_DISCLOSURE_TRIGGER_CLASSNAME}>
<span>{showMore ? 'Show fewer' : `Show ${overflowOrganizations.length} more`}</span>
<ChevronDown className="size-3.5 transition-transform" />
</CollapsibleTrigger>
<CollapsibleContent className="data-closed:animate-collapsible-up data-open:animate-collapsible-down overflow-hidden">
<div className="space-y-2 pt-1">
{overflowOrganizations.map((organization) => (
<ConnectOrganizationButton
key={organization.slug}
organization={organization}
selected={selectedSlug === organization.slug}
disabled={disabled}
onClick={() => onSelect(organization.slug)}
description={
getOrganizationDescription?.(organization) ?? getPlanDescription(organization)
}
/>
))}
</div>
</CollapsibleContent>
</Collapsible>
)}
{hasUnavailableOrganizations && (
<Collapsible>
<CollapsibleTrigger className={CONNECT_DISCLOSURE_TRIGGER_CLASSNAME}>
<span>Organizations that can't be linked</span>
<ChevronDown className="size-3.5 transition-transform" />
</CollapsibleTrigger>
<CollapsibleContent className="data-closed:animate-collapsible-up data-open:animate-collapsible-down overflow-hidden">
<div className="space-y-2 pt-1">
{unavailableOrganizations.map((organization) => (
<ConnectOrganizationButton
key={organization.slug}
organization={organization}
disabled
description={
getUnavailableOrganizationDescription?.(organization) ??
getPlanDescription(organization)
}
/>
))}
{unavailableReason && (
<p className="mx-auto max-w-xs text-center text-xs text-foreground-lighter text-balance">
{unavailableReason}
</p>
)}
</div>
</CollapsibleContent>
</Collapsible>
)}
</div>
</section>
)
}
const getPlanDescription = (organization: Organization) => `${organization.plan.name} Plan`
const ConnectOrganizationButton = ({
organization,
selected,
disabled,
onClick,
description,
}: {
organization: Organization
selected?: boolean
disabled?: boolean
onClick?: () => void
description?: ReactNode
}) => (
<button
type="button"
tabIndex={disabled ? -1 : 0}
disabled={disabled}
onClick={onClick}
aria-pressed={selected}
className={cn(
'group relative block w-full cursor-pointer text-left disabled:cursor-not-allowed disabled:opacity-50',
disabled && 'pointer-events-none'
)}
>
<OrganizationCard
isLink={false}
organization={organization}
description={description}
className={cn(
'pointer-events-none shadow-none transition-colors',
!disabled && !selected && 'group-hover:border-default group-hover:bg-surface-200',
selected &&
'border-primary-bright bg-primary-bright/10 pr-10 group-hover:border-primary-bright group-hover:bg-primary-bright/10'
)}
/>
{selected && (
<SuccessCheck className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 border-primary-bright bg-primary-bright text-black dark:text-black" />
)}
</button>
)