|
1 | | -# @rc-component/dom-align |
2 | | - |
3 | | ---- |
4 | | - |
5 | | -Align source html element with target html element flexibly. |
6 | | - |
7 | | -[![NPM version][npm-image]][npm-url] |
8 | | -[![npm download][download-image]][download-url] |
9 | | -[![build status][github-actions-image]][github-actions-url] |
10 | | -[![Codecov][codecov-image]][codecov-url] |
11 | | -[![bundle size][bundlephobia-image]][bundlephobia-url] |
12 | | -[![dumi][dumi-image]][dumi-url] |
13 | | - |
14 | | -[npm-image]: http://img.shields.io/npm/v/@rc-component/dom-align.svg?style=flat-square |
15 | | -[npm-url]: http://npmjs.org/package/@rc-component/dom-align |
16 | | -[travis-image]: https://img.shields.io/travis/react-component/dom-align/main?style=flat-square |
17 | | -[travis-url]: https://travis-ci.com/react-component/dom-align |
18 | | -[github-actions-image]: https://github.com/react-component/dom-align/actions/workflows/ci.yml/badge.svg |
19 | | -[github-actions-url]: https://github.com/react-component/dom-align/actions/workflows/ci.yml |
20 | | -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dom-align/main.svg?style=flat-square |
21 | | -[codecov-url]: https://app.codecov.io/gh/react-component/dom-align |
22 | | -[david-url]: https://david-dm.org/react-component/dom-align |
23 | | -[david-image]: https://david-dm.org/react-component/dom-align/status.svg?style=flat-square |
24 | | -[david-dev-url]: https://david-dm.org/react-component/dom-align?type=dev |
25 | | -[david-dev-image]: https://david-dm.org/react-component/dom-align/dev-status.svg?style=flat-square |
26 | | -[download-image]: https://img.shields.io/npm/dm/@rc-component/dom-align.svg?style=flat-square |
27 | | -[download-url]: https://npmjs.org/package/@rc-component/dom-align |
28 | | -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/dom-align |
29 | | -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/dom-align |
30 | | -[dumi-url]: https://github.com/umijs/dumi |
31 | | -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square |
32 | | - |
33 | | -## Screenshot |
34 | | - |
35 | | -<img height=444 src="http://gtms02.alicdn.com/tps/i2/TB1XIp2HXXXXXajaXXXgJfr8XXX-548-888.png"> |
| 1 | +<div align="center"> |
| 2 | + <h1>@rc-component/dom-align</h1> |
| 3 | + <p><sub><a href="https://ant.design"><img alt="Ant Design" height="14" src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" style="vertical-align: -0.125em;" /></a> Part of the Ant Design ecosystem.</sub></p> |
| 4 | + <p>📐 DOM alignment utility for positioning one element against another.</p> |
| 5 | + |
| 6 | + <p> |
| 7 | + <a href="https://npmjs.org/package/@rc-component/dom-align"><img alt="NPM version" src="https://img.shields.io/npm/v/@rc-component/dom-align.svg?style=flat-square"></a> |
| 8 | + <a href="https://npmjs.org/package/@rc-component/dom-align"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@rc-component/dom-align.svg?style=flat-square"></a> |
| 9 | + <a href="https://github.com/react-component/dom-align/actions/workflows/test.yml"><img alt="build status" src="https://github.com/react-component/dom-align/actions/workflows/test.yml/badge.svg"></a> |
| 10 | + <a href="https://app.codecov.io/gh/react-component/dom-align"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/react-component/dom-align/main.svg?style=flat-square"></a> |
| 11 | + <a href="https://bundlephobia.com/package/@rc-component/dom-align"><img alt="bundle size" src="https://img.shields.io/bundlephobia/minzip/@rc-component/dom-align?style=flat-square"></a> |
| 12 | + <a href="https://github.com/umijs/dumi"><img alt="dumi" src="https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square"></a> |
| 13 | + </p> |
| 14 | +</div> |
| 15 | + |
| 16 | +<p align="center">English | <a href="./README.zh-CN.md">简体中文</a></p> |
| 17 | + |
| 18 | +## Highlights |
| 19 | + |
| 20 | +| Area | Support | |
| 21 | +| ------- | ------------------------------------------------------------------ | |
| 22 | +| Purpose | DOM alignment utility for positioning one element against another. | |
| 23 | +| Package | `@rc-component/dom-align` | |
| 24 | +| Release | `@rc-component/np` / `rc-np` | |
36 | 25 |
|
37 | 26 | ## Install |
38 | 27 |
|
39 | | -[](https://npmjs.org/package/@rc-component/dom-align) |
40 | | - |
41 | | -## Feature |
42 | | - |
43 | | -- support Edge Chrome Firefox |
44 | | -- support align points and offset |
45 | | -- support auto adjust according to visible area |
| 28 | +```bash |
| 29 | +npm install @rc-component/dom-align |
| 30 | +``` |
46 | 31 |
|
47 | 32 | ## Usage |
48 | 33 |
|
49 | | -```js |
| 34 | +```tsx | pure |
50 | 35 | import domAlign from '@rc-component/dom-align'; |
51 | 36 |
|
52 | | -// use domAlign |
53 | | -// sourceNode's initial style should be position:absolute;left:-9999px;top:-9999px; |
| 37 | +domAlign(sourceNode, targetNode, { |
| 38 | + points: ['tl', 'tr'], |
| 39 | + offset: [10, 20], |
| 40 | + overflow: { adjustX: true, adjustY: true }, |
| 41 | +}); |
| 42 | +``` |
| 43 | + |
| 44 | +## API |
| 45 | + |
| 46 | +| Option | Description | |
| 47 | +| --- | --- | |
| 48 | +| `points` | Source and target alignment points. | |
| 49 | +| `offset` | Source node offset. | |
| 50 | +| `targetOffset` | Target node offset. | |
| 51 | +| `overflow` | Auto-adjust behavior when the source overflows viewport. | |
| 52 | +| `useCssRight` / `useCssBottom` / `useCssTransform` | Choose CSS positioning strategy. | |
54 | 53 |
|
55 | | -const alignConfig = { |
56 | | - points: ['tl', 'tr'], // align top left point of sourceNode with top right point of targetNode |
57 | | - offset: [10, 20], // the offset sourceNode by 10px in x and 20px in y, |
58 | | - targetOffset: ['30%', '40%'], // the offset targetNode by 30% of targetNode width in x and 40% of targetNode height in y, |
59 | | - overflow: { adjustX: true, adjustY: true }, // auto adjust position when sourceNode is overflowed |
60 | | -}; |
| 54 | +## Development |
61 | 55 |
|
62 | | -domAlign(sourceNode, targetNode, alignConfig); |
| 56 | +```bash |
| 57 | +npm install |
| 58 | +npm start |
| 59 | +npm test |
| 60 | +npm run lint |
| 61 | +npm run tsc |
| 62 | +npm run compile |
63 | 63 | ``` |
64 | 64 |
|
65 | | -## API |
| 65 | +The dumi site runs at `http://localhost:8000`. |
| 66 | + |
| 67 | +## Release |
| 68 | + |
| 69 | +```bash |
| 70 | +npm run prepublishOnly |
| 71 | +``` |
| 72 | + |
| 73 | +The release flow is handled by `@rc-component/np` through the `rc-np` command when the package uses the shared release flow. |
| 74 | + |
| 75 | +## Detailed API |
66 | 76 |
|
67 | 77 | ### void domAlign(source: HTMLElement, target: HTMLElement, alignConfig: Object):Function |
68 | 78 |
|
@@ -125,17 +135,10 @@ domAlign(sourceNode, targetNode, alignConfig); |
125 | 135 | </tbody> |
126 | 136 | </table> |
127 | 137 |
|
128 | | -## Development |
129 | | - |
130 | | -``` |
131 | | -pnpm install |
132 | | -pnpm start |
133 | | -``` |
134 | | - |
135 | 138 | ## Example |
136 | 139 |
|
137 | 140 | http://localhost:8000/ |
138 | 141 |
|
139 | 142 | ## License |
140 | 143 |
|
141 | | -@rc-component/dom-align is released under the MIT license. |
| 144 | +@rc-component/dom-align is released under the [MIT](./LICENSE.md) license. |
0 commit comments