Absolute
The Absolute component is a structural element designed to wrap content and position it precisely, independent of the normal document structure. It is ideal for creating dynamic notifications, pop-ups, overlays, moving nameplates, and other UI elements that require precise placement.
By default, the Absolute component positions its content relative to the closest Relative component parent. If no Relative component is present, it positions relative to the body.
The primary use case for the Absolute component is to position nested content precisely within a document. The component lets you define offsets using the top, left, right, and bottom properties.
import Relative from '@components/Layout/Relative/Relative';import Absolute from '@components/Layout/Absolute/Absolute';import Block from '@components/Layout/Block/Block';
const App = () => { return ( <Relative> <Absolute top="50px" right="50px"> <Block>Content with top and right offset by 50px</Block> </Absolute> </Relative> );};
export default App;| Prop Name | Type | Default | Description |
|---|---|---|---|
style | JSX.CSSProperties | {} | Inline styles to apply directly to the component’s root element. |
class | string | "" | Additional CSS classes to apply to the component |
ref | HTMLDivElement | undefined | Retrieves the component’s DOM element and assigns it to a variable. |
top, left, right, bottom | string | "" | Specify the position offset of the Absolute component. It accepts any valid css unit value |
onAction | Record<string, (scope?: string, ...args: any[]) => void> | undefined | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. |
anchor | string | HTMLElement | undefined | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. |
Positioning the component
Section titled “Positioning the component”The primary purpose of the Absolute component is to position content precisely. To achieve optimal control, it is recommended to nest the Absolute component within a Relative component. This allows the Relative component to act as a bounding box, ensuring the Absolute component is positioned relative to it rather than the document or screen.
Example
Section titled “Example”import Relative from '@components/Layout/Relative/Relative';import Absolute from '@components/Layout/Absolute/Absolute';import Block from '@components/Layout/Block/Block';
const App = () => { return ( <Relative style={{ width: '300px', height: '200px', border: '1px solid black' }}> <Block>Normally positioned content</Block> <Absolute top="20px" left="40px"> This content is positioned 20px from the top and 40px from the left of the Relative container. </Absolute> <Absolute bottom="0" right="0"> Positioned at the bottom right corner of the Relative container. </Absolute> </Relative> );};
export default App;Accessing the HTML element
Section titled “Accessing the HTML element”To access the HTML DOM element of the Absolute component.
- Declare a variable to hold the ref but don’t initialize it with a value
- The declared value should have a type of
HTMLDivElement. - Set the declared variable as the value of the
refprop of theAbsolutecomponent
Example
Section titled “Example”import Relative from '@components/Layout/Relative/Relative';import Absolute from '@components/Layout/Absolute/Absolute';import Block from '@components/Layout/Block/Block';
const App = () => { let absoluteRef!: HTMLDivElement;
return ( <Relative> <Absolute ref={absoluteRef} top="50px" right="50px"> <Block>Content with top and right offset by 50px</Block> </Absolute> </Relative> );};
export default App;Now you can access the HTML element of the component with absoluteRef and make modifications to it if needed.