Skip to content

Commit ee47e2d

Browse files
committed
3.0.0
1 parent ba8184f commit ee47e2d

4 files changed

Lines changed: 59 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 3.0.0
2+
3+
- Dropped floating UI. Used CSS anchor positioning API. See updated types in README.
4+
15
# 2.0.0
26

37
- Now triggerElement is optional. Moreover you can pass a CSS selector for a trigger element, so you have full control over

README.md

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
[![version](https://img.shields.io/npm/v/solid-simple-popover?style=for-the-badge)](https://www.npmjs.com/package/solid-simple-popover)
44
![npm](https://img.shields.io/npm/dw/solid-simple-popover?style=for-the-badge)
55

6-
A really simple and minimalistic popover component for your apps.
6+
A really simple and minimalistic popover component for your apps with CSS anchor position support.
77

8-
**IMPORTANT:**
9-
10-
- You may add `width: max-content` to the content element by yourself to avoid layout interference as it described [here](https://floating-ui.com/docs/computeposition#initial-layout).
8+
**V2 docs are [here](https://github.com/elite174/solid-simple-popover/tree/v2)**
119

1210
## Features
1311

1412
- Minimalistic - no wrapper DOM nodes!
1513
- Popover API support
16-
- Full control over position
14+
- Full control over position (CSS Anchor positioning)
1715
- Works with SSR and Astro
1816
- Multiple trigger events with vue-style modifiers
1917
- Custom anchor element
@@ -49,14 +47,11 @@ Don't forget to reset default browser styles for `[popover]`:
4947
You can pass all the options for positioning. See docs for [computePosition](https://floating-ui.com/docs/computePosition).
5048

5149
```tsx
52-
import { flip } from "@floating-ui/dom";
53-
5450
<button id="trigger-element">Toggle popover!</button>
5551
<Popover
5652
triggerElement="#trigger-element"
5753
// Full control over position
58-
autoUpdate
59-
computePositionOptions={{ placement: "bottom-start", middleware: [flip()] }}
54+
targetPositionArea="top center"
6055
>
6156
<div>I'm a content</div>
6257
</Popover>;
@@ -108,28 +103,21 @@ Sometimes it's necessary the anchor element to be different from trigger element
108103
This package has the following peer dependencies:
109104

110105
```json
111-
"@floating-ui/dom": "^1.5",
112106
"solid-js": "^1.8"
113107
```
114108

115109
so you need to install required packages by yourself.
116110

117-
`pnpm i solid-js @floating-ui/dom solid-simple-popover`
111+
`pnpm i solid-js solid-simple-popover`
118112

119113
## Usage
120114

121115
```tsx
122116
import { Popover } from "solid-simple-popover";
123-
import { flip } from "@floating-ui/dom";
124117

125118
<button id="trigger-button">Toggle popover</button>
126119
<Popover
127120
triggerElement="trigger-button"
128-
// Full control over position
129-
autoUpdate
130-
computePositionOptions={{ placement: "bottom-start", middleware: [flip()] }}
131-
// Highly customizable
132-
sameWidth
133121
dataAttributeName="data-open"
134122
// You may pass custom selector here
135123
anchorElement="#trigger-button"
@@ -143,9 +131,36 @@ import { flip } from "@floating-ui/dom";
143131
## Types
144132

145133
```tsx
146-
import { type ComputePositionConfig, type AutoUpdateOptions, type ComputePositionReturn } from "@floating-ui/dom";
147-
import { type JSXElement, type ParentComponent } from "solid-js";
148-
134+
import { JSXElement, ParentComponent } from "solid-js";
135+
type ValidPositionAreaX =
136+
| "left"
137+
| "right"
138+
| "start"
139+
| "end"
140+
| "center"
141+
| "selft-start"
142+
| "self-end"
143+
| "x-start"
144+
| "x-end";
145+
type ValidPositionAreaY =
146+
| "top"
147+
| "bottom"
148+
| "start"
149+
| "end"
150+
| "center"
151+
| "self-start"
152+
| "self-end"
153+
| "y-start"
154+
| "y-end";
155+
export type PositionArea = `${ValidPositionAreaY} ${ValidPositionAreaX}`;
156+
export type TargetPositionArea =
157+
| PositionArea
158+
| {
159+
top?: (anchorName: string) => string;
160+
left?: (anchorName: string) => string;
161+
right?: (anchorName: string) => string;
162+
bottom?: (anchorName: string) => string;
163+
};
149164
export type PopoverProps = {
150165
/**
151166
* HTML Element or CSS selector to find trigger element which triggers popover
@@ -164,10 +179,6 @@ export type PopoverProps = {
164179
* Note: if your trigger element has `disabled` state (like button or input), popover also won't be triggered
165180
*/
166181
disabled?: boolean;
167-
/** Should content have the same width as trigger */
168-
sameWidth?: boolean;
169-
/** Options for floating-ui computePosition function */
170-
computePositionOptions?: ComputePositionConfig;
171182
/**
172183
* @default "pointerdown"
173184
* If set to null no event would trigger popover,
@@ -194,26 +205,31 @@ export type PopoverProps = {
194205
* and position breaks
195206
*/
196207
contentElementSelector?: string;
197-
/**
198-
* autoUpdate option for floating ui
199-
* @see https://floating-ui.com/docs/autoupdate
200-
*/
201-
autoUpdate?: boolean;
202-
/**
203-
* Applies only if autoUpdate is true
204-
* @see https://floating-ui.com/docs/autoupdate#options
205-
*/
206-
autoUpdateOptions?: AutoUpdateOptions;
207208
/**
208209
* Close popover on escape key press.
209210
* Uses 'keydown' event with 'Escape' key.
210211
* @default true
211212
*/
212213
closeOnEscape?: boolean;
213214
onOpenChange?: (open: boolean) => void;
214-
onComputePosition?: (data: ComputePositionReturn) => void;
215+
/** @default absolute */
216+
targetPosition?: "absolute" | "fixed";
217+
/**
218+
* @see https://css-tricks.com/css-anchor-positioning-guide/#aa-position-area
219+
* @default "end center"
220+
*/
221+
targetPositionArea?: TargetPositionArea;
222+
/** @see https://css-tricks.com/css-anchor-positioning-guide/#aa-position-visibility */
223+
positionVisibility?: "always" | "anchors-visible" | "no-overflow";
224+
/** @see https://css-tricks.com/css-anchor-positioning-guide/#aa-position-try-fallbacks */
225+
positionTryFallbacks?: (anchorName: string) => string[];
226+
/** @see https://css-tricks.com/css-anchor-positioning-guide/#aa-position-try-order */
227+
positionTryOrder?: "normal" | "most-width" | "most-height" | "most-block-size" | "most-inline-size";
228+
/** @see https://css-tricks.com/css-anchor-positioning-guide/#aa-anchor-size */
229+
targetWidth?: string;
230+
/** @see https://css-tricks.com/css-anchor-positioning-guide/#aa-anchor-size */
231+
targetHeight?: string;
215232
};
216-
217233
export declare const Popover: ParentComponent<PopoverProps>;
218234
```
219235

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-simple-popover",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"description": "A simple popover component for SolidJS",
55
"author": "Vladislav Lipatov",
66
"type": "module",
@@ -23,7 +23,7 @@
2323
"keywords": [
2424
"solid",
2525
"popover",
26-
"floating-ui"
26+
"css anchor"
2727
],
2828
"license": "MIT",
2929
"publishConfig": {

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineConfig({
2020
outDir: "dist",
2121
minify: false,
2222
rollupOptions: {
23-
external: ["solid-js", "solid-js/web", "@floating-ui/dom"],
23+
external: ["solid-js", "solid-js/web"],
2424
},
2525
},
2626
});

0 commit comments

Comments
 (0)