-
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.
- Loading branch information
Showing
9 changed files
with
230 additions
and
41 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
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 @@ | ||
placeholder |
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,43 @@ | ||
import Align from 'rc-align'; | ||
import React, { Component } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const align = { | ||
points: ['cc', 'cc'], | ||
}; | ||
|
||
class Demo extends Component { | ||
state = { | ||
point: null, | ||
}; | ||
|
||
onClick = ({ pageX, pageY }) => { | ||
this.setState({ point: { pageX, pageY }}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={{ marginBottom: 170 }}> | ||
<div | ||
style={{ margin: 20, border: '1px solid red', padding: '100px 0', textAlign: 'center' }} | ||
onClick={this.onClick} | ||
> | ||
Click this region please : ) | ||
</div> | ||
|
||
<Align | ||
ref={this.alignRef} | ||
target={this.state.point} | ||
align={align} | ||
> | ||
<div | ||
style={{ position: 'absolute', width: 100, height: 100, background: 'rgba(0, 255, 0, 0.5)', pointerEvents: 'none' }} | ||
>Align</div> | ||
</Align> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render(<Demo />, document.getElementById('__react-content')); | ||
|
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
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
export function buffer(fn, ms) { | ||
let timer; | ||
|
||
function clear() { | ||
if (timer) { | ||
clearTimeout(timer); | ||
timer = null; | ||
} | ||
} | ||
|
||
function bufferFn() { | ||
clear(); | ||
timer = setTimeout(fn, ms); | ||
} | ||
|
||
bufferFn.clear = clear; | ||
|
||
return bufferFn; | ||
} | ||
|
||
export function isSamePoint(prev, next) { | ||
if (prev === next) return true; | ||
if (!prev || !next) return false; | ||
|
||
return (prev.pageX === next.pageX && prev.pageY === next.pageY) || | ||
(prev.clientX === next.clientX && prev.clientY === next.clientY); | ||
} | ||
|
||
export function isWindow(obj) { | ||
return obj && typeof obj === 'object' && obj.window === obj; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
require('core-js/es6/map'); | ||
require('core-js/es6/set'); | ||
const expect = require('expect.js'); | ||
const Align = require('../'); | ||
import 'core-js/es6/map'; | ||
import 'core-js/es6/set'; | ||
import $ from 'jquery'; | ||
import Align from '../src'; | ||
|
||
$('<style>html,body {padding:0;margin:0;border:none;}</style>') | ||
.appendTo(document.getElementsByTagName('head')); | ||
|
||
describe('rc-align', () => { | ||
it('exists', () => { | ||
expect(Align).to.be.ok(); | ||
}); | ||
}); | ||
|
||
require('./point.spec'); |
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,87 @@ | ||
/* eslint react/no-render-return-value:0 */ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import $ from 'jquery'; | ||
import expect from 'expect.js'; | ||
import Align from '../src'; | ||
|
||
describe('point align', () => { | ||
let container; | ||
|
||
function createAlign(props, callback) { | ||
class Test extends React.Component { | ||
state = {}; | ||
|
||
render() { | ||
return ( | ||
<Align {...props} {...this.state}> | ||
<div | ||
id="align" | ||
style={{ width: 20, height: 20, position: 'fixed' }} | ||
/> | ||
</Align> | ||
); | ||
} | ||
} | ||
|
||
return ReactDOM.render(<Test />, container[0], callback); | ||
} | ||
|
||
beforeEach(() => { | ||
container = $('<div>').appendTo(document.body); | ||
}); | ||
|
||
afterEach(() => { | ||
try { | ||
ReactDOM.unmountComponentAtNode(container[0]); | ||
} catch (e) { | ||
// do nothing... | ||
} | ||
if (container) container.remove(); | ||
container = null; | ||
}); | ||
|
||
it('not pass point', (done) => { | ||
createAlign( | ||
{ | ||
align: { points: ['cc'] }, | ||
target: null, | ||
}, | ||
() => { | ||
const $align = $('#align')[0]; | ||
expect($align).to.be.ok(); | ||
expect($align.style.left).to.not.be.ok(); | ||
expect($align.style.top).to.not.be.ok(); | ||
done(); | ||
}, | ||
); | ||
}); | ||
|
||
it('pass point', (done) => { | ||
const wrapper = createAlign( | ||
{ | ||
align: { points: ['tc'] }, | ||
target: null, | ||
}, | ||
); | ||
|
||
wrapper.setState({ | ||
target: { pageX: 1128, pageY: 903 }, | ||
}, () => { | ||
const $align = $('#align'); | ||
expect($align[0]).to.be.ok(); | ||
expect($align.offset().left).to.be(1118); | ||
expect($align.offset().top).to.be(903); | ||
|
||
wrapper.setState({ | ||
target: { pageX: 321, pageY: 613 }, | ||
}, () => { | ||
expect($align.offset().left).to.be(311); | ||
expect($align.offset().top).to.be(613); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |