Skip to content

Code Block

Get Ritla UI

Code with line numbers, a file name and Copy, and a code chip inside text.

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

PreviewCode
EnglishMirroredArabic
LTR →

Installation

  1. Add the component

    npx ritla add code-block

    Also works with shadcn: npx shadcn@latest add @ritla/code-block

  2. Dependencies it brings

    @phosphor-icons/react

  3. Or copy by hand

    Installing by hand copies the component's source into your project. The source comes with a Ritla UI license, so the CLI is the short way to the same files.

Usage

code-block.tsx
import { CodeBlock } from "@/components/ui/code-block";<CodeBlock code={source} fileName="greeting.tsx" />

API reference

CodeBlock

PropTypeDefaultDescription
codestringNoneThe code, as text.
fileNameReactNodeNoneFigma's File name.
languageSwitchReactNodeNoneFigma's Show language switch: a control the app passes.
showHeader / lineNumbersbooleantrueThe header and line numbers.
highlightLinesnumber[]NoneLines to highlight.

CodeChip

PropTypeDefaultDescription
childrenstringNoneFigma's Code.
copybooleanfalseFigma's Copy.

Accessibility

Keyboard

Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.

KeyAction
TabMoves to the copy button.

ARIA

  • The copy button is named and says Copied afterwards; line numbers are hidden from screen readers.

Arabic and RTL notes

Mirrors

  • Only the header row: Copy and the language switch on the left, the file name on the right.

Does not mirror

  • Code, line numbers and the file name are always left to right.
Numerals
Line numbers are Western.
Arabic typography
code-12 in the mono family.