-
Notifications
You must be signed in to change notification settings - Fork 5
/
command-palette-group.html
121 lines (111 loc) · 6.34 KB
/
command-palette-group.html
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
<script>
function setupComboboxCommandPaletteGroupData() {
let everybody = [
{ id: 1, img: 'https://github.com/adamwathan.png', name: 'Adam Wathan' },
{ id: 2, img: 'https://github.com/sschoger.png', name: 'Steve Schoger' },
{ id: 3, img: 'https://github.com/bradlc.png', name: 'Brad Cornes' },
{ id: 4, img: 'https://github.com/simonswiss.png', name: 'Simon Vrachliotis' },
{ id: 5, img: 'https://github.com/robinmalfait.png', name: 'Robin Malfait' },
{
id: 6,
img: 'https://pbs.twimg.com/profile_images/1478879681491394569/eV2PyCnm_400x400.jpg',
name: 'James McDonald',
},
{ id: 7, img: 'https://github.com/reinink.png', name: 'Jonathan Reinink' },
{ id: 8, img: 'https://github.com/thecrypticace.png', name: 'Jordan Pittman' },
]
return {
query: '',
activePerson: everybody[1],
get people() {
return this.query === ''
? everybody
: everybody.filter((person) =>
person.name.toLowerCase().includes(this.query.toLowerCase())
)
},
get groups() {
return this.people.reduce((groups, person) => {
let lastNameLetter = person.name.split(' ')[1][0]
groups.set(lastNameLetter, [...(groups.get(lastNameLetter) || []), person])
return groups
}, new Map())
},
get sortedGroups() {
return Array.from(this.groups.entries()).sort(([letterA], [letterZ]) =>
letterA.localeCompare(letterZ)
)
},
displayValue: () => (item) => item && item.name
}
}
</script>
<template x-component:page="combobox-command-palette-group" x-import="hui:combobox"
x-data="setupComboboxCommandPaletteGroupData()">
<div class=" flex h-full w-full justify-center bg-gray-50 p-12">
<div class="mx-auto w-full max-w-lg">
<div class="space-y-1">
<hui-combobox x-model="activePerson"
class="w-full overflow-hidden rounded border border-black/5 bg-white bg-clip-padding shadow-sm">
<div class="flex w-full flex-col">
<hui-combobox-input @change="query = $event.target.value"
class="w-full rounded-none border-none px-3 py-1 outline-none" placeholder="Search users…"
:display-value="displayValue"></hui-combobox-input>
<div class="flex">
<hui-combobox-options
class="shadow-xs max-h-60 flex-1 overflow-auto text-base leading-6 focus:outline-none sm:text-sm sm:leading-5">
<template x-for="[letter, people] of sortedGroups" :key="letter">
<div>
<div class="bg-gray-100 px-4 py-2" x-text="letter"></div>
<template x-for="person in people">
<hui-combobox-option :value="person">
<div :class="[
'relative flex cursor-default select-none space-x-4 py-2 pl-3 pr-9 focus:outline-none',
active ? 'bg-indigo-600 text-white' : 'text-gray-900',
]">
<img :src="person.img"
class="h-6 w-6 overflow-hidden rounded-full" />
<span
:class="['block truncate', selected ? 'font-semibold' : 'font-normal']"
x-text="person.name">
</span>
<span x-show="active" :class="[
'absolute inset-y-0 right-0 flex items-center pr-4',
active ? 'text-white' : 'text-indigo-600',
]">
<svg class="h-5 w-5" viewBox="0 0 25 24" fill="none">
<path d="M11.25 8.75L14.75 12L11.25 15.25"
stroke="currentColor" strokeWidth="1.5"
strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
</div>
</hui-combobox-option>
</template>
</div>
</template>
</hui-combobox-options>
<template x-if="people.length === 0">
<div class="w-full py-4 text-center">
No person selected
</div>
</template>
<template x-if="people.length > 0 && isOpen && activeOption">
<div class="border-l">
<div class="flex flex-col">
<div class="p-8 text-center">
<img :src="activeOption.img"
class="mb-4 inline-block h-16 w-16 overflow-hidden rounded-full" />
<div class="font-bold text-gray-900" x-text="activeOption.name"></div>
<div class="text-gray-700">Obviously cool person</div>
</div>
</div>
</div>
</template>
</div>
</div>
</hui-combobox>
</div>
</div>
</div>
</template>