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:
| Prop | Type | Description |
| align | [start|center|end, start|center|end] | BreakpointProp<align> | Optional. Defines the alignment of the layer. |
| width | string (number + % or px) | BreakpointProp<string> | Optional. Defines the width of the layer. |
| height | string (number + % or px) | BreakpointProp<string> | Optional. Defines the height of the layer. |
| top | string (number + % or px) | BreakpointProp<string> | Optional. Defines the top positioning of the layer. |
| right | string (number + % or px) | BreakpointProp<string> | Optional. Defines the right positioning of the layer. |
| bottom | string (number + % or px) | BreakpointProp<string> | Optional. Defines the bottom positioning of the layer. |
| left | string (number + % or px) | BreakpointProp<string> | Optional. Defines the left positioning of the layer. |
| layer | top | middle | bottom | BreakpointProp<layer> | Optional. Defines the layer's position in stack. |
| hide | boolean | 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!
_22import { PositionLayer } from '@ef-global/backpack/PositionLayer';_22import { Surface } from "@ef-global/backpack/Surface";_22import { Headline } from "@ef-global/backpack/Text";_22_22function 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_22export { 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!
_78import { PositionLayer } from "@ef-global/backpack/PositionLayer";_78import { Headline } from "@ef-global/backpack/Text";_78_78function 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_78export { 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!
_21import { PositionLayer } from '@ef-global/backpack/PositionLayer';_21import { Surface } from "@ef-global/backpack/Surface";_21import { 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>