-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetails.svelte
94 lines (81 loc) · 1.54 KB
/
Details.svelte
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<style>
details {
position: relative;
}
details[open] {
margin-left: 0.25em;
padding-left: 0.5em;
}
details > div {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
gap: 0.5em;
}
summary {
cursor: pointer;
-webkit-user-select: none;
user-select: none;
}
details[open] summary {
margin-bottom: 0.25em;
}
/* Cover left details border near summary */
/*
details[open] summary::before {
content: "";
display: inline-block;
width: 3px;
height: 1.5em;
position: absolute;
left: -1px;
background: var(--bg-color);
z-index: 1;
}
*/
button {
position: absolute;
top: 0;
bottom: 0;
left: -5px;
width: 10px;
border: 0;
cursor: pointer;
display: flex;
flex-direction: row;
justify-content: center;
align-items: stretch;
background: none;
}
button div {
width: 0;
border-left: 1px dashed var(--fg-color);
}
button:hover div {
border-left: 2px solid var(--fg-color);
}
button:active div {
border-left: 3px solid var(--fg-color);
}
</style>
<script>
let { summary, children, ...rest } = $props();
let details;
</script>
<details bind:this={details} {...rest}>
<summary>
{#if summary}
{@render summary()}
{:else}
Details
{/if}
</summary>
<div>
{@render children?.()}
</div>
<button
aria-label="Collapse details"
onclick={() => details.removeAttribute("open")}><div></div></button
>
</details>