Skip to content

Commit 4fe6382

Browse files
initial version
Signed-off-by: Phillip Kruger <[email protected]>
1 parent df7ce92 commit 4fe6382

File tree

7 files changed

+10695
-0
lines changed

7 files changed

+10695
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# qui-directory-tree
2+
A Lit-based web component to show files in a directory structure.
3+
4+
## Installation
5+
6+
```bash
7+
npm i @qomponent/qui-directory-tree
8+
```
9+
10+
## Usage
11+
12+
```javascript
13+
14+
15+
import { LitElement, html, css } from 'lit';
16+
import '@qomponent/qui-directory-tree';
17+
18+
class MyMainComponent extends LitElement {
19+
static styles = css`
20+
.file-info {
21+
font-weight: bold;
22+
color: blue;
23+
margin-top: 10px;
24+
}
25+
`;
26+
27+
static properties = {
28+
selectedFilePath: { type: String },
29+
};
30+
31+
constructor() {
32+
super();
33+
this.selectedFilePath = '';
34+
this.directoryData = [
35+
{
36+
name: 'Folder1',
37+
type: 'folder',
38+
children: [
39+
{ name: 'File1.txt', type: 'file' },
40+
{
41+
name: 'SubFolder1',
42+
type: 'folder',
43+
children: [{ name: 'File2.txt', type: 'file' }],
44+
},
45+
],
46+
},
47+
{ name: 'File3.txt', type: 'file' },
48+
];
49+
}
50+
51+
handleFileSelect(event) {
52+
const { file } = event.detail;
53+
this.selectedFilePath = file.path;
54+
}
55+
56+
render() {
57+
return html`
58+
<h2>Directory Tree</h2>
59+
<qui-directory-tree
60+
.directory="${this.directoryData}"
61+
header="Files and Folders"
62+
@file-select="${this.handleFileSelect}"
63+
></qui-directory-tree>
64+
65+
${this.selectedFilePath
66+
? html`<div class="file-info">Selected File Path: ${this.selectedFilePath}</div>`
67+
: html`<div class="file-info">No file selected</div>`}
68+
`;
69+
}
70+
}
71+
72+
customElements.define('my-main-component', MyMainComponent);
73+
74+
75+
```
76+
77+
## Example
78+
79+
To run the example:
80+
81+
```bash
82+
npm install
83+
npm start
84+
```
85+
86+
## Contributing
87+
88+
Pull requests are welcome. For major changes, please open an issue first
89+
to discuss what you would like to change.
90+
91+
## License
92+
93+
[Apache 2](http://www.apache.org/licenses/LICENSE-2.0)

example/index.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<title>Directory tree web component demo</title>
4+
<script type="module" src="./qui-directory-tree.js"></script>
5+
<style>
6+
.row {
7+
display: flex;
8+
align-items: baseline;
9+
}
10+
.col {
11+
display: flex;
12+
flex-direction: column;
13+
gap: 20px;
14+
}
15+
</style>
16+
17+
</head>
18+
<body>
19+
<h1>Directory Tree</h1>
20+
<!-- Use the directory tree component -->
21+
<qui-directory-tree></qui-directory-tree>
22+
23+
<script>
24+
// Define sample data for the directory structure
25+
const directoryData = [
26+
{
27+
name: 'Folder1',
28+
type: 'folder',
29+
children: [
30+
{ name: 'File1.txt', type: 'file' },
31+
{
32+
name: 'SubFolder1',
33+
type: 'folder',
34+
children: [{ name: 'File2.txt', type: 'file' }],
35+
},
36+
],
37+
},
38+
{ name: 'File3.txt', type: 'file' },
39+
];
40+
41+
// Set the directory data to the component
42+
const treeComponent = document.querySelector('qui-directory-tree');
43+
treeComponent.directory = directoryData;
44+
45+
treeComponent.addEventListener('file-select', (event) => {
46+
console.log('File selected:', event.detail.file);
47+
});
48+
</script>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)