chore(mermaid): basic logic for content switcher

This commit is contained in:
Elian Doran
2026-03-14 09:26:14 +02:00
parent 069d8b1ae4
commit 72038fb2ec
4 changed files with 54 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
.note-content-switcher {
--badge-radius: 12px;
position: relative;
top: 5px;
display: flex;
min-height: 35px;
gap: 5px;
.ext-badge {
--color: var(--input-background-color);
color: var(--main-text-color);
font-size: 0.9rem;
flex-shrink: 0;
}
}

View File

@@ -1,9 +1,25 @@
import { ComponentChildren } from "preact";
import "./NoteContentSwitcher.css";
import { Badge } from "../react/Badge";
export interface NoteContentTemplate {
name: string;
content: string;
}
interface NoteContentSwitcherProps {
children: ComponentChildren;
templates: NoteContentTemplate[];
}
export default function NoteContentSwitcher({ children }: NoteContentSwitcherProps) {
return <p>{children}</p>;
export default function NoteContentSwitcher({ templates }: NoteContentSwitcherProps) {
return (
<div className="note-content-switcher">
{templates.map(sample => (
<Badge
key={sample.name}
text={sample.name}
/>
))}
</div>
);
}

View File

@@ -4,6 +4,7 @@ import { getMermaidConfig, loadElkIfNeeded, postprocessMermaidSvg } from "../../
import NoteContentSwitcher from "../../layout/NoteContentSwitcher";
import SvgSplitEditor from "../helpers/SvgSplitEditor";
import { TypeWidgetProps } from "../type_widget";
import SAMPLE_DIAGRAMS from "./sample_diagrams";
let idCounter = 1;
let registeredErrorReporter = false;
@@ -33,9 +34,7 @@ export default function Mermaid(props: TypeWidgetProps) {
renderSvg={renderSvg}
noteType="mermaid"
extraContent={(
<NoteContentSwitcher>
Foo
</NoteContentSwitcher>
<NoteContentSwitcher templates={SAMPLE_DIAGRAMS} />
)}
{...props}
/>

View File

@@ -0,0 +1,17 @@
import type { NoteContentTemplate } from "../../layout/NoteContentSwitcher";
const SAMPLE_DIAGRAMS: NoteContentTemplate[] = [
{
name: "Flowchart",
content: `\
flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`
}
];
export default SAMPLE_DIAGRAMS;