Skip to content

The open alternative to Salesforce, designed for AI.

1.9 KB
Raw Blame
---
title: CommandBlock
description: Display command lines with an optional action.
---

import { PageBanner } from "/snippets/page-banner.mdx"

import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import CommandBlockReference from '/snippets/ui/generated/components/data-display/command-block.mdx';

## Overview

`CommandBlock` displays each supplied command with a prompt marker. It does not execute commands or provide copying automatically. Supply `actions` with any React node, such as a [Button](/ui/primitives/input/button), link or status. Command text uses `pre` and `code` semantics, preserves line breaks, and wraps within the available width. Prompt markers are decorative.

<StoryEmbed
  storyId="ui-components-data-display-commandblock--display"
  title="CommandBlock example"
  height={130}
/>

## Usage

```tsx
import { useState } from 'react';
import { CommandBlock } from 'twenty-ui/components/data-display';
import { Button } from 'twenty-ui/primitives/input';

export const InstallCommand = () => {
  const [copyLabel, setCopyLabel] = useState('Copy command');

  return (
    <CommandBlock
      commands={['yarn add twenty-ui']}
      actions={
        <Button
          onClick={async () => {
            try {
              await navigator.clipboard.writeText('yarn add twenty-ui');
              setCopyLabel('Copied');
            } catch {
              setCopyLabel('Select and copy the command');
            }
          }}
        >
          {copyLabel}
        </Button>
      }
    />
  );
};
```

Native attributes, event handlers, classes, styles and refs target the outer `div`. Use `render` to compose another root, for example `render={<section aria-label="Installation commands" />}`. `CommandBlockProps` is exported from `twenty-ui/components/data-display`.

When migrating, replace `button` with `actions`.

## Props

<CommandBlockReference />

<PageBanner illustration="card-page-cli" />