Math Block
moco/mathFreeComponent
Display equation with a plain-English restatement and a 'show the math' derivation disclosure. Children are typically KaTeX/MathML output — katex is an optional peer, not imported here.
Live preview
live · rendered by the registry
Rendered by moco on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://mocoui.site/r/math.jsonSource
1"use client";23import * as React from "react";4import "./math.css";56/**7 * A display equation with a plain-English restatement under it and a8 * progressive-disclosure button for the derivation.9 *10 * `children` is the rendered equation — typically KaTeX or MathML output.11 * katex is not imported here; render the math however you like.12 */13export interface MathBlockProps {14 children: React.ReactNode;15 plain: string;16 derivation?: React.ReactNode;17}1819export function MathBlock({ children, plain, derivation }: MathBlockProps) {20 const [open, setOpen] = React.useState(false);21 const id = React.useId();22 return (23 <div className="moco-math-block">24 {derivation ? (25 <div className="moco-math-head">26 <button27 type="button"28 className="moco-btn-sm"29 aria-expanded={open}30 aria-controls={id}31 onClick={() => setOpen((v) => !v)}32 >33 {open ? "Hide the math" : "Show the math"}34 </button>35 </div>36 ) : null}37 {children}38 <p className="moco-math-plain">{plain}</p>39 {derivation ? (40 <div id={id} className="moco-math-deriv" hidden={!open}>41 {derivation}42 </div>43 ) : null}44 </div>45 );46}
What it pulls in
Other registry items
Files it writes
More from moco
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Codecode | moco | Components | Free | 1 dep · 3 files | |
| Comparecompare | moco | Components | Free | no deps · 2 files | |
| Count Upcountup | moco | Components | Free | no deps · 2 files | |
| Covercover | moco | Components | Free | no deps · 2 files | |
| Diagram Kitdiagram | moco | Components | Free | no deps · 2 files | |
| Dot Griddotgrid | moco | Components | Free | no deps · 2 files | |
| Figurefigure | moco | Components | Free | no deps · 2 files | |
| Hookshooks | moco | Components | Free | no deps |
