import { Edit } 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) => (
) 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) => ( ) ExplorerToolbarIcon.displayName = 'ExplorerToolbarIcon' export type ExplorerToolbarTitleProps = Omit, '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 (
{isEditingTitle ? ( 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 ? ( } > {title} ) : ( title )}
) } 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) => (
) ExplorerToolbarActions.displayName = 'ExplorerToolbarActions' export type ExplorerToolbarActionProps = Omit< React.ComponentPropsWithRef, '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) => ( [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} ) ExplorerToolbarAction.displayName = 'ExplorerToolbarAction' export { ExplorerToolbar, ExplorerToolbarAction, ExplorerToolbarActions, ExplorerToolbarIcon, ExplorerToolbarTitle, }