Cell Components
Composable components for building notebook cell interfaces
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 rendererFull 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:
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.jsonCopy from nteract/elements.
Component Reference
CellContainer
The outer wrapper that provides focus styling and the data-cell-id attribute.
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | — | Cell identifier for data-cell-id |
isFocused | boolean | false | Shows focus border when true |
onFocus | () => void | — | Called on mousedown |
children | ReactNode | — | Cell content |
onDragStart | (e: DragEvent) => void | — | Enables dragging when provided |
onDragOver | (e: DragEvent) => void | — | Drag over handler |
onDrop | (e: DragEvent) => void | — | Drop handler |
className | string | — | Additional classes |
focusBgColor | string | "bg-primary/5" | Focus background |
focusBorderColor | string | "border-primary/60" | Focus border |
CellHeader
Slot-based layout for the cell toolbar.
| Prop | Type | Description |
|---|---|---|
leftContent | ReactNode | Left side (play button, type, status) |
rightContent | ReactNode | Right side (controls) |
draggable | boolean | Enable drag handle |
onDragStart | (e: DragEvent) => void | Drag handler |
className | string | Additional classes |
CellTypeButton
Color-coded button showing cell type. Also exports convenience components: CodeCellButton, MarkdownCellButton, SqlCellButton, AiCellButton.
| Prop | Type | Default | Description |
|---|---|---|---|
cellType | "code" | "markdown" | "sql" | "ai" | — | Cell type |
showIcon | boolean | true | Show type icon |
showPlus | boolean | false | Show + icon (for add buttons) |
label | string | — | Custom label |
PlayButton
Execute/interrupt button with state-based icons.
| Prop | Type | Description |
|---|---|---|
executionState | "idle" | "queued" | "running" | "completed" | "error" | Current state |
cellType | string | For tooltip text |
isFocused | boolean | Highlight when focused |
onExecute | () => void | Run callback |
onInterrupt | () => void | Stop callback |
isAutoLaunching | boolean | Show loading spinner |
ExecutionStatus
Badge showing execution state.
| Prop | Type | Description |
|---|---|---|
executionState | string | Shows badge for "queued", "running", "error" |
CellControls
Action buttons for source visibility, move, delete operations.
| Prop | Type | Description |
|---|---|---|
sourceVisible | boolean | Current visibility state |
toggleSourceVisibility | () => void | Toggle callback |
onDeleteCell | () => void | Delete callback |
onClearOutputs | () => void | Clear outputs callback |
hasOutputs | boolean | Enable clear outputs |
playButton | ReactNode | Optional play button slot |
onMoveUp/Down/ToTop/ToBottom | () => void | Move callbacks |
canMoveUp/Down | boolean | Enable move buttons |
forceVisible | boolean | Always show (bypass hover) |