|
| 1 | +--- |
| 2 | +title: Files |
| 3 | +description: Display interactive file tree structures with expandable folders |
| 4 | +--- |
| 5 | + |
| 6 | +The `<Files>` component creates visual file tree structures with expandable folders and nested files. Use it to show project structures, directory layouts, or any hierarchical file organization in your documentation. |
| 7 | + |
| 8 | +The component consists of three parts: `<Files>` as the container, `<Folder>` for directories, and `<File>` for individual files. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +<div className="highlight-frame"> |
| 13 | +<Files> |
| 14 | + <Folder name="components" defaultOpen> |
| 15 | + <File name="accordion.mdx" /> |
| 16 | + <File name="button.mdx" /> |
| 17 | + <File name="card.mdx" /> |
| 18 | + <File name="tabs.mdx" /> |
| 19 | + </Folder> |
| 20 | + <Folder name="assets"> |
| 21 | + <File name="styles.css" /> |
| 22 | + </Folder> |
| 23 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 24 | + <File name="README.md" /> |
| 25 | +</Files> |
| 26 | +</div> |
| 27 | + |
| 28 | +```jsx Markdown maxLines=10 |
| 29 | +<Files> |
| 30 | + <Folder name="components" defaultOpen> |
| 31 | + <File name="accordion.mdx" /> |
| 32 | + <File name="button.mdx" /> |
| 33 | + <File name="card.mdx" /> |
| 34 | + <File name="tabs.mdx" /> |
| 35 | + </Folder> |
| 36 | + <Folder name="assets"> |
| 37 | + <File name="styles.css" /> |
| 38 | + </Folder> |
| 39 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 40 | + <File name="README.md" /> |
| 41 | +</Files> |
| 42 | +``` |
| 43 | + |
| 44 | +## Variants |
| 45 | + |
| 46 | +### Nested folders |
| 47 | + |
| 48 | +You can nest folders within folders to create deep directory structures. The component automatically adds visual nesting lines to show the hierarchy. |
| 49 | + |
| 50 | +<div className="highlight-frame"> |
| 51 | +<Files> |
| 52 | + <Folder name="components" defaultOpen> |
| 53 | + <Folder name="layout" defaultOpen> |
| 54 | + <File name="header.mdx" /> |
| 55 | + <File name="footer.mdx" /> |
| 56 | + <File name="sidebar.mdx" /> |
| 57 | + </Folder> |
| 58 | + <Folder name="ui"> |
| 59 | + <File name="button.mdx" /> |
| 60 | + <File name="card.mdx" /> |
| 61 | + <File name="tabs.mdx" /> |
| 62 | + </Folder> |
| 63 | + <File name="accordion.mdx" /> |
| 64 | + </Folder> |
| 65 | + <Folder name="assets"> |
| 66 | + <File name="styles.css" /> |
| 67 | + </Folder> |
| 68 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 69 | + <File name="README.md" /> |
| 70 | +</Files> |
| 71 | +</div> |
| 72 | + |
| 73 | +```jsx Markdown maxLines=10 |
| 74 | +<Files> |
| 75 | + <Folder name="components" defaultOpen> |
| 76 | + <Folder name="layout" defaultOpen> |
| 77 | + <File name="header.mdx" /> |
| 78 | + <File name="footer.mdx" /> |
| 79 | + <File name="sidebar.mdx" /> |
| 80 | + </Folder> |
| 81 | + <Folder name="ui"> |
| 82 | + <File name="button.mdx" /> |
| 83 | + <File name="card.mdx" /> |
| 84 | + <File name="tabs.mdx" /> |
| 85 | + </Folder> |
| 86 | + <File name="accordion.mdx" /> |
| 87 | + </Folder> |
| 88 | + <Folder name="assets"> |
| 89 | + <File name="styles.css" /> |
| 90 | + </Folder> |
| 91 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 92 | + <File name="README.md" /> |
| 93 | +</Files> |
| 94 | +``` |
| 95 | + |
| 96 | +### Linked files and folders |
| 97 | + |
| 98 | +Add the `href` property to make files or folders clickable. This is useful for linking to documentation pages, GitHub repositories, or other resources. |
| 99 | + |
| 100 | +<div className="highlight-frame"> |
| 101 | +<Files> |
| 102 | + <Folder name="components"> |
| 103 | + <File name="accordion.mdx" href="/docs/writing-content/components/accordions" /> |
| 104 | + <File name="button.mdx" href="/docs/writing-content/components/button" /> |
| 105 | + <File name="card.mdx" href="/docs/writing-content/components/cards" /> |
| 106 | + <File name="tabs.mdx" href="/docs/writing-content/components/tabs" /> |
| 107 | + </Folder> |
| 108 | + <Folder name="assets"> |
| 109 | + <File name="styles.css" href="https://github.com/fern-api/docs/blob/main/fern/assets/styles.css" /> |
| 110 | + </Folder> |
| 111 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 112 | + <File name="README.md" href="https://github.com/fern-api/docs/blob/main/README.md" /> |
| 113 | +</Files> |
| 114 | +</div> |
| 115 | + |
| 116 | +```jsx Markdown maxLines=10 |
| 117 | +<Files> |
| 118 | + <Folder name="components"> |
| 119 | + <File name="accordion.mdx" href="/docs/writing-content/components/accordions" /> |
| 120 | + <File name="button.mdx" href="/docs/writing-content/components/button" /> |
| 121 | + <File name="card.mdx" href="/docs/writing-content/components/cards" /> |
| 122 | + <File name="tabs.mdx" href="/docs/writing-content/components/tabs" /> |
| 123 | + </Folder> |
| 124 | + <Folder name="assets"> |
| 125 | + <File name="styles.css" href="https://github.com/fern-api/docs/blob/main/fern/assets/styles.css" /> |
| 126 | + </Folder> |
| 127 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 128 | + <File name="README.md" href="https://github.com/fern-api/docs/blob/main/README.md" /> |
| 129 | +</Files> |
| 130 | +``` |
| 131 | + |
| 132 | +### Default open folders |
| 133 | + |
| 134 | +Use the `defaultOpen` property to have specific folders expanded when the page loads. This is useful for highlighting important directories or showing the most relevant parts of a file structure. |
| 135 | + |
| 136 | +<div className="highlight-frame"> |
| 137 | +<Files> |
| 138 | + <Folder name="components" defaultOpen> |
| 139 | + <File name="accordion.mdx" /> |
| 140 | + <File name="button.mdx" /> |
| 141 | + <File name="card.mdx" /> |
| 142 | + <File name="tabs.mdx" /> |
| 143 | + </Folder> |
| 144 | + <Folder name="assets"> |
| 145 | + <File name="styles.css" /> |
| 146 | + </Folder> |
| 147 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 148 | + <File name="README.md" /> |
| 149 | +</Files> |
| 150 | +</div> |
| 151 | + |
| 152 | +```jsx Markdown maxLines=10 |
| 153 | +<Files> |
| 154 | + <Folder name="components" defaultOpen> |
| 155 | + <File name="accordion.mdx" /> |
| 156 | + <File name="button.mdx" /> |
| 157 | + <File name="card.mdx" /> |
| 158 | + <File name="tabs.mdx" /> |
| 159 | + </Folder> |
| 160 | + <Folder name="assets"> |
| 161 | + <File name="styles.css" /> |
| 162 | + </Folder> |
| 163 | + <File name="markdown.mdx" href="/learn/docs/writing-content/markdown" /> |
| 164 | + <File name="README.md" /> |
| 165 | +</Files> |
| 166 | +``` |
| 167 | + |
| 168 | +## Properties |
| 169 | + |
| 170 | +### `<Files>` properties |
| 171 | + |
| 172 | +<ParamField path="children" type="JSX" required={true}> |
| 173 | + The file tree content. Should contain `<Folder>` and `<File>` components. |
| 174 | +</ParamField> |
| 175 | + |
| 176 | +<ParamField path="className" type="string" required={false}> |
| 177 | + Optional CSS class name for custom styling. |
| 178 | +</ParamField> |
| 179 | + |
| 180 | +### `<Folder>` properties |
| 181 | + |
| 182 | +<ParamField path="name" type="string" required={true}> |
| 183 | + The folder name to display. |
| 184 | +</ParamField> |
| 185 | + |
| 186 | +<ParamField path="defaultOpen" type="boolean" default={false}> |
| 187 | + Whether the folder should be expanded when the page loads. If not specified, the folder will be collapsed by default. |
| 188 | +</ParamField> |
| 189 | + |
| 190 | +<ParamField path="children" type="JSX" required={false}> |
| 191 | + The nested content within the folder. Can include `<File>` and other `<Folder>` components. |
| 192 | +</ParamField> |
| 193 | + |
| 194 | +<ParamField path="href" type="string" required={false}> |
| 195 | + Optional URL to make the folder name clickable. The name will show an underline on hover when a link is provided. |
| 196 | +</ParamField> |
| 197 | + |
| 198 | +<ParamField path="className" type="string" required={false}> |
| 199 | + Optional CSS class name for custom styling. |
| 200 | +</ParamField> |
| 201 | + |
| 202 | +### `<File>` properties |
| 203 | + |
| 204 | +<ParamField path="name" type="string" required={true}> |
| 205 | + The file name to display. |
| 206 | +</ParamField> |
| 207 | + |
| 208 | +<ParamField path="href" type="string" required={false}> |
| 209 | + Optional URL to make the file name clickable. The name will show an underline on hover when a link is provided. |
| 210 | +</ParamField> |
| 211 | + |
| 212 | +<ParamField path="className" type="string" required={false}> |
| 213 | + Optional CSS class name for custom styling. |
| 214 | +</ParamField> |
0 commit comments