Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🧩 A flexible and lightweight Vue 3 floating panel system powered by @floating-ui/vue — includes composable hooks and plug-and-play components with arrow and resize support.

License

NotificationsYou must be signed in to change notification settings

stefanBid/sb-floating-panel-vue

Repository files navigation

npmlicenseVue 3build

🔥 Features

  • 🧩 Floating panel positioning with arrow and smart shifting
  • ⚡ Built on top of@floating-ui/vue
  • 🎯 Support for resize syncing and animated transitions
  • 🧪 Dual usage: composable or plug-and-play components

👤 Author

Created with ❤️ byStefano Biddau


❓ Why This Library?

sb-floating-panel-vue was designed to make it extremely easy to implement dropdowns, tooltips, and floating panels in Vue 3, without worrying about placement logic, arrow positioning, or responsive syncing. It wraps@floating-ui/vue into a more ergonomic composable or ready-to-use components.


📦 Installation

# npmnpm install sb-floating-panel-vue# yarnyarn add sb-floating-panel-vue# pnpmpnpm add sb-floating-panel-vue

🧠 Composable Usage

Use the composableuseSbFloatingPanel() for complete control.

Options

OptionTypeRequiredDefaultDescription
placementPlacementYesPlacement of the floating panel
strategy'absolute' |'fixed'YesCSS positioning strategy
offsetValuenumberYesOffset between reference and floating
hasArrowbooleanNofalseWhether to render arrow
hasResizebooleanNofalseSync width of floating to reference

Return Values

PropertyTypeDescription
referenceRef<HTMLElement | null>Ref for the trigger element
floatingRef<FloatingElement | null>Ref for the floating panel
floatingArrowRef<HTMLElement | null>Ref for the arrow element
floatingPlacementRef<Placement>The actual resolved placement
floatingStyleComputedRef<CSSProperties>Style for the floating panel
floatingArrowStyleComputedRef<CSSProperties>Style for the arrow
isOpenRef<boolean>Panel visibility
toggle / open / close() => voidControl methods to toggle visibility

Example

In your Vue component, you can use the composable like this:

In your script tag, import the composable and use it:

import{useSbFloatingPanel}from'sb-floating-panel-vue';const{  reference,  floating,  floatingArrow,  floatingStyle,  floatingArrowStyle,  isOpen,  toggle,}=useSbFloatingPanel({placement:'bottom-start',strategy:'absolute',offsetValue:12,hasArrow:true,});

In your template, you can bind the refs and styles:

<template><buttonref="reference"@click="toggle()">Open Panel</button><divv-if="isOpen"ref="floating":style="floatingStyle">    Panel<divref="floatingArrow":style="floatingArrowStyle"/></div></template>

🧱 Component-Based Usage

Import the style

If you use components, youmust import styles inmain.ts:

import'sb-floating-panel-vue/style.css';

Available Components

<SbContainer>

Wraps everything and provides the context.

PropTypeDefaultDescription
placementPlacement'bottom-start'Placement of the floating panel relative to the reference element
strategy'absolute' | 'fixed''absolute'CSS positioning strategy for the floating panel
offsetValuenumber15Offset in pixels between reference and floating panel
hasArrowbooleanfalseWhether to render an arrow pointing to the reference
hasResizebooleanfalseWhether the floating panel should sync its width with the reference

<SbReference>

Trigger element

PropTypeDefaultDescription
referenceRefRef<HTMLElement | null>requiredReference element to which the floating panel is attached
as'button' | 'div' | 'span' | etc.'button'HTML tag to render. Defaults to<button> for accessibility
onClick() => voidOptional click handler, often used to toggle the floating panel visibility

<SbFloating>

Floating panel

PropTypeDefaultDescription
floatingRefRef<HTMLElement | null>requiredThe target element for the floating panel (popover, tooltip, etc.)
floatingArrowRefRef<HTMLElement | null>optionalThe element used as the floating arrow
isOpenbooleanrequiredControls visibility of the floating panel
floatingPlacementPlacementrequiredCurrent placement as resolved by@floating-ui/vue
floatingStyleCSSPropertiesrequiredInline style object applied to the floating panel
floatingArrowStyleCSSPropertiesoptionalInline style object applied to the arrow element
arrowDimensionsnumberoptionalSize (width/height) of the arrow in pixels
zIndexnumberundefinedCustom z-index applied to the floating and arrow elements
animation'fade' | 'scale-fade' | 'none''scale-fade'Defines the animation style for enter/leave transitions
durationnumber300Duration in ms for the transition animations

🧪 Component Usage Example

In your project, you can use the components like this:

In your script tag, import the components:

import{SbContainer,SbFloating,SbReference}from'sb-floating-panel-vue';

In your template, you can use the components as follows:

<SbContainer:has-arrow="true"strategy="fixed"><template#default="{    reference,    floating,    floatingArrow,    floatingPlacement,    floatingStyle,    floatingArrowStyle,    isOpen,    toggle  }"><SbReference:reference-ref="reference":onClick="toggle">Toggle</SbReference><SbFloating:is-open="isOpen.value":floating-ref="floating":floating-arrow-ref="floatingArrow":floating-placement="floatingPlacement.value":floating-style="floatingStyle.value":floating-arrow-style="floatingArrowStyle.value":arrow-dimensions="12":z-index="200">      Hello Panel!</SbFloating></template></SbContainer>

⚠️ Directive Note (Teleport Limitation)

Due to<teleport> in<SbFloating>, if you apply custom directives directly to the component, Vue will warn:

[Vue warn]: Extraneous non-props attributes ([directive-name]) were passed to component but could not be automatically inherited because component renders fragment or text or teleport root nodes.

Solution: Move the directive to an inner element using the slot.

Example Fix

<SbFloating ...>  <div v-click-outside>...</div></SbFloating>

📄 License

MIT License ©Stefano Biddau

About

🧩 A flexible and lightweight Vue 3 floating panel system powered by @floating-ui/vue — includes composable hooks and plug-and-play components with arrow and resize support.

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp