npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@altrex-ui/floating

v1.0.1

Published

Vue 3 composables for positioning floating elements (tooltips, dropdowns, popovers)

Readme

@altrex-ui/floating

Vue 3 composables for positioning floating elements (tooltips, dropdowns, popovers, modals).

Based on Floating UI - a low-level positioning library.

Installation

npm install @altrex-ui/floating

Quick Start

<script setup>
import { ref } from 'vue'
import { useFloating } from '@altrex-ui/floating'

const reference = ref(null)
const floating = ref(null)

const { floatingStyles } = useFloating(reference, floating, {
  placement: 'top'
})
</script>

<template>
  <button ref="reference">Hover me</button>
  <div ref="floating" :style="floatingStyles">
    Tooltip content
  </div>
</template>

API

useFloating(reference, floating, options)

Main composable for positioning a floating element relative to a reference element.

Parameters:

  • reference (Ref): Reference element (button, input, etc.)
  • floating (Ref): Floating element (tooltip, popover, etc.)
  • options (Object): Configuration options
    • placement (String): Preferred placement ('top', 'bottom', 'left', 'right', etc.)
    • middleware (Array): Middleware functions (offset, flip, shift, etc.)
    • strategy (String): Position strategy ('absolute' or 'fixed')
    • whileElementsMounted (Function): Callback when elements are mounted

Returns:

  • x (Ref): X coordinate
  • y (Ref): Y coordinate
  • placement (Ref): Final placement
  • strategy (Ref): Position strategy
  • middlewareData (Ref): Middleware results
  • isPositioned (Ref): Whether positioned
  • floatingStyles (ComputedRef): Ready-to-use styles
  • update (Function): Manually trigger update

Middleware

Arrow

Positions an arrow element pointing to the reference.

<script setup>
import { ref, computed } from 'vue'
import { useFloating, arrow } from '@altrex-ui/floating'

const reference = ref(null)
const floating = ref(null)
const arrowRef = ref(null)

const { floatingStyles, middlewareData } = useFloating(reference, floating, {
  placement: 'top',
  middleware: [
    arrow({ element: arrowRef })
  ]
})

const arrowX = computed(() => middlewareData.value.arrow?.x ?? 0)
const arrowY = computed(() => middlewareData.value.arrow?.y ?? 0)
</script>

<template>
  <button ref="reference">Reference</button>
  <div ref="floating" :style="floatingStyles">
    <div ref="arrowRef" :style="{ left: `${arrowX}px`, top: `${arrowY}px` }" />
    Content
  </div>
</template>

Offset

Displaces the floating element from its reference.

import { offset } from '@altrex-ui/floating'

useFloating(reference, floating, {
  middleware: [
    offset(10) // 10px offset
  ]
})

Flip

Flips the floating element to opposite side if no space.

import { flip } from '@altrex-ui/floating'

useFloating(reference, floating, {
  middleware: [
    flip()
  ]
})

Shift

Shifts the floating element along the axis to keep it in view.

import { shift } from '@altrex-ui/floating'

useFloating(reference, floating, {
  middleware: [
    shift({ padding: 5 })
  ]
})

Size

Resizes the floating element based on available space.

import { size } from '@altrex-ui/floating'

useFloating(reference, floating, {
  middleware: [
    size({
      apply({ availableWidth, availableHeight, elements }) {
        Object.assign(elements.floating.style, {
          maxWidth: `${availableWidth}px`,
          maxHeight: `${availableHeight}px`
        })
      }
    })
  ]
})

Auto Update

Automatically update position when things change.

<script setup>
import { useFloating, autoUpdate } from '@altrex-ui/floating'

const { floatingStyles } = useFloating(reference, floating, {
  placement: 'top',
  whileElementsMounted: autoUpdate
})
</script>

Advanced Usage

Multiple Middleware

import { useFloating, offset, flip, shift, arrow } from '@altrex-ui/floating'

const { floatingStyles, middlewareData } = useFloating(reference, floating, {
  placement: 'top',
  middleware: [
    offset(10),
    flip(),
    shift({ padding: 5 }),
    arrow({ element: arrowRef })
  ]
})

Available Placements

  • 'top', 'top-start', 'top-end'
  • 'bottom', 'bottom-start', 'bottom-end'
  • 'left', 'left-start', 'left-end'
  • 'right', 'right-start', 'right-end'

Position Strategies

  • 'absolute' (default) - Positioned relative to nearest positioned ancestor
  • 'fixed' - Positioned relative to viewport

Package Exports

// Main composable
import { useFloating } from '@altrex-ui/floating'

// Arrow middleware
import { arrow } from '@altrex-ui/floating'

// Core positioning (framework-agnostic)
import { computePosition } from '@altrex-ui/floating/core'

// DOM platform
import { autoUpdate } from '@altrex-ui/floating/dom'

// Utilities
import { toValue, getDPR } from '@altrex-ui/floating/utils'
import { getDocumentElement } from '@altrex-ui/floating/utils/dom'

Browser Support

  • Chrome/Edge (latest)
  • Firefox (latest)
  • Safari (latest)
  • iOS Safari (latest)
  • Chrome Android (latest)

License

MIT

Credits

Based on Floating UI by Atomiks.

Converted and adapted for the Altrex Design System.