@atawi/react-popover 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/index.js +1429 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +11 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/style.css +1 -0
- package/package.json +85 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Atawi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+

|
2
|
+
[](https://codecov.io/github/ahmedalatawi/react-popover)
|
3
|
+
[](https://github.com/AhmedAlatawi/react-popover/blob/master/LICENSE)
|
4
|
+
|
5
|
+
# React Popover Component
|
6
|
+
|
7
|
+
A fully-featured, accessible, and customizable popover component for React apps.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- 🎯 12 placement options with smart auto-positioning
|
12
|
+
- 🎨 Smooth animations and transitions
|
13
|
+
- 🔄 Multiple trigger types (click, hover, focus)
|
14
|
+
- 📱 Responsive and mobile-friendly
|
15
|
+
- ♿ Accessible (WAI-ARIA compliant)
|
16
|
+
- 🎛️ Controlled and uncontrolled modes
|
17
|
+
- 🎯 Auto-placement to stay within viewport
|
18
|
+
- 🖌️ Highly customizable styling
|
19
|
+
- 📦 TypeScript support
|
20
|
+
- ⚡ Optimized performance
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
```bash
|
25
|
+
npm install @atawi/react-popover
|
26
|
+
```
|
27
|
+
|
28
|
+
## Basic Usage
|
29
|
+
|
30
|
+
```tsx
|
31
|
+
import { Popover } from "@atawi/react-popover";
|
32
|
+
|
33
|
+
function App() {
|
34
|
+
return (
|
35
|
+
<Popover
|
36
|
+
trigger={<button>Click me</button>}
|
37
|
+
content={<div>Popover content</div>}
|
38
|
+
placement="top"
|
39
|
+
/>
|
40
|
+
);
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
## Props
|
45
|
+
|
46
|
+
| Prop | Type | Default | Description |
|
47
|
+
| -------------------- | ------------------------------------ | --------- | ------------------------------------- |
|
48
|
+
| `trigger` | `ReactNode` | - | The element that triggers the popover |
|
49
|
+
| `content` | `ReactNode` | - | The content to display in the popover |
|
50
|
+
| `placement` | `PopoverPlacement` | `'top'` | Preferred placement of the popover |
|
51
|
+
| `offset` | `number` | `8` | Distance between trigger and popover |
|
52
|
+
| `className` | `string` | `''` | Class name for the popover wrapper |
|
53
|
+
| `containerClassName` | `string` | `''` | Class name for the container |
|
54
|
+
| `contentClassName` | `string` | `''` | Class name for the content wrapper |
|
55
|
+
| `open` | `boolean` | - | Control popover visibility externally |
|
56
|
+
| `onOpenChange` | `(open: boolean) => void` | - | Callback when visibility changes |
|
57
|
+
| `style` | `CSSProperties` | - | Additional styles for the popover |
|
58
|
+
| `autoPlacement` | `boolean` | `false` | Enable automatic repositioning |
|
59
|
+
| `animated` | `boolean` | `false` | Enable enter/exit animations |
|
60
|
+
| `triggerType` | `PopoverTrigger \| PopoverTrigger[]` | `'click'` | How to trigger the popover |
|
61
|
+
| `hoverDelay` | `number` | `200` | Delay before showing on hover |
|
62
|
+
| `closeDelay` | `number` | `400` | Delay before hiding on hover out |
|
63
|
+
| `closeOnScroll` | `boolean` | `false` | Close popover when window is scrolled |
|
64
|
+
| `closeOnResize` | `boolean` | `false` | Close popover when window is resized |
|
65
|
+
|
66
|
+
## Examples
|
67
|
+
|
68
|
+
### Basic Popover
|
69
|
+
|
70
|
+
```tsx
|
71
|
+
<Popover
|
72
|
+
trigger={<button>Click me</button>}
|
73
|
+
content="Simple popover content"
|
74
|
+
placement="top"
|
75
|
+
/>
|
76
|
+
```
|
77
|
+
|
78
|
+
### With Auto-placement
|
79
|
+
|
80
|
+
```tsx
|
81
|
+
<Popover
|
82
|
+
trigger={<button>Hover me</button>}
|
83
|
+
content="Content that stays in viewport"
|
84
|
+
placement="top"
|
85
|
+
autoPlacement
|
86
|
+
triggerType="hover"
|
87
|
+
/>
|
88
|
+
```
|
89
|
+
|
90
|
+
### Animated Popover
|
91
|
+
|
92
|
+
```tsx
|
93
|
+
<Popover
|
94
|
+
trigger={<button>Animated</button>}
|
95
|
+
content="Smooth animation"
|
96
|
+
placement="right"
|
97
|
+
animated
|
98
|
+
/>
|
99
|
+
```
|
100
|
+
|
101
|
+
### Multiple Triggers
|
102
|
+
|
103
|
+
```tsx
|
104
|
+
<Popover
|
105
|
+
trigger={<button>Interactive</button>}
|
106
|
+
content="Accessible content"
|
107
|
+
placement="bottom"
|
108
|
+
triggerType={["hover", "focus"]}
|
109
|
+
/>
|
110
|
+
```
|
111
|
+
|
112
|
+
### Controlled Mode
|
113
|
+
|
114
|
+
```tsx
|
115
|
+
function ControlledExample() {
|
116
|
+
const [open, setOpen] = useState(false);
|
117
|
+
|
118
|
+
return (
|
119
|
+
<Popover
|
120
|
+
trigger={<button>Controlled</button>}
|
121
|
+
content="Controlled content"
|
122
|
+
open={open}
|
123
|
+
onOpenChange={setOpen}
|
124
|
+
/>
|
125
|
+
);
|
126
|
+
}
|
127
|
+
```
|
128
|
+
|
129
|
+
### Custom Styling
|
130
|
+
|
131
|
+
```tsx
|
132
|
+
<Popover
|
133
|
+
trigger={<button>Styled</button>}
|
134
|
+
content="Custom styled content"
|
135
|
+
className="custom-popover"
|
136
|
+
contentClassName="custom-content"
|
137
|
+
arrowClassName="custom-arrow"
|
138
|
+
style={{ maxWidth: "300px" }}
|
139
|
+
/>
|
140
|
+
```
|
141
|
+
|
142
|
+
## Placement Options
|
143
|
+
|
144
|
+
The `placement` prop accepts the following values:
|
145
|
+
|
146
|
+
- `top` | `top-start` | `top-end`
|
147
|
+
- `bottom` | `bottom-start` | `bottom-end`
|
148
|
+
- `left` | `left-start` | `left-end`
|
149
|
+
- `right` | `right-start` | `right-end`
|
150
|
+
|
151
|
+
## Trigger Types
|
152
|
+
|
153
|
+
The `triggerType` prop accepts:
|
154
|
+
|
155
|
+
- `'click'` - Opens on click/tap
|
156
|
+
- `'hover'` - Opens on mouse hover
|
157
|
+
- `'focus'` - Opens on focus (keyboard navigation)
|
158
|
+
- Array of the above for multiple triggers
|
159
|
+
|
160
|
+
## Styling
|
161
|
+
|
162
|
+
The component uses CSS modules and provides several class names for customization:
|
163
|
+
|
164
|
+
- `.container` - The root container
|
165
|
+
- `.trigger` - The trigger wrapper
|
166
|
+
- `.content` - The popover content wrapper
|
167
|
+
- `.contentInner` - The inner content container
|
168
|
+
- `.animated` - Applied when animations are enabled
|
169
|
+
- `.enter` - Applied during enter animation
|
170
|
+
- `.exit` - Applied during exit animation
|
171
|
+
|
172
|
+
## Accessibility
|
173
|
+
|
174
|
+
The component follows WAI-ARIA guidelines:
|
175
|
+
|
176
|
+
- Proper ARIA attributes
|
177
|
+
- Keyboard navigation support
|
178
|
+
- Focus management
|
179
|
+
- Screen reader friendly
|
180
|
+
|
181
|
+
## Browser Support
|
182
|
+
|
183
|
+
- Chrome (latest)
|
184
|
+
- Firefox (latest)
|
185
|
+
- Safari (latest)
|
186
|
+
- Edge (latest)
|
187
|
+
- IE11 (with polyfills)
|
188
|
+
|
189
|
+
## Contributing
|
190
|
+
|
191
|
+
Contributions are welcome! Please read our contributing guidelines before submitting a pull request.
|
192
|
+
|
193
|
+
## License
|
194
|
+
|
195
|
+
MIT © Atawi
|