Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@floating-ui/utils
Advanced tools
Package description
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.
Readme
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.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).