forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebarItem.svelte
More file actions
99 lines (86 loc) · 2.59 KB
/
Copy pathSidebarItem.svelte
File metadata and controls
99 lines (86 loc) · 2.59 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script>
import Tag from "../../../shared/Components/Tag.svelte";
import Toggle from "../../../shared/Components/Toggle.svelte";
// the data that will populate the item contents in sidebar
export let data = {};
export let toggleClick;
let showTitle = false;
// if description > 120 characters, truncate and add ellipsis
// also trim for instances where an empty space is the last character
// this prevents ellipsis from being added next to empty space
// when description truncated, add title attr with full description text
function formatDescription(str) {
if (str && str.length > 120) {
showTitle = true;
return `${str.substring(0, 120).trim()}...`;
}
showTitle = false;
return str;
}
$: description = formatDescription(data.description);
</script>
<div
class="item {data.class || ""}"
class:active={data.active}
class:disabled={data.disabled}
class:temp={data.temp}
data-filename={data.filename}
data-last-modified={data.lastModified}
data-type={data.type}
on:click
>
<div class="item__header">
<Tag type={data.request ? "request" : data.type}/>
<div class="item__title truncate">{data.name}</div>
<Toggle checked={!data.disabled} on:click={toggleClick}/>
</div>
{#if description}
<div class="item__description" title="{showTitle ? data.description : null}">
{description}
</div>
{/if}
</div>
<style>
.item {
background-color: var(--color-bg-secondary);
border-bottom: 1px solid var(--color-black);
cursor: pointer;
padding: 1rem 1rem calc(1rem - 1px);
}
/* .item.temp {
position: -webkit-sticky;
top: 0;
z-index: 2;
} */
.item:hover {
background-color: var(--color-bg-primary);
}
.item.active {
background-color: var(--color-script-highlighted);
background-color: #364049;
cursor: default;
}
.item__header {
align-items: center;
display: flex;
}
.item__title {
flex: 1 0 0;
font-weight: 500;
letter-spacing: var(--letter-spacing-default);
padding-right: 0.25rem;
}
.item__description {
color: var(--text-color-secondary);
font: var(--text-small);
letter-spacing: var(--letter-spacing-small);
}
:global(.sidebar--compact) .item__description {
display: none;
}
.disabled .item__title,
.disabled :global(.item__tag),
.disabled .item__description {
opacity: 0.65;
}
</style>