# Build with agents (/docs/build-with-agents) ## Plain-text docs [#plain-text-docs] Our documentation is also available in condensed Markdown text, available in two versions: - [llms.txt](/llms.txt) is a short index of the pages - [llms-full.txt](/llms-full.txt) is the everything in the docs — prose, API lists, and code examples Every page is also available on its own: append `.md` to its URL, or use the "Copy Markdown" button under the page title. Copy and paste as needed, or provide the URLs to your agent. # Customize icons (/docs/guides/customize-icons) Start with the built-in icon sets. Then add targeted remaps only where your product needs them. Most apps do not need to replace the whole icon system. ## Start with the built-in icon sets [#start-with-the-built-in-icon-sets] `solid-trees` includes three built-in sets: - `minimal` for low-noise file and folder visuals - `standard` for common language and file-type recognition - `complete` for the broadest built-in coverage Pass the set name directly when you need only a different baseline. ```ts title="icons-basic.ts" const tree = createFileTree({ paths, icons: 'standard', }); ``` ## Adjust color mode before you remap icons [#adjust-color-mode-before-you-remap-icons] Built-in sets use semantic icon colors by default. Turn the colors off before you use a sprite sheet. Do this when the product needs a quieter or monochrome look. ```ts title="icons-colored-off.ts" const tree = createFileTree({ paths, icons: { set: 'complete', colored: false, }, }); ``` Use the styling system for broader appearance control. Do not treat icons as a parallel theme surface. Read [Style and theme the tree](/docs/guides/style-and-theme-the-tree). ## Use the object form for targeted remaps [#use-the-object-form-for-targeted-remaps] Switch to `FileTreeIconConfig` when a plain set name is not enough. The practical remap surfaces are: - `remap` for built-in slots such as the generic file icon, chevron, dot, or lock - `byFileName` for exact basenames such as `package.json` - `byFileExtension` for suffixes such as `ts` or `spec.ts` - `byFileNameContains` for broader patterns such as `dockerfile` ```ts title="icons-remap.ts" const tree = createFileTree({ paths, icons: { set: 'standard', byFileName: { 'package.json': 'icon-package-json', }, byFileExtension: { 'spec.ts': 'icon-test-file', }, byFileNameContains: { dockerfile: 'icon-dockerfile', }, remap: { 'file-tree-icon-lock': 'icon-locked', }, }, }); ``` This approach keeps the built-in mapping for every icon that you did not change. ## Rule precedence matters [#rule-precedence-matters] File-specific rules win over broader rules. `solid-trees` resolves icons in this order: 1. exact basename matches 2. basename-contains matches 3. extension matches, and the more specific suffix wins 4. the chosen built-in set 5. the generic file-slot remap or fallback For the full lookup contract, read [Icons](/docs/reference/icons#resolution-order). ## Use a sprite sheet only for advanced cases [#use-a-sprite-sheet-only-for-advanced-cases] Use `spriteSheet` in two cases. Use it when you already have branded SVG symbols. Also use it when you need a few custom symbols next to the built-in set. ```ts title="icons-sprite-sheet.ts" const tree = createFileTree({ paths, icons: { set: 'standard', spriteSheet: ` `, byFileName: { 'package.json': 'icon-package-json', }, }, }); ``` Keep the contract simple. Provide `` definitions. Then point remap rules at those symbols. Each tree prefixes the symbol ids of its sprite sheet, so several trees in one document never resolve each other's icons. Do not make sprite sheets the default docs path. # Get started (/docs/guides/get-started) `solid-trees` gives you one path-first model and a thin Solid layer over it: `createFileTree(...)` creates the model, and `` renders it. The primitives `createFileTreeSelection(...)`, `createFileTreeSearch(...)`, and `createFileTreeSelector(...)` derive reactive values from the same model. ## Path-first identity [#path-first-identity] Use canonical path strings as the public identity for each item in the tree. For example, `src/components/Button.tsx` is more than a label on screen. It is the value that you read from selection state. It is the path that you focus in code. It is also the target that you rename or move later. To learn the shared terms behind this rule, read [Shared concepts](/docs/reference/shared-concepts). ## Install `solid-trees` [#install-solid-trees] The package needs Solid 2 (`solid-js` and `@solidjs/web` `^2.0.3`) next to it. ```npm npm install solid-trees solid-js @solidjs/web ``` Import the stylesheet once. `` injects the structural layer itself, so trees work without it, but the stylesheet adds the visual styles. ```ts title="main.ts" import 'solid-trees/styles.css'; ``` ## Create the model with `createFileTree(...)` [#create-the-model-with-createfiletree] `createFileTree(...)` creates the model one time. The current reactive owner owns it, so the model is cleaned up when the owner disposes. Options are read once. Later option changes do not update the model. Update the model through methods when the tree data or runtime behavior changes after mount. The methods include `resetPaths(...)`, `setComposition(...)`, `setGitStatus(...)`, and `setIcons(...)`. For small trees, pass raw `paths`. For scalable trees, use `preparedInput`. Create `preparedInput` on the server or another non-UI boundary. ```tsx title="project-tree.tsx" import { createFileTree, FileTree } from 'solid-trees'; import type { FileTreePreparedInput } from 'solid-trees'; interface ProjectTreeProps { preparedInput: FileTreePreparedInput; } export function ProjectTree(props: ProjectTreeProps) { const tree = createFileTree({ preparedInput: props.preparedInput, search: true, initialExpandedPaths: ['src', 'src/components'], }); return ( ); } ``` Read [Shape tree data for fast rendering](/docs/guides/shape-tree-data-for-fast-rendering) after this quickstart if you must still decide how to shape that input. ## Render with `` [#render-with-filetree-modelmodel-] `` is a thin Solid view over the model. It renders the tree into the light DOM. It forwards normal host props such as `class` and `style`. The tree virtualizes its rows, so give it a bounded height. Swapping the `model` prop remounts the view. Keep the mental model simple. The model owns the tree state. The Solid component renders it. ## Read and update tree state through the model [#read-and-update-tree-state-through-the-model] Solid code reads from the model through primitives and model getters. Solid code writes back through model methods. ```tsx title="searchable-tree.tsx" import { createFileTree, createFileTreeSearch, createFileTreeSelection, FileTree, } from 'solid-trees'; export function SearchableTree(props: { paths: readonly string[] }) { const tree = createFileTree({ paths: props.paths, fileTreeSearchMode: 'hide-non-matches', search: true, }); const selectedPaths = createFileTreeSelection(tree); const search = createFileTreeSearch(tree); return (
search.setValue(event.currentTarget.value)} placeholder="Search files" />

{selectedPaths().length} item(s) selected.

); } ``` Use `createFileTreeSelector(model, selector, isEqual?)` when sibling UI needs a custom derived value. It only notifies when the selected value changes. Model getters such as `getFocusedPath()` also track inside Solid scopes, so you can read them directly in JSX. For the shared interaction terms, read [Navigate selection, focus, and search](/docs/guides/navigate-selection-focus-and-search) and [Solid API](/docs/reference/solid-api). ## Use simple `paths` input only when the tree is small [#use-simple-paths-input-only-when-the-tree-is-small] Raw `paths` is the low-ceremony path for demos, tests, and very small static trees. It is not the scalable default. Move the shape or sort work out of the UI when the tree becomes expensive on the client. ## Move to prepared input before the tree gets expensive [#move-to-prepared-input-before-the-tree-gets-expensive] Use this recommended scale path: 1. Load canonical paths on the server or another non-UI boundary. 2. Prepare the tree input one time. 3. Pass `preparedInput` into `createFileTree(...)`. Use `preparePresortedFileTreeInput(...)` when the server already knows the final order. It is the highest-performance prepared-input variant. The client can skip both the shaping work and the extra sorting work. Unlike upstream, `solid-trees` renders on the client only. There is no SSR preload or hydration step. See [Differences from `@pierre/trees`](/docs/reference/differences-from-pierre-trees). # Handle large trees efficiently (/docs/guides/handle-large-trees-efficiently) To make large trees fast, first reduce unnecessary client work. Shape and order the data before it reaches the UI. Then tune rendering only where the visible window needs help. ## Start with the main recommendation [#start-with-the-main-recommendation] Use: - raw `paths` for small demos and low-ceremony cases - `preparedInput` for larger trees - `preparePresortedFileTreeInput(...)` when the server already owns the final order This order matters. Do not go straight to the rendering knobs while the client still does avoidable shape or sort work. ## Prepare input before it reaches the client [#prepare-input-before-it-reaches-the-client] For larger trees, move the shape work out of the UI. Prepared input is the scale-oriented public path. ```ts title="load-workspace-tree.ts" import { preparePresortedFileTreeInput } from 'solid-trees'; export async function loadWorkspaceTree() { const sortedPaths = await fetchSortedWorkspacePaths(); return preparePresortedFileTreeInput(sortedPaths); } ``` Use `prepareFileTreeInput(...)` instead when you have only an unsorted path list. In both cases, pass the prepared result into `createFileTree(...)` or `resetPaths(...)`. ## Keep rendering work small [#keep-rendering-work-small] `solid-trees` already virtualizes the visible row window. Most apps do not need custom virtualization primitives. The main rendering knobs are: - the host element CSS height, because layout sets the steady-state viewport size - `initialVisibleRowCount`, to budget first-render work before measurement - `density`, when your design changes the row density enough to matter. Pass `'compact' | 'default' | 'relaxed'` or a custom numeric factor. This option sets both the row height and the spacing in one place. Use `itemHeight` only when you need a row height that does not match a preset. - `overscan`, to trade a little extra work for smoother scrolling ```ts title="virtualization-knobs.ts" const tree = createFileTree({ preparedInput, initialVisibleRowCount: 14, itemHeight: 30, overscan: 8, }); ``` Give the rendered tree host a real CSS height. The row-count hint only shapes the first render. The browser then measures the actual viewport. Keep the language outcome-focused. The tree mounts the visible slice and a small buffer around it. ## Expansion and search still affect scale [#expansion-and-search-still-affect-scale] Prepared input lowers the cost to shape the data. But expansion and search still change how many rows stay visible at once. Large expanded trees and broad search results can widen the mounted window. This is another reason to start with the input story first. Do not recompute the tree shape in the client while the visible tree also changes often. ## Swap data in place [#swap-data-in-place] When the path list changes wholesale, keep the model and call `resetPaths(...)`. Pass `{ preparedInput }` alone to skip the parse and sort that raw `paths` would require. Swapping the `model` prop of `` remounts the whole view. ## Common pitfalls [#common-pitfalls] Avoid these patterns when the tree grows: - you send only raw `paths` for huge server-known datasets - you re-sort on the client after the server already chose the order - you use low-level virtualization ideas as the first fix - you rebuild the model when `resetPaths(...)` with matching prepared input does the job ## What to read next [#what-to-read-next] - [Shape tree data for fast rendering](/docs/guides/shape-tree-data-for-fast-rendering) for the shared input story - [Shared concepts](/docs/reference/shared-concepts#scale-and-rendering-settings) for the rendering knobs - [Model API](/docs/reference/model-api) for `resetPaths(...)` and the other data methods # Navigate selection, focus, and search (/docs/guides/navigate-selection-focus-and-search) The tree model tracks three user-facing states: selection, focus, and the visible row set. Search builds on the same model. It does not add a separate identity system. ## Start with the interaction state model [#start-with-the-interaction-state-model] Selection, focus, keyboard movement, and search all use canonical paths. The visible tree can change when a branch collapses or when search removes rows. Your app still uses the same path values. For this reason, the public APIs return path-based results. Selected paths are a `readonly string[]`. Focused items are path strings. Search matches are path strings. ## Selection and focus are related but different [#selection-and-focus-are-related-but-different] Focus tells you where keyboard actions land. Selection tells you which rows the app treats as chosen. The two often move together. But they are not the same. Read the selected paths when you need the multi-select state in surrounding UI. Read the focused path or item handle when you need to know where a rename, keyboard action, or command lands next. ## Keyboard navigation follows the visible tree [#keyboard-navigation-follows-the-visible-tree] Keyboard movement works on the visible, expanded tree. Expand or collapse a branch to change which row receives focus next. Search changes the same visible tree. So search also changes where keyboard movement lands. For this reason, `solid-trees` exposes focus and selection through the model. It does not use DOM order or row indexes. ## Add search on top of that same state [#add-search-on-top-of-that-same-state] Search matches the same path-first tree data. It changes what stays visible. But it does not add a second identity model. Selection and focus still use paths. The visible window changes around the current query. ## Guide default: `hide-non-matches` [#guide-default-hide-non-matches] Start with `hide-non-matches`. Change it only when the product needs unrelated branches on screen. This mode fits the common "find the thing I want" workflow. It keeps the visible tree close to the current search intent. `solid-trees` also supports `collapse-non-matches` and `expand-matches`. Use those modes when the surrounding UI needs more context. But keep `hide-non-matches` as the default mental model. The shared meaning of all three modes is in [Shared concepts](/docs/reference/shared-concepts#search-mode-semantics). ## Solid integration notes [#solid-integration-notes] Solid reads from the model through primitives and tracked model getters. Solid writes back through model methods. ```tsx title="search-panel.tsx" import { createFileTree, createFileTreeSearch, createFileTreeSelection, FileTree, } from 'solid-trees'; export function SearchPanel(props: { paths: readonly string[] }) { const tree = createFileTree({ paths: props.paths, search: true, fileTreeSearchMode: 'hide-non-matches', }); const selectedPaths = createFileTreeSelection(tree); const search = createFileTreeSearch(tree); return (

{selectedPaths().length} selected

Focused: {tree.getFocusedPath() ?? '(none)'}

); } ``` Use `createFileTreeSelector(...)` when sibling UI needs a custom derived value. Outside Solid scopes, the same getters (`getSelectedPaths()`, `getFocusedPath()`, `getSearchMatchingPaths()`) return the current values imperatively. The DOM is not the source of truth. The model is the source of truth. ## What to read next [#what-to-read-next] - For API lookup, read [Solid API](/docs/reference/solid-api) or [Model API](/docs/reference/model-api). - For shared search-mode semantics, read [Shared concepts](/docs/reference/shared-concepts#search-mode-semantics). - For row-level editing workflows that build on this focus model, continue with [Rename, drag, and trigger item actions](/docs/guides/rename-drag-and-trigger-item-actions). # Rename, drag, and trigger item actions (/docs/guides/rename-drag-and-trigger-item-actions) This guide covers the main row-level editing workflows. Rename comes first. Drag and drop comes second. Optional command surfaces, such as context menus, come last. Every callback stays path-first. ## Start with direct row actions [#start-with-direct-row-actions] The core row workflows are: 1. rename in place 2. drag and drop 3. optional context-menu commands Learn these flows before you use a generic mutation inventory. Users care about three things. They care about which path moved. They care about which path changed its name. They care about which row stays focused next. ## Rename items in place [#rename-items-in-place] Enable `renaming` when users must rename rows inline. The common policy hooks are: - `canRename(item)` to block protected files or folders - `onRename(event)` to respond to the final path change - `onError(error)` to show invalid rename attempts The rename event reports three values. It reports the source path. It reports the destination path. It reports whether the item was a folder. ```tsx title="rename.tsx" const tree = createFileTree({ paths, renaming: { canRename: (item) => item.path !== 'package.json', onRename: ({ sourcePath, destinationPath }) => { console.log(`Renamed ${sourcePath} -> ${destinationPath}`); }, onError: (message) => { console.error(message); }, }, }); tree.startRenaming('src/index.ts'); ``` ## Move items with drag and drop [#move-items-with-drag-and-drop] Enable `dragAndDrop` when users must move files or folders directly in the tree. The practical hooks are: - `canDrag(paths)` to lock specific paths - `canDrop(event)` to reject invalid destinations - `onDropComplete(event)` for persistence or adjacent UI updates - `onDropError(error, event)` for visible failures ```ts title="drag-and-drop.ts" const tree = createFileTree({ paths, dragAndDrop: { canDrag: (draggedPaths) => draggedPaths.includes('package.json') === false, canDrop: ({ target }) => target.directoryPath !== 'dist/', onDropComplete: ({ draggedPaths, target }) => { console.log( 'Moved', draggedPaths, 'to', target.directoryPath ?? '(root)' ); }, onDropError: (message) => { console.error(message); }, }, }); ``` Drop callbacks report the dragged paths and the resolved target shape. They do not ask you to find the DOM rows yourself. ## Combine rename and drag safely [#combine-rename-and-drag-safely] A common editable project tree enables both `renaming` and `dragAndDrop`. Then it adds policy guards for protected paths. Typical rules include: - block rename for root config files such as `package.json` - reject drops into generated directories such as `dist/` - show rename and drop failures outside the tree; do not fail silently ## Add a context menu as an optional command surface [#add-a-context-menu-as-an-optional-command-surface] Context menus are secondary command surfaces over the same model. Keep rename and drag available. Do not require the menu. Pass `renderContextMenu` to `` and the tree renders the menu content for you, as Solid JSX. Providing it enables the context menu. `composition.contextMenu` keeps the behavior flags: ```tsx title="context-menu.tsx" const tree = createFileTree({ paths, composition: { contextMenu: { triggerMode: 'both', buttonVisibility: 'when-needed', }, }, renaming: true, }); ( )} />; ``` The menu renders inside the tree's floating anchor. If you portal menu content elsewhere, mark its root with `data-file-tree-context-menu-root="true"` so that clicks inside it do not count as outside clicks. ## Lock window scroll while a menu is open [#lock-window-scroll-while-a-menu-is-open] A user scroll inside the tree pane closes the open menu. But the tree cannot reach the scroll containers that your page owns. A menu opened with a right click sits at a fixed point in the viewport, and so does a portaled menu. So the menu disconnects from its row when the window scrolls. Lock the window scroll for the menu's lifetime. Release the lock when the menu closes: ```tsx title="window-scroll-lock.tsx" import { onSettled } from 'solid-js'; // Hide the window scrollbar and compensate for its width so the page // content does not shift under the already-positioned menu. function lockWindowScroll(): () => void { const { body, documentElement } = document; const scrollbarWidth = window.innerWidth - documentElement.clientWidth; const previousOverflow = body.style.overflow; const previousPaddingRight = body.style.paddingRight; body.style.overflow = 'hidden'; if (scrollbarWidth > 0) { body.style.paddingRight = `${scrollbarWidth}px`; } return () => { body.style.overflow = previousOverflow; body.style.paddingRight = previousPaddingRight; }; } // Solid: the menu content mounts exactly while the menu is open, so locking // once it settles and releasing on disposal covers the menu's whole lifetime. function TreeMenu() { onSettled(() => lockWindowScroll()); return
{/* menu items */}
; } ``` Some menu primitives have a modal mode that locks scroll for you. Apply the manual lock for a non-modal menu. ## Keep keyboard and focus behavior predictable [#keep-keyboard-and-focus-behavior-predictable] The focused row is the anchor for rename and keyboard commands. Restore focus in a predictable way when a menu opens and closes. Keyboard users must reach the main actions without pointer-only gestures. ## The tree owns the interaction surface. Your app owns persistence. [#the-tree-owns-the-interaction-surface-your-app-owns-persistence] `solid-trees` emits path-based rename and drop events. Your app decides whether to save those changes. It can save them to a server, local state, or another boundary. Keep this separation clear. To learn the shared terms behind those events, read [Shared concepts](/docs/reference/shared-concepts#mutation-vocabulary). For API lookup, read [Solid API](/docs/reference/solid-api) or [Model API](/docs/reference/model-api). # Shape tree data for fast rendering (/docs/guides/shape-tree-data-for-fast-rendering) Shape the tree before it reaches the UI when the dataset is large. Then this out-of-UI preparation is worth the effort. `solid-trees` treats prepared input as a first-class public concept. It is not an internal optimization trick. ## Start with server-prepared input for scalable trees [#start-with-server-prepared-input-for-scalable-trees] `prepareFileTreeInput(...)` lets the client skip repeated tree-shape work. Do this preparation on the server, a loader, or another non-UI boundary. That boundary already has the full path list. ```ts title="load-project-tree-input.ts" import { prepareFileTreeInput } from 'solid-trees'; export async function loadProjectTreeInput(projectId: string) { const paths = await fetchProjectPaths(projectId); return prepareFileTreeInput(paths, { flattenEmptyDirectories: true, }); } ``` The client still uses the same path-first model. Only the expensive preparation step moves earlier. ## Pass `preparedInput` into the model [#pass-preparedinput-into-the-model] `createFileTree(...)` accepts the prepared payload in place of raw `paths`. ```tsx title="project-tree.tsx" import { createFileTree, FileTree } from 'solid-trees'; import type { FileTreePreparedInput } from 'solid-trees'; export function ProjectTree(props: { preparedInput: FileTreePreparedInput }) { const tree = createFileTree({ preparedInput: props.preparedInput }); return ; } ``` ## Use simple `paths` input only for small trees [#use-simple-paths-input-only-for-small-trees] Raw `paths` is still the right choice for small demos, tests, and very small static trees. ```ts title="small-paths.ts" const tree = createFileTree({ paths: ['README.md', 'src/index.ts', 'src/components/Button.tsx'], }); ``` This is the easy start path, not the scale-oriented default. Move the preparation work out of the client when the tree grows. ## Presorted input is the highest-performance prepared-input path [#presorted-input-is-the-highest-performance-prepared-input-path] Use `preparePresortedFileTreeInput(...)` when your server or indexer already knows the final order. It skips the tree-shape work. It also skips the extra sort work that a normal prepared-input pass applies. ```ts title="presorted.ts" import { preparePresortedFileTreeInput } from 'solid-trees'; const preparedInput = preparePresortedFileTreeInput([ 'README.md', 'src/index.ts', 'src/components/Button.tsx', ]); ``` Use this path when the backend, build step, or cached index already owns the sort order. Do not write the default order again in the client only to reach the presorted path. ## Prepare on the server, render on the client [#prepare-on-the-server-render-on-the-client] Use this simple split: 1. Load canonical paths outside the UI. 2. Prepare the input one time. 3. Pass `preparedInput` into `createFileTree(...)`, or into `resetPaths(...)` when the tree already exists. This split reduces client CPU work. It makes the startup cost more predictable. It also lets one prepared payload feed every tree that shows the same paths. ## Keep client-side sorting and preparation secondary [#keep-client-side-sorting-and-preparation-secondary] Sometimes the data exists only in the browser. Sometimes custom order must run there. `solid-trees` supports both cases, but they are the exception path. Start with prepared input when the app can move the work out of the UI. Use client-side shaping only as a fallback. To learn the shared contract behind these inputs, read [Shared concepts](/docs/reference/shared-concepts). For the scale-oriented version of this guidance, continue with [Handle large trees efficiently](/docs/guides/handle-large-trees-efficiently). # Show Git status and row annotations (/docs/guides/show-git-status-and-row-annotations) Use built-in `gitStatus` when the signal is Git-like. Use `renderRowDecoration` when the row needs product-specific metadata that is not Git state. ## Start with built-in `gitStatus` [#start-with-built-in-gitstatus] `gitStatus` is the default row-signal path. It attaches statuses to canonical paths. Folders can reflect changed descendants automatically. `solid-trees` supports these built-in statuses: - `added` - `modified` - `deleted` - `ignored` - `renamed` - `untracked` ```ts title="git-status.ts" const tree = createFileTree({ paths, gitStatus: [ { path: 'README.md', status: 'untracked' }, { path: 'package.json', status: 'renamed' }, { path: 'src/index.ts', status: 'modified' }, { path: 'src/components/Button.tsx', status: 'added' }, ], }); ``` This is the shortest path when the row signal already matches Git semantics. ## Know when `gitStatus` is enough [#know-when-gitstatus-is-enough] Use `gitStatus` only when the meaning is Git-like. Do not invent fake Git state only to show a badge. Let `solid-trees` own the built-in status lane. Let the styling system control how those signals look. ## Update status sets over time [#update-status-sets-over-time] Replace the current status data directly when the surrounding app changes. Examples are new commits, branches, comparison views, or status visibility. Use `applyGitStatusPatch(...)` when only a few paths change. ```ts title="set-git-status.ts" tree.setGitStatus(nextStatuses); tree.setGitStatus(undefined); tree.applyGitStatusPatch({ set: [{ path: 'src/index.ts', status: 'modified' }], remove: ['README.md'], }); ``` This step keeps the runtime accurate. It does not promise a filesystem watcher or a repo-sync framework. ## Add custom row annotations with `renderRowDecoration` [#add-custom-row-annotations-with-renderrowdecoration] Use `renderRowDecoration` when the row needs metadata that is not Git-like. ```ts title="render-row-decoration.ts" const tree = createFileTree({ paths, renderRowDecoration: ({ item }) => { if (item.path.endsWith('.generated.ts')) { return { text: 'GEN', title: 'Generated file' }; } if (item.path.startsWith('remote/')) { return { icon: 'icon-remote', title: 'Remote source' }; } return null; }, }); ``` Good fits include generated-file markers, remote-storage indicators, validation markers, and short secondary labels. ## Choose between the two paths [#choose-between-the-two-paths] Use: - `gitStatus` when the meaning is Git-like - `renderRowDecoration` for everything else - both together when a row needs Git state and one extra product-specific signal Keep annotations short and easy to read. Give a decoration accessible text or a tooltip when it affects user decisions. ## Keep styling separate from annotation meaning [#keep-styling-separate-from-annotation-meaning] Keep Git-status colors and decoration visuals in the same appearance system as the rest of the tree. Use the styling and theming controls for color. Do not add a second theme layer for annotations. For that part of the API, read [Style and theme the tree](/docs/guides/style-and-theme-the-tree) and [Styling and theming](/docs/reference/styling-and-theming). # Style and theme the tree (/docs/guides/style-and-theme-the-tree) Start with the host element. Then move inward. Host styles control the outer panel. CSS variables control most of the tree appearance. `themeToTreeStyles(...)` maps an editor-like theme into the same variable system. The tree renders into the light DOM, so plain page CSS is the escape hatch when the supported surfaces cannot reach a narrow case. ## Start with host styling [#start-with-host-styling] The host element is the outer panel boundary. Use it for width, height, borders, radius, background, and layout placement. Pass normal host props to ``. ```tsx title="host-styling.tsx" ``` ## Use CSS variables for most visual changes [#use-css-variables-for-most-visual-changes] CSS variables are the main public styling surface inside the tree. Use them before you write selectors against the tree's markup. Solid's `style` object takes custom properties directly. ```tsx title="css-variables.tsx" ``` You can also set the variables on any ancestor in a stylesheet. This approach keeps the normal fallback chain in place: 1. explicit override variables (`--trees-*-override`) 2. `--trees-theme-*` variables from theme helpers 3. library defaults For the token families behind those variables, read [Styling and theming](/docs/reference/styling-and-theming). ## Match an editor palette with `themeToTreeStyles(...)` [#match-an-editor-palette-with-themetotreestyles] Use `themeToTreeStyles(...)` when your app already has a VS Code or Shiki-style theme object. It maps that theme to host styles. It also maps the theme to the `--trees-theme-*` variables that the tree understands. The result is a Solid `style` object, keyed by CSS property names. ```tsx title="theme-to-tree-styles.tsx" import dracula from '@shikijs/themes/dracula'; import { themeToTreeStyles } from 'solid-trees'; const treeStyles = themeToTreeStyles(dracula); ; ``` This helper gives you matching panel colors, selection colors, search-field colors, and Git-status colors. You do not rebuild the theme system by hand. ## Set density with `density` [#set-density-with-density] Pass `density` to `createFileTree(...)`. This option sets row height and spacing together. The keyword form (`'compact'`, `'default'`, `'relaxed'`) sets both values at once. The numeric form keeps the default row height and sets a custom spacing factor. `` paints `--trees-item-height` and `--trees-density-override` onto the host from the resolved density. This step keeps the virtualized row height and the painted row height aligned. Set `itemHeight` only when you need a row height that does not match a preset. The keyword presets are exported as `FILE_TREE_DENSITY_PRESETS`. So helpers such as `initialVisibleRowCount` can divide by the preset row height. They do not hard-code it. ## Follow your page's color scheme [#follow-your-pages-color-scheme] The tree root sets `color-scheme: light dark`, so its colors follow the OS preference. When your page has its own light and dark toggle, pin the tree to it with `style={{ 'color-scheme': 'dark' }}`, `'inherit'`, or a page CSS rule. ## Choose the right styling layer [#choose-the-right-styling-layer] Use: - host styles for layout and panel framing - CSS variables for product-specific appearance changes inside the tree - `themeToTreeStyles(...)` when the tree must inherit an editor palette - plain page CSS for narrow cases the variables cannot express Add explicit overrides on top when the imported theme is close but not final. ## Page CSS is the escape hatch [#page-css-is-the-escape-hatch] Upstream injects custom CSS into its shadow root through `unsafeCSS`. Here the tree lives in the light DOM, so ordinary page CSS reaches it. Unlayered page CSS overrides every `solid-trees` layer. Keep it small, local, and secondary. ```css title="tree-overrides.css" .project-tree [data-item-focused='true'] { text-decoration: underline; } ``` Do not start here. Do not rebuild the whole visual system from raw selectors. For a broad lookup of the supported styling surfaces, read [Styling and theming](/docs/reference/styling-and-theming). For icon-specific appearance changes, continue with [Customize icons](/docs/guides/customize-icons). # Overview (/docs) **solid-trees** uses one path-first model. It is a SolidJS 2 port of [`@pierre/trees`](https://trees.software): the model layer is vendored from upstream, and the view is a native Solid rewrite rendered into the light DOM. Selection, focus, search, rename, drag and drop, Git status, and row annotations all use canonical paths. These docs are guide-first. First, create a model and render it. Next, shape the tree data before it reaches the UI. Then add search, item actions, styling, icons, or row signals when you need them. Create a model with `createFileTree` and render it with ``. The path-first vocabulary behind every option and event. # Differences from @pierre/trees (/docs/reference/differences-from-pierre-trees) `solid-trees` vendors upstream's model layer (path store, controller, focus, selection, search, rename, drag and drop, Git status). The view is a native Solid 2 rewrite of upstream's Preact `FileTreeView`, rendered into the light DOM, with upstream's visual styles shipped as an importable stylesheet. ## Runtimes [#runtimes] - One runtime: `createFileTree(...)` plus ``. There is no React wrapper, vanilla `FileTree` class, `render(...)`, or `hydrate(...)`. - No SSR or hydration: no `preloadFileTree(...)`, `@pierre/trees/ssr` entry, or `preloadedData` prop. The tree renders on the client. ## DOM and styling [#dom-and-styling] - No shadow DOM, custom element, or `unsafeCSS`; use page CSS. - The DOM keeps upstream's data attributes (`data-type="item"`, `data-item-path`, `data-item-selected`, `data-item-focused`, `data-item-git-status`, `data-item-section`, `data-file-tree-sticky-row`, ...) and name markup (`MiddleTruncate` / `Truncate`), so upstream CSS ports over. - `themeToTreeStyles` returns CSS property names (`background-color`), not React's camelCase. - The scrollbar gutter (`--trees-scrollbar-gutter-measured`) is measured once per document, not per tree. ## Composition [#composition] - Header and context-menu content are Solid JSX (`header`, `renderContextMenu` props); `composition.contextMenu` keeps the behavior flags (`enabled`, `triggerMode`, `buttonVisibility`) and `onOpen`/`onClose`. ## Icons [#icons] - Each tree prefixes the symbol ids of its sprite sheet (built-in set plus `icons.spriteSheet`) so several trees in one document never resolve each other's icons; names a sheet does not define resolve document-wide. # Icons (/docs/reference/icons) This page is the lookup reference for icon sets, icon remaps, sprite-sheet extension, and icon-specific configuration rules. ## Entry points [#entry-points] Built-in set selection: - `icons: 'minimal' | 'standard' | 'complete'` - `minimal` keeps the visual noise low - `standard` adds common language and file-type icons - `complete` has the broadest built-in coverage, and is the default Object configuration: - use `FileTreeIconConfig` when a string set is not enough - combine a base set with color toggles, slot remaps, or file-specific remaps ## Configuration shape [#configuration-shape] Base set and color mode: - `set?: 'minimal' | 'standard' | 'complete' | 'none'` - `colored?: boolean` `set: 'none'` turns off the built-in file-type mappings. File rows still fall back to the generic file icon. Remaps can replace that icon. When you pass custom rules without a `set`, it defaults to `'none'`. Sprite-sheet extension: - `spriteSheet?: string` - supply an SVG string with `` definitions that remaps can target Built-in slot remapping: - `remap?: Record` - common slots: `file-tree-icon-chevron`, `file-tree-icon-file`, `file-tree-icon-dot` (modified state), `file-tree-icon-lock` (locked path) File-specific remapping: - `byFileName` for exact basename matches such as `package.json` - `byFileNameContains` for basename substring rules such as `dockerfile` - `byFileExtension` for extension rules without a leading dot, and for multi-part suffixes such as `spec.ts` ## Resolution order [#resolution-order] File icon lookup resolves in this order: 1. exact basename match from `byFileName` 2. basename-contains match from `byFileNameContains` 3. extension match from `byFileExtension`, and the more specific suffix wins 4. built-in set mapping 5. generic file-slot remap or fallback So `spec.ts` wins over `ts` when both rules exist. ## `RemappedIcon` shape [#remappedicon-shape] `RemappedIcon` supports two forms: - a string symbol id - an object with `name`, and optional `width`, `height`, and `viewBox` Use the object form when the replacement symbol needs non-default geometry metadata. ## Sprite sheets and several trees [#sprite-sheets-and-several-trees] Each tree prefixes the symbol ids of its sprite sheet (the built-in set plus `icons.spriteSheet`), so several trees in one document never resolve each other's icons. Names a sheet does not define resolve document-wide. `getBuiltInSpriteSheet(...)` and `createFileTreeIconResolver(...)` expose the built-in sheet and the lookup for custom rendering. ## Runtime touchpoints [#runtime-touchpoints] - pass the icon configuration to `createFileTree(...)` - update it later with `setIcons(...)` For the lookup around those touchpoints, read [Solid API](/docs/reference/solid-api) and [Model API](/docs/reference/model-api). ## Icon color interplay [#icon-color-interplay] Turn off the built-in colored icons with `colored: false`. The token lookup and the fallback precedence for icon colors are in [Styling and theming](/docs/reference/styling-and-theming). ## Related pages [#related-pages] - [Customize icons](/docs/guides/customize-icons) for the walkthrough - [Style and theme the tree](/docs/guides/style-and-theme-the-tree) for broader appearance changes # Model API (/docs/reference/model-api) `FileTreeModel` is the imperative model surface behind every tree. Create it with `createFileTree(...)`; the class is also exported for type annotations and for code that must own the lifecycle itself. ## Model-first story [#model-first-story] Create the model. Then render it with ``. ```ts title="model.ts" import { createFileTree } from 'solid-trees'; const tree = createFileTree({ paths: ['README.md', 'src/index.ts'], search: true, }); tree.focusPath('src/index.ts'); tree.openSearch('index'); ``` For shared option meanings, read [Shared concepts](/docs/reference/shared-concepts#shared-option-groups). ## Lifecycle [#lifecycle] `createFileTree(options)` - accepts the shared options surface - creates the model one time - expects later updates through model methods; do not rebuild option objects for every render `cleanUp()` - final teardown: subscription cleanup and model destruction. The owner calls it for you when the model came from `createFileTree(...)` inside a reactive owner. `getId()` - returns the tree's identity from the `id` option ## Read APIs [#read-apis] Common read methods are: - `getItem(path)` - `getFocusedItem()` - `getFocusedPath()` - `getFocusedIndex()` - `getVisibleCount()` - `getVisibleRows(start, end)` - `getSelectedPaths()` - `getComposition()` - `isSearchOpen()` - `getSearchValue()` - `getSearchMatchingPaths()` - `getItemHeight()` / `getDensityFactor()` These reads stay path-oriented and model-oriented. They do not ask you to infer the tree state from DOM order. Inside Solid scopes they track, so JSX and memos update when the model changes. ## Item handles [#item-handles] `getItem(path)` returns a file handle, a directory handle, or `null`. Shared handle actions: - `getPath()` - `focus()` - `select()` - `toggleSelect()` - `deselect()` - `isFocused()` / `isSelected()` / `isDirectory()` Directory-only actions: - `expand()` - `collapse()` - `toggle()` - `isExpanded()` ## Write and control APIs [#write-and-control-apis] Focus and selection control: - `focusPath(path)` - `focusNearestPath(path | null)` - `focusFirstItem()` / `focusLastItem()` - `focusNextItem()` / `focusPreviousItem()` - `focusParentItem()` - `scrollToPath(path, { offset: 'top' | 'center' | 'nearest', focus?: boolean })` - `startRenaming(path?)` - item-handle selection and focus methods `scrollToPath(...)` scrolls the virtualizer without moving DOM focus. It updates model focus by default. Pass `focus: false` to keep model focus unchanged. The traversal methods follow the current visible tree, including its active expansion and search state. `getVisibleRows(start, end)` uses inclusive row indexes and returns path-first row metadata for building custom navigation. Search control: - `setSearch(value)` - `openSearch(initialValue?)` - `closeSearch()` - `focusNextSearchMatch()` - `focusPreviousSearchMatch()` Data and mutation control: - `add(path)` - `remove(path, options?)` - `move(fromPath, toPath, options?)` - `batch(operations)` - `resetPaths(paths, options?)` or `resetPaths({ preparedInput })` - `onMutation(type, handler)` Runtime reconfiguration helpers: - `setComposition(composition?)` - `setGitStatus(gitStatus?)` - `applyGitStatusPatch({ set?, remove? })` - `setIcons(icons?)` - `setLabels(labels?)` To localize the text the tree renders (the search placeholder, accessible names, and git status tooltips), pass a `labels` option at construction or call `setLabels(...)` later. Any label you leave out falls back to its English default from `DEFAULT_FILE_TREE_LABELS`. ## Subscriptions and external systems [#subscriptions-and-external-systems] Use `subscribe(listener)` when code outside Solid must refresh a derived snapshot on any tree change. Use `onMutation(...)` when add, remove, move, reset, or batch intent matters. Both return an unsubscribe function. This separation keeps model subscriptions for state reads. It keeps mutation events for semantic side effects. ## Composition surface [#composition-surface] The composition surface covers: - header content, through the `header` prop of `` - context-menu behavior, through `composition.contextMenu` - context-menu content, through the `renderContextMenu` prop of `` - runtime updates through `setComposition(...)` Read [Rename, drag, and trigger item actions](/docs/guides/rename-drag-and-trigger-item-actions) for workflow-level guidance. ## Appearance boundary [#appearance-boundary] This page names the runtime touchpoints such as `setGitStatus(...)` and `setIcons(...)`. For styling variables and theme helpers, read [Styling and theming](/docs/reference/styling-and-theming). For icon remaps and icon-set lookup, read [Icons](/docs/reference/icons). # Shared concepts (/docs/reference/shared-concepts) This page owns the shared language for `solid-trees`. Every option, primitive, and model method uses the same path-first identity model. They use the same tree-defining inputs. They use the same mutation vocabulary. ## Path-first identity [#path-first-identity] Canonical path strings are the public identity for tree items. Use paths for: - selection values - focused-item lookups - search matches - rename and drag-and-drop events - Git status attachment - row annotations Files and directories share the same identity space. The APIs mark the item kind when that difference matters. ## Input shapes [#input-shapes] `solid-trees` accepts three related input shapes: - `paths`: the low-ceremony path for demos, tests, and small static trees - `preparedInput`: the recommended scale-oriented input shape - presorted prepared input: the highest-performance prepared-input path when the server already knows the final order Use `prepareFileTreeInput(...)` and `preparePresortedFileTreeInput(...)` from `solid-trees` to create the prepared forms. Treat prepared input as an opaque tree-input object. Do not build the shape by hand. ## Shared option groups [#shared-option-groups] This table lists the meaning of the `createFileTree(...)` options. | Option | Meaning | Typical use | | ------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------ | | `paths` | Raw canonical path list. | Small demos, tests, very small static trees. | | `preparedInput` | Pre-shaped tree input created ahead of render. | Recommended input for larger trees. | | `id` | Stable identity for the tree. | Set a predictable DOM id (`__tree`) on the rendered root. | | `initialExpansion` | Baseline expansion policy for the first render. | Start broadly open, broadly closed, or at a specific depth. | | `initialExpandedPaths` | Specific paths that should begin expanded. | Keep key folders open on first render. | | `initialSelectedPaths` | Paths selected on first render. | Seed selection for previews or restored state. | | `flattenEmptyDirectories` | Flattens chains of single-child directories into one visible row. | Compact repo-style trees. | | `sort` | Client-side ordering for non-presorted input. | Secondary path when order must be chosen in the client. | | `search` | Enables the built-in search surface and model search methods. | Searchable trees. | | `initialSearchQuery` | Starting search value. | Preloaded filtered views or restored search state. | | `fileTreeSearchMode` | Controls how matches change the visible tree. | Choose between filtering, collapsing, or expanding around matches. | | `searchBlurBehavior` | Whether blurring the search input closes the search (`'close'`). | Keep a filter applied with `'retain'`. | | `onSearchChange` | Callback for search-value changes. | Sync surrounding controls or analytics. | | `onSelectionChange` | Callback for selection changes. | Update sibling UI that tracks current selection. | | `dragAndDrop` | Enables drag and drop plus its policy hooks. | Editable trees. | | `renaming` | Enables inline rename plus policy hooks. | Rename-in-place workflows. | | `composition` | Context-menu behavior flags and lifecycle callbacks. | Choose the menu trigger and button visibility. | | `gitStatus` | Built-in Git-style row signals. | Added, modified, deleted, ignored, renamed, and untracked states. | | `icons` | Built-in icon set or icon configuration object. | Set selection, color mode, remaps, or sprite-sheet extension. | | `labels` | User-visible text the tree renders. | Localize the search placeholder, accessible names, and tooltips. | | `renderRowDecoration` | Custom non-Git row signal renderer. | Generated-file badges, remote markers, validation hints. | | `density` | Density preset or custom spacing factor. | Tune row height and spacing in one place. | | `itemHeight` | Explicit row-height override. | Row height that doesn't match a `density` preset. | | `overscan` | Extra rows rendered outside the visible window. | Smooth scrolling tradeoffs. | | `initialVisibleRowCount` | Optional first-render row budget before the browser measures height. | Tune first-render work without pinning steady-state size. | | `stickyFolders` | Pins the ancestor folders of the top row while scrolling. | Keep context visible in deep trees. | ## Tree-shape options [#tree-shape-options] The tree-shape options are `paths`, `preparedInput`, `initialExpansion`, `initialExpandedPaths`, `flattenEmptyDirectories`, and `sort`. Use them to answer three questions: 1. where the tree data comes from 2. what the initial visible shape must be 3. whether the client must still shape or sort the data For the recommended setup, read [Shape tree data for fast rendering](/docs/guides/shape-tree-data-for-fast-rendering). ## Search mode semantics [#search-mode-semantics] `solid-trees` supports three search modes: - `hide-non-matches`: shows only the matches and the ancestor chain that keeps them navigable. This is the guide default. - `collapse-non-matches`: keeps the matching paths and the ancestor chain visible. It collapses unrelated branches out of the way. - `expand-matches`: expands the matching branches into the surrounding tree context. It keeps non-matching rows visible. The built-in search input, `createFileTreeSearch(...)`, and the model search methods all use the same search modes. ## Selection, focus, and item handles [#selection-focus-and-item-handles] Selection is path-based. Focus is path-based. Item handles are path-oriented helpers for a known item. Common lookup topics are: - get an item by path - read the focused and selected state - focus, select, toggle, or deselect through the model or item handle - expand, collapse, or toggle directories through a directory handle Read [Navigate selection, focus, and search](/docs/guides/navigate-selection-focus-and-search) for workflows. Read [Solid API](/docs/reference/solid-api) for the reactive primitives. Read [Model API](/docs/reference/model-api) for direct model methods. ## Interaction and editing options [#interaction-and-editing-options] `dragAndDrop`, `renaming`, and `composition` are the editing surfaces. They share the same path-first event model. Header and context-menu content are Solid JSX, passed to `` as the `header` and `renderContextMenu` props. Read [Rename, drag, and trigger item actions](/docs/guides/rename-drag-and-trigger-item-actions) for the user-facing workflows that build on those options. ## Appearance and annotation options [#appearance-and-annotation-options] `gitStatus`, `icons`, and `renderRowDecoration` all affect how rows look. But they do different jobs: - `gitStatus` is the built-in Git-style signal lane - `icons` controls icon sets, remaps, and sprite-sheet extension - `renderRowDecoration` adds non-Git row metadata Page CSS is the narrow fallback when public styling surfaces are not enough. For deeper lookup, read [Styling and theming](/docs/reference/styling-and-theming) and [Icons](/docs/reference/icons). ## Scale and rendering settings [#scale-and-rendering-settings] `initialVisibleRowCount`, `density`, `itemHeight`, and `overscan` are rendering knobs, not onboarding concepts. The rendered container sets the steady-state height. These options only tune the first-render budget, the visual density, and the virtualized row window. For density, use the `density` keyword (`'compact' | 'default' | 'relaxed'`) or a numeric factor. It sets both the row height and the spacing in one place. `` paints `--trees-item-height` and `--trees-density-override` for you. Use `itemHeight` only when you need a row height that does not match a preset. Read [Handle large trees efficiently](/docs/guides/handle-large-trees-efficiently) when scale becomes the real problem. ## Mutation vocabulary [#mutation-vocabulary] `solid-trees` exposes semantic tree mutations, not DOM events. The shared mutation terms are: - `add` - `remove` - `move` - `batch` - `resetPaths` - `onMutation` Mutation payloads stay path-first. Reset events also report whether prepared input was involved. Invalidation metadata reports whether the canonical state or the projected visible state changed. Use these events to sync adjacent UI, analytics, or persistence layers. Do not turn them into a filesystem-sync tutorial. # Solid API (/docs/reference/solid-api) Everything lives at the package root, `solid-trees`. The Solid layer is a thin integration over one imperative model, `FileTreeModel`. ## Model-first story [#model-first-story] Start with `createFileTree(options)`. Do not build a large controlled component. The primitive creates one stable model for the owner's lifetime. Later option changes do not reconfigure the model. Update the model through model methods instead. ```tsx title="project-tree.tsx" import { createFileTree, FileTree } from 'solid-trees'; export function ProjectTree(props: { paths: readonly string[] }) { const tree = createFileTree({ paths: props.paths, search: true }); return ; } ``` For the shared option meanings behind that call, read [Shared concepts](/docs/reference/shared-concepts#shared-option-groups). ## `createFileTree(...)` [#createfiletree] `createFileTree(...)`: - accepts the shared tree-options surface - creates the model one time - cleans up the model when the current reactive owner disposes (called outside an owner, call `cleanUp()` yourself) - returns the `FileTreeModel` Use model methods when the tree changes after mount. The methods include `resetPaths(...)`, `setComposition(...)`, `setGitStatus(...)`, `setIcons(...)`, `setLabels(...)`, and the search or mutation methods. ## `` [#filetree-] The Solid component renders the model into the light DOM. Primary props: - `model` - normal host HTML attributes such as `class` and `style` Composition props: - `header` - `renderContextMenu` Behavior notes: - it renders a virtualized list, so give it a bounded height - swapping the `model` prop remounts the view - the root DOM id comes from the model's `id` option (`__tree`), not an `id` prop - `header` and `renderContextMenu` add Solid rendering onto the model composition surface ## Reading tree state from Solid [#reading-tree-state-from-solid] Model getters track inside Solid scopes and always return current values imperatively. Read them directly in JSX, or derive values through the primitives below. Solid code writes back through model methods. Common read patterns include: - selected paths for sibling panels or action bars - search state for search inputs and result counts - custom derived values such as "is this path focused?" ## Primitives [#primitives] `createFileTreeSelector(model, selector, isEqual?)` - generic bridge from the model into a Solid memo - returns an accessor for a value selected from the current model - accepts an optional equality function when the selected value needs custom comparison; `areArraysEqual` covers path lists `createFileTreeSelection(model)` - convenience accessor for `readonly string[]` selected paths `createFileTreeSearch(model)` - returns the current search snapshot as the `state` accessor, plus the model-backed actions - snapshot fields: `isOpen`, `matchingPaths`, `value` - actions: `open(initialValue?)`, `close()`, `setValue(value)`, `focusNextMatch()`, `focusPreviousMatch()` ```tsx title="primitives.tsx" const tree = createFileTree({ paths, search: true }); const selectedPaths = createFileTreeSelection(tree); const search = createFileTreeSearch(tree); const focusedPath = createFileTreeSelector(tree, (model) => model.getFocusedPath() ); ``` ## Writing to the model from Solid [#writing-to-the-model-from-solid] Solid writes through the imperative model methods. Typical write paths are: - focus and selection methods on the model or item handles. This includes `scrollToPath(...)`, which reveals a path without moving DOM focus and makes optional model focus changes. - visible-tree traversal through `focusFirstItem()`, `focusLastItem()`, `focusNextItem()`, `focusPreviousItem()`, and `focusParentItem()`. - visible row inspection through `getFocusedIndex()`, `getVisibleCount()`, and `getVisibleRows(start, end)` when surrounding UI needs custom navigation. - search methods such as `setSearch(...)` and `openSearch(...)` - mutation methods such as `add(...)`, `remove(...)`, `move(...)`, `batch(...)`, and `resetPaths(...)` - runtime reconfiguration methods such as `setComposition(...)`, `setGitStatus(...)`, `setIcons(...)`, and `setLabels(...)` The full list is in [Model API](/docs/reference/model-api). ## Composition surface [#composition-surface] `` adds two composition props on top of the model: - `header` for Solid-rendered header content, above the search input and rows - `renderContextMenu(item, context)` for Solid-rendered context menus; providing it enables the menu Use `composition.contextMenu` on the model for the behavior flags (`enabled`, `triggerMode`, `buttonVisibility`) and the `onOpen` / `onClose` callbacks. The shared meaning of the composition options is in [Shared concepts](/docs/reference/shared-concepts#interaction-and-editing-options). ## Mutation and subscriptions from Solid [#mutation-and-subscriptions-from-solid] Use primitives and tracked getters when Solid UI needs reactive reads. Use `model.onMutation(...)` when you need semantic side effects. Examples are persistence, logging, or analytics around add, remove, move, reset, or batch operations. ## Appearance boundary [#appearance-boundary] Style the host with normal host props such as `class` and `style`. For deeper lookup, read [Styling and theming](/docs/reference/styling-and-theming) and [Icons](/docs/reference/icons). # Styling and theming (/docs/reference/styling-and-theming) This page is the lookup reference for host styling, CSS-variable families, `themeToTreeStyles(...)`, the stylesheet layers, and page CSS. ## Styling entry points [#styling-entry-points] Host styling comes first. Use normal host `class` and `style` props on ``. Host styles own width, height, borders, background, and panel placement. CSS variables control the UI inside that host. Import the stylesheet once: ```ts title="main.ts" import 'solid-trees/styles.css'; ``` ## CSS custom property families [#css-custom-property-families] The tree styling surface uses variable families, not one flat list. Core families include: - panel, background, and foreground tokens - hover, selection, and focus tokens - input and search tokens - Git-status color tokens - icon color tokens for supported built-in icon sets - density and spacing tokens ## Fallback precedence [#fallback-precedence] `solid-trees` resolves styling in this order: 1. explicit override variables such as `--trees-*-override` 2. `--trees-theme-*` variables from theme helpers 3. library defaults So `themeToTreeStyles(...)` fills the middle layer. Direct overrides still win. ## `themeToTreeStyles(...)` [#themetotreestyles] `themeToTreeStyles(theme)` maps a VS Code or Shiki-style theme object into host styles. It also maps the theme to the `--trees-theme-*` variables that the tree understands. Input shape: - `TreeThemeInput` - key fields: `type`, `colors` Output shape: - `TreeThemeStyles` - keyed by CSS property names (`background-color`, not `backgroundColor`), so it works directly as a Solid `style` object ```ts title="theme-to-tree-styles.ts" import { themeToTreeStyles } from 'solid-trees'; const treeStyles = themeToTreeStyles(theme); ``` The helper covers panel colors, selection colors, focus rings, input colors, and Git-status colors. Explicit overrides can still replace any derived token later. ## Scoping and layers [#scoping-and-layers] Every rule sits in `@scope ([data-file-tree-virtualized-root])`. Header and context-menu content is excluded from the scope; it still inherits color and font from the root. The stylesheet uses three cascade layers: `@layer solid-trees.structure, solid-trees.base, solid-trees.theme`. - `solid-trees.structure` holds the virtualizer layout, row lanes, and truncation mechanics. `` injects it itself, so trees work without the stylesheet. - `solid-trees.base` comes from `solid-trees/styles.css`. - `solid-trees.theme` is reserved for your theme rules. Unlayered page CSS overrides every layer. ## Page resets [#page-resets] The base layer starts with a reset for the tree's own controls, so element rules from layers declared earlier (for example Tailwind's preflight in `@layer base`) do not leak into rows. Rules in later layers or unlayered rules still win. Import `solid-trees/styles.css` after your reset, or declare the order up front: ```css title="layers.css" @layer theme, base, components, utilities, solid-trees; ``` ## Color scheme [#color-scheme] The root sets `color-scheme: light dark`, so colors follow the OS preference. Pin it with `style={{ 'color-scheme': 'dark' }}` or CSS. ## Page CSS escape hatch [#page-css-escape-hatch] The tree renders into the light DOM, so page CSS reaches it. It replaces upstream's `unsafeCSS`. Use it only when the supported host and variable surfaces cannot express the customization. The DOM keeps upstream's data attributes (`data-type="item"`, `data-item-path`, `data-item-selected`, `data-item-focused`, `data-item-git-status`, `data-item-section`, `data-file-tree-sticky-row`, ...), so upstream CSS ports over. The focused row's parent indent guide carries `data-item-guide-focused="true"`. Keep it narrow. Do not rebuild the visual system from raw selectors. ## Related pages [#related-pages] - [Style and theme the tree](/docs/guides/style-and-theme-the-tree) for the walkthrough - [Icons](/docs/reference/icons) for icon-specific configuration - [Show Git status and row annotations](/docs/guides/show-git-status-and-row-annotations) for signal meaning