'use client'; import { Layers2Icon } from 'lucide-react'; import type React from 'react'; import { useState } from 'react'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; import { toUsageSnippet } from '@/lib/exampleSnippet'; import { extractStorySource } from '@/lib/extractStorySource'; import { generateKnobs, initKnobValues } from '@/lib/generateKnobs'; import type { StoryModule } from '@/lib/types'; import { cn, fillsFrame } from '@/lib/utils'; import { StoryMosaicProvider } from './ChaosProvider'; import { CodeFooter } from './CodeFooter'; import type { CompositionPiece } from './Composition'; import { CompositionPanel } from './Composition'; interface StoryEmbedProps { name: string; storyModule: StoryModule; /** Whether to show the story's source footer. */ showCode?: boolean; /** When provided, a collapsible "Composition" footer is attached to the example card. */ composition?: CompositionPiece[]; } /** A collapsible "Composition" footer listing the lower-layer pieces an example composes. */ function CompositionFooter({ composition }: { composition: CompositionPiece[] }) { const [open, setOpen] = useState(false); return (
Composition
); } export function StoryEmbed({ name, storyModule, showCode = true, composition }: StoryEmbedProps) { const StoryComp = storyModule[name] as React.ComponentType>; if (!StoryComp) { return
Story "{name}" not found
; } const knobs = generateKnobs(storyModule.meta); const defaultValues = initKnobValues(knobs); // Present only for modules that expose `__source` (see `StoryModule.__source`). The raw // story function is a knob harness, so reduce it to a clean usage snippet for the footer. const rawSource = extractStorySource(storyModule.__source, name); const source = showCode && rawSource ? toUsageSnippet(rawSource) : null; return (
*]:w-full', )} >
{source ? : null} {composition ? : null}
); }