-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add keepAlign support * add test case
- Loading branch information
Showing
3 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { Component } from 'react'; | ||
import Align from '../src'; | ||
|
||
const align = { | ||
points: ['cc', 'cc'], | ||
}; | ||
|
||
class Demo extends Component { | ||
state = { | ||
left: 0, | ||
top: 0, | ||
}; | ||
|
||
eleRef = React.createRef(); | ||
|
||
render() { | ||
const { left, top } = this.state; | ||
|
||
return ( | ||
<div style={{ marginBottom: 170 }}> | ||
<div | ||
style={{ | ||
margin: 20, | ||
border: '1px solid red', | ||
padding: '100px 0', | ||
textAlign: 'center', | ||
position: 'relative', | ||
}} | ||
onClick={this.onClick} | ||
> | ||
<div | ||
ref={this.eleRef} | ||
style={{ | ||
width: 10, | ||
height: 10, | ||
background: 'red', | ||
position: 'absolute', | ||
left, | ||
top, | ||
}} | ||
/> | ||
</div> | ||
|
||
<Align | ||
ref={this.alignRef} | ||
target={() => this.eleRef.current} | ||
align={align} | ||
keepingAlign | ||
> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
width: 100, | ||
height: 100, | ||
background: 'rgba(0, 255, 0, 0.5)', | ||
pointerEvents: 'none', | ||
}} | ||
> | ||
Align | ||
</div> | ||
</Align> | ||
|
||
<button | ||
type="button" | ||
onClick={() => { | ||
this.setState({ | ||
left: Math.random() * 500, | ||
top: Math.random() * 200, | ||
}); | ||
}} | ||
> | ||
Random Position | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Demo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4f6ac65
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: