@edux-design/popovers 0.0.6 → 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/CHANGELOG.md +16 -0
- package/README.md +77 -0
- package/package.json +1 -1
- package/src/demos/Popover.stories.jsx +5 -5
- package/src/elements/Popover.jsx +1 -1
- package/src/elements/Popover.test.jsx +62 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @edux-design/popovers
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @edux-design/utils@0.1.0
|
|
9
|
+
|
|
10
|
+
## 0.0.7
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- b9d0d32: Added documentation
|
|
15
|
+
- Updated dependencies [b9d0d32]
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @edux-design/utils@0.0.3
|
|
18
|
+
|
|
3
19
|
## 0.0.6
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @edux-design/popovers
|
|
2
|
+
|
|
3
|
+
Thin, design-token-aware wrappers around Radix UI’s popover primitives. Use them directly or via higher-level components (menus, tooltips, etc.).
|
|
4
|
+
|
|
5
|
+
Exports: `PopoverProvider`, `Popover`, `PopoverTrigger`, `PopoverAnchor`, `PopoverPortal`, `PopoverContent`, `PopoverClose`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @edux-design/popovers @radix-ui/react-popover @edux-design/utils
|
|
13
|
+
# or
|
|
14
|
+
npm install @edux-design/popovers @radix-ui/react-popover @edux-design/utils
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Peer deps: `react@^19.1.0`, `react-dom@^19.1.0`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import {
|
|
25
|
+
Popover,
|
|
26
|
+
PopoverTrigger,
|
|
27
|
+
PopoverContent,
|
|
28
|
+
PopoverClose,
|
|
29
|
+
} from "@edux-design/popovers";
|
|
30
|
+
|
|
31
|
+
export function HelpPopover() {
|
|
32
|
+
return (
|
|
33
|
+
<Popover>
|
|
34
|
+
<PopoverTrigger asChild>
|
|
35
|
+
<button className="underline text-sm">Need help?</button>
|
|
36
|
+
</PopoverTrigger>
|
|
37
|
+
<PopoverContent side="right" className="max-w-xs">
|
|
38
|
+
<p className="text-sm">
|
|
39
|
+
Reach out to support@example.com for additional guidance.
|
|
40
|
+
</p>
|
|
41
|
+
<PopoverClose className="absolute top-2 right-2 text-xs underline">
|
|
42
|
+
Close
|
|
43
|
+
</PopoverClose>
|
|
44
|
+
</PopoverContent>
|
|
45
|
+
</Popover>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### PopoverContent props
|
|
51
|
+
|
|
52
|
+
- `side`, `align`, `sideOffset`, `alignOffset`, `avoidCollisions`, `forceMount`
|
|
53
|
+
- `showArrow` (adds the Radix arrow SVG)
|
|
54
|
+
- `className` / `style`
|
|
55
|
+
- `contentProps` for passing any other Radix content props
|
|
56
|
+
|
|
57
|
+
Everything is wrapped in `PopoverPortal` so content escapes stacking context issues by default.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm --filter @edux-design/popovers lint
|
|
65
|
+
pnpm --filter @edux-design/popovers check-types
|
|
66
|
+
pnpm --filter @edux-design/popovers build
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Stories: `src/demos/Popover.stories.jsx`.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Notes
|
|
74
|
+
|
|
75
|
+
- Since these components forward all props to Radix, refer to the Radix documentation for advanced features (modals, anchors, collision handling).
|
|
76
|
+
- The default surface uses the `bg-fg-base` / `text-fg-invert` combo; override via Tailwind classes when you need alternate skins.
|
|
77
|
+
- Consumers should wrap popovers in `PopoverProvider` if they need to tweak the default delay group or share open states.
|
package/package.json
CHANGED
|
@@ -48,7 +48,7 @@ Built with [@radix-ui/react-popover](https://www.radix-ui.com/primitives/docs/co
|
|
|
48
48
|
export default meta;
|
|
49
49
|
/**
|
|
50
50
|
* ───────────────────────────────────────────────
|
|
51
|
-
*
|
|
51
|
+
* Basic Popover
|
|
52
52
|
* ───────────────────────────────────────────────
|
|
53
53
|
*/
|
|
54
54
|
export const Basic = {
|
|
@@ -86,7 +86,7 @@ export const Basic = {
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* ───────────────────────────────────────────────
|
|
89
|
-
*
|
|
89
|
+
* Custom Content
|
|
90
90
|
* ───────────────────────────────────────────────
|
|
91
91
|
*/
|
|
92
92
|
export const CustomContent = {
|
|
@@ -131,7 +131,7 @@ export const CustomContent = {
|
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
133
|
* ───────────────────────────────────────────────
|
|
134
|
-
*
|
|
134
|
+
* Controlled Popover
|
|
135
135
|
* ───────────────────────────────────────────────
|
|
136
136
|
*/
|
|
137
137
|
export const Controlled = {
|
|
@@ -169,7 +169,7 @@ export const Controlled = {
|
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* ───────────────────────────────────────────────
|
|
172
|
-
*
|
|
172
|
+
* All Sides Example
|
|
173
173
|
* ───────────────────────────────────────────────
|
|
174
174
|
*/
|
|
175
175
|
export const Sides = {
|
|
@@ -200,7 +200,7 @@ export const Sides = {
|
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* ───────────────────────────────────────────────
|
|
203
|
-
*
|
|
203
|
+
* No Auto Focus Example
|
|
204
204
|
* ───────────────────────────────────────────────
|
|
205
205
|
*/
|
|
206
206
|
export const NoAutoFocus = {
|
package/src/elements/Popover.jsx
CHANGED
|
@@ -118,7 +118,7 @@ export const PopoverContent = forwardRef(
|
|
|
118
118
|
// Base styling; consuming apps can override via className or wrapping
|
|
119
119
|
const base =
|
|
120
120
|
"bg-fg-base text-fg-invert text-sm font-normal rounded-xl shadow-lg px-12 py-8 animate-fade-in";
|
|
121
|
-
// A transform to “nudge” content initially
|
|
121
|
+
// A transform to “nudge” content initially
|
|
122
122
|
const positioning = {
|
|
123
123
|
top: "translate-y-[-4px]",
|
|
124
124
|
right: "translate-x-[4px]",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import {
|
|
4
|
+
Popover,
|
|
5
|
+
PopoverTrigger,
|
|
6
|
+
PopoverContent,
|
|
7
|
+
PopoverClose,
|
|
8
|
+
} from "./Popover";
|
|
9
|
+
|
|
10
|
+
vi.mock("@radix-ui/react-popover", () => {
|
|
11
|
+
const Passthrough = ({ children, ...props }) => (
|
|
12
|
+
<div {...props}>{children}</div>
|
|
13
|
+
);
|
|
14
|
+
const Buttonish = ({ children, ...props }) => (
|
|
15
|
+
<button type="button" {...props}>
|
|
16
|
+
{children}
|
|
17
|
+
</button>
|
|
18
|
+
);
|
|
19
|
+
const Content = React.forwardRef(
|
|
20
|
+
({ sideOffset, alignOffset, avoidCollisions, forceMount, ...props }, ref) => (
|
|
21
|
+
<div ref={ref} data-testid="radix-content" {...props} />
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
Content.displayName = "RadixContent";
|
|
25
|
+
const Arrow = (props) => <div data-testid="popover-arrow" {...props} />;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
Provider: Passthrough,
|
|
29
|
+
Root: Passthrough,
|
|
30
|
+
Trigger: Buttonish,
|
|
31
|
+
Anchor: Passthrough,
|
|
32
|
+
Portal: Passthrough,
|
|
33
|
+
Content,
|
|
34
|
+
Close: Buttonish,
|
|
35
|
+
Arrow,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("PopoverContent", () => {
|
|
40
|
+
it("merges Tailwind classes and optionally renders arrow", () => {
|
|
41
|
+
render(
|
|
42
|
+
<PopoverContent className="custom" showArrow side="top" data-testid="content">
|
|
43
|
+
Body
|
|
44
|
+
</PopoverContent>
|
|
45
|
+
);
|
|
46
|
+
const content = screen.getByTestId("content");
|
|
47
|
+
expect(content).toHaveClass("custom");
|
|
48
|
+
expect(screen.getByTestId("popover-arrow")).toBeInTheDocument();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("plays nicely with Popover + Trigger exports", () => {
|
|
52
|
+
render(
|
|
53
|
+
<Popover>
|
|
54
|
+
<PopoverTrigger>Open</PopoverTrigger>
|
|
55
|
+
<PopoverContent>Panel</PopoverContent>
|
|
56
|
+
<PopoverClose>Close</PopoverClose>
|
|
57
|
+
</Popover>
|
|
58
|
+
);
|
|
59
|
+
expect(screen.getByText("Open")).toBeInTheDocument();
|
|
60
|
+
expect(screen.getAllByText(/close|panel/i).length).toBeGreaterThan(0);
|
|
61
|
+
});
|
|
62
|
+
});
|