Inputs
Markdown Toolbar Textarea
A field with a formatting toolbar: the buttons wrap the selection in markdown characters through setRangeText, so the browser's undo history stays alive.
- textarea
- toolbar
- markdown
- editor
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/textarea-004?lang=en
Markdown is supported: **жирный**, _курсив_
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "textarea-004" (Markdown Toolbar Textarea) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/textarea-004.json
Registry item: https://vibeui.ru/r/textarea-004.json
Installs to: components/vibeui/textarea-004.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A field with a formatting toolbar: the buttons wrap the selection in markdown characters through setRangeText, so the browser's undo history stays alive.
A field with a markdown toolbar over a plain textarea. One file, zero dependencies, a client component.
## 3. How to use it
import { Textarea004 } from "@/components/vibeui/textarea-004"
<Textarea004
label="Release notes"
hint="Markdown is supported"
/>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-textarea-004-* palette — do not swap it for your theme tokens
- setRangeText instead of rebuilding the string: writing straight into value wipes the browser's undo history
- restoring the selection after insertion — otherwise a second button press misses the text
- role="toolbar" on the panel: a set of buttons above the field has to be announced as a group
- the plain textarea instead of contenteditable: it submits with the form and needs no sanitiser
- the component's own light surface — without it the dark text disappears on a dark page
## 6. You may change
- the caption through label and the placeholder text through placeholder
- the hint under the field through hint
- the set of buttons in the TOOLS constant
- the accent colour through accent
## 7. Rules
- The component renders no preview: it edits the source, and whoever displays it parses the markup.
- Pressing again does not remove formatting — the wrapper is only added.
- The list button prefixes the current line, not every selected one: multi-line support needs extending the logic.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/textarea-004.jsonhttps://vibeui.ru/r/textarea-004.jsonКлиентский компонент: useRef на textarea, useState на текст. Обёртка выделения сделана setRangeText, а не сборкой новой строки: только так браузер сохраняет собственную историю отмены и Ctrl+Z продолжает работать; после вставки выделение возвращается на место. Кнопка списка ставит префикс в начало текущей строки, найденной по последнему переводу строки. Панель объявлена role="toolbar". Палитра в --vibeui-textarea-004-*.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useId, useRef, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Textarea004Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
label?: string
placeholder?: string
hint?: string
accent?: string
}
// Идея компонента: панель форматирования над обычным textarea. Богатый
// редактор здесь не нужен — люди пишут в markdown, а кнопки просто
// оборачивают выделение символами. Обёртка сделана через setRangeText:
// он сохраняет историю отмены браузера, чего не делает прямая запись
// в value, и возвращает выделение на место, чтобы можно было жать дальше.
const STYLES = `
:where([data-vibeui-block="textarea-004"]){
--vibeui-textarea-004-bg:oklch(1 0 0);
--vibeui-textarea-004-fg:oklch(0.22 0.014 265);
--vibeui-textarea-004-muted:oklch(0.55 0.014 265);
--vibeui-textarea-004-border:oklch(0.9 0.006 265);
--vibeui-textarea-004-field:oklch(0.985 0.002 265);
--vibeui-textarea-004-bar:oklch(0.97 0.003 265);
--vibeui-textarea-004-accent:oklch(0.55 0.19 262);
--vibeui-textarea-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-textarea-004-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
[data-vibeui-block="textarea-004"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:23rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-textarea-004-bg);
border:1px solid var(--vibeui-textarea-004-border);border-radius:0.875rem;
font-family:var(--vibeui-textarea-004-font);color:var(--vibeui-textarea-004-fg);
}
[data-vibeui-block="textarea-004"] [data-part="label"]{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="textarea-004"] [data-part="shell"]{
display:flex;flex-direction:column;
border:1px solid var(--vibeui-textarea-004-border);border-radius:0.625rem;overflow:hidden;
transition:border-color .16s ease,box-shadow .16s ease;
}
[data-vibeui-block="textarea-004"] [data-part="shell"]:focus-within{
border-color:var(--vibeui-textarea-004-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-textarea-004-accent) 18%,transparent);
}
/* Панель — настоящая toolbar с ролью: кнопки объявляются группой, а не
набором случайных кнопок над полем. */
[data-vibeui-block="textarea-004"] [data-part="toolbar"]{
display:flex;align-items:center;gap:0.125rem;
padding:0.25rem;background:var(--vibeui-textarea-004-bar);
border-bottom:1px solid var(--vibeui-textarea-004-border);
}
[data-vibeui-block="textarea-004"] button{
appearance:none;cursor:pointer;flex:none;
min-width:1.75rem;height:1.75rem;padding:0 0.375rem;
border:0;border-radius:0.375rem;background:transparent;color:inherit;
font:inherit;font-size:0.8125rem;line-height:1;
transition:background-color .16s ease;
}
[data-vibeui-block="textarea-004"] button:hover{background:color-mix(in oklab,var(--vibeui-textarea-004-accent) 12%,transparent)}
[data-vibeui-block="textarea-004"] button:focus-visible{outline:2px solid var(--vibeui-textarea-004-accent);outline-offset:-2px}
[data-vibeui-block="textarea-004"] [data-part="bold"]{font-weight:800}
[data-vibeui-block="textarea-004"] [data-part="italic"]{font-style:italic;font-family:Georgia,"Times New Roman",serif}
[data-vibeui-block="textarea-004"] [data-part="code"]{font-family:var(--vibeui-textarea-004-mono);font-size:0.75rem}
[data-vibeui-block="textarea-004"] [data-part="sep"]{
width:1px;height:1rem;margin:0 0.25rem;flex:none;
background:var(--vibeui-textarea-004-border);
}
[data-vibeui-block="textarea-004"] textarea{
box-sizing:border-box;width:100%;min-height:6rem;resize:vertical;
margin:0;padding:0.625rem 0.75rem;border:0;
background:var(--vibeui-textarea-004-field);color:inherit;
font:inherit;font-size:0.875rem;line-height:1.55;
}
[data-vibeui-block="textarea-004"] textarea:focus{outline:none}
[data-vibeui-block="textarea-004"] [data-part="hint"]{
margin:0;font-size:0.75rem;color:var(--vibeui-textarea-004-muted);
}
[data-vibeui-block="textarea-004"] code{
font-family:var(--vibeui-textarea-004-mono);font-size:0.6875rem;
padding:0.0625rem 0.25rem;border-radius:0.25rem;
background:var(--vibeui-textarea-004-bar);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="textarea-004"] *{animation:none!important;transition:none!important}}
`
const TOOLS = [
{ part: "bold", wrap: "**", caption: "B", title: "Полужирный" },
{ part: "italic", wrap: "_", caption: "I", title: "Курсив" },
{ part: "code", wrap: "`", caption: "</>", title: "Код" },
]
const START =
"Компонент ставится **одной командой** и не тянет зависимости.\nВнутри — обычный `textarea`."
/**
* Поле с панелью форматирования: кнопки оборачивают выделение через setRangeText.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Textarea004({
label = "Описание релиза",
placeholder = "Что изменилось в этой версии",
hint = "Поддерживается разметка markdown",
accent,
className,
style,
...props
}: Textarea004Props) {
const id = useId()
const field = useRef<HTMLTextAreaElement>(null)
const [value, setValue] = useState(START)
const wrap = (marks: string) => {
const element = field.current
if (!element) {
return
}
const { selectionStart, selectionEnd } = element
// setRangeText, а не сборка новой строки: так браузер сохраняет
// собственную историю отмены и Ctrl+Z продолжает работать.
element.setRangeText(marks, selectionEnd, selectionEnd, "end")
element.setRangeText(marks, selectionStart, selectionStart, "start")
element.setSelectionRange(
selectionStart + marks.length,
selectionEnd + marks.length,
)
element.focus()
setValue(element.value)
}
const prefixLines = (marks: string) => {
const element = field.current
if (!element) {
return
}
const start =
element.value.lastIndexOf("\n", element.selectionStart - 1) + 1
element.setRangeText(marks, start, start, "end")
element.focus()
setValue(element.value)
}
const palette = {
...(accent ? { "--vibeui-textarea-004-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-textarea-004" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="textarea-004"
className={className}
style={palette}
>
<label data-part="label" htmlFor={id}>
{label}
</label>
<div data-part="shell">
<div data-part="toolbar" role="toolbar" aria-label="Форматирование">
{TOOLS.map((tool) => (
<button
key={tool.part}
type="button"
data-part={tool.part}
title={tool.title}
aria-label={tool.title}
onClick={() => wrap(tool.wrap)}
>
{tool.caption}
</button>
))}
<span data-part="sep" aria-hidden="true" />
<button
type="button"
data-part="list"
title="Маркированный список"
aria-label="Маркированный список"
onClick={() => prefixLines("- ")}
>
•—
</button>
</div>
<textarea
id={id}
ref={field}
value={value}
placeholder={placeholder}
onChange={(event) => setValue(event.target.value)}
/>
</div>
<p data-part="hint">
{hint}: <code>**жирный**</code>, <code>_курсив_</code>
</p>
</div>
</>
)
}