Files
supabase/apps/studio/components/interfaces/Explorer/ExplorerToolbar.tsx
Joshen Lim 09a1f431bc Mass update for all lucide icon imports to use the component with Icon suffix (#51659)
## Context

This is largely just a mechanical change here:
Opting to use lucide icons with the `Icon` suffix across all icon
imports within `studio`
- so that it’s clearer which components are icons + reduces the
possibility of name collision with our own components
- e.g <User /> vs <UserIcon />

Also added a eslint rule for this:
<img width="1069" height="167" alt="image"
src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc"
/>

And updated `AGENTS.md` as such:
```
Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced).
```
2026-10-14 12:56:55 +02:00

182 lines
5.1 KiB
TypeScript

import { EditIcon } from 'lucide-react'
import React, { useState } from 'react'
import { Button, cn } from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
export type ExplorerToolbarProps = React.ComponentProps<'div'>
/**
* Shared toolbar row for Explorer resources such as notebooks and queries.
* Defaults to 40px and follows `--header-height` from the `md` breakpoint up, so
* a consumer that defines its own header height gets toolbars matching it. The
* fallback keeps the row at its default height in apps that leave the variable
* unset, rather than dropping the rule.
*/
const ExplorerToolbar = ({ className, role = 'toolbar', ...props }: ExplorerToolbarProps) => (
<div
data-slot="explorer-toolbar"
role={role}
className={cn(
'flex h-10 w-full shrink-0 items-center gap-2 border-b bg-transparent px-3',
className
)}
{...props}
/>
)
ExplorerToolbar.displayName = 'ExplorerToolbar'
export type ExplorerToolbarIconProps = React.ComponentProps<'span'>
/** Decorative resource icon shown before the toolbar title. */
const ExplorerToolbarIcon = ({
'aria-hidden': ariaHidden = true,
className,
...props
}: ExplorerToolbarIconProps) => (
<span
data-slot="explorer-toolbar-icon"
aria-hidden={ariaHidden}
className={cn('shrink-0 text-tertiary-foreground', className)}
{...props}
/>
)
ExplorerToolbarIcon.displayName = 'ExplorerToolbarIcon'
export type ExplorerToolbarTitleProps = Omit<React.ComponentProps<'div'>, 'children'> & {
children: string
onSaveTitle?: (value: string) => void
}
/** Flexible title region for static text or an editable resource name. */
const ExplorerToolbarTitle = ({
children: title,
className,
onSaveTitle,
...props
}: ExplorerToolbarTitleProps) => {
const [isEditingTitle, setIsEditingTitle] = useState(false)
const [value, setValue] = useState(title)
const handleStartEditing = () => {
setValue(title)
setIsEditingTitle(true)
}
return (
<div
data-slot="explorer-toolbar-title"
className={cn('min-w-0 flex-1 truncate text-sm', className)}
{...props}
>
{isEditingTitle ? (
<Input
autoFocus
size="tiny"
containerClassName="max-w-64 has-[[data-slot=input-group-control]:focus-visible]:ring-0"
className="outline-none"
value={value}
onChange={(e) => setValue(e.target.value)}
onBlur={() => {
if (isEditingTitle) {
setIsEditingTitle(false)
onSaveTitle?.(value)
}
}}
onKeyDown={(e) => {
if (e.key === 'Escape') {
e.preventDefault()
e.stopPropagation()
setIsEditingTitle(false)
} else if (e.key === 'Enter') {
e.preventDefault()
e.stopPropagation()
setIsEditingTitle(false)
onSaveTitle?.(value)
}
}}
/>
) : onSaveTitle ? (
<ExplorerToolbarAction
className="group/title"
onClick={handleStartEditing}
iconRight={
<EditIcon
size={16}
strokeWidth={2}
className="opacity-0 transition group-hover/title:opacity-100 group-focus-visible/title:opacity-100"
/>
}
>
{title}
</ExplorerToolbarAction>
) : (
title
)}
</div>
)
}
ExplorerToolbarTitle.displayName = 'ExplorerToolbarTitle'
export type ExplorerToolbarActionsProps = React.ComponentProps<'div'>
/**
* Trailing region for direct actions and composite controls such as badges,
* source menus, and display configuration.
*/
const ExplorerToolbarActions = ({ className, ...props }: ExplorerToolbarActionsProps) => (
<div
data-slot="explorer-toolbar-actions"
className={cn('ml-auto flex shrink-0 items-center gap-px', className)}
{...props}
/>
)
ExplorerToolbarActions.displayName = 'ExplorerToolbarActions'
export type ExplorerToolbarActionProps = Omit<
React.ComponentPropsWithRef<typeof Button>,
'size' | 'variant'
> & {
tooltip?: React.ReactNode
}
/**
* The standard tiny, text-style button used for a direct toolbar action.
* Icon-only actions receive the prototype's compact 28px width automatically.
* `!h-auto !w-auto` lets Lucide's `size` prop win over Button `tiny`'s 14px icon box.
*/
const ExplorerToolbarAction = ({
children,
className,
ref,
tooltip,
...props
}: ExplorerToolbarActionProps) => (
<ButtonTooltip
ref={ref}
data-slot="explorer-toolbar-action"
variant="text"
size="tiny"
className={cn(
'text-tertiary-foreground hover:text-foreground data-[state=open]:text-foreground',
'[&>[aria-hidden]]:text-current [&_svg]:!h-auto [&_svg]:!w-auto',
children == null && 'w-7 px-0',
className
)}
tooltip={{ content: { side: 'bottom', text: tooltip } }}
{...props}
>
{children}
</ButtonTooltip>
)
ExplorerToolbarAction.displayName = 'ExplorerToolbarAction'
export {
ExplorerToolbar,
ExplorerToolbarAction,
ExplorerToolbarActions,
ExplorerToolbarIcon,
ExplorerToolbarTitle,
}