Skip to content

Commit 88563fb

Browse files
committed
REFACTOR shortcut group, add search input
1 parent edf85f9 commit 88563fb

File tree

2 files changed

+101
-65
lines changed

2 files changed

+101
-65
lines changed

src/foreground/App.vue

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,30 @@
55
<span>No shortcuts found! Edit <pre>shortcuts.yaml</pre> to get started.</span>
66
</div>
77
<template v-else>
8-
<article v-for="group in groups" class="shortcuts-group">
9-
<h3 class="shortucts-group__title">{{ group.name }}</h3>
10-
<ul class="shortcuts-list">
11-
<li class="shortcuts-list__item" v-for="item in group.items" :key="item.keys + item.name">
12-
<span>{{ item.name }}</span>
13-
<pre>{{ item.keys }}</pre>
14-
</li>
15-
</ul>
16-
</article>
8+
<input class="shortcuts-search" v-model="search" placeholder="Search" autofocus />
9+
<ShortcutGroup v-for="group in groups" :key="group.name" :name="group.name" :items="filter(group.items)" />
1710
</template>
1811
</main>
1912
</div>
2013
</template>
2114

2215
<script>
16+
import ShortcutGroup from './ShortcutGroup.vue';
17+
2318
export default {
19+
components: {
20+
ShortcutGroup
21+
},
2422
data() {
2523
return {
24+
search: '',
2625
groups: []
27-
}
26+
};
2827
},
2928
computed: {
3029
commandOrControl() {
3130
return window.os === 'darwin' ? '' : 'Ctrl';
32-
}
31+
},
3332
},
3433
methods: {
3534
async loadShortcuts() {
@@ -39,12 +38,23 @@ export default {
3938
},
4039
async handleEditShortcuts() {
4140
api.editShortcuts();
41+
},
42+
43+
filter(items) {
44+
const searchTerm = this.search.toLowerCase();
45+
46+
return searchTerm
47+
? items.filter((item) =>
48+
item.name.toLowerCase().includes(searchTerm) ||
49+
item.keys.toLowerCase().includes(searchTerm)
50+
)
51+
: items;
4252
}
4353
},
4454
async mounted() {
4555
await this.loadShortcuts();
4656
}
47-
}
57+
};
4858
</script>
4959

5060
<style lang="scss">
@@ -69,6 +79,13 @@ export default {
6979
font-size: .85rem;
7080
font-family: Arial, Helvetica, sans-serif;
7181
82+
.shortcuts-search {
83+
font-family: inherit;
84+
font-size: inherit;
85+
width: 100%;
86+
padding: .25rem;
87+
}
88+
7289
.no-shortcuts-config {
7390
display: flex;
7491
justify-content: center;
@@ -79,58 +96,5 @@ export default {
7996
display: inline;
8097
}
8198
}
82-
83-
.shortcuts-group {
84-
85-
.shortucts-group__title {
86-
margin: 1rem 0 .25rem;
87-
text-align: center;
88-
}
89-
90-
.shortcuts-list {
91-
display: flex;
92-
flex-direction: row;
93-
flex-wrap: wrap;
94-
margin: 0;
95-
96-
.shortcuts-list__item {
97-
display: flex;
98-
flex-direction: row;
99-
width: 100%;
100-
justify-content: space-between;
101-
align-items: center;
102-
padding: .25rem .5rem;
103-
104-
&:first-child {
105-
border-start-start-radius: 5px;
106-
border-start-end-radius: 5px;
107-
}
108-
109-
&:last-child {
110-
border-end-start-radius: 5px;
111-
border-end-end-radius: 5px;
112-
}
113-
114-
&:nth-child(even) {
115-
background-color: #efefef;
116-
}
117-
118-
&:nth-child(odd) {
119-
background-color: #dedede;
120-
}
121-
122-
> span {
123-
display: block;
124-
width: auto;
125-
}
126-
127-
> pre {
128-
display: block;
129-
width: auto;
130-
margin: 0;
131-
}
132-
}
133-
}
134-
}
13599
}
136100
</style>

src/foreground/ShortcutGroup.vue

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<template>
2+
<article class="shortcuts-group" v-if="items.length">
3+
<h3 class="shortucts-group__title">{{ name }}</h3>
4+
<ul class="shortcuts-list">
5+
<li class="shortcuts-list__item" v-for="item in items" :key="item.keys + item.name">
6+
<span>{{ item.name }}</span>
7+
<pre>{{ item.keys }}</pre>
8+
</li>
9+
</ul>
10+
</article>
11+
</template>
12+
13+
<script>
14+
export default {
15+
props: [ 'name', 'items' ]
16+
};
17+
</script>
18+
19+
<style lang="scss">
20+
.shortcuts-group {
21+
.shortucts-group__title {
22+
margin: 1rem 0 .25rem;
23+
text-align: center;
24+
}
25+
26+
.shortcuts-list {
27+
display: flex;
28+
flex-direction: row;
29+
flex-wrap: wrap;
30+
margin: 0;
31+
padding: 0;
32+
33+
.shortcuts-list__item {
34+
display: flex;
35+
flex-direction: row;
36+
width: 100%;
37+
justify-content: space-between;
38+
align-items: center;
39+
padding: .25rem .5rem;
40+
41+
&:first-child {
42+
border-start-start-radius: 5px;
43+
border-start-end-radius: 5px;
44+
}
45+
46+
&:last-child {
47+
border-end-start-radius: 5px;
48+
border-end-end-radius: 5px;
49+
}
50+
51+
&:nth-child(even) {
52+
background-color: #efefef;
53+
}
54+
55+
&:nth-child(odd) {
56+
background-color: #dedede;
57+
}
58+
59+
> span {
60+
display: block;
61+
width: auto;
62+
}
63+
64+
> pre {
65+
display: block;
66+
width: auto;
67+
margin: 0;
68+
}
69+
}
70+
}
71+
}
72+
</style>

0 commit comments

Comments
 (0)