Files
supabase/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.tsx
Anthony Lio 9659778769 feat(ui): scrollbar track (#52493)
## Problem

- proposal to lift scroll bar ui accross the apps
- fix shared `ScrollBar` in `ui` showing only a thin `bg-border` thumb
with no track, so the scroll position is hard to see

## Solution

- replaces the native scrollbars in the docs left nav and in the guide
right column with the shared scroll area
- replaces the native scrollbar in the docs search v2 results with the
shared scroll area, and keeps the animated list height and the bottom
fade
- changes the command menu list to the shared scroll area, with the bar
2px from the edge so it does not touch the hover highlight
- changes the studio connect sheet body and its framework combobox to
the shared scroll area, so long code lines still scroll inside their own
code blocks

| state | preview |
| -------|------|
| before | <img width="473" height="260" alt="image"
src="https://github.com/user-attachments/assets/ef22e643-b92a-4a23-9c77-6b10851e1445"
/> |
| after | <img width="473" height="260" alt="image"
src="https://github.com/user-attachments/assets/46fe95e9-0574-4eef-afbd-20d591baa859"
/> |

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. open
[/design-system/docs/components/scroll-area](https://design-system-git-antlio-feat-ui-scrollbar-track-supabase.vercel.app/design-system/docs/components/scroll-area),
scroll the vertical and horizontal demos, and make sure that the thumb
moves on a visible track and gets lighter on hover
2. open
[/docs/guides/database/postgres/row-level-security](https://docs-git-antlio-feat-ui-scrollbar-track-supabase.vercel.app/docs/guides/database/postgres/row-level-security),
scroll the left nav and the right column, and make sure that each shows
the new scrollbar
3. resize the page to mobile width, open the menu, and make sure that it
scrolls above the footer
4. make sure that the results scroll with the trackpad and with the
arrow keys, and that the bottom fade shows
5. open
[/dashboard](https://studio-git-antlio-feat-ui-scrollbar-track-supabase.vercel.app/dashboard),
press `⌘K`, scroll the command menu, and make sure that the thumb does
not touch the hover highlight of an item
6. open
[/dashboard/project/_?showConnect=true](https://studio-git-antlio-feat-ui-scrollbar-track-supabase.vercel.app/dashboard/project/_?showConnect=true),
scroll the connect sheet, and make sure that long code lines scroll
inside their code blocks and do not widen the sheet

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-05 09:16:06 +02:00

434 lines
15 KiB
TypeScript

import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react'
import { useState } from 'react'
import {
Button,
cn,
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
Popover,
PopoverContent,
PopoverTrigger,
RadioGroupStacked,
RadioGroupStackedItem,
ScrollBar,
ScrollRoot,
ScrollViewport,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Switch,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import {
MultiSelector,
MultiSelectorContent,
MultiSelectorItem,
MultiSelectorList,
MultiSelectorTrigger,
} from 'ui-patterns/multi-select'
import type { ConnectMode, FieldOption, ResolvedField } from './Connect.types'
import { getOptionMatchScore } from './ConnectConfigSection.utils'
import { ConnectionIcon } from './ConnectionIcon'
import {
ConnectModeButton,
getConnectModeButtonCornerVariants,
getConnectModeEmptySlotClasses,
} from './ConnectModeButton'
interface ConnectConfigSectionProps {
activeFields: ResolvedField[]
state: Record<string, string | boolean | string[]>
onFieldChange: (fieldId: string, value: string | boolean | string[]) => void
getFieldOptions: (fieldId: string) => FieldOption[]
}
export function ConnectConfigSection({
activeFields,
state,
onFieldChange,
getFieldOptions,
}: ConnectConfigSectionProps) {
if (activeFields.length === 0) return null
return (
<div className="flex flex-col gap-y-4">
{activeFields.map((field) => {
const options = getFieldOptions(field.id)
const value = state[field.id]
// Skip fields with no options (or single option that's auto-selected)
// Exception: switch and multi-select fields don't require options
if (field.type !== 'switch' && field.type !== 'multi-select') {
if (options.length === 0) return null
if (options.length === 1) return null
}
switch (field.type) {
case 'combobox':
return (
<FormItemLayout
key={field.id}
isReactForm={false}
layout="horizontal"
label={field.label}
description={field.description}
name={`connect-${field.id}`}
>
<ConnectCombobox
id={`connect-${field.id}`}
options={options}
value={String(value ?? '')}
onValueChange={(v) => onFieldChange(field.id, v)}
placeholder={field.combobox?.placeholder ?? 'Select option'}
searchPlaceholder={field.combobox?.searchPlaceholder ?? 'Search...'}
emptyMessage={field.combobox?.emptyMessage ?? 'No results found'}
/*
[Joshen] Omitting MCP icons for now as the images are not optimized (large)
and is causing noticeably latency issues on the browser (even with the existing Connect UI)
*/
showIcons={field.id === 'framework'}
/>
</FormItemLayout>
)
case 'radio-grid':
return (
<FormItemLayout
key={field.id}
isReactForm={false}
layout="horizontal"
label={field.label}
>
<RadioGroupStacked
value={String(value ?? '')}
onValueChange={(v) => onFieldChange(field.id, v)}
className="flex-row gap-3 space-y-0"
>
{options.map((option) => (
<RadioGroupStackedItem
key={option.value}
id={`connect-${field.id}-${option.value}`}
value={option.value}
label=""
className="flex-1 rounded-lg text-left"
>
<div className="flex items-center gap-2">
{option.icon && <ConnectionIcon supportsDarkMode icon={option.icon} />}
<span className="text-sm">{option.label}</span>
</div>
</RadioGroupStackedItem>
))}
</RadioGroupStacked>
</FormItemLayout>
)
case 'radio-list':
return (
<FormItemLayout
key={field.id}
isReactForm={false}
layout="horizontal"
label={field.label}
>
<RadioGroupStacked
value={String(value ?? '')}
onValueChange={(v) => onFieldChange(field.id, v)}
className="min-w-0 w-full"
>
{options.map((option) => (
<RadioGroupStackedItem
key={option.value}
id={`connect-${field.id}-${option.value}`}
value={option.value}
className="min-w-0 w-full text-left"
label={
<span className="flex min-w-0 items-center gap-2">
{option.icon && <ConnectionIcon icon={option.icon} />}
<span className="truncate">{option.label}</span>
</span>
}
description={option.description}
/>
))}
</RadioGroupStacked>
</FormItemLayout>
)
case 'select':
return (
<FormItemLayout
key={field.id}
isReactForm={false}
layout="horizontal"
label={field.label}
description={field.description}
name={`connect-${field.id}`}
>
<Select
value={String(value ?? '')}
onValueChange={(v) => onFieldChange(field.id, v)}
>
<SelectTrigger
id={`connect-${field.id}`}
size="small"
className="[&>span:first-child]:flex [&>span:first-child]:items-center [&>span:first-child]:gap-x-2"
>
<SelectValue />
</SelectTrigger>
<SelectContent>
{options.map((option) => (
<SelectItem
key={option.value}
value={option.value}
className="[&>span:last-child]:flex [&>span:last-child]:items-center [&>span:last-child]:gap-x-2"
>
{/*
[Joshen] Omitting MCP icons for now as the images are not optimized (large)
and is causing noticeably latency issues on the browser (even with the existing Connect UI)
*/}
{field.id === 'framework' && option.icon && (
<ConnectionIcon icon={option.icon} />
)}
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItemLayout>
)
case 'switch':
return (
<FormItemLayout
key={field.id}
isReactForm={false}
layout="horizontal"
label={field.label}
description={field.description}
name={field.id}
className="[&>div>label>span]:break-keep! [&>div>label>span]:text-balance"
>
<Switch
id={field.id}
checked={Boolean(value)}
onCheckedChange={(v) => onFieldChange(field.id, v)}
/>
</FormItemLayout>
)
case 'multi-select':
return (
<FormItemLayout
key={field.id}
isReactForm={false}
layout="horizontal"
label={field.label}
description={field.description}
name={`connect-${field.id}`}
>
<MultiSelector
values={Array.isArray(value) ? value : []}
onValuesChange={(v) => onFieldChange(field.id, v)}
>
<MultiSelectorTrigger
id={`connect-${field.id}`}
className="w-full"
label="Select features"
badgeLimit="wrap"
showIcon={true}
/>
<MultiSelectorContent>
<MultiSelectorList>
{options.map((option) => (
<MultiSelectorItem
key={option.value}
value={option.value}
className="items-start"
>
<div className="flex flex-col ml-2 gap-y-0.5">
<span className="font-medium">{option.label}</span>
{option.description && (
<span className="text-xs text-foreground-light">
{option.description}
</span>
)}
</div>
</MultiSelectorItem>
))}
</MultiSelectorList>
</MultiSelectorContent>
</MultiSelector>
</FormItemLayout>
)
default:
return null
}
})}
</div>
)
}
interface ConnectComboboxProps {
id: string
options: FieldOption[]
value: string
onValueChange: (value: string) => void
placeholder: string
searchPlaceholder: string
emptyMessage: string
showIcons: boolean
}
function ConnectCombobox({
id,
options,
value,
onValueChange,
placeholder,
searchPlaceholder,
emptyMessage,
showIcons,
}: ConnectComboboxProps) {
const [isOpen, setIsOpen] = useState(false)
const [search, setSearch] = useState('')
const [listboxElementId, setListboxElementId] = useState<string>()
const selectedOption = options.find((option) => option.value === value)
const showEmptyStatus =
search.trim().length > 0 &&
!options.some((option) => getOptionMatchScore(option.label, search, [option.value]) > 0)
const handleOpenChange = (open: boolean) => {
setIsOpen(open)
if (!open) setSearch('')
}
return (
<Popover open={isOpen} onOpenChange={handleOpenChange} modal={false}>
<PopoverTrigger asChild>
<Button
id={id}
variant="default"
size="small"
role="combobox"
aria-expanded={isOpen}
aria-controls={listboxElementId}
className={cn('w-full justify-between', !selectedOption && 'text-foreground-muted')}
iconRight={<ChevronsUpDownIcon className="h-4 w-4 shrink-0 opacity-50" strokeWidth={1} />}
>
<span className="flex min-w-0 items-center gap-x-2">
{showIcons && selectedOption?.icon && (
<span aria-hidden="true" className="flex shrink-0">
<ConnectionIcon icon={selectedOption.icon} />
</span>
)}
<span className="truncate">{selectedOption?.label ?? placeholder}</span>
</span>
</Button>
</PopoverTrigger>
<PopoverContent align="start" className="p-0" sameWidthAsTrigger>
<Command filter={getOptionMatchScore}>
<CommandInput placeholder={searchPlaceholder} value={search} onValueChange={setSearch} />
<p className="sr-only" role="status" aria-live="polite">
{showEmptyStatus ? emptyMessage : ''}
</p>
<ScrollRoot className="flex flex-col">
<ScrollViewport className="max-h-72 overscroll-contain">
<CommandList
className="max-h-none overflow-visible"
ref={(node) => {
if (node?.id) setListboxElementId(node.id)
}}
>
<CommandEmpty>{emptyMessage}</CommandEmpty>
<CommandGroup>
{options.map((option) => (
<CommandItem
key={option.value}
value={option.label}
keywords={[option.value]}
onSelect={() => {
onValueChange(option.value)
handleOpenChange(false)
}}
className="gap-x-2"
>
<CheckIcon
className={cn(
'h-4 w-4 shrink-0',
option.value === value ? 'opacity-100' : 'opacity-0'
)}
/>
{showIcons && option.icon && (
<span aria-hidden="true" className="flex shrink-0">
<ConnectionIcon icon={option.icon} />
</span>
)}
<span className="truncate">{option.label}</span>
</CommandItem>
))}
</CommandGroup>
</CommandList>
</ScrollViewport>
<ScrollBar />
</ScrollRoot>
</Command>
</PopoverContent>
</Popover>
)
}
interface ModeSelectorProps {
modes: Array<{ id: ConnectMode; label: string; description: string }>
selected: ConnectMode
onChange: (mode: ConnectMode) => void
}
export function ModeSelector({ modes, selected, onChange }: ModeSelectorProps) {
const count = modes.length
// 2-col layout leaves an empty cell when count is odd; hide it once we switch to a single row
const emptySlots = count % 2 === 1 ? 1 : 0
return (
// Container query: 2-col when the sheet is narrow; one equal row when there's room
<div className="@container">
<div
className={cn(
'grid',
'grid-cols-2',
count === 3 && '@[28rem]:grid-cols-3',
count === 4 && '@[30rem]:grid-cols-4',
count === 5 && '@[32rem]:grid-cols-5',
count >= 6 && '@[36rem]:grid-cols-6'
)}
>
{modes.map((mode, index) => (
<ConnectModeButton
key={mode.id}
modeId={mode.id}
label={mode.label}
description={mode.description}
selected={selected === mode.id}
onClick={() => onChange(mode.id)}
{...getConnectModeButtonCornerVariants({ index, count, emptySlots })}
/>
))}
{Array.from({ length: emptySlots }, (_, index) => (
<div
key={`empty-${index}`}
aria-hidden
className={getConnectModeEmptySlotClasses(count)}
/>
))}
</div>
</div>
)
}