nteract elements

CellControls

Cell action menu with source visibility toggle, move controls, and dropdown menu for delete and clear operations

A control panel for notebook cells that provides:

  • Source visibility toggle - Show/hide cell source code
  • Dropdown menu - Move cells, clear outputs, delete cell
  • Optional AI context toggle - For AI-assisted notebook interfaces

By default, controls are hidden on desktop and shown on hover (always visible on mobile). Use forceVisible to always show controls.

Installation

npx shadcn@latest add https://nteract-elements.vercel.app/r/cell-controls.json

Copy from nteract/elements.

Usage

import { CellControls } from "@/registry/cell/CellControls"

export function CellToolbar() {
  const [sourceVisible, setSourceVisible] = useState(true)

  return (
    <CellControls
      sourceVisible={sourceVisible}
      toggleSourceVisibility={() => setSourceVisible(!sourceVisible)}
      onDeleteCell={() => console.log("Delete")}
      onClearOutputs={() => console.log("Clear")}
      hasOutputs={true}
    />
  )
}

Examples

Basic Controls

<CellControls
  sourceVisible={sourceVisible}
  toggleSourceVisibility={() => setSourceVisible(!sourceVisible)}
  onDeleteCell={handleDelete}
  onClearOutputs={handleClear}
  hasOutputs={true}
/>

With Move Controls

<CellControls
  sourceVisible={sourceVisible}
  toggleSourceVisibility={() => setSourceVisible(!sourceVisible)}
  onDeleteCell={handleDelete}
  onClearOutputs={handleClear}
  hasOutputs={true}
  canMoveUp={true}
  canMoveDown={true}
  onMoveUp={handleMoveUp}
  onMoveDown={handleMoveDown}
  onMoveToTop={handleMoveToTop}
  onMoveToBottom={handleMoveToBottom}
/>

With AI Context Mode

<CellControls
  sourceVisible={sourceVisible}
  toggleSourceVisibility={() => setSourceVisible(!sourceVisible)}
  onDeleteCell={handleDelete}
  onClearOutputs={handleClear}
  hasOutputs={true}
  contextSelectionMode={true}
  aiContextVisible={aiContextVisible}
  toggleAiContextVisibility={() => setAiContextVisible(!aiContextVisible)}
/>

With PlayButton

import { PlayButton } from "@/registry/cell/PlayButton"

<CellControls
  sourceVisible={sourceVisible}
  toggleSourceVisibility={() => setSourceVisible(!sourceVisible)}
  onDeleteCell={handleDelete}
  onClearOutputs={handleClear}
  hasOutputs={true}
  playButton={
    <PlayButton
      executionState="idle"
      cellType="code"
      onExecute={handleExecute}
      onInterrupt={handleInterrupt}
    />
  }
/>

Props

PropTypeDefaultDescription
sourceVisiblebooleanWhether cell source is visible
toggleSourceVisibility() => voidToggle source visibility
onDeleteCell() => voidCallback to delete the cell
onClearOutputs() => voidCallback to clear cell outputs
hasOutputsbooleanWhether cell has outputs to clear
playButtonReact.ReactNodeOptional play button component
onMoveUp() => voidCallback to move cell up
onMoveDown() => voidCallback to move cell down
onMoveToTop() => voidCallback to move cell to top
onMoveToBottom() => voidCallback to move cell to bottom
canMoveUpbooleanfalseWhether cell can move up
canMoveDownbooleanfalseWhether cell can move down
onDeleteAllBelow() => voidCallback to delete all cells below
hasCellsBelowbooleanfalseWhether there are cells below
aiContextVisiblebooleanfalseWhether AI context is visible
contextSelectionModebooleanfalseWhether context selection mode is active
toggleAiContextVisibility() => voidToggle AI context visibility
forceVisiblebooleanForce controls to always be visible
classNamestringAdditional CSS classes

On this page