Skip to content

Commit 2ec5b9f

Browse files
committed
chore: add listbox demo
1 parent 7c90f8f commit 2ec5b9f

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

storage/framework/core/components/dialog/src/DialogDemo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function handleClose() {
2222

2323
<template >
2424
<div>
25-
<div class="flex flex-col m-2" >
25+
<div class="flex flex-col my-2" >
2626
<span class="text-xl font-medium text-gray-900">
2727
Basic
2828
</span>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script lang="ts" setup>
2+
import { ref } from 'vue'
3+
import {
4+
Listbox,
5+
ListboxButton,
6+
ListboxOption,
7+
ListboxOptions,
8+
} from '@headlessui/vue'
9+
10+
interface Person {
11+
id: number
12+
name: string
13+
unavailable: boolean
14+
}
15+
16+
const people: Person[] = [
17+
{ id: 1, name: 'Durward Reynolds', unavailable: false },
18+
{ id: 2, name: 'Kenton Towne', unavailable: false },
19+
{ id: 3, name: 'Therese Wunsch', unavailable: false },
20+
{ id: 4, name: 'Benedict Kessler', unavailable: true },
21+
{ id: 5, name: 'Katelyn Rohan', unavailable: false },
22+
]
23+
24+
const selectedPerson = ref<Person>(people[0] as Person)
25+
26+
27+
</script>
28+
29+
<template>
30+
<div class="flex flex-col">
31+
<div class="font-semibold text-lg">
32+
Basic Demo
33+
</div>
34+
<Listbox v-model="selectedPerson">
35+
<div class="relative mt-1">
36+
<ListboxButton
37+
class="relative w-full cursor-default rounded-lg bg-white py-2 pl-3 pr-10 text-left shadow-md focus-visible:border-indigo-500 sm:text-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-white/75 focus-visible:ring-offset-orange-300"
38+
>
39+
<span class="block truncate">{{ selectedPerson.name }}</span>
40+
<span
41+
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"
42+
>
43+
<div class="i-heroicons-chevron-up-down-20-solid" />
44+
</span>
45+
</ListboxButton>
46+
47+
<transition
48+
leave-active-class="transition duration-100 ease-in"
49+
leave-from-class="opacity-100"
50+
leave-to-class="opacity-0"
51+
>
52+
<ListboxOptions
53+
class="absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black/5 sm:text-sm focus:outline-none"
54+
>
55+
<ListboxOption
56+
v-for="person in people"
57+
v-slot="{ active, selected }"
58+
:key="person.name"
59+
:value="person"
60+
as="template"
61+
>
62+
<li
63+
class="relative cursor-default select-none py-2 pl-10 pr-4" :class="[
64+
active ? 'bg-amber-100 text-amber-900' : 'text-gray-900',
65+
]"
66+
>
67+
<span
68+
class="block truncate" :class="[
69+
selected ? 'font-medium' : 'font-normal',
70+
]"
71+
>{{ person.name }}</span>
72+
<span
73+
v-if="selected"
74+
class="absolute inset-y-0 left-0 flex items-center pl-3 text-amber-600"
75+
>
76+
<div class="i-heroicons-check-20-solid" />
77+
</span>
78+
</li>
79+
</ListboxOption>
80+
</ListboxOptions>
81+
</transition>
82+
</div>
83+
</Listbox>
84+
</div>
85+
</template>

0 commit comments

Comments
 (0)