-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathFileTreeItem.astro
More file actions
78 lines (68 loc) · 1.63 KB
/
FileTreeItem.astro
File metadata and controls
78 lines (68 loc) · 1.63 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
import Icon from "./Icon.astro";
import Tooltip from "./Tooltip.astro";
import { type IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {
faBan,
faFile,
faFileCode,
faFileImage,
faFolder,
} from "@fortawesome/free-solid-svg-icons";
const TYPE_ICONS: { [key: string]: IconDefinition } = {
file: faFile,
code: faFileCode,
image: faFileImage,
directory: faFolder,
};
const { name, type, open, gitignored } = Astro.props;
const icon = TYPE_ICONS[type];
if (icon === undefined) {
throw new Error(`Invalid file tree item type: ${type}`);
}
export interface Props {
/** Name of the file */
name: string;
/** Type of the entry. This dictates the icon that will be used */
type: "file" | "code" | "image" | "directory";
/** Whether it is ignored and should have a little "blocked" icon next to it. Defaults to false. */
gitignored?: boolean;
/** Whether this element should be open/expanded by default. Defaults to false. */
open?: boolean;
}
---
<details class="file-tree-item" open={open}>
<summary>
<Icon icon={icon} />
{name}
{
gitignored && (
<Tooltip content="Git ignored" placement="right">
<Icon icon={faBan} />
</Tooltip>
)
}
</summary>
<slot />
</details>
<style lang="scss">
details.file-tree-item {
summary {
list-style: none;
margin-left: 1em;
:global(i.fa-solid) {
margin-right: 0.5em;
}
:global(i.fa-ban) {
margin: 0px 0px 0px 1em;
}
}
:global(p) {
margin-top: 0px;
margin-bottom: 0px;
}
& > :global(*) {
margin-left: 2em;
}
}
</style>