Yugen UI

CodeBlock

CodeBlock shows code with lightweight built-in syntax highlighting (no Prism / Shiki), line numbers, highlighted lines, diffs, wrapping and a copy button.

Supports tsx, ts, jsx, js, css, html, bash, json and md. The header shows the file name and a language label. maxHeight collapses long blocks behind a Show more / Show less button. appearance is auto (follows the theme) or dark. Always dir="ltr". Comes with CodeTabs (several files) and PackageManagerTabs (npm / pnpm / yarn / bun; remembers the choice and keeps every block in sync).
SaveBar.tsxTSX
import { Button } from "@/components/ui";export function SaveBar({ onSave }: { onSave: () => void }) {  // The main action uses the primary appearance  return (    <Button appearance="primary" onClick={onSave}>      Save changes    </Button>  );}

Import

Install from npm, copy the source into your project with @yugen-ui/cli or the shadcn CLI, or import directly when working in this repo.

TSX
// npm install yugen-uiimport { CodeBlock, CodeTabs, PackageManagerTabs } from "yugen-ui";

Variants

Each tile is a standalone example: hover to copy, or press Code to see the source.

Switch to a primary buttonTSX
<ButtonRemoved:   appearance="outline"Added:   appearance="primary"Added:   icon={<Save20Regular />}>  Save</Button>

Diff

+ / - lines are colored green / red and keep their sign; Copy takes the version after the change.

tokens.cssCSS
[data-brand="sakura"] {  --brand-10: #240c16;  --brand-20: #391324;  --brand-30: #4c1930;  --brand-40: #61213f;  --brand-50: #79274d;  --brand-60: #912d5c;  --brand-70: #a72f69;  --brand-80: #c2347a;  --brand-90: #e24a92;  --brand-100: #fa65a8;  --brand-110: #fb7cb2;  --brand-120: #fd8ebc;}

Collapsing long blocks

maxHeight cuts the block off and adds a Show more / Show less button (aria-expanded).

TSX
import { YugenProvider, Button } from "@/components/ui";export default function App() {  return (    <YugenProvider applyToDocument theme="dark">      <Button appearance="primary">Hello</Button>    </YugenProvider>  );}

CodeTabs

Several files in one block; the language is guessed from the file extension. appearance="dark" always has a dark background.

npm install @fluentui/react-icons class-variance-authority
npm install -D tailwindcss @tailwindcss/vite

PackageManagerTabs

Pick a package manager in one block: every other block on the page follows, and the choice is remembered for next time.

Usage

Do
  • Set filename when the code belongs to a specific file, so readers know where to paste it.
  • Use highlightLines to point at the exact lines being explained.
  • Use diff when explaining a change to existing code instead of printing the whole file again.
Don't
  • Don't use CodeBlock for short code inside a sentence. Use inline <code>.
  • Don't set maxHeight so low that readers have to expand every block.
  • Don't expect IDE-level highlighting. The tokenizer is deliberately small.

Props

Prop · TypeDefaultDescription
codestringDefault: —Code content.
language"tsx" | "ts" | "jsx" | "js" | "css" | "html" | "bash" | "json" | "md" | "text"Default: "tsx"Syntax highlighter.
title / filenameReactNode / stringDefault: —Shows the header with the language label, a wrap button and a copy button.
showLineNumbersbooleanDefault: falseLine number column.
highlightLinesstring | number[]Default: —Highlighted lines: "2,4-6".
diffbooleanDefault: falseLines starting with + / - are colored.
wrap / defaultWrap / onWrapChangebooleanDefault: falseWraps lines instead of scrolling horizontally.
maxHeightnumber | stringDefault: —Collapses when taller; Show more / Show less button.
appearance"auto" | "dark"Default: "auto"Follows the theme, or always dark (left unchanged in high contrast).
size / copyable / bare"small" | "medium" / boolean / booleanDefault: "medium" / true / falseText size; copy button; no frame, for nesting in another surface.
CodeTabs.files{ name, code, language?, highlightLines? }[]Default: —List of files; value / defaultValue / onValueChange select a file.
PackageManagerTabs.packagesstring | string[]Default: —Packages to install, or the command when command="dlx".
PackageManagerTabs.dev / command / managersboolean / "install" | "dlx" / PackageManager[]Default: —devDependency; npx / pnpm dlx / yarn dlx / bunx; limits the list.

Messages

Text built into the component: labels, aria-labels, screen reader announcements.

English by default. Change it with the messages prop of YugenProvider, by the namespace below; messagesVi has the Vietnamese set. See Interface language.

messages.copyCodeButton

Key · TypeDefault (English)messagesVi
copystring

Chữ trên nút (showLabel).

Default (English)"Copy"messagesVi"Sao chép"
copiedstringDefault (English)"Copied"messagesVi"Đã chép"
copyLabelstring

Tên nút chỉ có icon.

Default (English)"Copy code"messagesVi"Sao chép code"
copiedLabelstringDefault (English)"Copied"messagesVi"Đã sao chép"
copiedStatusstring

Đọc qua vùng status sau khi sao chép.

Default (English)"Copied to clipboard"messagesVi"Đã sao chép vào bộ nhớ tạm"

messages.codeBlock

Key · TypeDefault (English)messagesVi
wrapstring

Tên nút bật / tắt xuống dòng.

Default (English)"Word wrap"messagesVi"Xuống dòng"
wrapOnstring

Tooltip của nút khi đang tắt / đang bật xuống dòng.

Default (English)"Turn on word wrap"messagesVi"Bật xuống dòng"
wrapOffstringDefault (English)"Turn off word wrap"messagesVi"Tắt xuống dòng"
addedstring

Chữ ẩn trước dòng thêm / xoá trong diff.

Default (English)"Added:"messagesVi"Thêm:"
removedstringDefault (English)"Removed:"messagesVi"Xoá:"
collapsestringDefault (English)"Show less"messagesVi"Thu gọn"
expand(lines: number) => string

Nút mở rộng khối code bị thu gọn.

Default (English)(lines) => `Show more (${lines} ${lines === 1 ? "line" : "lines"})`messagesVi(lines) => `Xem thêm (${lines} dòng)`

messages.codeTabs

Key · TypeDefault (English)messagesVi
filesstring

Tên danh sách tab tệp.

Default (English)"Files"messagesVi"Tệp"

messages.packageManagerTabs

Key · TypeDefault (English)messagesVi
labelstring

Tên danh sách tab trình quản lý gói.

Default (English)"Package manager"messagesVi"Trình quản lý gói"