/** * Standardized data types for all data-driven components. * * Pattern: * - `id` - unique identifier (required, string) * - `label` - human-readable display text * - `value` - numeric/data payload (where applicable) * * @see docs/plans/2026-01-07-standardize-id-label-pattern-design.md */ import type { ComponentType, ReactNode } from 'react'; /** * Base item pattern used across all data-driven components. */ export interface BaseItem { /** Unique identifier used for keys, callbacks, and state management */ id: string; /** Human-readable display text */ label: string; } /** * Item with a numeric data value (charts, metrics). */ export interface DataItem extends BaseItem { /** Numeric data value */ value: number; } /** * Item that can be disabled (selects, menus). */ export interface SelectableItem extends BaseItem { /** Whether the item is disabled */ disabled?: boolean; } /** * Generic grouping pattern for categorizing items. */ export interface ItemGroup { /** Unique identifier for the group */ id: string; /** Display label for the group */ label: string; /** Items within this group */ items: T[]; } /** * Chart series definition for multi-series charts (Bar, Line, Radar, etc.). */ export interface ChartSeries { /** Unique identifier referenced by data points */ id: string; /** Display label for legends and tooltips */ label: string; /** Optional custom color (CSS color value) */ color?: string; } /** * Chart data point with values keyed by series id. * Used for multi-series charts (Bar, Line, Radar, etc.). */ export interface ChartDataPoint { /** Unique identifier for this data point */ id: string; /** Display label (X-axis label, category name) */ label: string; /** Values keyed by series id - e.g., { revenue: 5000, expenses: 3000 } */ values: Record; } /** * Pie/Donut chart data item - single value per item. */ export interface PieChartItem { /** Unique identifier */ id: string; /** Display label for legend and tooltip */ label: string; /** Numeric value (slice size) */ value: number; /** Optional custom color (CSS color value) */ color?: string; } /** * Typed chart configuration for theming and labeling series. * Object keys must match series ids for type safety. * * @example * ```ts * const config: ChartConfig<"revenue" | "expenses"> = { * revenue: { label: "Revenue ($)", color: "#10b981" }, * expenses: { label: "Expenses ($)", color: "#ef4444" }, * }; * ``` */ export type ChartConfig = { [K in SeriesId]: { /** Display label for this series */ label: string; /** Optional icon component */ icon?: ComponentType; } & ({ color?: string; theme?: never; } | { color?: never; theme: Record<'light' | 'dark', string>; }); }; /** * Item for Autocomplete, Select, and similar selection components. */ export interface SelectItem extends SelectableItem { } /** * Group of selectable items. */ export interface SelectGroup extends ItemGroup { } /** * Command menu item. */ export interface CommandItem extends SelectableItem { /** Additional search keywords for filtering */ keywords?: string[]; /** Callback when item is selected */ onSelect?: () => void; } /** * Dropdown/Context menu item. */ export interface MenuItem extends SelectableItem { /** Icon to display */ icon?: ReactNode; /** Keyboard shortcut hint */ shortcut?: string; } /** * Group of menu items. */ export interface MenuGroup extends ItemGroup { }