Code Block
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
Add the component
npx ritla add code-blockAlso works with shadcn:
npx shadcn@latest add @ritla/code-blockDependencies it brings
@phosphor-icons/reactOr 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
import { CodeBlock } from "@/components/ui/code-block";<CodeBlock code={source} fileName="greeting.tsx" />API reference
CodeBlock
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | None | The code, as text. |
fileName | ReactNode | None | Figma's File name. |
languageSwitch | ReactNode | None | Figma's Show language switch: a control the app passes. |
showHeader / lineNumbers | boolean | true | The header and line numbers. |
highlightLines | number[] | None | Lines to highlight. |
CodeChip
| Prop | Type | Default | Description |
|---|---|---|---|
children | string | None | Figma's Code. |
copy | boolean | false | Figma'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.
| Key | Action |
|---|---|
| Tab | Moves 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-12in the mono family.