Skip to content

Commit 3204745

Browse files
author
stefanBid
committed
docs: update README with usage examples and API details
fix: bump version to 0.1.5 in package.json and package-lock.json
1 parent 1c680f3 commit 3204745

File tree

3 files changed

+141
-7
lines changed

3 files changed

+141
-7
lines changed

README.md

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,138 @@
2121
```bash
2222
npm install sb-floating-panel-vue
2323
# or
24-
yarn add sb-floating-panel-vue
24+
yarn add sb-floating-panel-vue
25+
```
26+
27+
---
28+
29+
## 🧩 Usage
30+
31+
The `useSbFloatingPanel` composable provides an easy-to-integrate API to handle floating panels, such as tooltips, popovers, dropdowns, and other UI overlays.
32+
33+
### Importing
34+
35+
```ts
36+
import { useSbFloatingPanel } from 'sb-floating-panel-vue';
37+
```
38+
39+
### 🧠 API
40+
41+
```ts
42+
const {
43+
reference,
44+
floating,
45+
popperArrow,
46+
isOpen,
47+
floatingPosition,
48+
floatingStyles,
49+
floatingArrowStyles,
50+
changeFloatingVisibility,
51+
} = useSbFloatingPanel(settings);
52+
```
53+
54+
### Parameters
55+
56+
The composable takes a `settings` object:
57+
58+
```ts
59+
interface FloatingSettings {
60+
placement: Placement; // e.g., 'bottom', 'top-start', etc.
61+
strategy: Strategy; // 'absolute' | 'fixed'
62+
offsetValue: number; // offset in pixels from the reference element
63+
hasArrow?: boolean; // enable arrow positioning
64+
hasResize?: boolean; // enable auto-resizing with anchor element
65+
}
66+
```
67+
68+
---
69+
70+
## 🔍 Computed Values Explained
71+
72+
### `floatingStyles`
73+
74+
A Vue `computed` value containing the CSS style object that must be applied to your floating panel. It is dynamically calculated by `@floating-ui/vue` to maintain optimal placement relative to the reference element.
75+
76+
### `floatingPosition`
77+
78+
The actual resolved placement string, e.g., `'bottom-start'`, useful for adding custom animations or behavior depending on where the panel is placed.
79+
80+
### `floatingArrowStyles`
81+
82+
An object that includes styles for positioning the optional arrow element (enabled via the `hasArrow` setting). You can directly bind this to the arrow’s `style` attribute.
83+
84+
---
85+
86+
## 🧪 Example
87+
88+
```ts
89+
<script setup lang="ts">
90+
import { ref } from 'vue';
91+
import { useSbFloatingPanel } from 'sb-floating-panel-vue';
92+
93+
const {
94+
reference,
95+
floating,
96+
popperArrow,
97+
isOpen,
98+
floatingStyles,
99+
floatingArrowStyles,
100+
changeFloatingVisibility,
101+
} = useSbFloatingPanel({
102+
placement: 'bottom',
103+
strategy: 'absolute',
104+
offsetValue: 8,
105+
hasArrow: true,
106+
hasResize: true,
107+
});
108+
109+
const togglePanel = () => {
110+
changeFloatingVisibility(!isOpen.value);
111+
};
112+
</script>
113+
```
114+
115+
```vue
116+
<template>
117+
<button ref="reference" @click="togglePanel">Toggle Panel</button>
118+
<div
119+
v-if="isOpen"
120+
ref="floating"
121+
:style="floatingStyles"
122+
class="popover"
123+
>
124+
I'm a floating panel!
125+
<div ref="popperArrow" :style="floatingArrowStyles.arrow" class="arrow" />
126+
</div>
127+
</template>
128+
```
129+
130+
---
131+
132+
## 🎨 Styling
133+
134+
You can use your own CSS or utility classes (like Tailwind CSS) to style the panel and the arrow. Example:
135+
136+
```css
137+
.popover {
138+
background: white;
139+
border: 1px solid #ccc;
140+
padding: 0.75rem;
141+
border-radius: 0.5rem;
142+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
143+
}
144+
145+
.arrow {
146+
width: 10px;
147+
height: 10px;
148+
background: white;
149+
transform: rotate(45deg);
150+
position: absolute;
151+
}
152+
```
153+
154+
---
155+
156+
## 📄 License
157+
158+
MIT © [Stefano Biddau](https://github.com/stefanobiddau)

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sb-floating-panel-vue",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "A lightweight Vue 3 composable hook built on top of @floating-ui/vue to manage floating panels with arrow and resize support.",
55
"main": "dist/sb-floating-panel.umd.js",
66
"module": "dist/sb-floating-panel.es.js",

0 commit comments

Comments
 (0)