-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathExampleFileTree.tsx
More file actions
32 lines (29 loc) · 1017 Bytes
/
ExampleFileTree.tsx
File metadata and controls
32 lines (29 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import FileTree from '@tutorialkit/react/core/FileTree';
import { useState, type ComponentProps } from 'react';
export default function ExampleFileTree() {
const [files, setFiles] = useState(INITIAL_FILES);
const [selectedFile, setSelectedFile] = useState(INITIAL_FILES[0].path);
return (
<FileTree
files={files}
hideRoot
className="my-file-tree"
hiddenFiles={['package-lock.json']}
selectedFile={selectedFile}
onFileSelect={setSelectedFile}
onFileChange={async (event) => {
if (event.method === 'add') {
setFiles([...files, { path: event.value, type: event.type }]);
}
}}
/>
);
}
const INITIAL_FILES: ComponentProps<typeof FileTree>['files'] = [
{ path: '/package-lock.json', type: 'file' },
{ path: '/package.json', type: 'file' },
{ path: '/src/assets/logo.svg', type: 'file' },
{ path: '/src/index.html', type: 'file' },
{ path: '/src/index.js', type: 'file' },
{ path: '/vite.config.js', type: 'file' },
];