|
1 |
| -import { |
2 |
| - Combobox, |
3 |
| - ComboboxControl, |
4 |
| - ComboboxIcon, |
5 |
| - ComboboxInput, |
6 |
| - ComboboxLabel, |
7 |
| - ComboboxListbox, |
8 |
| - ComboboxOption, |
9 |
| - ComboboxPopover, |
10 |
| - ComboboxTrigger, |
11 |
| - ResolvedOption, |
12 |
| -} from '@qwik-ui/headless'; |
13 |
| - |
14 | 1 | import { component$, useSignal } from '@builder.io/qwik';
|
| 2 | +import { Popover, PopoverTrigger } from '@qwik-ui/headless'; |
| 3 | +import { usePopover } from '@qwik-ui/headless'; |
15 | 4 |
|
16 | 5 | export default component$(() => {
|
17 |
| - const inputValueSig = useSignal(''); |
18 |
| - type PlacementExample = { |
19 |
| - value: string; |
20 |
| - label: string; |
21 |
| - }; |
22 |
| - |
23 |
| - const placementExample: Array<PlacementExample> = [ |
24 |
| - { value: '0', label: 'Up' }, |
25 |
| - { value: '1', label: 'Down' }, |
26 |
| - { value: '2', label: 'Left' }, |
27 |
| - { value: '3', label: 'Right' }, |
28 |
| - ]; |
| 6 | + const { showPopover, hidePopover } = usePopover(`placement-id`); |
| 7 | + const triggerRef = useSignal<HTMLButtonElement>(); |
| 8 | + const popoverRef = useSignal<HTMLElement>(); |
29 | 9 |
|
30 | 10 | return (
|
31 | 11 | <>
|
32 |
| - <Combobox |
33 |
| - class="w-fit" |
34 |
| - options={placementExample} |
35 |
| - optionDisabledKey="myDisabledKey" |
36 |
| - bind:inputValue={inputValueSig} |
| 12 | + <div class="flex flex-col items-center justify-center gap-2"> |
| 13 | + <p>I'm a mini tooltip!</p> |
| 14 | + <PopoverTrigger |
| 15 | + ref={triggerRef} |
| 16 | + disableClickInitPopover |
| 17 | + onPointerEnter$={() => { |
| 18 | + showPopover(); |
| 19 | + }} |
| 20 | + onPointerLeave$={() => { |
| 21 | + hidePopover(); |
| 22 | + }} |
| 23 | + popoverTargetAction="show" |
| 24 | + popovertarget="placement-id" |
| 25 | + class="popover-trigger" |
| 26 | + > |
| 27 | + Hover over me |
| 28 | + </PopoverTrigger> |
| 29 | + </div> |
| 30 | + |
| 31 | + <Popover |
| 32 | + ref={popoverRef} |
| 33 | + anchorRef={triggerRef} |
| 34 | + floating={true} |
| 35 | + placement="right" |
| 36 | + gutter={4} |
| 37 | + id="placement-id" |
| 38 | + class="popover listbox !p-4" |
37 | 39 | >
|
38 |
| - <ComboboxLabel class="text-white">Positions</ComboboxLabel> |
39 |
| - <ComboboxControl class="relative mt-2 flex items-center rounded-base border-[1px] border-slate-400 bg-[#1f2532]"> |
40 |
| - <ComboboxInput class="px-d2 w-44 rounded-base bg-slate-900 px-2 pr-6 text-white placeholder:text-slate-500" /> |
41 |
| - <ComboboxTrigger class="group absolute right-0 h-6 w-6"> |
42 |
| - <ComboboxIcon class="stroke-white transition-transform duration-500 group-aria-expanded:-rotate-180" /> |
43 |
| - </ComboboxTrigger> |
44 |
| - </ComboboxControl> |
45 |
| - <ComboboxPopover gutter={8} placement="top"> |
46 |
| - <ComboboxListbox |
47 |
| - class="w-44 rounded-base border-[1px] border-slate-400 bg-slate-900 px-4 py-2" |
48 |
| - optionRenderer$={(option: ResolvedOption, index: number) => ( |
49 |
| - <ComboboxOption |
50 |
| - key={option.key} |
51 |
| - 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" |
52 |
| - index={index} |
53 |
| - resolved={option} |
54 |
| - > |
55 |
| - {option.label} |
56 |
| - </ComboboxOption> |
57 |
| - )} |
58 |
| - /> |
59 |
| - </ComboboxPopover> |
60 |
| - </Combobox> |
| 40 | + I am anchored to the trigger! |
| 41 | + </Popover> |
61 | 42 | </>
|
62 | 43 | );
|
63 | 44 | });
|
0 commit comments