Backpack UI
Components
Position Layer

PositionLayer

The PositionLayer component is a utility used to handle the position and other properties of a layer based on the screen's breakpoints. It's a versatile component that enables complex layer positioning and behavior according to the properties passed to it.

Props

Here are the properties you can pass to the PositionLayer component:

PropTypeDescription
align[start|center|end, start|center|end] | BreakpointProp<align>Optional. Defines the alignment of the layer.
widthstring (number + % or px) | BreakpointProp<string>Optional. Defines the width of the layer.
heightstring (number + % or px) | BreakpointProp<string>Optional. Defines the height of the layer.
topstring (number + % or px) | BreakpointProp<string>Optional. Defines the top positioning of the layer.
rightstring (number + % or px) | BreakpointProp<string>Optional. Defines the right positioning of the layer.
bottomstring (number + % or px) | BreakpointProp<string>Optional. Defines the bottom positioning of the layer.
leftstring (number + % or px) | BreakpointProp<string>Optional. Defines the left positioning of the layer.
layertop | middle | bottom | BreakpointProp<layer>Optional. Defines the layer's position in stack.
hideboolean | BreakpointProp<boolean>Optional. Defines the visibility of the layer.

Example

The bare bones example below shows a position layer inside a Surface. NB: the position layer component can only be added inside another component which has a stacking context. It will always overlay this component.

Hi!


_22
import { PositionLayer } from '@ef-global/backpack/PositionLayer';
_22
import { Surface } from "@ef-global/backpack/Surface";
_22
import { Headline } from "@ef-global/backpack/Text";
_22
_22
function PositionLayerExample() {
_22
return (
_22
<Surface
_22
style={{ width: '300px', height: '300px', backgroundColor: 'coral' }}
_22
radius={'xxs'}
_22
>
_22
<PositionLayer align={['center', 'center']}>
_22
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_22
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_22
Hi!
_22
</Headline>
_22
</div>
_22
</PositionLayer>
_22
</Surface>
_22
);
_22
}
_22
_22
export { PositionLayerExample };

In the above example, we create a PositionLayer that covers the top half of the viewport, aligning its content at the center top. The layer does not hide and its z-index is set to overlay the containing element.

Example with multiple position layers.

You can use as many position layers as you need. Since they are all absolutely positioned the only thing you need to worry about is which should overlay which. The 'layer' prop can override this to an extent, placing layers on the 'top', 'middle', or 'bottom' z-index, but where the layer prop is set to the same value the source order becomes important.

Hi!

Hi!

Hi!

Hi!

Hi!

Hi!

Hi!

Hi!

Hi!


_78
import { PositionLayer } from "@ef-global/backpack/PositionLayer";
_78
import { Headline } from "@ef-global/backpack/Text";
_78
_78
function PositionLayerExampleMultiple() {
_78
return (
_78
<Surface
_78
style={{ width: '300px', height: '300px', backgroundColor: 'coral' }}
_78
radius={'xxs'}
_78
className={'u-mt-l'}
_78
>
_78
<PositionLayer align={['start', 'start']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['start', 'center']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['start', 'end']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['center', 'start']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['center', 'center']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['center', 'end']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['end', 'start']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['end', 'center']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
<PositionLayer align={['end', 'end']}>
_78
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_78
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_78
Hi!
_78
</Headline>
_78
</div>
_78
</PositionLayer>
_78
</Surface>
_78
)
_78
}
_78
_78
export { PositionLayerExampleMultiple };

Example with breakpoint config.

The PositionLayer component supports per-breakpoint config for its props, so you can also pass an object of breakpoints with various configurations, as in the example below.

Hi!


_21
import { PositionLayer } from '@ef-global/backpack/PositionLayer';
_21
import { Surface } from "@ef-global/backpack/Surface";
_21
import { Headline } from "@ef-global/backpack/Text";
_21
_21
<Surface
_21
style={{ width: '300px', height: '300px', backgroundColor: 'coral' }}
_21
radius={'xxs'}
_21
>
_21
<PositionLayer align={{
_21
s: ['start', 'start'],
_21
m: ['start', 'end'],
_21
l: ['end', 'start'],
_21
xl: ['end', 'end'],
_21
}}>
_21
<div style={{ backgroundColor: 'black', padding: '10px' }}>
_21
<Headline as={'h4'} variant={'header3'} inverse align={'center'}>
_21
Hi!
_21
</Headline>
_21
</div>
_21
</PositionLayer>
_21
</Surface>