-
Notifications
You must be signed in to change notification settings - Fork 1k
/
popover.tsx
89 lines (80 loc) · 2.96 KB
/
popover.tsx
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
import { Popover, Transition } from '@headlessui/react'
import React, { forwardRef } from 'react'
let Button = forwardRef(
(props: React.ComponentProps<'button'>, ref: React.MutableRefObject<HTMLButtonElement>) => {
return (
<Popover.Button
className="border-2 border-transparent bg-gray-300 px-3 py-2 text-left focus:border-blue-900 focus:outline-none"
{...props}
ref={ref}
/>
)
}
)
export default function Home() {
let items = ['First', 'Second', 'Third', 'Fourth']
return (
<div className="flex items-center justify-center space-x-12 p-12">
<button>Previous</button>
<Popover.Group as="nav" aria-label="Mythical University" className="flex space-x-3">
<Popover as="div" className="relative">
<Transition
enter="transition ease-out duration-300 transform"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition ease-in duration-300 transform"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<Popover.Overlay className="fixed inset-0 z-20 bg-gray-500 bg-opacity-75"></Popover.Overlay>
</Transition>
<Popover.Button className="relative z-30 border-2 border-transparent bg-gray-300 px-3 py-2 focus:border-blue-900 focus:outline-none">
Normal
</Popover.Button>
<Popover.Panel className="absolute z-30 flex w-64 flex-col border-2 border-blue-900 bg-gray-100">
{items.map((item, i) => (
<Button key={item} hidden={i === 2}>
Normal - {item}
</Button>
))}
</Popover.Panel>
</Popover>
<Popover as="div" className="relative">
<Button>Focus</Button>
<Popover.Panel
focus
className="absolute flex w-64 flex-col border-2 border-blue-900 bg-gray-100"
>
{items.map((item) => (
<Button key={item}>Focus - {item}</Button>
))}
</Popover.Panel>
</Popover>
<Popover as="div" className="relative">
<Button>Portal</Button>
<Popover.Panel
anchor="bottom start"
className="flex w-64 flex-col border-2 border-blue-900 bg-gray-100 [--anchor-gap:theme(spacing.1)]"
>
{items.map((item) => (
<Button key={item}>Portal - {item}</Button>
))}
</Popover.Panel>
</Popover>
<Popover as="div" className="relative">
<Button>Focus in Portal</Button>
<Popover.Panel
focus
anchor="bottom start"
className="flex w-64 flex-col border-2 border-blue-900 bg-gray-100 [--anchor-gap:theme(spacing.1)]"
>
{items.map((item) => (
<Button key={item}>Focus in Portal - {item}</Button>
))}
</Popover.Panel>
</Popover>
</Popover.Group>
<button>Next</button>
</div>
)
}