Codecomponent
Code({ children, plain, ...props }: CodeProps): ReactElement| Param | Type | |
|---|---|---|
props | CodeProps | Props for Code — colour and typography variants, optional children, plus a plain toggle. required |
.plain | boolean |
| Return | |
|---|---|
ReactElement | Rendered <code> element. |
Inline code span — renders a <code> element.
- Pass
plainto drop the default background and padding.
An inline code span — renders a <code> element with monospace type and a subtle tinted background. Code.tsx exports four siblings that share the same monospace styling but carry different HTML semantics:
| Component | HTML element | Use for |
|---|---|---|
Code | <code> | Inline code fragments |
Keyboard | <kbd> | Keyboard input, e.g. Ctrl+S |
Sample | <samp> | Program output |
Variable | <var> | Variable names in documentation |
Things to know:
- Pick the sibling whose semantics match — they all look the same but mean different things to assistive tech and search.
- Pass
plainto drop the default background and inline padding (useful when the code already sits inside a tinted container). - Painted from the tint ladder: the background is
--tint-90and the text--tint-00, so it re-tints with its surrounding scope. - Inside
<Prose>raw<code>/<kbd>/<samp>/<var>pick up the same styling, and code inside a<pre>drops the inline box automatically.
Usage
Inline code and keyboard input
import { Code, Keyboard, Sample } from "shelving/ui";
<p>Run <Code>npm install</Code>, then press <Keyboard>Enter</Keyboard>.</p>
<p>It prints <Sample>Done.</Sample></p>Plain (no background)
import { Code } from "shelving/ui";
<Code plain>const x = 1;</Code>Styling
Code paints from the tint ladder; the box (background / color) reads ladder steps directly, while type, padding, and radius have per-property hooks.
| Variable | Styles | Default |
|---|---|---|
--code-font | Font family | var(--font-code) |
--code-weight | Font weight | var(--weight-code) |
--code-size | Font size | var(--size-smaller) |
--code-leading | Line height | var(--leading) |
--code-padding | Inline padding (non-plain) | var(--space-xxsmall) |
--code-radius | Corner radius (non-plain) | var(--radius-xxsmall) |
Global tokens it reads: --font-code, --weight-code, --size-smaller, --leading, --space-xxsmall, --radius-xxsmall, and the tint-ladder steps --tint-00 / --tint-90 for the box fill and text.
Examples
<Code>npm install</Code>