Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@floating-ui/utils
Advanced tools
The @floating-ui/utils package provides utility functions for positioning floating elements (like tooltips, popovers, dropdowns, etc.) in relation to reference elements in the DOM. It is part of the Floating UI library, which offers a low-level toolkit for creating floating elements.
computePosition
This feature calculates the position of a floating element relative to a reference element and applies the calculated position to the floating element.
import {computePosition} from '@floating-ui/dom';
const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');
computePosition(referenceElement, floatingElement).then(data => {
Object.assign(floatingElement.style, {
left: `${data.x}px`,
top: `${data.y}px`,
});
});
arrow
The arrow utility positions an arrow element within a floating element so that it is properly aligned with the reference element.
import {computePosition, arrow} from '@floating-ui/dom';
const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');
const arrowElement = floatingElement.querySelector('#arrow');
computePosition(referenceElement, floatingElement, {
middleware: [arrow({element: arrowElement})],
}).then(data => {
Object.assign(floatingElement.style, {
left: `${data.x}px`,
top: `${data.y}px`,
});
Object.assign(arrowElement.style, data.middlewareData.arrow);
});
autoPlacement
The autoPlacement utility automatically chooses the best placement for a floating element based on available space in the viewport.
import {computePosition, autoPlacement} from '@floating-ui/dom';
const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');
computePosition(referenceElement, floatingElement, {
middleware: [autoPlacement()],
}).then(data => {
Object.assign(floatingElement.style, {
left: `${data.x}px`,
top: `${data.y}px`,
});
});
flip
The flip utility adjusts the placement of the floating element to prevent it from overflowing the viewport.
import {computePosition, flip} from '@floating-ui/dom';
const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');
computePosition(referenceElement, floatingElement, {
middleware: [flip()],
}).then(data => {
Object.assign(floatingElement.style, {
left: `${data.x}px`,
top: `${data.y}px`,
});
});
offset
The offset utility adds space between the reference element and the floating element, defined by the offset value.
import {computePosition, offset} from '@floating-ui/dom';
const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');
computePosition(referenceElement, floatingElement, {
middleware: [offset(10)],
}).then(data => {
Object.assign(floatingElement.style, {
left: `${data.x}px`,
top: `${data.y}px`,
});
});
Popper.js is a library used to create poppers in web applications. It is similar to @floating-ui/utils in that it provides positioning logic for tooltips, popovers, and other floating elements. Popper.js was the predecessor to the Floating UI library, which @floating-ui/utils is a part of.
Tippy.js is a highly customizable tooltip and popover library that wraps around Popper.js. It provides a higher-level abstraction over the positioning logic, making it easier to create tooltips and popovers with less setup compared to @floating-ui/utils.
Tooltip.js is another library for creating and managing tooltips in web applications. It is built on top of Popper.js and provides a simpler API for creating tooltips, similar to Tippy.js. Compared to @floating-ui/utils, Tooltip.js offers less low-level control but is easier to use for common tooltip scenarios.
Utility functions shared across Floating UI packages. You may use these functions in your own projects, but are subject to breaking changes.
FAQs
Utilities for Floating UI
We found that @floating-ui/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.