Magoo Component UI logo Magoo Component UI
← Catalog

AI Code Block

code-block-ai molecule experimental

A code block with a language header, one-click copy, and an optional Run button for AI-generated snippets.

The width preview needs a screen wider than the chosen width — use a larger device (or a desktop browser) to see the desktop and tablet layouts.

Default
javascript
function debounce(fn, wait) {
  let t;
  return (...args) => {
    clearTimeout(t);
    t = setTimeout(() => fn(...args), wait);
  };
}
RunnablePython
python
def fib(n):
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a

print([fib(i) for i in range(10)])

Props

NameTypeReq
language string
code string ✓
runnable boolean

Related components

How to use

behavior.js reads the rendered text from the code element, so no configuration is needed. Copy writes the code to the clipboard and swaps the button label to "Copied!" for a moment before restoring it. When runnable is on, the Run button dispatches a bubbling "code:run" CustomEvent with { code } for a parent to execute. The code is rendered verbatim and escaped.

Use cases

highlight WCAG AA SEO 25 dir: ltr ai-generated