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 🙏

© 2024 – Pkg Stats / Ryan Hefner

solid-floating-ui

v0.3.1

Published

SolidJS bindings for Floating UI

Downloads

41,119

Readme

solid-floating-ui

SolidJS bindings for Floating UI. Based on @floating-ui/react-dom

NPM JavaScript Style Guide

Install

npm install --save @floating-ui/dom solid-floating-ui
yarn add @floating-ui/dom solid-floating-ui
pnpm add @floating-ui/dom solid-floating-ui

Usage

import { createSignal } from 'solid-js';
import { useFloating } from 'solid-floating-ui';

function App() {
  const [reference, setReference] = createSignal();
  const [floating, setFloating] = createSignal();

  // `position` is a reactive object.
  const position = useFloating(reference, floating);
 
  return (
    <>
      <button ref={setReference}>Button</button>
      <div
        ref={setFloating}
        style={{
          position: position.strategy,
          top: position.x ?? 0,
          left: position.y ?? 0,
        }}
      >
        Tooltip
      </div>
    </>
  );
}

position is based on computePosition's return value has the following fields:

  • x and y are the positioning coords. Initial values are null.
  • strategy is either absolute (default) or fixed. Refer to strategy option
  • placement is refers to the placement options

Middlewares can also be used:

import { useFloating } from 'solid-floating-ui';
import { offset, flip, shift } from '@floating-ui/dom';

const [reference, setReference] = createSignal();
const [floating, setFloating] = createSignal();

useFloating(reference, floating, {
  placement: 'right',
  strategy: 'fixed',
  middleware: [offset(10), flip(), shift()],
});

Updating

useFloating() only calculates the position once on render, or when the reference/floating elements changed — for example, the floating element gets mounted via conditional rendering.

If the floating element lives in a different offsetParent context to the reference element, it will need to be updated while mounted to remain “anchored”. This includes scrolling and resizing the window or the elements themselves.

To do so, use the autoUpdate utility:

import { useFloating } from 'solid-floating-ui';
import { autoUpdate } from '@floating-ui/dom';
 
function App() {
  const [reference, setReference] = createSignal();
  const [floating, setFloating] = createSignal();

  useFloating(reference, floating, {
    whileElementsMounted: autoUpdate,
 
    // Or, pass options. Ensure the cleanup function is returned.
    whileElementsMounted: (reference, floating, update) => (
      autoUpdate(reference, floating, update, {
        animationFrame: true,
      }),
    )
  });
}

Alternatively (or additionally), you may want to update manually in some cases. The primitive returns an update() function to update the position at will:


const position = useFloating();

position.update();

Virtual Elements

See Virtual Elements for details.

function App() {
  const [floating, setFloating] = createSignal();

  const position = useFloating(
    () => ({
      getBoundingClientRect() {
        return {
          // ...
        };
      },
    }),
    floating,
  );

  return (
    <div
      ref={floating}
      style={{
        position: position.strategy,
        top: position.y ?? 0,
        left: position.x ?? 0,
      }}
    >
      Tooltip
    </div>
  );
}

Sponsors

Sponsors

License

MIT © lxsmnsyc