@@jsxConfig({version: 4, mode: "automatic", module_: "BaseUi.BaseUiJsxDOM"}) // ComponentPreview: async server component that renders a demo with source code tabs. module Type = { type t = | @as("block") Block | @as("component") Component | @as("example") Example } @react.component let make = async ( ~name, @as("type") ~type_: option=?, ~className=?, ~previewClassName=?, ~align=ComponentPreviewTabs.Align.Center, ~hideCode=false, ~chromeLessOnMobile=false, ~direction=BaseUi.Types.TextDirection.Ltr, ~caption=?, ~selection: option=?, ) => { switch name { | None => React.null | Some(name) => // Block type: render images + iframe instead of inline component switch type_ { | Some(Type.Block) => // Render block components inline in a contained wrapper. // `transform: scale(1)` creates a new containing block so that // position:fixed children (e.g. Sidebar) are trapped inside. let componentElement = let content =
{componentElement}
switch caption { | Some(caption) =>
content
{caption->React.string}
| None => content } | Some(Component | Example) | None => // Render demo client-side via DemoLoader (avoids RSC client reference issues // with nested submodule access like Accordion.Item.make) let componentElement = let selections = switch selection { | Some(selection) => [selection] | None => Config.Lib.all->Array.flatMap(lib => Config.Style.all->Array.map(style => {Config.LibStyle.lib, style}) ) } let sources = selections->Array.map(({lib, style}) => { { ComponentPreviewTabs.StyleSource.lib, style, source: , sourcePreview: , } }) let content = switch caption { | Some(caption) =>
content
{caption->React.string}
| None => content } } } }