Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ak-layer

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ak-layer

A React layer component responsible for the position of an element on a page

  • 62.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
97
decreased by-60.89%
Maintainers
1
Weekly downloads
 
Created
Source

AtlasKit component registry Commitizen friendly semantic-release Report an issue Ask in our forum

Layer

The layer is responsible for the positioning of an element on a page. For example, you wrap a tooltip with a layer to make its position relative to a target. You can specify up to 12 different positions.

If you use a layer with a component that could be opened or closed, you have to make sure you re-render the layer the first time you open the component, otherwise it will end up with a wrong position.

Example of Layer

Try it out

Interact with a live demo of the ak-layer component.

Installation

npm install ak-layer

Using the component

HTML

This package exports the ak-layer React component.

Import the component in your React app as follows:

import Layer from 'ak-layer';

const myContent = (<div>I'm going to be aligned to the right!</div>);

ReactDOM.render(<Layer position="right middle" content={myContent}>
  <div>Some content</div>
</Layer>, container);

Any content that is passed to Layer as children will always be rendered and any content passed throught the content prop will be rendered aligned to the internal content.

Layer

Kind: global class

new Layer()

The layer is responsible for the positioning of an element on a page relative to another element.

layer.position : String

Position of a layer relative to its target. The position attribute takes two positional arguments in the format position="edge edge-position", where edge specifies what edge to align the layer to, and edge-position specifies where on that edge the layer should appear. Refer to the table below for examples:

top lefttop centertop right
left topright top
left middletargetright middle
left bottomright bottom
bottom leftbottom centerbottom right

Kind: instance property of Layer
Default: "right middle"
HTML Example

<Layer position="top left"></Layer>

layer.boundariesElement : String

Element to act as a boundary for the Layer. The Layer will not sit outside this element if it can help it. If, through it's normal positoning, it would end up outside the boundary the layer will flip positions if the autoPosition prop is set.

Valid values are "window" and "viewport" If not set the boundary will be the current viewport.

Kind: instance property of Layer
Default: "viewport"
HTML Example

<Layer autoPosition boundariesElement="window"></Layer>

layer.autoPosition : Boolean

Sets whether a Layer will flip it's position if there is not enough space in the requested position. i.e. if a layer is set to position="top middle" but placing it there would cause it to be outside the viewport (or the boundariesElement if that is set) the Layer will instead be positioned in "bottom middle".

Kind: instance property of Layer
HTML Example

<Layer autoPosition={true}></Layer>

layer.offset : String

A string representing the offsets from the target element in the format "[x-offset] [y-offset]", measured in pixels.

Kind: instance property of Layer
HTML Example

<Layer offset="0 2"></Layer>

layer.content : ReactElement

HTML content to display in the layer. Will be aligned to the target according to the position prop.

Kind: instance property of Layer
HTML Example

const myContent = (<div>Some content</div>);

ReactDOM.render(<Layer position="right middle" content={myContent}>
  <div>I'm the target!</div>
</Layer>, container);

layer.onFlippedChange : function

Callback that is used to know when the flipped state of Layer changes. This occurs when placing a Layered element in the requested position would cause Layer to be rendered outside of the boundariesElement (usually viewport).

The callback will be passed an object with the following properties:

KeyTypeDescription
flippedbooleanwhether the Layer has been moved away from its original position
actualPositionstringthe current position of the Layer ("top left", etc)
originalPositionstringthe position that Layer originally tried to position to

Kind: instance property of Layer
HTML Example

const handleFlipChange = ({ flipped, actualPosition, originalPosition }) => { ... };

ReactDOM.render(<Layer position="right middle" onFlippedChange={handleFlipChange}>
  <div>I'm the target!</div>
</Layer>, container);

Support and feedback

We're here to help!

Let us know what you think of our components and docs, your feedback is really important for us.

Community support

Ask a question in our forum.

Check if someone has already asked the same question before.

Create a support ticket

Are you in trouble? Let us know!

Keywords

FAQs

Package last updated on 24 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc