UseFloating
Last updated: 3.0.0 (04/07/2024) | Added: 2.0.0
The useFloating() hook provides a simple interface for generating CSS styles that respect the safe areas of a given device. It is used in the Floating Toolbar and all button components to provide float functionality.
Usage
import { useFloating, Flex, Text } from "@valence-ui/core";
function MyComponent() {
const floating = useFloating({
"left", // Horizontal position.
"top", // Vertical position
20, // Offset
);
const FlexStyle = {
position: "fixed",
zIndex: 200,
...floating.style, // Generated styles applied
}
return (
<Flex style={FlexStyle}>
<Text>Hi there!</Text>
</Flex>
)
}The offset can also be customized far more:
useFloating is also responsive, allowing you to define behavior for specific breakpoints:
Types
PositionHorizontal
PositionVertical
FloatingOffset
Props
Property
Type
Default
Description
calculateOffset
boolean
true
Whether to include safe areas (such as the notch and navigation cutouts in new iPhones) when calculating offsets.
Changelog
3.0.0: Added hook.
Last updated
Was this helpful?