mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 03:15:06 +03:00
## What kind of change does this PR introduce? Bug fix + small shared component ## What is the current behavior? After the recent colour system changes, several UI elements lost contrast in light mode: - `InfoIcon` with a background appeared as a flat grey circle (glyph fill matched the background) - Several buttons forced `text-white`, which no longer contrasts correctly against the updated brand fills - Selected / completed check badges were inconsistent between call sites ## What is the new behavior? - `InfoIcon` uses `text-background` for the glyph fill so the "i" is visible against the grey circle - www primary buttons drop hardcoded `text-white` and use standard `Button` colours - New shared `SuccessCheck` in `ui` for selected state and completion progress (green circle; white check in light mode, black check in dark mode) - Documented in the design system with selected + progress examples Note on `InfoIcon`: [#47933](https://github.com/supabase/supabase/pull/47933) landed a related fix using `text-background-200` (`--card`). This PR keeps `text-background` instead, to match `CheckIcon` / `EyeOffIcon` in the same file and avoid the legacy alias. | Before | After | | --- | --- | | <img width="688" height="268" alt="CleanShot 2026-07-10 at 11 30 25@2x" src="https://github.com/user-attachments/assets/c0276b0c-1023-46c8-805c-35a22def1353" /> | <img width="664" height="278" alt="CleanShot 2026-07-10 at 11 29 43@2x" src="https://github.com/user-attachments/assets/3508cf37-1b48-4fb7-a939-83522feb44f1" /> | | <img width="468" height="550" alt="CleanShot 2026-07-10 at 11 31 04@2x" src="https://github.com/user-attachments/assets/acd42273-15ce-4fb2-9d0c-5a43ac23073c" /> | <img width="460" height="540" alt="CleanShot 2026-07-10 at 11 32 50@2x" src="https://github.com/user-attachments/assets/f66fb4bc-81f7-4df1-95f5-63980c4e8537" /> | ## To test Use the staging preview link from this PR and check the following in **light mode** (and spot-check dark mode): **www** - Visit `/404` — "Head back" button should have readable text (not white-on-green) - Visit `/company` — "Join the team" button in the Team section - Visit a product page with a hero CTA (e.g. `/database`, `/realtime`) — primary "Start for free" button **studio** - Database → Replication → deploy a read replica — footer `InfoIcon` next to the pricing line should show a visible "i" inside the grey circle - `/redeem` — select an org; green `SuccessCheck` should match light/dark contrast (white check / black check) - Settings → API → service role key row — red "secret" tag text should be readable **design system** - `/docs/components/success-check` — demo, selected-state, and progress examples
220 lines
7.8 KiB
TypeScript
220 lines
7.8 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"
|
|
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-brand bg-brand-200/20 dark:bg-brand-300 pr-10 group-hover:border-brand group-hover:bg-brand-200/20'
|
|
)}
|
|
/>
|
|
{selected && (
|
|
<SuccessCheck className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2" />
|
|
)}
|
|
</button>
|
|
)
|