/* Copyright 2026 Marimo. All rights reserved. */ import React, { type JSX, type PropsWithChildren } from "react"; import { z } from "zod"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { renderHTML } from "../core/RenderHTML"; import type { IStatelessPlugin, IStatelessPluginProps, } from "../stateless-plugin"; interface Data { /** * The labels for each item; raw HTML. */ labels: string[]; /** * Whether to allow multiple tabs to be open. */ multiple: boolean; expanded: string[]; } export class AccordionPlugin implements IStatelessPlugin { public tagName = "marimo-accordion"; public validator = z.object({ labels: z.array(z.string()), multiple: z.boolean(), expanded: z.array(z.string()).default([]), }); public render(props: IStatelessPluginProps): JSX.Element { return ( {props.children} ); } } const AccordionComponent = ({ labels, multiple, expanded, children, }: PropsWithChildren): JSX.Element => { const expansionProps = multiple ? { type: "multiple" as const, defaultValue: expanded } : { type: "single" as const, defaultValue: expanded[0], collapsible: true }; return ( {React.Children.map(children, (child, index) => { return ( {renderHTML({ html: labels[index] })} {child} ); })} ); };