CodeDisplay
Read-only code block with a copy button. Optional title, language caption, lineNumbers, wrap and maxHeight. Code is colored by language (js, jsx, ts, tsx, json, bash, sh, html, xml, svg, css, scss, apache, htaccess, nginx, yaml, yml; other languages stay plain, or pass your own tokenizer as highlighter) with a palette that follows the light / dark theme; turn it off with highlight={false} or override any color with colors.
import { Button } from 'xedonium' export default function App() { return <Button>Bello!</Button>}// Custom paletteconst bananas = 42export const greet = name => `Bello ${name}`Props
CodeDisplay
codestringCode to show.
languagestringCaption shown in the header, and the syntax colors: js, jsx, ts, tsx, json, bash, sh, html, xml, svg, css, scss, apache, htaccess, nginx, yaml, yml (other values stay plain).
titlestringHeader text; overrides
languageas the caption.lineNumbersbooleanDefault:falseShow line numbers.
copyablebooleanDefault:trueShow a copy button.
wrapbooleanDefault:falseWrap long lines instead of scrolling.
maxHeightnumber | stringMaximum height before the block scrolls.
highlightbooleanDefault:trueColor the code by syntax (see
languagefor the supported languages).colorsCodeColorsOverride the theme-aware default colors with any CSS colors; see the CodeDisplayColors table below.
highlighter(code, language) => Segment[][]Your own tokenizer: one array of { kind, text } segments per line (kind is a token kind or null). Used instead of the built-in languages.
classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | – | Code to show. |
language | string | – | Caption shown in the header, and the syntax colors: js, jsx, ts, tsx, json, bash, sh, html, xml, svg, css, scss, apache, htaccess, nginx, yaml, yml (other values stay plain). |
title | string | – | Header text; overrides language as the caption. |
lineNumbers | boolean | false | Show line numbers. |
copyable | boolean | true | Show a copy button. |
wrap | boolean | false | Wrap long lines instead of scrolling. |
maxHeight | number | string | – | Maximum height before the block scrolls. |
highlight | boolean | true | Color the code by syntax (see language for the supported languages). |
colors | CodeColors | – | Override the theme-aware default colors with any CSS colors; see the CodeDisplayColors table below. |
highlighter | (code, language) => Segment[][] | – | Your own tokenizer: one array of { kind, text } segments per line (kind is a token kind or null). Used instead of the built-in languages. |
className | string | '' | Extra classes for the root element. |
CodeDisplayColors
commentstringDefault:--xd-tok-commentComments.
stringstringDefault:--xd-tok-stringQuoted strings and attribute values.
keywordstringDefault:--xd-tok-keywordKeywords, at-rules and directives.
tagstringDefault:--xd-tok-tagTags and CSS selectors.
attrstringDefault:--xd-tok-attrAttribute names, object keys and CSS properties.
numberstringDefault:--xd-tok-numberNumbers, units and hex colors.
fnstringDefault:--xd-tok-fnFunction names and expressions.
textstringColor of everything that is not highlighted. The theme text color by default.
backgroundstringBackground of the code block. The theme card color by default.
| Prop | Type | Default | Description |
|---|---|---|---|
comment | string | --xd-tok-comment | Comments. |
string | string | --xd-tok-string | Quoted strings and attribute values. |
keyword | string | --xd-tok-keyword | Keywords, at-rules and directives. |
tag | string | --xd-tok-tag | Tags and CSS selectors. |
attr | string | --xd-tok-attr | Attribute names, object keys and CSS properties. |
number | string | --xd-tok-number | Numbers, units and hex colors. |
fn | string | --xd-tok-fn | Function names and expressions. |
text | string | – | Color of everything that is not highlighted. The theme text color by default. |
background | string | – | Background of the code block. The theme card color by default. |