Design system / Molecules
Molecule / Editing
MarkdownTextarea
MarkdownTextarea edits a controlled source string with Bold and Italic commands. Formatting wraps the current selection in Markdown markers. Rendering a preview, validation and persistence are separate responsibilities.
Live example
Current component with fictional data. Example changes are not persisted.
Responsibility
Textarea and its formatting toolbar complete one text-entry concern. Typing and formatting report a complete source string through onChange. Preview rendering, validation and saving remain separate.
Public contract
The table describes supported inputs, exported parts and caller responsibilities. A callback supplies a command, such as saving a draft. These notes are maintained manually; check current source types before integration.
| Prop / part | Type | Requirement | Responsibility |
|---|---|---|---|
| value | string | Required | Controlled Markdown source text. |
| onChange | (value: string) => void | Required | Receives the complete next string from typing or formatting. Not a native input event. |
| id / name | string | Optional | Forwarded to Textarea; consumer supplies a label matching id. |
| placeholder | string | Optional | Hint only; not a persistent accessible label. |
| rows | number | Optional · default 4 | Textarea row count. |
| className | string | Optional | Applied to the outer wrapper, not forwarded as Textarea classes. |
API notes are curated documentation, not generated types. The source linked above is the current implementation; update these notes alongside API changes.
State and behavior
Identify which values the caller controls and which behavior the component or underlying primitive owns. A local example does not supply persistence, authorization or a complete product lifecycle.
The consumer owns value through value/onChange. A local ref tracks the textarea; useCallback wraps selection with ** or *, emits a new value and restores focus/cursor on the next frame. No dedicated behavior hook or async persistence lives here. Ctrl/Meta+B and Ctrl/Meta+I trigger formatting.
Dependencies
- Button (ghost / icon, h-7 w-7 overrides)
- Textarea
- Lucide Bold and Italic
- React useRef/useCallback and requestAnimationFrame
Token and styling contract
These notes identify theme roles, utilities and direct style values used by the source. Direct colors or timings are implementation exceptions, not recommendations to bypass the theme.
bg-muted/40 / border-input- Toolbar surface and boundary roles.
text-supporting / text-muted-foreground- “Markdown supported” helper text.
rounded-t-md / rounded-t-none- Joined toolbar/textarea shape.
ghost / icon, h-7 w-7, focus-visible:ring-0- Explicit compact action overrides and Textarea ring overrides; document rather than infer upstream changes.
Boundaries and limitations
- There is no disabled, error, aria-label, aria-describedby, onBlur or generic native-prop passthrough in the exposed API.
- Markdown content stays plain source text here. Rendering or sanitizing a preview belongs elsewhere.
- Selected text is wrapped; with no selection, markers are inserted at the cursor. Focus/cursor behavior and onChange’s string signature are part of the consumer contract.
Where to make a change
Change generic formatting/selection behavior in markdown-textarea.tsx; change field meaning, persistence and validation in its consumer. A Textarea change reaches the embedded editor, but local ring/border classes can override it. Adding disabled/error support is a deliberate molecule API change, not a prop that already exists.
Selected real uses
ProgramSetupTab
The draft-only integrity-statement section supplies its value, change handler, four rows and placeholder. The inspected product use has no associated label/id; its nearby heading does not create that relationship. Our example supplies it explicitly.
Repository path: src/app/(tenants)/console/[tenantCode]/admin/programs/[programCode]/program-setup-tab.tsx
These traces describe selected uses, not every dependency. Repository-only paths are shown as references; only approved files have public source views.
Usage contract
import { MarkdownTextarea } from "@/components/ui/markdown-textarea";
// The consumer owns value and setValue.
<Label htmlFor="integrity-statement">Integrity statement</Label>
<MarkdownTextarea
id="integrity-statement" name="integrityStatement"
value={value} onChange={setValue} rows={4}
/>Illustrative consumer bindings, not a self-contained product workflow. Live examples supply only local state or explicit fictional props.