Symbol Outline

A file's symbols as a tree, in file order rather than alphabetical. An outline is a map of the document you are reading; re-sorting it makes the outline and the editor disagree about where things are.

src/components/ui/symbol-outline.tsx

About

From the component's own source, where it was written.

A file's symbols as a tree.

Filtering keeps ancestors of a match. Flattening to matched leaves loses the class a method belongs to, and render on its own is useless when six components define one.

Order is the order in the file, not alphabetical. An outline is a map of the document you are reading; re-sorting it means the outline and the editor disagree about where things are.

Exported symbols are marked. "Is this part of the public surface" is the question an outline gets used for most, and it cannot be answered from the name.

Install

npx astralyx-ui add symbol-outline

Usage

import { SymbolOutline } from '@/components/ui/symbol-outline'

<SymbolOutline symbols={symbols} onSelect={goTo} />

Composer

Change the props and the source below follows.

Props
tsx
<SymbolOutline symbols={symbols} onSelect={goTo} />

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

SymbolOutline

Extends Omit<ComponentProps<'div'>, 'onSelect'>.

PropTypeDefaultDescription
symbolsCodeSymbol[]required{ id, name, kind, line?, exported?, children? }.
onSelect(id: string) => void——
selectedstring——
searchablebooleantrue—
searchPlaceholderstring'Filter symbols'—
searchLabelstring'Filter symbols'—
emptyMessageReactNode'No symbols match.'—
exportedLabelstring'exported'Accessible name for the export marker.
orderfile order—Never alphabetical.

Functions

FunctionSignatureDescription
filterSymbols(nodes: CodeSymbol[], needle: string) => CodeSymbol[]Keeps a node when it matches, or when any descendant does.

Types

CodeSymbol

FieldTypeDescription
idstring—
namestring—
kindSymbolKind—
line?number—
exported?booleanDraws a dot. "Is this part of the public surface" is what an outline gets used for, and the name cannot answer it.
children?CodeSymbol[]—
TypeDefinitionDescription
SymbolKind
| 'function' | 'class' | 'interface' | 'type' | 'constant' | 'variable' | 'property'
A file's symbols as a tree.

Behaviour

TopicDetailDescription
filteringkeeps ancestorsFlattening to matched leaves loses the class a method belongs to, and render alone is useless when six components define one.