-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathRulesSettings.svelte
186 lines (174 loc) · 4.03 KB
/
RulesSettings.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<script>
import { categories } from './scripts/rules.js';
export let rules = {};
let categoryState = Object.fromEntries(
categories.map((c) => {
return [
c.title,
{
close: true
}
];
})
);
function onAllClick(category, e) {
const newRules = Object.assign({}, rules);
for (const rule of category.rules) {
if (e.target.checked) {
newRules[rule.ruleId] = 'error';
} else {
delete newRules[rule.ruleId];
}
}
rules = newRules;
}
function onClick(ruleId, e) {
const newRules = Object.assign({}, rules);
if (e.target.checked) {
newRules[ruleId] = 'error';
} else {
delete newRules[ruleId];
}
rules = newRules;
}
function isErrorState(rules, ruleId) {
return rules[ruleId] === 'error' || rules[ruleId] === 2;
}
</script>
<div class="rules-settings">
<ul class="categories">
{#each categories as category (category.title)}
{#if category.rules.length}
<li class="category">
<button
class="category-button"
class:category-button--close={categoryState[category.title].close}
on:click={() => {
categoryState = Object.fromEntries(
categories.map((c) => {
const close = categoryState[c.title].close;
return [
c.title,
{
close: category.title === c.title ? !close : close
}
];
})
);
}}
aria-label="expand/collapse"
>
<svg xmlns="http://www.w3.org/2000/svg" height="10" viewBox="0 0 10 10" width="10">
<path d="M2.5 10l5-5-5-5v10z" fill="#ddd" />
</svg>
</button>
<div class="category-title-wrapper">
<label class="category-title">
<input
type="checkbox"
checked={category.rules.every((rule) => isErrorState(rules, rule.ruleId))}
indeterminate={!category.rules.every((rule) => isErrorState(rules, rule.ruleId)) &&
!category.rules.every((rule) => !isErrorState(rules, rule.ruleId))}
on:input={(e) => onAllClick(category, e)}
/>
{category.title}
</label>
</div>
{#if !categoryState[category.title].close}
<ul class="rules">
{#each category.rules as rule (rule.ruleId)}
<li class="rule">
<label>
<input
type="checkbox"
checked={isErrorState(rules, rule.ruleId)}
on:input={(e) => onClick(rule.ruleId, e)}
/>
{rule.ruleId}
</label>
<a
href={rule.url}
target="_blank"
rel="noopener noreferrer"
aria-label="open in new tab"
><svg
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
x="0px"
y="0px"
viewBox="0 0 100 100"
width="15"
height="15"
class="icon outbound"
>
<path
fill="currentColor"
d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"
/>
<polygon
fill="currentColor"
points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"
/></svg
></a
>
</li>
{/each}
</ul>
{/if}
</li>
{/if}
{/each}
</ul>
</div>
<style>
.rules-settings {
height: 100%;
overflow: auto;
width: 25%;
box-sizing: border-box;
}
.categories {
font-size: 14px;
list-style-type: none;
}
.category {
position: relative;
}
.category-button {
position: absolute;
left: -24px;
top: 2px;
background-color: transparent;
color: #ddd;
border: none;
appearance: none;
cursor: pointer;
padding: 0;
}
.category-button--close {
transform: rotate(90deg);
}
.category-title {
font-size: 14px;
font-weight: bold;
}
.rules {
padding-left: 0;
}
.rule {
font-size: 12px;
line-height: 24px;
vertical-align: top;
list-style-type: none;
display: flex;
}
.rule a {
margin-left: auto;
}
a {
text-decoration: none;
}
.category {
color: #fff;
}
</style>