nteract elements

Cell Components

Composable components for building notebook cell interfaces

# Click the play button to run
print("Hello from nteract-elements!")

The cell components work together to create notebook cell interfaces. Click the play button above to see it in action.

Composition Pattern

A notebook cell is built from composable parts:

CellContainer          <- Focus wrapper with selection border
└── CellHeader         <- Toolbar layout (left/right slots)
    ├── PlayButton     <- Execute/interrupt control
    ├── CellTypeButton <- Cell type indicator (code, markdown, etc.)
    ├── ExecutionStatus<- Running/queued/error badges
    └── CellControls   <- Source toggle, move, delete actions
└── [Source content]   <- Your editor component
└── [Output content]   <- Your output renderer

Full Example

Here's how to compose a complete cell:

import { CellContainer } from "@/registry/cell/CellContainer";
import { CellHeader } from "@/registry/cell/CellHeader";
import { CellControls } from "@/registry/cell/CellControls";
import { CellTypeButton } from "@/registry/cell/CellTypeButton";
import { PlayButton } from "@/registry/cell/PlayButton";
import { ExecutionStatus } from "@/registry/cell/ExecutionStatus";

function NotebookCell({ cell, isFocused, onFocus }) {
  const [sourceVisible, setSourceVisible] = useState(true);

  return (
    <CellContainer
      id={cell.id}
      isFocused={isFocused}
      onFocus={onFocus}
    >
      <CellHeader
        leftContent={
          <>
            <PlayButton
              executionState={cell.executionState}
              cellType={cell.type}
              isFocused={isFocused}
              onExecute={() => executeCell(cell.id)}
              onInterrupt={() => interruptCell(cell.id)}
            />
            <CellTypeButton cellType={cell.type} size="sm" />
            <ExecutionStatus executionState={cell.executionState} />
          </>
        }
        rightContent={
          <CellControls
            sourceVisible={sourceVisible}
            toggleSourceVisibility={() => setSourceVisible(!sourceVisible)}
            onDeleteCell={() => deleteCell(cell.id)}
            onClearOutputs={() => clearOutputs(cell.id)}
            hasOutputs={cell.outputs.length > 0}
            forceVisible={isFocused}
          />
        }
      />
      {sourceVisible && <CodeEditor value={cell.source} />}
      {cell.outputs.map(output => <OutputRenderer output={output} />)}
    </CellContainer>
  );
}

Multiple Cells

Click different cells to see focus behavior:

x = 42 print(f"The answer is {x}")
## Results This cell shows markdown content.
import pandas as pd df = pd.DataFrame({'a': [1,2,3]})

Installation

Install all cell components:

npx shadcn@latest add https://nteract-elements.vercel.app/r/cell-container.json
npx shadcn@latest add https://nteract-elements.vercel.app/r/cell-header.json
npx shadcn@latest add https://nteract-elements.vercel.app/r/cell-controls.json
npx shadcn@latest add https://nteract-elements.vercel.app/r/cell-type-button.json
npx shadcn@latest add https://nteract-elements.vercel.app/r/play-button.json
npx shadcn@latest add https://nteract-elements.vercel.app/r/execution-status.json

Copy from nteract/elements.


Component Reference

CellContainer

The outer wrapper that provides focus styling and the data-cell-id attribute.

Unfocused cell (hover to see border)
Focused cell with selection border
PropTypeDefaultDescription
idstringCell identifier for data-cell-id
isFocusedbooleanfalseShows focus border when true
onFocus() => voidCalled on mousedown
childrenReactNodeCell content
onDragStart(e: DragEvent) => voidEnables dragging when provided
onDragOver(e: DragEvent) => voidDrag over handler
onDrop(e: DragEvent) => voidDrop handler
classNamestringAdditional classes
focusBgColorstring"bg-primary/5"Focus background
focusBorderColorstring"border-primary/60"Focus border

CellHeader

Slot-based layout for the cell toolbar.

PropTypeDescription
leftContentReactNodeLeft side (play button, type, status)
rightContentReactNodeRight side (controls)
draggablebooleanEnable drag handle
onDragStart(e: DragEvent) => voidDrag handler
classNamestringAdditional classes

CellTypeButton

Color-coded button showing cell type. Also exports convenience components: CodeCellButton, MarkdownCellButton, SqlCellButton, AiCellButton.

PropTypeDefaultDescription
cellType"code" | "markdown" | "sql" | "ai"Cell type
showIconbooleantrueShow type icon
showPlusbooleanfalseShow + icon (for add buttons)
labelstringCustom label

PlayButton

Execute/interrupt button with state-based icons.

Idle
Running
PropTypeDescription
executionState"idle" | "queued" | "running" | "completed" | "error"Current state
cellTypestringFor tooltip text
isFocusedbooleanHighlight when focused
onExecute() => voidRun callback
onInterrupt() => voidStop callback
isAutoLaunchingbooleanShow loading spinner

ExecutionStatus

Badge showing execution state.

Queued
Running
Error
PropTypeDescription
executionStatestringShows badge for "queued", "running", "error"

CellControls

Action buttons for source visibility, move, delete operations.

PropTypeDescription
sourceVisiblebooleanCurrent visibility state
toggleSourceVisibility() => voidToggle callback
onDeleteCell() => voidDelete callback
onClearOutputs() => voidClear outputs callback
hasOutputsbooleanEnable clear outputs
playButtonReactNodeOptional play button slot
onMoveUp/Down/ToTop/ToBottom() => voidMove callbacks
canMoveUp/DownbooleanEnable move buttons
forceVisiblebooleanAlways show (bypass hover)

On this page