|
1 |
| -import { |
2 |
| - Combobox, |
3 |
| - ComboboxControl, |
4 |
| - ComboboxIcon, |
5 |
| - ComboboxInput, |
6 |
| - ComboboxListbox, |
7 |
| - ComboboxOption, |
8 |
| - ComboboxPopover, |
9 |
| - ComboboxTrigger, |
10 |
| - ResolvedOption, |
11 |
| -} from '@qwik-ui/headless'; |
12 |
| - |
13 |
| -import { component$ } from '@builder.io/qwik'; |
| 1 | +import { component$, useSignal } from '@builder.io/qwik'; |
| 2 | +import { Popover, PopoverTrigger } from '@qwik-ui/headless'; |
14 | 3 |
|
15 | 4 | export default component$(() => {
|
16 |
| - type FlipExample = { |
17 |
| - value: string; |
18 |
| - label: string; |
19 |
| - }; |
20 |
| - |
21 |
| - const flipExample: Array<FlipExample> = [ |
22 |
| - { value: '0', label: 'Up! ☝️' }, |
23 |
| - { value: '1', label: 'Up! ☝️' }, |
24 |
| - { value: '2', label: 'Down! 👇' }, |
25 |
| - { value: '3', label: 'Up! ☝️' }, |
26 |
| - { value: '4', label: 'Down! 👇' }, |
27 |
| - { value: '5', label: 'Down! 👇' }, |
28 |
| - { value: '6', label: 'Down! 👇' }, |
29 |
| - { value: '7', label: 'Up! ☝️' }, |
30 |
| - ]; |
| 5 | + const triggerRef = useSignal<HTMLButtonElement>(); |
| 6 | + const popoverRef = useSignal<HTMLElement>(); |
31 | 7 |
|
32 | 8 | return (
|
33 |
| - <div class="flex flex-col items-center"> |
34 |
| - <p class="text-center text-white">☝️ Scroll up and down with me open! 👇</p> |
35 |
| - <Combobox class="w-fit" options={flipExample} optionDisabledKey="myDisabledKey"> |
36 |
| - <ComboboxControl class="relative mt-2 flex items-center rounded-base border-[1px] border-slate-400 bg-[#1f2532]"> |
37 |
| - <ComboboxInput class="px-d2 w-44 rounded-base bg-slate-900 px-2 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={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> |
58 |
| - </div> |
| 9 | + <> |
| 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="popover-id" |
| 16 | + class="popover-trigger" |
| 17 | + > |
| 18 | + Click me |
| 19 | + </PopoverTrigger> |
| 20 | + </div> |
| 21 | + |
| 22 | + <Popover |
| 23 | + ref={popoverRef} |
| 24 | + anchorRef={triggerRef} |
| 25 | + floating={true} |
| 26 | + flip |
| 27 | + gutter={4} |
| 28 | + id="popover-id" |
| 29 | + class="popover listbox !p-4" |
| 30 | + > |
| 31 | + I am anchored to the trigger! |
| 32 | + </Popover> |
| 33 | + </> |
59 | 34 | );
|
60 | 35 | });
|
0 commit comments