Code
Inline or block code formatting for identifiers, expressions, and short snippets — semantic <code> with <pre> wrapping when needed.
Renders a native <code> (inline) or <pre><code> (block); assistive tech announces the content as code without extra ARIA wiring.
Preview
tsx
import { Code } from '@arshad-shah/cynosure-react';
export default function Example() {
return <Code>const x = 1</Code>;
}
Variants
Section titled “Variants”Two variants: inline (default) renders a bare <code> and slots into prose; block wraps <code> inside <pre> so multi-line snippets retain whitespace.
Preview
tsx
import { Code } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
<Code variant="inline">npm install @arshad-shah/cynosure-react</Code>
<Code variant="block">{`function greet(name) {
return \`Hello, \${name}!\`;
}`}</Code>
</div>
);
}
Pick sm for dense inline usage or md (default) for body-aligned snippets.
Preview
tsx
import { Code } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.75rem', alignItems: 'center' }}>
<Code size="sm">size="sm"</Code>
<Code size="md">size="md"</Code>
</div>
);
}
Color schemes
Section titled “Color schemes”colorScheme tints the surface and border — neutral (default), accent, success, and danger cover the common roles (e.g. red for deprecated identifiers, green for new APIs).
Preview
tsx
import { Code } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.5rem', alignItems: 'center' }}>
<Code colorScheme="neutral">neutral</Code>
<Code colorScheme="accent">accent</Code>
<Code colorScheme="success">success</Code>
<Code colorScheme="danger">danger</Code>
</div>
);
}
Inline in prose
Section titled “Inline in prose”Code slots cleanly inside a Text paragraph for identifiers and short expressions.
Preview
tsx
import { Code, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Text>
Install the package with <Code>npm install @arshad-shah/cynosure-react</Code> and import
components from <Code>@arshad-shah/cynosure-react</Code>.
</Text>
);
}
PropTypeDefaultDescription
size
"sm"|"md"
"md"
Font-size step for the monospace glyphs.
variant
"inline"|"block"
"inline"
`"inline"` renders a bare `<code>`; `"block"` wraps in `<pre><code>` so
multi-line snippets preserve whitespace and line breaks.
colorScheme
"neutral"|"accent"|"success"|"danger"
"neutral"
Background / foreground palette token for the chip.
className
string
—
Additional class names appended after Cynosure's base classes.
style
CSSProperties
—
Inline style overrides merged last.
children
ReactNode
—
Code text content.
paddingX
—
Horizontal padding (left + right). Overrides `padding` on the X axis.
paddingY
—
Vertical padding (top + bottom). Overrides `padding` on the Y axis.
height
—
Element height. Accepts a `SpaceToken`, `LengthValue`, or named alias.
minWidth
—
Minimum width — useful for preventing flex children from collapsing.
background
—
Background colour. Use a `ColorToken` like `"bg.surface"` for theme awareness.
borderColor
—
Border colour. Pair with `borderWidth` to make the border visible.
opacity
Responsive<number | `${number}`>
—
Opacity 0–1. Use sparingly — prefer surface tokens over translucency.
overflowX
—
Horizontal-axis overflow control. Overrides `overflow` for the X axis.
display
—
CSS `display` value. `"contents"` removes the element's box from layout.
position
—
CSS `position`. Pair with `top`/`right`/`bottom`/`left` for placement.
top
—
Top inset (when positioned). Accepts a `SpaceToken`, `"auto"`, `"0"`, or `LengthValue`.
flex
Responsive<"1" | "none" | "auto" | "initial" | (string & {})>
—
Shorthand: `1 | auto | none | initial | <css>`. Resolves to `flex` on the child.
asChild
boolean
—
When `true`, renders the primitive's single React child via `Slot`,
forwarding className/style/ref/event handlers onto it.
Accessibility
Section titled “Accessibility”- Renders the native
<code>element so screen readers identify the content as code. variant="block"wraps<code>in<pre>so newlines and indentation are preserved for both visual and assistive consumers.- Avoid color-only signals — pair
colorScheme="danger"with descriptive surrounding copy. - For multi-line code with syntax highlighting reach for the dedicated
CodeBlockcomponent once available;Code variant="block"is intentionally style-only.
Recipes
Section titled “Recipes”- Inline
Codereads best wrapped inside aTextor paragraph element. - Keep inline snippets short — break longer code into a
variant="block"snippet or a full code block. - Combine with
Kbdto differentiate keyboard input from code output in tutorials. - Use
colorScheme="success"or"danger"sparingly to flag newly added or deprecated APIs in changelogs.