Skip to main content
Urbicon UI

CodeExample

Code example card with live preview, syntax highlighting, copy-to-clipboard, and a collapsible code panel.

Playground

Basic Example

Short explanation
<Button>Click</Button>
<CodeExample />

01 Examples

The core props in action

Preview + code

Children render as the live preview; the code prop feeds the highlighted panel.
<CodeExample title="Save action" code={buttonSnippet} language="svelte">
  <Button intent="primary">Save changes</Button>
</CodeExample>

Code-only

preview=false hides the preview stage — for snippets that are not renderable UI.
import { codeExampleVariants } from '@urbicon-ui/docs';

const styles = codeExampleVariants({ size: 'sm' });

Collapsed by default

defaultExpanded=false starts with the code panel folded, overriding the page-wide toggle.
Active
<CodeExample title="Status" defaultExpanded={false} code={badgeSnippet}>
  <Badge intent="success">Active</Badge>
</CodeExample>

02 Usage Notes

Best practices and important considerations

03 Accessibility

Preview and code are one figure, two regions

The preview stage and the code panel are separate regions, each named from the example's title, so a screen-reader user can tell which of the two they have landed in rather than hearing the same name twice.

Nothing is preview-only

Whatever the preview renders is also in the code panel, so a reader who cannot use the visual preview still gets the whole example. This is why isolate exists: it extracts the children as the snippet at build time instead of letting the two drift.

The collapse is a button, not a heading

Expanding the code panel is an ordinary button with aria-expanded, in the tab order, with a visible focus ring. The example title above it stays a heading, so the page outline does not change when a panel is folded.

04 API Reference

Complete list of component properties and their configurations

16 props
Prop
Type
Default
Description

05 Types

Local type definitions used by this component.

6 types
Name
Kind
Category
Used by
Description

06 Installation

Import

import { CodeExample } from '@urbicon-ui/docs';