Code Display
Read-only code surfaces — a highlighted code block, a single-line snippet, a tabbed CLI command block and a unified/split diff.
Preview
npx shadcn@latest add button
const schema = z.object({ email: z.string().email() })
git remote add origin [email protected]:acme/app.git
<div class="flex w-full flex-col items-start gap-3">
<x-ui.code-line code="npx shadcn@latest add button" />
<x-ui.code-line label="TS" code="const schema = z.object({ email: z.string().email() })" />
<x-ui.code-line code="git remote add origin git@github.com:acme/app.git" :hide-copy="true" />
</div>
Installation
php artisan ui:add code-line
Use with AI
A brief for your coding agent: install command, usage, props, guidance and the rules. Copy it, or open a prompt about this component in an assistant.
# Brok UI: Code Line (`code-line`)
A compact single-line code snippet with an optional label and an inline copy-to-clipboard button.
Brok UI is a Laravel Blade component registry. Installed components are plain Blade files the app owns.
## Install
```bash
php artisan ui:add code-line
```
## Usage
```blade
<div class="flex w-full flex-col items-start gap-3">
<x-ui.code-line code="npx shadcn@latest add button" />
<x-ui.code-line label="TS" code="const schema = z.object({ email: z.string().email() })" />
<x-ui.code-line code="git remote add origin [email protected]:acme/app.git" :hide-copy="true" />
</div>
```
## Props
- `code` (string, default ``)
- `label` (mixed|null, default `null`)
- `hideCopy` (bool, default `false`)
## Use when
- Use for exact technical detail, code readability, diagnostics, and copyable reference material.
- Presenting a single command or value a reader is meant to copy, inline in prose.
- Labelling that one line, for example an API key name or an install command.
## Avoid when
- Do not surface developer-specific patterns in end-user flows unless the task genuinely requires them.
- Showing more than one line; code-block carries the language tag, line numbers and scrolling.
- Rendering an editable field; this is a read-only value.
## Anti-patterns
- Exposing developer tooling in end-user flows without a task need
## Rules
- Use the `<brok:code-line>` tag (or `<x-ui.code-line>`) in Blade; do not rewrite the component.
- Prefer the documented props and variants over utility-class overrides; when a utility must win, use the `!` important modifier.
- Use semantic design tokens (`bg-primary`, `text-muted-foreground`), never raw colour utilities.
- Keep the `data-slot` attributes; they are the styling and test hooks.
## Links
- Docs: https://brokui.dev/docs/components/code-line
- Registry JSON (files, props, contract): https://brokui.dev/r/open/code-line.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| code | string | ||
| label | mixed | null | null | |
| hideCopy | bool | false |
Slots
default—
Data slots
Stable hooks for CSS overrides and browser tests.
Behavior
- The line does not wrap: a long value scrolls horizontally rather than reflowing the surrounding text.
- The copy button is present unless hideCopy is set.
- Declares registry capability flags: a11y, responsive, rtl, darkMode, localized.
Guidance
Expose exact technical or diagnostic information.
Use when
- Use for exact technical detail, code readability, diagnostics, and copyable reference material.
- Presenting a single command or value a reader is meant to copy, inline in prose.
- Labelling that one line, for example an API key name or an install command.
Avoid when
- Do not surface developer-specific patterns in end-user flows unless the task genuinely requires them.
- Showing more than one line; code-block carries the language tag, line numbers and scrolling.
- Rendering an editable field; this is a read-only value.
Use instead
- Plain-language product UI for nontechnical users
Anti-patterns
- Exposing developer tooling in end-user flows without a task need
- Anatomy
- Theming hooks
Accessibility
- Keyboard
- No component-owned keyboard interaction; native element behavior applies.
- Focus
none
- The copy control is a real button with an accessible name from copy-button.
- The label is associated text, not a placeholder, so it survives zoom and reflow.
- Semantic HTML and a stable
data-slotattribute for styling and scripting hooks. - Focus-visible rings use the
ringtoken, so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces in the preview.
- Labels go through
__()and layout uses logical properties (ms-*,text-start), so it mirrors underdir="rtl"— flip the preview to RTL to confirm. - Dark mode uses the same semantic tokens under the
darkclass; high contrast follows forced-color system tokens.
Livewire
Livewire can update this component through forwarded wire:* attributes.
Source
The exact, editable file ui:add writes
into your app. Previews render this same code; there are no preview-only components.
@props([
'code' => '',
'label' => null,
'hideCopy' => false,
])
@php
// The snippet is rendered, never evaluated: it lives inside <code> and Blade
// escapes the {{ $code }} body. The copy-button writes the same plain string.
$code = (string) $code;
$hideCopy = filter_var($hideCopy, FILTER_VALIDATE_BOOLEAN);
@endphp
<div
data-slot="code-line"
{{ $attributes->merge(['class' => 'inline-flex max-w-full items-center gap-2 rounded-md border border-border bg-muted/40 py-1 ps-3 '.($hideCopy ? 'pe-3' : 'pe-2').' text-foreground']) }}
>
@if ($label !== null)
<span class="shrink-0 text-xs font-medium text-muted-foreground select-none">{{ $label }}</span>
@endif
<code class="min-w-0 flex-1 overflow-x-auto whitespace-nowrap font-mono text-sm leading-6">{{ $code }}</code>
@unless ($hideCopy)
<x-ui.copy-button
:value="$code"
:label="__('Copy')"
:copied-label="__('Copied')"
class="size-6 h-6 w-6 shrink-0 border-transparent bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground"
/>
@endunless
</div>
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.0.4 - Status
- Stable
- License
-
open - Accessibility reviewed
- No review date recorded
- Last breaking change
- No date recorded
- Deprecation
- Not deprecated
- Contract
-
v6 - Foundation
-
≥ 1.0.0