File trees

Components•3 min read|
|

Display directory structures and hierarchical data with file tree and generic tree components.

File tree

Use wc-files, wc-dir, and wc-file to render a directory structure:

<wc-files> <wc-dir name="my-docs" open> <wc-file name="docslit.json" highlight></wc-file> <wc-dir name="docs" open> <wc-file name="introduction.md"></wc-file> <wc-file name="quickstart.md"></wc-file> </wc-dir> <wc-dir name="components"> <wc-file name="my-widget.js"></wc-file> </wc-dir> <wc-dir name="dist"> <wc-file name="index.html"></wc-file> </wc-dir> </wc-dir> </wc-files>

A directory is open by default. Add collapsed to start it closed, highlight to draw attention to a row, comment for a short note after the name, and href to make a name a link. Files get an icon that follows their type.

<wc-files> <wc-dir name="src" comment="sources" highlight> <wc-file name="index.js" href="/0.3/getting-started/quickstart"></wc-file> <wc-file name="config.json" comment="settings"></wc-file> <wc-dir name="legacy" collapsed> <wc-file name="old.js"></wc-file> </wc-dir> </wc-dir> </wc-files> The directory name. Expand the directory. This is the default. Start the directory closed. Set to false for a non-interactive folder that is always open. Make the directory name a link. A short comment displayed after the name. Highlight the directory row. The file name. Highlight this file to draw attention to it. A short comment displayed after the file name. Make the file name a link.

Generic tree

For non-file hierarchies, use wc-tree and wc-tree-item:

<wc-tree> <wc-tree-item title="Organization" open> <wc-tree-item title="Engineering" open> <wc-tree-item title="Frontend"></wc-tree-item> <wc-tree-item title="Backend"></wc-tree-item> <wc-tree-item title="Infrastructure"></wc-tree-item> </wc-tree-item> <wc-tree-item title="Design"> <wc-tree-item title="Product design"></wc-tree-item> <wc-tree-item title="Brand"></wc-tree-item> </wc-tree-item> </wc-tree-item> </wc-tree>

Provide file downloads with wc-download:

<wc-download href="/assets/themes/peppermint-light.webp" filename="peppermint-light.webp" label="Download the screenshot" size="16 KB"></wc-download>

The link text comes from label, or from the text between the tags, then the file name, then "Download".

To bundle several files into one ZIP that is built in the reader's browser, use sources instead of href. The files must be readable from the page, which means the same origin or CORS enabled:

<wc-download sources="/assets/themes/frond-light.webp, /assets/themes/frond-dark.webp" filename="frond-screenshots.zip" label="Download both screenshots"></wc-download> The URL or path of the file. Not needed when you use sources. Comma-separated, space-separated or JSON-array URLs to bundle into one ZIP, instead of href. The suggested file name. With sources, it is the name of the ZIP, download.zip by default. The link text. File size text shown in parentheses, such as 2.4 MB.

Copy chip

Add a standalone copy-to-clipboard chip. It fits inline, so use it for versions, commands and keys:

Install with <wc-copy text="npm install -g docslit">npm install -g docslit</wc-copy>, or copy a different value than the one shown: <wc-copy clipboard="docslit init my-docs">docslit init</wc-copy>.

Install with npm install -g docslit, or copy a different value than the one shown: docslit init.

The text copied to the clipboard. Defaults to the text shown. The displayed text. Defaults to the text between the tags, then text. Copy this value instead of the displayed text.