Pilipinas Interface

Foundation

  • Overview
  • Get Started
  • Colors
  • Typography
  • Icons
  • Layout & Spacing
  • States & Feedback
  • Motion & Transitions
  • Expressions

Components

  • Overview
  • Accordion
  • Alert
  • Avatar
  • Badge
  • Banner
  • Breadcrumb
  • Button
  • Card
  • Checkbox
  • Code Block
  • Combobox
  • Command Menu
  • Dialog
  • Popover
  • Progress
  • Radio Group
  • Scroll Area
  • Select
  • Skeleton
  • Switch
  • Table
  • Tabs
  • Text Field
  • Tooltip

Resources

  • Registry

Components

Code Block

Code with a copy affordance and an optional header. Used in these docs for install commands and source examples; it is not a syntax highlighter.

Preview
tsx
1import { Button } from "@/components/ui/button";2
3export function Submit() {4  return <Button variant="primary">Submit application</Button>;5}
<CodeBlock
  language="tsx"
  lineNumbers
  code={'<Button variant="primary">Save</Button>'}
/>

Usage

Short source or command snippets where the exact string matters.

Do and don't

  • Do. Set a language label and keep lines short enough to read on a phone.
  • Don't. Use it for prose or paste long transcripts into it.

Composition

CodeBlock takes the plain code string as its source of truth. Pass children only when a highlighter supplies its own markup; the copy button still copies the plain string.

Props

  • code; required plain text, also what the copy button writes.
  • language, title; header label. hideHeader floats the copy button over the block instead.
  • lineNumbers, wrap, maxHeight, size, onCopy.

Behavior and states

The copy button reports success in place, then settles back to its idle label. Long lines scroll sideways unless wrap is set; a maxHeight makes taller blocks scroll inside the body. Line numbers apply to plain code only.

Accessibility

The copy control has an accessible name. Keep the language or file label visible when the code is not self-evident, and do not rely on color alone to show copy success. This component renders preformatted text; it does not announce or describe the code to a screen reader.

Responsive

The block scrolls horizontally on narrow screens. Prefer short lines in examples so a phone does not require sideways scrolling to read the snippet.

Related

Tooltip provides the copy hint in other controls, Scroll Area documents the overflow pattern, and Motion & Transitions covers the short state change.

← PreviousCheckboxNext →Combobox

Install

npx shadcn@latest add @pilipinas/code-block

For your coding agent