Skip to content
ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

144 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

@rc-component/dom-align

Ant Design Part of the Ant Design ecosystem.

๐Ÿ“ DOM alignment utility for positioning one element against another.

NPM version npm downloads build status Codecov bundle size dumi

English | ็ฎ€ไฝ“ไธญๆ–‡

Highlights

Area Support
Purpose DOM alignment utility for positioning one element against another.
Package @rc-component/dom-align
Release @rc-component/np / rc-np

Install

npm install @rc-component/dom-align

Usage

import domAlign from '@rc-component/dom-align';

domAlign(sourceNode, targetNode, {
  points: ['tl', 'tr'],
  offset: [10, 20],
  overflow: { adjustX: true, adjustY: true },
});

API

Option Description
points Source and target alignment points.
offset Source node offset.
targetOffset Target node offset.
overflow Auto-adjust behavior when the source overflows viewport.
useCssRight / useCssBottom / useCssTransform Choose CSS positioning strategy.

Development

npm install
npm start
npm test
npm run lint
npm run tsc
npm run compile

The dumi site runs at http://localhost:8000.

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command when the package uses the shared release flow.

Detailed API

void domAlign(source: HTMLElement, target: HTMLElement, alignConfig: Object):Function

alignConfig object details

name type description
points String[2] move point of source node to align with point of target node, such as ['tr','cc'], align top right point of source node with center point of target node. point can be 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right)
offset Number[2] offset source node by offset[0] in x and offset[1] in y. If offset contains percentage string value, it is relative to sourceNode region.
targetOffset Number[2] offset target node by offset[0] in x and offset[1] in y. If targetOffset contains percentage string value, it is relative to targetNode region.
overflow Object: `{ adjustX: boolean, adjustY: boolean, alwaysByViewport:boolean }` if adjustX field is true, then will adjust source node in x direction if source node is invisible. if adjustY field is true, then will adjust source node in y direction if source node is invisible. if alwaysByViewport is true, the it will adjust if node is not inside viewport
useCssRight Boolean whether use css right instead of left to position
useCssBottom Boolean whether use css bottom instead of top to position
useCssTransform Boolean whether use css transform instead of left/top/right/bottom to position if browser supports. Defaults to false.

Example

http://localhost:8000/

License

@rc-component/dom-align is released under the MIT license.

About

๐Ÿ“ Align DOM nodes flexibly

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages