Skip to content
Brok UI

Loading…

No results

AI Tools

Open source

AI tool surfaces — text writer, image generator, code generator, an assistant chat, a full-height inbox rail, and a model playground, each with live output panels.

Preview

3 of 7

resources/views/blocks/ai-tools-code.blade.php Blade
@props([
    'model' => 'Claude 3.5',
])

<x-ui.section space="xl" {{ $attributes }}>
    <div class="mx-auto max-w-5xl px-4">
        <div
            x-data="{
                prompt: '',
                lang: 'javascript',
                code: '',
                loading: false,
                timer: null,
                snippets: {
                    javascript: (p) => 'async function process(input) {\n  // ' + p + '\n  const result = await fetch(\'/api/process\', {\n    method: \'POST\',\n    headers: { \'Content-Type\': \'application/json\' },\n    body: JSON.stringify({ input }),\n  });\n  return result.json();\n}',
                    python: (p) => 'def process(input_data):\n    # ' + p + '\n    import httpx\n    response = httpx.post(\n        \'/api/process\',\n        json={\'input\': input_data},\n    )\n    return response.json()',
                    php: (p) => 'function process(string $input): array\n{\n    // ' + p + '\n    $response = Http::post(\'/api/process\', [\n        \'input\' => $input,\n    ]);\n    return $response->json();\n}',
                    typescript: (p) => 'async function process(input: string): Promise<unknown> {\n  // ' + p + '\n  const res = await fetch(\'/api/process\', {\n    method: \'POST\',\n    headers: { \'Content-Type\': \'application/json\' },\n    body: JSON.stringify({ input }),\n  });\n  return res.json();\n}',
                },
                generate() {
                    if (!this.prompt || this.loading) return;
                    this.loading = true;
                    const p = this.prompt;
                    const l = this.lang;
                    this.timer = setTimeout(() => {
                        const fn = this.snippets[l];
                        this.code = fn ? fn(p) : '// No snippet for ' + l;
                        this.loading = false;
                    }, 900);
                },
                copy() {
                    if (this.code) navigator.clipboard.writeText(this.code);
                },
                placeholder() {
                    return '// ' + (this.prompt ? this.prompt : 'Your generated code will appear here…');
                },
                destroy() {
                    clearTimeout(this.timer);
                },
            }"
        >
        <x-ui.card>
            <x-ui.card.header class="flex flex-row items-center justify-between gap-4 border-b border-border pb-4">
                <div class="flex items-center gap-2">
                    <svg class="size-5 text-primary" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                        <polyline points="16 18 22 12 16 6" stroke-linecap="round" stroke-linejoin="round"/>
                        <polyline points="8 6 2 12 8 18" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                    <span class="text-base font-semibold text-foreground">{{ __('AI Code Generator') }}</span>
                </div>
                <x-ui.badge variant="secondary">{{ $model }}</x-ui.badge>
            </x-ui.card.header>

            <x-ui.card.content class="pt-6">
                <div class="grid gap-8 lg:grid-cols-[1fr_1.4fr]">

                    {{-- LEFT: controls --}}
                    <div class="flex flex-col gap-6">
                        <div class="flex flex-col gap-2">
                            <label for="cg-prompt" class="text-sm font-medium text-foreground">{{ __('Describe what to build') }}</label>
                            <x-ui.textarea
                                id="cg-prompt"
                                name="prompt"
                                :rows="6"
                                placeholder="{{ __('e.g. fetch data from an API and return JSON…') }}"
                                x-model="prompt"
                                required
                                x-on:keydown.meta.enter="generate()"
                                class="resize-none"
                            />
                        </div>

                        <div class="flex flex-col gap-2">
                            <label for="cg-lang" class="text-sm font-medium text-foreground">{{ __('Language') }}</label>
                            <x-ui.select id="cg-lang" name="lang" x-model="lang">
                                <option value="javascript">JavaScript</option>
                                <option value="typescript">TypeScript</option>
                                <option value="python">Python</option>
                                <option value="php">PHP</option>
                            </x-ui.select>
                        </div>

                        <x-ui.button
                            x-on:click="generate()"
                            x-bind:disabled="!prompt || loading"
                            x-bind:aria-busy="loading"
                            class="w-full gap-2"
                        >
                            <span x-show="loading" aria-hidden="true">
                                <svg class="size-4 animate-spin motion-reduce:animate-none" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                    <path d="M21 12a9 9 0 1 1-6.219-8.56" stroke-linecap="round"/>
                                </svg>
                            </span>
                            <span x-show="loading">{{ __('Generating…') }}</span>
                            <span x-show="!loading">
                                <span class="flex items-center gap-2">
                                    <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                                        <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" stroke-linecap="round" stroke-linejoin="round"/>
                                    </svg>
                                    {{ __('Generate code') }}
                                </span>
                            </span>
                        </x-ui.button>
                    </div>

                    {{-- RIGHT: code panel --}}
                    <div
                        class="flex flex-col overflow-hidden rounded-lg border border-border bg-muted"
                        aria-live="polite"
                        aria-atomic="true"
                        aria-label="{{ __('Generated code output') }}"
                        x-bind:aria-busy="loading"
                    >
                        {{-- Window chrome --}}
                        <div class="flex items-center gap-4 border-b border-border bg-muted px-4 py-4">
                            {{-- Traffic dots --}}
                            <div class="flex items-center gap-2" aria-hidden="true">
                                <span class="size-3 rounded-full bg-muted-foreground/30"></span>
                                <span class="size-3 rounded-full bg-muted-foreground/30"></span>
                                <span class="size-3 rounded-full bg-muted-foreground/30"></span>
                            </div>

                            {{-- Language badge --}}
                            <x-ui.badge variant="outline" class="ms-2 font-mono text-xs capitalize" x-text="lang"></x-ui.badge>

                            {{-- Actions pushed to the end --}}
                            <div class="ms-auto flex items-center gap-2">
                                <button
                                    type="button"
                                    x-on:click="copy()"
                                    x-bind:disabled="!code"
                                    class="flex items-center gap-2 rounded-md px-2 py-2 text-xs text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40"
                                    aria-label="{{ __('Copy code') }}"
                                >
                                    <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                                        <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
                                        <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke-linecap="round" stroke-linejoin="round"/>
                                    </svg>
                                    {{ __('Copy') }}
                                </button>
                                <button
                                    type="button"
                                    x-bind:disabled="!code"
                                    class="flex items-center gap-2 rounded-md px-2 py-2 text-xs text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40"
                                    aria-label="{{ __('Run code') }}"
                                >
                                    <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                                        <polygon points="5 3 19 12 5 21 5 3" stroke-linecap="round" stroke-linejoin="round"/>
                                    </svg>
                                    {{ __('Run') }}
                                </button>
                            </div>
                        </div>

                        {{-- Shimmer while loading --}}
                        <div x-show="loading" class="flex flex-col gap-4 p-6" aria-hidden="true">
                            <x-ui.skeleton class="h-3 w-2/3" />
                            <x-ui.skeleton class="h-3 w-full" />
                            <x-ui.skeleton class="h-3 w-4/5" />
                            <x-ui.skeleton class="h-3 w-3/5" />
                            <x-ui.skeleton class="h-3 w-full" />
                            <x-ui.skeleton class="h-3 w-2/4" />
                        </div>

                        {{-- Code output --}}
                        <pre x-show="!loading" class="overflow-x-auto p-6 text-sm"><code class="font-mono text-foreground" x-text="code || placeholder()"></code></pre>
                    </div>

                </div>
            </x-ui.card.content>
        </x-ui.card>
        </div>
    </div>
</x-ui.section>

Installation

terminal
php artisan ui:add blocks/ai-tools-code

Registry contract

Install confidence

php artisan ui:add blocks/ai-tools-code writes only the generated targets below. The CLI validates each file hash before writing and prompts before replacing local changes unless --force is used.

Version
1.1.6
License
open
Stability
stable
Contract
v1
Foundation
≥ 1.0.0
Type Generated target
blade resources/views/blocks/ai-tools-code.blade.php

Registry dependencies

badge button card section select textarea skeleton

Package dependencies

composer: jml/brok:^0.2

Use with AI

A brief for your coding agent: what the block is, the install command, how to render it, its props and the rules. Copy it, or open a prompt about this block in an assistant.

ai-tools-code.md
# Brok UI block: Code Generator (`ai-tools-code`)

Interactive AI code tool with language selector, a window-chrome code panel, and inline copy/run actions.

Brok UI is a Laravel Blade registry. `ui:add` copies this block into the app as plain Blade the app owns; it composes installed `<brok:*>` primitives and semantic design tokens.

## Install

```bash
php artisan ui:add blocks/ai-tools-code
```

## Render it

```blade
<x-blocks.ai-tools-code />
```

## Props

- `model` (string, default `Claude 3.5`)

## Use when

- Demoing an AI code tool where a visitor types a prompt, picks a language, and reads a generated snippet in a window-chrome code panel.
- Showing an inline copy action on the generated code alongside a language selector.

## Avoid when

- Use ai-tools-text for a text-generation demo or ai-tools-image for an image-generation demo; ai-tools-code is code-only.

## Rules

- Render the installed block with `<x-blocks.ai-tools-code />` and pass data through its props; edit the copied file only for structural changes.
- Keep the semantic design tokens (`bg-background`, `text-muted-foreground`); never swap in raw colour utilities.
- Keep the `data-slot` attributes and the logical (start/end) spacing so the markup still mirrors under `dir="rtl"`.

## Links

- Docs: https://brokui.dev/blocks/ai-tools-code
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/ai-tools-code.json

Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.

Guidance

Use when

  • Demoing an AI code tool where a visitor types a prompt, picks a language, and reads a generated snippet in a window-chrome code panel.
  • Showing an inline copy action on the generated code alongside a language selector.

Avoid when

  • Use ai-tools-text for a text-generation demo or ai-tools-image for an image-generation demo; ai-tools-code is code-only.

Anti-patterns

  • Do not replace semantic props with conflicting utility classes.
  • Do not remove labels, focus styles, or state attributes.

Usage

Render the block as a component, passing data where useful:

resources/views/welcome.blade.php Blade
<x-blocks.ai-tools-code />

Built from primitives

Composes <brok:*> Semantic tokens Re-themeable RTL-ready

This block composes installed <brok:*> primitives and semantic design tokens only — it does not reimplement any primitive. Re-theme it (light, dark, admin, customer) by editing CSS variables; flip the preview to RTL to confirm it mirrors.

Source

The exact, editable file ui:add writes into your app. The preview above renders this same source — there are no preview-only blocks.

resources/views/blocks/ai-tools-code.blade.php Blade
@props([
    'model' => 'Claude 3.5',
])

<x-ui.section space="xl" {{ $attributes }}>
    <div class="mx-auto max-w-5xl px-4">
        <div
            x-data="{
                prompt: '',
                lang: 'javascript',
                code: '',
                loading: false,
                timer: null,
                snippets: {
                    javascript: (p) => 'async function process(input) {\n  // ' + p + '\n  const result = await fetch(\'/api/process\', {\n    method: \'POST\',\n    headers: { \'Content-Type\': \'application/json\' },\n    body: JSON.stringify({ input }),\n  });\n  return result.json();\n}',
                    python: (p) => 'def process(input_data):\n    # ' + p + '\n    import httpx\n    response = httpx.post(\n        \'/api/process\',\n        json={\'input\': input_data},\n    )\n    return response.json()',
                    php: (p) => 'function process(string $input): array\n{\n    // ' + p + '\n    $response = Http::post(\'/api/process\', [\n        \'input\' => $input,\n    ]);\n    return $response->json();\n}',
                    typescript: (p) => 'async function process(input: string): Promise<unknown> {\n  // ' + p + '\n  const res = await fetch(\'/api/process\', {\n    method: \'POST\',\n    headers: { \'Content-Type\': \'application/json\' },\n    body: JSON.stringify({ input }),\n  });\n  return res.json();\n}',
                },
                generate() {
                    if (!this.prompt || this.loading) return;
                    this.loading = true;
                    const p = this.prompt;
                    const l = this.lang;
                    this.timer = setTimeout(() => {
                        const fn = this.snippets[l];
                        this.code = fn ? fn(p) : '// No snippet for ' + l;
                        this.loading = false;
                    }, 900);
                },
                copy() {
                    if (this.code) navigator.clipboard.writeText(this.code);
                },
                placeholder() {
                    return '// ' + (this.prompt ? this.prompt : 'Your generated code will appear here…');
                },
                destroy() {
                    clearTimeout(this.timer);
                },
            }"
        >
        <x-ui.card>
            <x-ui.card.header class="flex flex-row items-center justify-between gap-4 border-b border-border pb-4">
                <div class="flex items-center gap-2">
                    <svg class="size-5 text-primary" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                        <polyline points="16 18 22 12 16 6" stroke-linecap="round" stroke-linejoin="round"/>
                        <polyline points="8 6 2 12 8 18" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                    <span class="text-base font-semibold text-foreground">{{ __('AI Code Generator') }}</span>
                </div>
                <x-ui.badge variant="secondary">{{ $model }}</x-ui.badge>
            </x-ui.card.header>

            <x-ui.card.content class="pt-6">
                <div class="grid gap-8 lg:grid-cols-[1fr_1.4fr]">

                    {{-- LEFT: controls --}}
                    <div class="flex flex-col gap-6">
                        <div class="flex flex-col gap-2">
                            <label for="cg-prompt" class="text-sm font-medium text-foreground">{{ __('Describe what to build') }}</label>
                            <x-ui.textarea
                                id="cg-prompt"
                                name="prompt"
                                :rows="6"
                                placeholder="{{ __('e.g. fetch data from an API and return JSON…') }}"
                                x-model="prompt"
                                required
                                x-on:keydown.meta.enter="generate()"
                                class="resize-none"
                            />
                        </div>

                        <div class="flex flex-col gap-2">
                            <label for="cg-lang" class="text-sm font-medium text-foreground">{{ __('Language') }}</label>
                            <x-ui.select id="cg-lang" name="lang" x-model="lang">
                                <option value="javascript">JavaScript</option>
                                <option value="typescript">TypeScript</option>
                                <option value="python">Python</option>
                                <option value="php">PHP</option>
                            </x-ui.select>
                        </div>

                        <x-ui.button
                            x-on:click="generate()"
                            x-bind:disabled="!prompt || loading"
                            x-bind:aria-busy="loading"
                            class="w-full gap-2"
                        >
                            <span x-show="loading" aria-hidden="true">
                                <svg class="size-4 animate-spin motion-reduce:animate-none" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                    <path d="M21 12a9 9 0 1 1-6.219-8.56" stroke-linecap="round"/>
                                </svg>
                            </span>
                            <span x-show="loading">{{ __('Generating…') }}</span>
                            <span x-show="!loading">
                                <span class="flex items-center gap-2">
                                    <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                                        <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" stroke-linecap="round" stroke-linejoin="round"/>
                                    </svg>
                                    {{ __('Generate code') }}
                                </span>
                            </span>
                        </x-ui.button>
                    </div>

                    {{-- RIGHT: code panel --}}
                    <div
                        class="flex flex-col overflow-hidden rounded-lg border border-border bg-muted"
                        aria-live="polite"
                        aria-atomic="true"
                        aria-label="{{ __('Generated code output') }}"
                        x-bind:aria-busy="loading"
                    >
                        {{-- Window chrome --}}
                        <div class="flex items-center gap-4 border-b border-border bg-muted px-4 py-4">
                            {{-- Traffic dots --}}
                            <div class="flex items-center gap-2" aria-hidden="true">
                                <span class="size-3 rounded-full bg-muted-foreground/30"></span>
                                <span class="size-3 rounded-full bg-muted-foreground/30"></span>
                                <span class="size-3 rounded-full bg-muted-foreground/30"></span>
                            </div>

                            {{-- Language badge --}}
                            <x-ui.badge variant="outline" class="ms-2 font-mono text-xs capitalize" x-text="lang"></x-ui.badge>

                            {{-- Actions pushed to the end --}}
                            <div class="ms-auto flex items-center gap-2">
                                <button
                                    type="button"
                                    x-on:click="copy()"
                                    x-bind:disabled="!code"
                                    class="flex items-center gap-2 rounded-md px-2 py-2 text-xs text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40"
                                    aria-label="{{ __('Copy code') }}"
                                >
                                    <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                                        <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
                                        <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke-linecap="round" stroke-linejoin="round"/>
                                    </svg>
                                    {{ __('Copy') }}
                                </button>
                                <button
                                    type="button"
                                    x-bind:disabled="!code"
                                    class="flex items-center gap-2 rounded-md px-2 py-2 text-xs text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40"
                                    aria-label="{{ __('Run code') }}"
                                >
                                    <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                                        <polygon points="5 3 19 12 5 21 5 3" stroke-linecap="round" stroke-linejoin="round"/>
                                    </svg>
                                    {{ __('Run') }}
                                </button>
                            </div>
                        </div>

                        {{-- Shimmer while loading --}}
                        <div x-show="loading" class="flex flex-col gap-4 p-6" aria-hidden="true">
                            <x-ui.skeleton class="h-3 w-2/3" />
                            <x-ui.skeleton class="h-3 w-full" />
                            <x-ui.skeleton class="h-3 w-4/5" />
                            <x-ui.skeleton class="h-3 w-3/5" />
                            <x-ui.skeleton class="h-3 w-full" />
                            <x-ui.skeleton class="h-3 w-2/4" />
                        </div>

                        {{-- Code output --}}
                        <pre x-show="!loading" class="overflow-x-auto p-6 text-sm"><code class="font-mono text-foreground" x-text="code || placeholder()"></code></pre>
                    </div>

                </div>
            </x-ui.card.content>
        </x-ui.card>
        </div>
    </div>
</x-ui.section>

Ownership & lifecycle

Owner, release state, review evidence and adoption for this item.
Owner
Platform UI (@JoshJML)
Current version
1.1.6
Status
Stable
License
open
Deprecation
Not deprecated
Contract
v1
Foundation
≥ 1.0.0