CodeBlock

A styled code block with a copy button, and an optional tabbed Preview/Code switcher for live component examples.

Installation

npx dafink-ui add code-block

Also installs: Toggle-group

Demo

import Button from '@/src/components/Button/Button';

export default function Example() {
  return <Button>Click me</Button>;
}

Props

NameTypeDefaultDescription
codestring-Required. The raw source code rendered in the code panel.
variant"code" | "example""code""code" renders the block alone. "example" adds a Preview/Code ToggleGroup above the panel.
childrenReact.ReactNode-Required when variant="example". Rendered in the Preview tab.
labelstring"example"Accessible label for the ToggleGroup tab strip (example variant only).
minHeightstring"200px"CSS min-height on the preview pane (example variant only).
align"center" | "start""center"Flex alignment of content in the preview pane (example variant only).
classNamestring""Additional Tailwind classes merged onto the root wrapper.