├── .eslintignore
├── .gitignore
├── .prettierrc.json
├── CHANGELOG.md
├── LICENSE
├── README.md
├── eslint.config.js
├── package.json
├── pnpm-lock.yaml
├── react-tiny-popover-short-demo.gif
├── src
├── ArrowContainer.tsx
├── Popover.tsx
├── PopoverPortal.tsx
├── index.d.ts
├── useArrowContainer.ts
├── useElementRef.ts
├── useHandlePrevValues.ts
├── useMemoizedArray.ts
├── usePopover.ts
└── util.ts
└── tsconfig.json
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist/
2 | docs/
3 | node_modules/
4 | *.d.ts
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | /dist/
3 | npm-debug.log
4 | .idea
5 | **/.DS_Store
6 | **/yarn-error.log
7 | .vscode
8 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "arrowParens": "always",
3 | "jsxSingleQuote": true,
4 | "printWidth": 100,
5 | "semi": true,
6 | "singleQuote": true,
7 | "tabWidth": 2,
8 | "trailingComma": "all"
9 | }
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | ## [8.1.6] - 2025-2-2
4 |
5 | ### Fixed
6 |
7 | - Resolved newly introduced module declaration issue from previous release
8 |
9 | ## [8.1.5] - 2025-2-2
10 |
11 | ### Fixed
12 |
13 | - Resolved an issue where popover position sometimes did not occur on window resize
14 |
15 | ## [8.1.4] - 2024-11-20
16 |
17 | ### Fixed
18 |
19 | - Resolved type declaration issue that caused ts errors when rendering Popover component on certain versions of React
20 |
21 | ## [8.1.3] - 2024-11-20
22 |
23 | ### Fixed
24 |
25 | - Popover now immediately positions on open before requesting browser animation
26 | frame for subsequent updates (thanks @cozmo)
27 |
28 | ## [8.1.2] - 2024-9-13
29 |
30 | ### Fixed npm deployment issue
31 |
32 | ## [8.1.1] - 2024-9-13
33 |
34 | ### Fixed
35 |
36 | - Popover now re-renders properly on the following prop changes
37 | - `reposition`
38 | - `positions`
39 | - `boundaryElement`
40 | - `boundaryInset`
41 | - `transform`
42 | - `transformMode`
43 | - `childRect` changes
44 | - `popoverRect` changes
45 | - `padding`
46 | - `align`
47 |
48 | ## [8.1.0] - 2024-9-12
49 |
50 | ### Changed
51 |
52 | - Prior to this change, the portal DOM elements generated when a popover appears
53 | were given the id `react-tiny-popover-container` and `react-tiny-popover-scout`
54 | - From now on, both `react-tiny-popover-container` and `react-tiny-popover-scout` are
55 | now assigned as class names rather than ids. The absence of this functionality
56 | has been an oversight, since multiple popovers can be present in the DOM
57 | simultaneously. This resulted in more than one element having the same id.
58 |
59 | ## [8.0.3] - 2023-10-19
60 |
61 | ### Fixed
62 |
63 | - `align` and `padding` no longer erroneously required as props
64 |
65 | ## [8.0.2] - 2023-10-19
66 |
67 | ### Fixed
68 |
69 | - Removed some debugging statements erroneously published
70 |
71 | ## [8.0.1] - 2023-10-19
72 |
73 | ### Fixed
74 |
75 | - Rolled back `DOMRect` changes as it interferes with SSR, replaced with custom `Rect` interface that mirrors the same API
76 |
77 | ## [8.0.0] - 2023-10-18
78 |
79 | ### Changed
80 |
81 | - `contentLocation` prop has been renamed to `positionTransform`, behaves exactly the same
82 | - `positions` prop now accepts a single string in addition to an array of prioritized strings
83 | - Migrated from deprecated `ClientRect` to `DOMRect` (thanks @jafin)
84 |
85 | ### Added
86 |
87 | - A new `transformMode` prop now accepts string values of `"absolute"` or `"relative"`. `"absolute"` mode is its default, and causes behavior identical to `contentLocation`. The `"relative"` value, however, will cause the provided `top` and `left` values of the transform to merely be summed to the existing `nudgeTop` and `nudgeLeft` values, behaving as a relative positioning system.
88 |
89 | ## [7.2.2] - 2023-02-13
90 |
91 | ### Fixed
92 |
93 | - popover positioning miscalculation issue
94 |
95 | ## [7.2.1] - 2023-02-11
96 |
97 | ### Fixed
98 |
99 | - blurry popover on non-retina displays (thanks @D34THWINGS)
100 | - click-outside support now works across different windows (thanks @dutziworks)
101 |
102 | ## [7.2.0] - 2021-08-24
103 |
104 | ### Added
105 |
106 | - added `clickOutsideCapture` prop to `Popover`
107 |
108 | ## [7.1.0] - 2021-08-24
109 |
110 | ### Added
111 |
112 | - added `violations` property to `PopoverState`
113 | - added `hasViolations` property to `PopoverState`
114 | - React 18 is now an accepted peer dependency
115 |
116 | ### Changed
117 |
118 | - `onClickOutside` now uses event capturing (thanks @davidjgross)
119 |
120 | ### Fixed
121 |
122 | - `usePopover` now returns immediately when popover is not open, fixing an issue where utility and positioning functions sometimes fired even when popover was not open
123 |
124 | ## [7.0.1] - 2021-08-24
125 |
126 | ### Fixed
127 |
128 | - Issue where popovers within a new stacking context would sometimes not render at the correct position
129 |
130 | ## [7.0.0] - 2021-08-24
131 |
132 | ### Added
133 |
134 | - SSR support
135 | - `boundaryElement` prop
136 |
137 | ### Changed
138 |
139 | - Renamed `containerParent` to `parentElement`
140 |
141 | ### Fixed
142 |
143 | - Popovers not rendering at proper location within translated container elements
144 |
145 | ## [6.0.10] - 2021-08-04
146 |
147 | ### Changed
148 |
149 | - Removed `custom` string type from `position` and `align` props, replaced with `undefined`
150 | - `useArrowContainer` does not render an arrow if `position` is `undefined`
151 |
152 | ## [6.0.9] - 2021-08-02
153 |
154 | ### Fixed
155 |
156 | - `ArrowContainer` now handles custom class names properly (thanks KWLEvans)
157 |
158 | ## [6.0.8] - 2021-08-02
159 |
160 | ### Changed
161 |
162 | - Inline source maps
163 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 by Alex Katz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-tiny-popover
2 |
3 | 
4 |
5 | ## [Click here for a full demo](https://alexkatz.github.io/react-tiny-popover-demo/) :+1:
6 |
7 | - [Install](#install)
8 | - [Examples](#examples)
9 | - [Hooks](#hooks)
10 | - [Small breaking change in 8.1](#small-breaking-change-in-81)
11 | - [Migrating to 8.0](#migrating-to-80)
12 | - [Migrating to 5.0](#migrating-to-50)
13 | - [API](#api)
14 | - [Popover](#popover)
15 | - [PopoverState](#popoverstate)
16 | - [ArrowContainer](#arrowcontainer)
17 |
18 | A lightweight, highly customizable, non-intrusive, and Typescript friendly popover react HOC with no other dependencies!
19 |
20 | The component renders its child directly, without wrapping it with anything on the DOM, and in addition renders solely the JSX you provide when shown. It simply grabs the child component's coordinates and provides a robust and non-intrusive way for you to position your own content around the child. Your content will be appended to `document.body` (or an element of your choice) when shown, and removed when hidden. You can use it to generate little popups around input or button elements, menu fly-outs, or in pretty much any situation where you want some content to appear and disappear dynamically around a target. You can also specify your own location for your popover content or hook into the existing positioning process, allowing you to essentially make modal windows and the like, as well!
21 |
22 | `react-tiny-popover` can also guard against container boundaries and reposition itself to prevent any kind of hidden overflow. You can specify a priority of desired positions to fall back to, if you'd like.
23 |
24 | Optionally, you can provide a renderer function for your popover content that injects the popover's current position, in case your content needs to know where it sits in relation to its target.
25 |
26 | Since `react-tiny-popover` tries to be as non-invasive as possible, it will simply render the content you provide with the position and padding from the target that you provide. If you'd like an arrow pointing to the target to appear along with your content and don't feel like building it yourself, you may be interested in wrapping your content with the customizable `ArrowContainer` component, also provided! `ArrowContainer`'s arrow will follow its target dynamically, and handles boundary collisions as well.
27 |
28 | ## Install
29 |
30 | ```shell
31 | npm i react-tiny-popover --save
32 | ```
33 |
34 | ## Examples
35 |
36 | ```JSX
37 | import { Popover } from 'react-tiny-popover'
38 |
39 | ...
40 |
41 | Hi! I'm popover content.}
45 | >
46 |
104 |
105 | )}
106 | >
107 |
110 | ;
111 | ```
112 |
113 | If you'd like to use a custom React element as `Popover`'s target, you'll have to pass the `ref` that `Popover` provides to an inner DOM element of your component. The best way to accomplish this is with [React's ref forwarding API](https://reactjs.org/docs/forwarding-refs.html). Here's a simple example, using Typescript:
114 |
115 | ```JSX
116 | import React, { useState } from 'react';
117 | import { Popover } from 'react-tiny-popover';
118 |
119 | interface CustomComponentProps extends React.ComponentPropsWithoutRef<'div'> {
120 | onClick(): void;
121 | }
122 |
123 | const CustomComponent = React.forwardRef((props, ref) => (
124 |
}>
134 | setIsPopoverOpen(!isPopoverOpen)}>
135 | hey from a custom target component
136 |
137 |
138 |
139 | );
140 | };
141 |
142 | export default App;
143 | ```
144 |
145 | ## Hooks
146 |
147 | If you prefer going completely headless (though `react-tiny-popover` is fairly headless as is), you may prefer `usePopover` and `useArrowContainer` instead.
148 |
149 | To create your own custom arrow container, the `useArrowContainer` hook works as so:
150 |
151 | ```JSX
152 | import { useArrowContainer } from 'react-tiny-popover';
153 |
154 | // ...
155 |
156 | const { arrowContainerStyle, arrowStyle } = useArrowContainer({
157 | childRect // from PopoverState,
158 | popoverRect // from PopoverState,
159 | position // from PopoverState,
160 | arrowColor // string,
161 | arrowSize // number,
162 | });
163 |
164 | // ...
165 |
166 | // You can then use these styles to render your arrow container in whatever way you'd like
167 | return (
168 |
169 |
170 | {children}
171 |
172 | );
173 | ```
174 |
175 | Similarly, `usePopover` allows you to create your own popover component as so:
176 |
177 | ```JSX
178 | import { usePopover } from 'react-tiny-popover'
179 |
180 | // ...
181 |
182 | const onPositionPopover = useCallback(
183 | (popoverState: PopoverState) => setPopoverState(popoverState),
184 | [],
185 | );
186 |
187 | const [positionPopover, popoverRef] = usePopover({
188 | childRef,
189 | containerClassName,
190 | parentElement,
191 | transform,
192 | positions,
193 | align,
194 | padding,
195 | boundaryInset,
196 | boundaryElement,
197 | reposition,
198 | onPositionPopover,
199 | });
200 |
201 | // ...
202 |
203 | ```
204 |
205 | After attaching `popoverRef` and `childRef` to the DOM, you can fire `positionPopover` at any time to update your popover's position.
206 |
207 | This is a bit more advanced, but play around and see what you can come up with! Feel free to examine the internal Popover component to see how the hook is used there.
208 |
209 | ## Small Breaking Change in 8.1
210 |
211 | Prior to 8.1, the two DOM elements generated via React Portal by `react-tiny-popover` were given the ids `react-tiny-popover-container` and `react-tiny-popover-scout`. In 8.1 and above, both `react-tiny-popover-container` and `react-tiny-popover-scout` are now assigned as class names. This solves the issue of multiple DOM elements sharing the same id if you have more than one popover open at once.
212 |
213 | If you select for `react-tiny-popover-container` or `react-tiny-popover-scout` by id in your code, you'll have to select via class name instead.
214 |
215 | ## Migrating to 8.0
216 |
217 | `react-tiny-popover` 8.0 removes the `contentLocation` prop and replaces it with a slightly more capable `transform` prop. By default, the `transform` prop behaves exactly as `contentLocation` did.
218 |
219 | ```JSX
220 | Hi! I'm popover content.}
224 | >
225 | {/* ... */}
226 | ;
227 | ```
228 |
229 | Becomes:
230 |
231 | ```JSX
232 | Hi! I'm popover content.}
236 | >
237 | {/* ... */}
238 | ;
239 | ```
240 |
241 | Now, you have access to an additional handy prop, `transformMode`:
242 |
243 | ```JSX
244 | Hi! I'm popover content.}
249 | >
250 | {/* ... */}
251 | ;
252 | ```
253 |
254 | The above popover will now render 20 pixels down and left of where it originally would have appeared without the transform, rather than at a fixed/absolute position.
255 |
256 | The other `transformMode` value, `"absolute"` is the default value when `transformMode` is omitted. This produces the same behavior that `contentLocation` did.
257 |
258 | ## Migrating to 5.0
259 |
260 | `react-tiny-popover` 5 and up has abandoned use of `findDOMNode` to gain a reference to `Popover`'s target DOM node, and now explicitly relies on a ref. Since React has deprecated `findDOMNode` in `StrictMode`, now seems like an appropriate time to shift away from this under-the-hood logic toward a clearer and more declarative API.
261 |
262 | If your code looked this way, it can stay this way. React elements handle refs out of the box with no issues:
263 |
264 | ```JSX
265 | Hi! I'm popover content.}
268 | >
269 |
272 | ;
273 | ```
274 |
275 | However, if you use a custom component as a your `Popover`'s child, you'll have to implement ref forwarding. Without ref forwarding, `Popover` will not be able to inject a reference into your component and refer to it.
276 |
277 | For example:
278 |
279 | ```JSX
280 | interface Props extends React.ComponentPropsWithoutRef<'div'> {
281 | onClick(): void;
282 | }
283 |
284 | // this component will no longer work as a Popover child
285 | const CustomComponent: React.FC = props => (
286 |
296 | ));
297 | ```
298 |
299 | Check out [React's ref forwarding API](https://reactjs.org/docs/forwarding-refs.html) for more info, and see the examples above.
300 |
301 | ## API
302 |
303 | ### Popover
304 |
305 | | Property | Type | Required | Description |
306 | | ------------------- | ------------------------------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
307 | | children | `JSX.Element` | ✔️ | The component you place here will render directly to the DOM. Totally headless. If you provide a custom component, it must use [ref forwarding](https://reactjs.org/docs/forwarding-refs.html). |
308 | | isOpen | `boolean` | ✔️ | When this boolean is set to true, the popover is visible and tracks the target. When the boolean is false, the popover content is neither visible nor present on the DOM. |
309 | | content | `JSX.Element` or `(popoverState: PopoverState) => JSX.Element` | ✔️ | Here, you'll provide the content that will appear as the popover. If you're providing a function, see `PopoverState` below. |
310 | | padding | `number` | | This number determines the gap, in pixels, between your target content and your popover content. Defaults to 0. |
311 | | reposition | `boolean` | | If false, rather than the popover content repositioning on a boundary collision, the popover content container will move beyond your `parentElement`'s bounds. You are, however, supplied with `nudgedLeft` and `nudgedTop` values by the function you can opt to provide to `content`, so you may choose to handle content overflow as you wish. |
312 | | positions | `string[]` | | You may provide a priority list of preferred positions for your popover content in relation to its target, in the form of an array. Valid values for the array are `'top', 'bottom', 'left', 'right'`. If the popover reaches the edge of the window or its otherwise specified boundary (see `parentElement` and `boundaryInset`), and repositioning is enabled, it will attempt to render in the order you specify. The default order is `['top', 'left', 'right', 'bottom']`. If you'd like, you can provide a shorter array like `['top', 'left']`. Once the array of positions is exhausted, the popover will no longer attempt to reposition. |
313 | | align | `string` | | Possible values are `start`, `center`, and `end`. If `start` is specified, the popover content's top or left location is aligned with its target's. With `end` specified, the content's bottom or right location is aligned with its target's. If `center` is specified, the popover content and target's centers are aligned. Defaults to `center`. |
314 | | ref | `React.Ref` | | Since `Popover` relies on ref forwarding to access its child, it's not simple to obtain a second reference to that child. This property acts as a "pass through" for you to obtain a ref to the child you've provided `Popover`. The value of the ref you provide here will be `Popover`'s child. |
315 | | onClickOutside | `(e: MouseEvent) => void` | | If `react-tiny-popover` detects a click event outside of the target and outside of the popover, you may handle this event here. |
316 | | clickOutsideCapture | `boolean` | | This boolean represents the `useCapture` option passed along as the third argument to the internal `window.addEventListener` used by `onClickOutside`. |
317 | | transform | `{ top: number; left: number}` or `(popoverState: PopoverState) => { top: number, left: number }` | | If you'd like to hook directly into the positioning process, you may do so here! `top` and `left` positions provided or returned here will override the popover content's (`popoverRect`) location in a fashion specified by the `transformMode` prop. |
318 | | transformMode | `"absolute"` or `"relative"` | | A value of `"absolute"` will popsition the popover at precisely the `top` and `left` values provided by `transform`, relative to the `parentElement`. A value of `"relative"` will "nudge" the popover from where it would appear pre-transform by the `top` and `left` values provided in `transform`. |
319 | | parentElement | `HTMLElement` | | Provide an HTML element ref here to have your popover content appended to that element rather than `document.body`. This is useful if you'd like your popover to sit at a particular place within the DOM. Supplying a `parentElement` ref will not in most cases directly affect the positioning of the popover. |
320 | | boundaryInset | `number` | | This number specifies the inset around your `parentElement`'s border that boundary violations are determined at. Defaults to 0. Can be negative. |
321 | | boundaryElement | `HTMLElement` | | If provided (and `reposition` is enabled), your popover will adhere to the boundaries of this element as determined by `Element.getBoundingDOMRect()`. |
322 | | containerStyle | `object` (`CSSStyleDeclaration`) | | Your popover content is rendered to the DOM in a single container `div`. If you'd like to apply style directly to this container `div`, you may do so here! Be aware that as this `div` is a DOM element and not a React element, all style values must be strings. For example, 5 pixels must be represented as `'5px'`, as you'd do with vanilla DOM manipulation in JavaScript. |
323 | | containerClassName | `string` | | If you'd like to apply styles to the single container `div` that your popover content is rendered within via stylesheets, you can specify a custom className for the container here. |
324 |
325 | ### PopoverState
326 |
327 | | Property | Type | Description |
328 | | -------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
329 | | isPositioned | `boolean` | After the popover has positioned its contents, this field is true. Prior, it is false. |
330 | | childRect | `Rect` | The current rect of the popover's child (i.e., the source from which the popover renders). |
331 | | popoverRect | `Rect` | The current rect of the popover's contents. |
332 | | parentRect | `Rect` | The current rect of the popover child's parent. |
333 | | position | `'left'` \| `'right'` \| `'top'` \| `'bottom'` \| `undefined` | The current position of the popover in relation to the child. `undefined` implies the user has set an absolute transform. |
334 | | align | `'start'` \| `'center'` \| `'end'` \| `undefined` | The cross-axis alignment of the popover's contents. `undefined` implies the user has set an explicit `contentLocation`. |
335 | | padding | `number` | The distance between the popover's child and contents. If set to zero, the two are touching. |
336 | | nudgedLeft | `number` | If the popover's contents encounter a boundary violation that does not warrant a reposition, the contents are instead "nudged" by the appropriate top and left values to keep the contents within the boundary. This is the left value. |
337 | | nudgedTop | `number` | If the popover's contents encounter a boundary violation that does not warrant a reposition, the contents are instead "nudged" by the appropriate top and left values to keep the contents within the boundary. This is the top value. |
338 | | boundaryInset | `number` | The popover's contents will encounter boundary violations prior to the actual `parentElement`'s boundaries by this number in pixels. Can be negative. |
339 | | boundaryRect | `Rect` | The current rect of the popover's boundaries. |
340 | | transform | `{ top?: number; left?: number; }` \| undefined | The values you provided to the `transform` prop, if they exist. |
341 | | violations | `{ top: number; left: number; bottom: number; right: number; }` | An object containing boundary violations. Expect a value of `0` if no boundary violation exists at that bound (i.e., your popover is entirely within that bound), and expect positive values representing pixels beyond that bound if a violation exists (i.e., your popover exceeds the `top` bound by ten pixels, `top` will be `10`). |
342 | | hasViolations | `boolean` | `true` if violations exist at any boundary, `false` otherwise. |
343 |
344 | ### ArrowContainer
345 |
346 | | Property | Type | Required | Description |
347 | | -------------- | ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
348 | | position | `string` | ✔️ | The `ArrowContainer` needs to know its own position in relation to the target, so it can point in the correct direction! |
349 | | children | `JSX.Element` | ✔️ | You'll provide the `ArrowContainer` with a JSX.Element child to render as your popover content. |
350 | | targetRect | `object` | ✔️ | The `ArrowContainer` must know its target's bounding rect in order to position its arrow properly. This object is of type `{ width: number, height: number, top: number, left: number, right: number, bottom: number }`. |
351 | | popoverRect | `object` | ✔️ | This allows the `ArrowContainer` to know its own bounding rect in order to position its arrow properly. This object is of type `{ width: number, height: number, top: number, left: number, right: number, bottom: number }`. |
352 | | arrowSize | `number` | | The size of the triangle arrow. Defaults to 10 or something like that. |
353 | | arrowColor | `string` | | The color of the arrow! Exciting. |
354 | | arrowStyle | `object` | | You may append to the arrow's style here. |
355 | | style | `object` | | If you'd like to append to the style of the `ArrowContainer` itself, do so here. Rad. |
356 |
--------------------------------------------------------------------------------
/eslint.config.js:
--------------------------------------------------------------------------------
1 | const globals = require('globals');
2 | const pluginJs = require('@eslint/js');
3 | const tseslint = require('typescript-eslint');
4 | const pluginReact = require('eslint-plugin-react');
5 | const eslintConfigPrettier = require('eslint-config-prettier');
6 |
7 | module.exports = [
8 | { languageOptions: { globals: globals.browser } },
9 | pluginJs.configs.recommended,
10 | ...tseslint.configs.recommended,
11 | pluginReact.configs.flat.recommended,
12 | eslintConfigPrettier,
13 | {
14 | files: ['**/*.{ts,tsx}'],
15 | rules: {
16 | 'react/react-in-jsx-scope': 'off',
17 | 'react/display-name': 'off',
18 | },
19 | },
20 | ];
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-tiny-popover",
3 | "version": "8.1.6",
4 | "description": "A simple and highly customizable popover react higher order component with no other dependencies!",
5 | "keywords": [
6 | "react",
7 | "popover",
8 | "react-popover",
9 | "popout",
10 | "pop",
11 | "out",
12 | "modal"
13 | ],
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/alexkatz/react-tiny-popover.git"
17 | },
18 | "files": [
19 | "dist"
20 | ],
21 | "license": "MIT",
22 | "author": "Alex Katz",
23 | "main": "dist/Popover.js",
24 | "types": "dist/index.d.ts",
25 | "scripts": {
26 | "build": "tsc -p . && pnpm run copy-types",
27 | "clean": "rimraf dist/",
28 | "copy-types": "shx cp src/index.d.ts dist/index.d.ts",
29 | "start-demo": "cd docs && pnpm run start",
30 | "watch": "tsc-watch -p . --onSuccess 'pnpm run copy-types'"
31 | },
32 | "devDependencies": {
33 | "@eslint/js": "^9.10.0",
34 | "@types/react": "^18.3.12",
35 | "@types/react-dom": "^18.3.1",
36 | "eslint": "^9.10.0",
37 | "eslint-config-prettier": "^9.1.0",
38 | "eslint-config-react-app": "^7.0.1",
39 | "eslint-plugin-react": "^7.36.1",
40 | "globals": "^15.12.0",
41 | "prettier": "^3.3.3",
42 | "rimraf": "^4.4.1",
43 | "shx": "^0.3.4",
44 | "tsc-watch": "^6.2.1",
45 | "typescript": "5.6.3",
46 | "typescript-eslint": "^8.5.0"
47 | },
48 | "peerDependencies": {
49 | "react": ">=16.8.0",
50 | "react-dom": ">=16.8.0"
51 | },
52 | "packageManager": "pnpm@10.1.0+sha512.c89847b0667ddab50396bbbd008a2a43cf3b581efd59cf5d9aa8923ea1fb4b8106c041d540d08acb095037594d73ebc51e1ec89ee40c88b30b8a66c0fae0ac1b"
53 | }
54 |
--------------------------------------------------------------------------------
/react-tiny-popover-short-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexkatz/react-tiny-popover/fecaaef1fbd61bbe0dd0b22be38635c57af6ceed/react-tiny-popover-short-demo.gif
--------------------------------------------------------------------------------
/src/ArrowContainer.tsx:
--------------------------------------------------------------------------------
1 | import React, { useMemo } from 'react';
2 | import { ArrowContainerProps } from '.';
3 | import { useArrowContainer } from './useArrowContainer';
4 |
5 | export const ArrowContainer = ({
6 | childRect,
7 | popoverRect,
8 | position,
9 | arrowColor,
10 | arrowSize,
11 | arrowClassName,
12 | arrowStyle: externalArrowStyle,
13 | className,
14 | children,
15 | style: externalArrowContainerStyle,
16 | }: ArrowContainerProps) => {
17 | const { arrowContainerStyle, arrowStyle } = useArrowContainer({
18 | childRect,
19 | popoverRect,
20 | position,
21 | arrowColor,
22 | arrowSize,
23 | });
24 |
25 | const mergedContainerStyle = useMemo(
26 | () => ({
27 | ...arrowContainerStyle,
28 | ...externalArrowContainerStyle,
29 | }),
30 | [arrowContainerStyle, externalArrowContainerStyle],
31 | );
32 |
33 | const mergedArrowStyle = useMemo(
34 | () => ({
35 | ...arrowStyle,
36 | ...externalArrowStyle,
37 | }),
38 | [arrowStyle, externalArrowStyle],
39 | );
40 |
41 | return (
42 |