Unified UI

Code

Inline code and block code display components with syntax highlighting support, copy button, line numbers, filename label, and a dark variant.

Basic

Two composable code display components: InlineCode for short snippets within prose, and CodeBlock for multi-line code with copy button, line numbers, filename label, and dark/light variants.

Run npm install @work-rjkashyap/unified-ui to get started.

Button.tsxtsx
import { Button } from "@work-rjkashyap/unified-ui";export function App() {return <Button variant="primary">Click me</Button>;}

Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add code
pnpm dlx @work-rjkashyap/unified-ui add code
npx @work-rjkashyap/unified-ui add code
bunx @work-rjkashyap/unified-ui add code

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import {
	InlineCode,
	CodeBlock,
	CopyButton,
	Button,
	Slider,
	Card,
	Badge,
} from "@work-rjkashyap/unified-ui";

InlineCode

InlineCode renders a short code snippet as a styled <code> element — suitable for use within sentences and paragraphs.

Basic Usage

<p>
  Import with <InlineCode>import {"{"} Button {"}"} from "@work-rjkashyap/unified-ui"</InlineCode>.
</p>

<p>
  Set <InlineCode>variant="primary"</InlineCode> for the brand color.
</p>

In Context

Use the cn() utility from @unified-ui/utils/cn to merge Tailwind classes safely.

All components forward refs — access the DOM node via ref on any component.

The variant prop accepts "primary", "secondary", "ghost", or "danger".

InlineCode Props

PropTypeDefaultDescription
classNamestringAdditional CSS classes.
childrenReactNodeThe code content.

All standard <code> HTML attributes are also accepted.


CodeBlock

CodeBlock renders a multi-line code snippet with an optional header bar showing the filename, language badge, and copy button.

Basic Usage

<CodeBlock>
	{`const greeting = "Hello, world!";
console.log(greeting);`}
</CodeBlock>

With Filename and Language

slider.tsxtsx
import { Slider } from "@work-rjkashyap/unified-ui";export function VolumeControl() {const [volume, setVolume] = useState([50]);return (<Slidervalue={volume}onValueChange={setVolume}min={0}max={100}showTooltipformatTooltip={(v) => `${v}%`}/>);}

With Copy Button

Set showCopyButton (default true) to render a copy button in the header bar.

bash
npm install @work-rjkashyap/unified-ui framer-motion

With Line Numbers

Set showLineNumbers to render gutter line numbers on the left side.

theme-provider.tsxtsx
import { DSThemeProvider } from "@work-rjkashyap/unified-ui/theme";import "@work-rjkashyap/unified-ui/styles.css";export default function RootLayout({ children }) {return (  <DSThemeProvider defaultTheme="system">    {children}  </DSThemeProvider>);}

Dark Variant

The dark variant uses a near-black background with light text — ideal for embedding code examples in dark-themed sections or marketing pages.

App.tsxtsx
import { Button, Card, Badge } from "@work-rjkashyap/unified-ui";import "@work-rjkashyap/unified-ui/styles.css";export function App() {return (  <Card>    <Button variant="primary">      Get Started    </Button>    <Badge variant="success">Live</Badge>  </Card>);}

Header Only

Combine filename with no language to show just the filename label without a language badge.

<CodeBlock filename=".env.local">
	{`NEXT_PUBLIC_API_URL=https://api.example.com
DATABASE_URL=postgresql://localhost:5432/mydb
JWT_SECRET=your-secret-key`}
</CodeBlock>

No Header

Omit all header props to render a minimal code block with no header bar.

<CodeBlock showCopyButton={false}>
	{`const x = 42;
const y = x * 2;
console.log(y); // 84`}
</CodeBlock>

CodeBlock Props

PropTypeDefaultDescription
variant"default" | "dark""default"Color scheme — light muted background or near-black dark.
languagestringLanguage label displayed in the header badge (e.g., "tsx", "bash").
filenamestringFilename shown on the left side of the header bar.
showLineNumbersbooleanfalseWhether to render gutter line numbers.
showCopyButtonbooleantrueWhether to show the copy button in the header bar.
classNamestringAdditional CSS classes on the root wrapper element.
childrenReactNodeThe code string to display. Strings enable line numbers and copy.

All standard <pre> HTML attributes are also accepted and forwarded to the inner <pre> element.


Side-by-Side: InlineCode vs CodeBlock

FeatureInlineCodeCodeBlock
Element<code> (inline)<pre><code> (block)
Use caseWithin prose / labelsMulti-line code examples
Copy buttonNoYes (optional)
Line numbersNoYes (optional)
Filename labelNoYes (optional)
Language badgeNoYes (optional)
Dark variantNoYes (variant="dark")

Pairing with CopyButton

For cases where you need a standalone copy button next to an inline code snippet, compose InlineCode with CopyButton.

npm install @work-rjkashyap/unified-ui
sk_live_••••••••4242

Motion

  • Copy feedback — The copy button inside CodeBlock uses AnimatePresence to cross-fade between the copy icon and "Copied!" text via the fadeInFast preset.
  • Animations respect prefers-reduced-motion via useReducedMotion().

Accessibility

  • InlineCode renders as a semantic <code> element — screen readers announce it as code context.
  • CodeBlock renders as <pre> + <code> — the standard HTML pairing for preformatted code.
  • Line numbers are aria-hidden="true" and use select-none so they are not included when copying text.
  • The copy button inside CodeBlock has aria-label that dynamically updates ("Copy code""Copied!").
  • Both components pass data-ds-component attributes for debugging and automated testing.

Design Tokens

TokenUsage
--mutedInlineCode and CodeBlock background
--muted-fgInlineCode text color
--borderInlineCode border and CodeBlock border
--radius-mdInlineCode border radius
--radius-lgCodeBlock border radius
--font-monoMonospaced font for all code elements

On this page