> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devreadykit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Snippet

> A code snippet component for displaying code with syntax highlighting

export const CodeSnippetReactComponentExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetReactComponentExample" frameBorder="0" width="100%" height="380"></iframe>;

export const CodeSnippetInstallationExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetInstallationExample" frameBorder="0" width="100%" height="360"></iframe>;

export const CodeSnippetApiResponseExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetApiResponseExample" frameBorder="0" width="100%" height="360"></iframe>;

export const CodeSnippetLineNumbersExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetLineNumbersExample" frameBorder="0" width="100%" height="360"></iframe>;

export const CodeSnippetCopyButtonExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetCopyButtonExample" frameBorder="0" width="100%" height="340"></iframe>;

export const CodeSnippetCssExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetCssExample" frameBorder="0" width="100%" height="320"></iframe>;

export const CodeSnippetPythonExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetPythonExample" frameBorder="0" width="100%" height="340"></iframe>;

export const CodeSnippetJavaScriptExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetJavaScriptExample" frameBorder="0" width="100%" height="320"></iframe>;

export const CodeSnippetBasicExamplePreview = () => <iframe src="https://kerny-custom.vercel.app/preview/CodeSnippetBasicExample" frameBorder="0" width="100%" height="360"></iframe>;

## Overview

The CodeSnippet component displays code with syntax highlighting and copy functionality.

## Basic Usage

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    import { CodeSnippet } from '@peppermint-design/devreadykit-custom';

    export default function App() {
      const code = `function hello() {
      console.log("Hello, World!");
    }`;

      return (
        <CodeSnippet
          tabs={[
            {
              id: "javascript",
              label: "javascript",
              language: "javascript",
              code,
            },
          ]}
        />
      );
    }
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetBasicExamplePreview />
  </Tab>
</Tabs>

## Different Languages

### JavaScript

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    <CodeSnippet 
      tabs={[{
        id: "javascript",
        label: "javascript",
        language: "javascript",
        code: `const greeting = "Hello, World!";\nconsole.log(greeting);`,
      }]}
    />
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetJavaScriptExamplePreview />
  </Tab>
</Tabs>

### Python

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    <CodeSnippet 
      tabs={[{
        id: "python",
        label: "python",
        language: "python",
        code: `def hello():\n    print("Hello, World!")\n\nhello()`,
      }]}
    />
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetPythonExamplePreview />
  </Tab>
</Tabs>

### CSS

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    <CodeSnippet 
      tabs={[{
        id: "css",
        label: "css",
        language: "css",
        code: `.button {\\n  background-color: #007bff;\\n  color: white;\\n  padding: 10px 20px;\\n}`,
      }]}
    />
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetCssExamplePreview />
  </Tab>
</Tabs>

## With Line Numbers

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    <CodeSnippet 
      tabs={[{
        id: "utility",
        label: "utility",
        language: "javascript",
        code: `function calculateSum(a, b) {\n  return a + b;\n}\n\nconst result = calculateSum(5, 3);\nconsole.log(result);`,
      }]}
      collapsible={false}
    />
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetLineNumbersExamplePreview />
  </Tab>
</Tabs>

## Props

<PropsTable>
  | Prop               | Type                                                                                                       | Default      | Description                                 |
  | ------------------ | ---------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------- |
  | tabs               | `Array<{ id: string; label: string; code: string; language?: string; codeByPm?: Record<string, string> }>` | -            | Snippet panes to render                     |
  | defaultTabId       | `string`                                                                                                   | first tab    | Tab selected on load                        |
  | collapsible        | `boolean`                                                                                                  | `true`       | Enable collapse behaviour for long snippets |
  | initiallyCollapsed | `boolean`                                                                                                  | `false`      | Whether the snippet starts collapsed        |
  | previewLines       | `number`                                                                                                   | `12`         | Lines shown when collapsed                  |
  | maxExpandedLines   | `number`                                                                                                   | `24`         | Maximum lines when expanded                 |
  | showToggle         | `boolean`                                                                                                  | `true`       | Display the show more/less toggle           |
  | copyButtonLabel    | `string`                                                                                                   | `"Copy"`     | Custom label for the copy button            |
  | pmTabs             | `Array<{ id: string; label: string }>`                                                                     | -            | Optional package manager tab switcher       |
  | defaultPmId        | `string`                                                                                                   | first pm tab | Default package manager tab                 |
  | className          | `string`                                                                                                   | -            | Additional CSS classes                      |
</PropsTable>

## Examples

### API Response

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    function ApiResponse({ data }) {
      const jsonCode = JSON.stringify(data, null, 2);

      return (
        <CodeSnippet 
          tabs={[{
            id: "response",
            label: "json",
            language: "json",
            code: jsonCode,
          }]}
          collapsible={false}
        />
      );
    }
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetApiResponseExamplePreview />
  </Tab>
</Tabs>

### Installation Instructions

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    function InstallationCode() {
      const installCode = `npm install @peppermint-design/devreadykit-custom

    # or with yarn
      yarn add @peppermint-design/devreadykit-custom

    # or with pnpm
      pnpm add @peppermint-design/devreadykit-custom`;

      return (
        <CodeSnippet 
          tabs={[{
            id: "bash",
            label: "bash",
            language: "bash",
            code: installCode,
          }]}
          copyButtonLabel="Copy command"
        />
      );
    }
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetInstallationExamplePreview />
  </Tab>
</Tabs>

### React Component Example

<Tabs>
  <Tab title="Code">
    ```tsx theme={null}
    function ComponentExample() {
      const reactCode = `import { Button } from '@peppermint-design/devreadykit-custom';

    export default function MyComponent() {
      return (
        <Button 
          variant="filled" 
          color="primary"
          onClick={() => console.log('Clicked!')}
        >
          Click me
        </Button>
      );
    }`;

      return (
        <CodeSnippet 
          tabs={[{
            id: "tsx",
            label: "tsx",
            language: "tsx",
            code: reactCode,
          }]}
          collapsible={false}
          copyButtonLabel="Copy component"
        />
      );
    }
    ```
  </Tab>

  <Tab title="Preview">
    <CodeSnippetReactComponentExamplePreview />
  </Tab>
</Tabs>
