Skip to content
Brok UI

Loading…

No results

Code Display

Open source

Read-only code surfaces — a highlighted code block, a single-line snippet, a tabbed CLI command block and a unified/split diff.

Version
v1.0.4
Stability
stable
License
MIT
Related
Kbd
Input Copy
JSON Viewer

Code Line — A compact single-line code snippet with an optional label and an inline copy-to-clipboard button.

Preview

npx shadcn@latest add button
TS const schema = z.object({ email: z.string().email() })
git remote add origin [email protected]:acme/app.git
previews.components.code-line.default.blade.php 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 git@github.com:acme/app.git" :hide-copy="true" />
</div>

Installation

terminal
php artisan ui:add code-line

Registry contract

php artisan ui:add code-line writes only the files below. The CLI validates each file hash before writing and asks before it replaces a local change, unless you pass --force.

  • blade resources/views/components/ui/code-line.blade.php
Registry dependencies
copy-button
Packages
composer: jml/brok:^0.2

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.

code-line.md
# 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

manifest knowledge + registry-derived coverage

Props

Props accepted by this component: name, type, default value and description.
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.

code-line

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

Developer and documentation tool

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
root
Theming hooks
code-line

Accessibility

WCAG 2.2 AA Keyboard focus-visible RTL-ready Localized labels Dark mode
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-slot attribute for styling and scripting hooks.
  • Focus-visible rings use the ring token, 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 under dir="rtl" — flip the preview to RTL to confirm.
  • Dark mode uses the same semantic tokens under the dark class; high contrast follows forced-color system tokens.

Livewire

Safe

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.

resources/views/components/ui/code-line.blade.php Blade
@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