"use client"
/**
* LeoGenerationSurface — wrap ANY component Leo can create (card, chart, form,
* panel) to give it the shared inited → thinking → completed treatment.
*
* }>
*
*
*
* - `state` null/undefined → children render untouched.
* - `inited` → status bar with Leo's mark playing its invited gesture;
* children are not shown.
* - `thinking` → shimmering status bar over `skeleton` (or generic bars);
* `aria-busy` is set.
* - `completed` → a lone check bar; clear `state` (set null) to reveal the children.
*
* Single brand colour only. Table rows use the same contract via
* `DataTable leoLoading` / `LeoLoadingRow`.
*/
import * as React from "react"
import { cn } from "../../lib/utils"
import {
LEO_GENERATION_ICON_STATE,
LEO_GENERATION_LABEL,
type LeoGenerationState,
} from "../../lib/leo-generation"
import { LeoIcon } from "./leo-icon"
import { LeoBrandBackdrop } from "./leo-brand-backdrop"
import { Button } from "./button"
import { Tip } from "./tip"
/**
* Stop action for an in-flight generation. Render only while `inited` or
* `thinking` — a completed generation has nothing left to stop.
*/
export function LeoStopButton({
onStop,
label = "Stop",
className,
}: {
onStop: () => void
/** Accessible name and tooltip. */
label?: string
className?: string
}) {
return (
)
}
export interface LeoGenerationStatusProps {
/** Shows a Stop button while inited or thinking. */
onStop?: () => void
state: LeoGenerationState
label?: string
className?: string
}
/** The status line: Leo mark (+ check when done) and a label. Reused by rows. */
export function LeoGenerationStatus({ state, label, onStop, className }: LeoGenerationStatusProps) {
return (
)
}
export interface LeoGenerationSurfaceProps {
state?: LeoGenerationState | null
/** Adds a Stop button to the status bar while inited or thinking. */
onStop?: () => void
/** Overrides the state's status text. */
label?: string
/** What `thinking` shows in place of the content. Defaults to generic bars. */
skeleton?: React.ReactNode
className?: string
children?: React.ReactNode
}
export function LeoGenerationSurface({ state, label, onStop, skeleton, className, children }: LeoGenerationSurfaceProps) {
if (!state) return <>{children}>
return (
{state === "thinking" ? (
{skeleton ?? }
) : null}
)
}
// ─── Section (parent) ────────────────────────────────────────────────────────
interface LeoGenerationScopeValue {
state: LeoGenerationState | null
onStop?: () => void
}
const LeoGenerationScope = React.createContext(null)
/**
* Read the nearest section's generation state. A child (table, chart, list)
* calls this to know its parent is mid-run without being wired by hand.
*/
export function useLeoGenerationScope(): LeoGenerationScopeValue | null {
return React.useContext(LeoGenerationScope)
}
export interface LeoGenerationSectionProps {
title: React.ReactNode
description?: React.ReactNode
/** The section's own run. Its content stays visible; children show their own progress. */
state?: LeoGenerationState | null
label?: string
/** Stops the whole section's run. */
onStop?: () => void
className?: string
children?: React.ReactNode
}
/**
* LeoGenerationSection — the PARENT in a parent / child run.
*
* A section that holds other components (a table, a chart, a list). When Leo is
* asked to fill the section, the section header shows Leo working (brand
* backdrop, status, Stop) while its children stay on screen and show their own
* progress — a table adds rows, a chart draws points. Children read the
* section's state with `useLeoGenerationScope()`.
*/
export function LeoGenerationSection({
title,
description,
state,
label,
onStop,
className,
children,
}: LeoGenerationSectionProps) {
const scope = React.useMemo(() => ({ state: state ?? null, onStop }), [state, onStop])
return (
{state ? : null}