Documentation
Snippet

Snippet

The Snippet component is used to display blocks of code or text with a convenient copy-to-clipboard feature. It supports customization through different accent colors and can optionally display a command-line prompt before each line.

Usage

First of all, you need to import the Snippet component from the kitchn package.

import { Snippet } from "kitchn"

Default

npm install kitchn
Code Editor
<Snippet text={"npm install kitchn"} w={300} />

Multi-line

git init
git add .
git commit -m 'Initial commit'
Code Editor
<Snippet text={[ "git init", "git add .", "git commit -m 'Initial commit'", ]} />

No prompt

npm install kitchn
Code Editor
<Snippet text={"npm install kitchn"} w={300} prompt={false} />

Callback

npm install kitchn
Code Editor
<Snippet text={"npm install kitchn"} w={300} onCopy={() => alert("copied")} />

Type

npm install kitchn
npm install kitchn
npm install kitchn
Code Editor
<Container gap={"small"}>
  <Snippet text={"npm install kitchn"} w={300} type={"success"} />
  <Snippet text={"npm install kitchn"} w={300} type={"warning"} />
  <Snippet text={"npm install kitchn"} w={300} type={"danger"} />
</Container>

Props

NameTypeDefaultRequiredDescription
textstring | string[]""YesThe text or code to be displayed in the snippet. Can be a single string or an array of strings for multi-line snippets.
promptbooleantrueNoIf true, displays a command-line prompt ($) before each line of text.
typekeyof AccentColors"primary"NoDefines the accent color for the snippet.
onCopy(text: string) => voidnullNoCallback function that gets triggered when the text is copied.
Last updated on