Skip to content
Back to skills

Collapse

ASecurity

Expand and collapse node hierarchies. Collapsed nodes hide their descendants while maintaining the graph structure.

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 7, 2026
ai-agentsnode

Works with

  • cli

Security analysis

A100/100

Scanned September 7, 2026

npx -y skills add reaviz/skills --skill collapse --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collapse?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collapse
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/reaviz-collapse-skills/badge)](https://www.skillsdirectory.com/skills/reaviz-collapse-skills)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Collapse

Expand and collapse node hierarchies. Collapsed nodes hide their descendants while maintaining the graph structure.

## Import

```tsx
import { useCollapse, GraphCanvas } from 'reagraph';
```

## useCollapse Hook

### Parameters

| Param | Type | Default | Description |
|-------|------|---------|-------------|
| `collapsedNodeIds` | `string[]` | `[]` | Currently collapsed node IDs |
| `nodes` | `GraphNode[]` | `[]` | Node data |
| `edges` | `GraphEdge[]` | `[]` | Edge data |

### Return Value

| Property | Type | Description |
|----------|------|-------------|
| `getIsCollapsed` | `(nodeId: string) => boolean` | Check if a node is collapsed |
| `getExpandPathIds` | `(nodeId: string) => string[]` | Get IDs to expand to reveal a node |

## Basic Usage

```tsx
import { GraphCanvas, useCollapse } from 'reagraph';

const [collapsedIds, setCollapsedIds] = useState<string[]>([]);

<GraphCanvas
  nodes={nodes}
  edges={edges}
  collapsedNodeIds={collapsedIds}
  onNodeClick={(node, { canCollapse, isCollapsed }) => {
    if (canCollapse) {
      setCollapsedIds((prev) =>
        isCollapsed
          ? prev.filter((id) => id !== node.id)
          : [...prev, node.id]
      );
    }
  }}
/>
```

## With Context Menu

```tsx
<GraphCanvas
  nodes={nodes}
  edges={edges}
  collapsedNodeIds={collapsedIds}
  contextMenu={({ data, onClose, canCollapse, isCollapsed, onCollapse }) => (
    <RadialMenu
      onClose={onClose}
      items={[
        ...(canCollapse
          ? [{
              label: isCollapsed ? 'Expand' : 'Collapse',
              onClick: () => { onCollapse(); onClose(); },
            }]
          : []),
      ]}
    />
  )}
/>
```

## Checking Collapse State

```tsx
const { getIsCollapsed, getExpandPathIds } = useCollapse({
  collapsedNodeIds,
  nodes,
  edges,
});

// Check if a specific node is collapsed
const isHidden = getIsCollapsed('node-5');

// Get path to expand to reveal a hidden node
const pathToExpand = getExpandPathIds('node-5');
```

## Notes

- Nodes need `parents` property or outbound edges to establish hierarchy
- `canCollapse` in the click/context-menu callback indicates whether a node has children
- Collapsing a node hides all its descendants
- `collapsedNodeIds` is a controlled prop — manage it in your state
- `onCollapse` in context menu events toggles the collapse state for you

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.