'use client' import React from 'react' import { Button } from '../ui/button' import { Copy02Icon } from '../icons-v2-generated/documents/copy-02-icon' import { cn } from '../../utils/cn' export interface CommandBoxAction { /** Button label */ label: string /** Click handler */ onClick: () => void /** Button variant */ variant?: 'accent' | 'outline' | 'transparent' | 'destructive' /** Icon to display before the label */ icon?: React.ReactNode /** Whether the button is disabled */ disabled?: boolean /** Whether the button is in loading state */ loading?: boolean } export interface CommandBoxProps { /** The command text to display */ command: string /** Title displayed above the command box */ title?: string /** Primary action button (displayed on the right) */ primaryAction?: CommandBoxAction /** Secondary action button (displayed before primary) */ secondaryAction?: CommandBoxAction /** Additional CSS classes for the container */ className?: string /** Additional CSS classes for the command text */ commandClassName?: string /** Maximum lines to show (uses line-clamp, 0 for unlimited) */ maxLines?: number /** When set, shows a copy icon button in the top-right corner of the box */ onCopy?: () => void /** Accessible label for the corner copy button */ copyAriaLabel?: string } /** * CommandBox - Unified component for displaying commands with action buttons * * Features: * - Displays command text in monospace font * - Optional title * - Primary and secondary action buttons * - Configurable line clamping * - Consistent ODS styling * * Usage Example: * ```tsx * import { CommandBox } from '@flamingo/ui-kit/components/features' * import { Copy, Play } from 'lucide-react' * * , * variant: 'primary' * }} * secondaryAction={{ * label: 'Run on Current Machine', * onClick: handleRun, * icon: , * variant: 'outline' * }} * /> * ``` */ // Static mapping for line-clamp classes (Tailwind needs static class names at build time) const lineClampClasses: Record = { 1: 'line-clamp-1', 2: 'line-clamp-2', 3: 'line-clamp-3', 4: 'line-clamp-4', 5: 'line-clamp-5', 6: 'line-clamp-6', } export function CommandBox({ command, title, primaryAction, secondaryAction, className, commandClassName, maxLines = 0, onCopy, copyAriaLabel = 'Copy command' }: CommandBoxProps) { // Get static line-clamp class or undefined for unlimited const lineClampClass = maxLines > 0 ? lineClampClasses[maxLines] : undefined const commandText = (
{command}
) return (
{title && (
{title}
)}
{onCopy ? (
{commandText}
) : ( commandText )} {(primaryAction || secondaryAction) && (
{secondaryAction && ( )} {primaryAction && ( )}
)}
) }