React Layout Utils

Questions? Ask in Slack #vcc-ui

@volvo-cars/react-layout-utils

@volvo-cars/react-layout-utils@volvo-cars/react-layout-utils@volvo-cars/react-layout-utils

This package exposes useful utility hooks that can be use to help you with layout concerns.

Installation

$ yarn add @volvo-cars/react-layout-utils

💡 This package includes Typescript definitions


useElementDimensions

Useful for obtaining static render-time dimensions of a given DOM element. Returns a ref and Dimensions object.

NameDescriptionTypeDefault Value
disabledIf true, hook does not refresh dimensionsbooleanfalse
throttleA debounce interval to limit the frequency of dimension updatesnumber0

useResizeObserver

Useful for obtaining dynamic dimensions of a DOM element, where you need to act upon dimension changes in real time. Returns ref, width, and height.

NameDescriptionTypeDefault Value
refA ref to observeundefined | RefObject | HTMLElementundefined
boxThe box model to use for observation.undefined | "border-box" | "content-box" | "device-pixel-content-box"content-box
onResizeA callback receiving the element size. If given, then the hook will not return the size, and instead will call this callback.undefined | ({ width?: number, height?: number }) => voidundefined
roundA function to use for rounding values instead of the default.numberMath.round()

Examples

Demonstration implementations of the hooks can be found in the Storybook.

2024 © Volvo Car Corporation