AI agent JS behaviour

Code block

Syntax-light code: a filename header, language badge, line numbers, highlighted lines, green/red diff lines, a copy button and line wrapping — always left-to-right.

Real scenarios

The component as it is used in a product — not a specimen grid.

app/Livewire/OrderList.php php
<?php

namespace App\Livewire;

use App\Models\Order;
use Livewire\Component;

class OrderList extends Component
{
    public string $status = 'paid';

    // Uses the composite index (status, created_at).
    public function render()
    {
        return view('livewire.order-list', [
            'orders' => Order::where('status', $this->status)->latest()->paginate(20),
        ]);
    }
}
resources/js/cart.ts ts
export function total(items: Item[], coupon?: Coupon) {
  const sum = items.reduce((acc, item) => acc + item.price, 0);
  return sum - coupon.amount;
  const sum = items.reduce((acc, item) => acc + item.price * item.qty, 0);
  // An empty coupon used to arrive as null and crash checkout.
  return Math.max(0, sum - (coupon?.amount ?? 0));
}
bash
docker run --rm -it -v "$PWD":/app -w /app -e APP_ENV=testing -e DB_CONNECTION=sqlite php:8.4-cli vendor/bin/pest --parallel --coverage --min=85 --filter=Checkout

Important props

Important props
Prop Type Default What it does
code / language / filename string — The source, its language (colouring and badge) and the file name.
highlight string|array null Highlighted lines: "4, 9-11" or [4, [9, 11]].
diff bool auto + and − lines coloured; automatic for language="diff".
wrap / line-numbers / max-height bool · bool · string false · true · null Wrap from the start, show line numbers, and the height before it scrolls.

Snippet

<x-nx::code-block filename="app/Models/Order.php" language="php" highlight="4, 9-11" :code="$source" />