|
1 | | -import { component$ } from '@builder.io/qwik'; |
2 | | -import { |
3 | | - Combobox, |
4 | | - ComboboxControl, |
5 | | - ComboboxInput, |
6 | | - ComboboxTrigger, |
7 | | - ComboboxPopover, |
8 | | - ComboboxListbox, |
9 | | - ComboboxOption, |
10 | | - ResolvedOption, |
11 | | - ComboboxIcon, |
12 | | -} from '@qwik-ui/headless'; |
| 1 | +import { component$, useSignal } from '@builder.io/qwik'; |
| 2 | +import { Popover, PopoverTrigger } from '@qwik-ui/headless'; |
13 | 3 |
|
14 | 4 | export default component$(() => { |
15 | | - type AutoPlacementExample = { |
16 | | - value: string; |
17 | | - label: string; |
18 | | - }; |
19 | | - |
20 | | - const autoPlacementExample: Array<AutoPlacementExample> = [ |
21 | | - { value: '0', label: 'Audi 🚗' }, |
22 | | - { value: '1', label: 'BMW 🚙' }, |
23 | | - { value: '2', label: 'Mercedes 🚕' }, |
24 | | - { value: '3', label: 'Tesla 🚓' }, |
25 | | - ]; |
| 5 | + const triggerRef = useSignal<HTMLButtonElement>(); |
| 6 | + const popoverRef = useSignal<HTMLElement>(); |
26 | 7 |
|
27 | 8 | return ( |
28 | 9 | <> |
29 | | - <div class="flex h-[10rem] flex-col items-center justify-center"> |
30 | | - <p class="text-center text-white">My Car Collection 🚘</p> |
31 | | - <Combobox |
32 | | - class="w-fit" |
33 | | - options={autoPlacementExample} |
34 | | - optionDisabledKey="myDisabledKey" |
| 10 | + <div class="flex flex-col items-center justify-center gap-2"> |
| 11 | + <p>auto placed on scroll 📜</p> |
| 12 | + <PopoverTrigger |
| 13 | + ref={triggerRef} |
| 14 | + popoverTargetAction="show" |
| 15 | + popovertarget="auto-placement-id" |
| 16 | + class="popover-trigger" |
35 | 17 | > |
36 | | - <ComboboxControl class="relative mt-2 flex items-center rounded-base border-[1px] border-slate-400 bg-[#1f2532]"> |
37 | | - <ComboboxInput class="px-d2 h-[44px] w-44 rounded-base bg-slate-900 px-4 pr-6 text-white placeholder:text-slate-500" /> |
38 | | - <ComboboxTrigger class="group absolute right-0 h-6 w-6"> |
39 | | - <ComboboxIcon class="stroke-white transition-transform duration-500 group-aria-expanded:-rotate-180" /> |
40 | | - </ComboboxTrigger> |
41 | | - </ComboboxControl> |
42 | | - <ComboboxPopover flip={false} autoPlacement={true} gutter={8}> |
43 | | - <ComboboxListbox |
44 | | - class="w-44 rounded-base border-[1px] border-slate-400 bg-slate-900 px-4 py-2" |
45 | | - optionRenderer$={(option: ResolvedOption, index: number) => ( |
46 | | - <ComboboxOption |
47 | | - key={option.key} |
48 | | - class="group rounded-base border-2 border-transparent px-2 text-white hover:bg-slate-500 aria-disabled:text-slate-600 aria-disabled:hover:bg-slate-700 aria-selected:border-slate-200 aria-selected:bg-slate-500" |
49 | | - index={index} |
50 | | - resolved={option} |
51 | | - > |
52 | | - {option.label} |
53 | | - </ComboboxOption> |
54 | | - )} |
55 | | - /> |
56 | | - </ComboboxPopover> |
57 | | - </Combobox> |
| 18 | + Click me |
| 19 | + </PopoverTrigger> |
58 | 20 | </div> |
59 | | - <div class="h-[1px] w-[calc(100%+200px)]"></div> |
| 21 | + |
| 22 | + <Popover |
| 23 | + ref={popoverRef} |
| 24 | + anchorRef={triggerRef} |
| 25 | + floating={true} |
| 26 | + flip={false} |
| 27 | + autoPlacement |
| 28 | + gutter={4} |
| 29 | + id="auto-placement-id" |
| 30 | + class="popover listbox !p-4" |
| 31 | + > |
| 32 | + I am anchored to the trigger! |
| 33 | + </Popover> |
60 | 34 | </> |
61 | 35 | ); |
62 | 36 | }); |
0 commit comments