2017-12-12 07:05:45 +00:00
|
|
|
<script>
|
2019-01-12 03:33:27 +00:00
|
|
|
import Align from '../index';
|
|
|
|
import BaseMixin from '../../_util/BaseMixin';
|
2017-12-12 07:05:45 +00:00
|
|
|
|
|
|
|
export default {
|
2018-01-12 08:10:41 +00:00
|
|
|
mixins: [BaseMixin],
|
2017-12-12 07:05:45 +00:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
monitor: true,
|
|
|
|
align: {
|
|
|
|
points: ['tl', 'tc'],
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2017-12-12 07:05:45 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getTarget () {
|
2019-01-12 03:33:27 +00:00
|
|
|
const ref = this.$refs.container;
|
2018-09-05 13:28:54 +00:00
|
|
|
if (!ref) {
|
|
|
|
// parent ref not attached
|
2019-01-12 03:33:27 +00:00
|
|
|
return document.getElementById('container');
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return ref;
|
2017-12-12 07:05:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleMonitor () {
|
|
|
|
this.setState({
|
|
|
|
monitor: !this.$data.monitor,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2017-12-12 07:05:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
forceAlign () {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.$refs.align.forceAlign();
|
2017-12-12 07:05:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
2017-12-26 11:04:28 +00:00
|
|
|
margin: '50px',
|
2017-12-12 07:05:45 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<p>
|
2018-09-05 13:28:54 +00:00
|
|
|
<button onClick={this.forceAlign}>Force align</button>
|
2017-12-12 07:05:45 +00:00
|
|
|
|
2018-09-05 13:28:54 +00:00
|
|
|
<label>
|
|
|
|
<input type='checkbox' checked={this.monitor} onInput={this.toggleMonitor} />
|
|
|
|
|
|
|
|
Monitor window resize
|
|
|
|
</label>
|
2017-12-12 07:05:45 +00:00
|
|
|
</p>
|
|
|
|
<div
|
|
|
|
ref='container'
|
|
|
|
id='container'
|
|
|
|
style={{
|
|
|
|
width: '80%',
|
|
|
|
height: '500px',
|
|
|
|
border: '1px solid red',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Align
|
2018-09-05 13:28:54 +00:00
|
|
|
ref='align'
|
2017-12-12 07:05:45 +00:00
|
|
|
target={this.getTarget}
|
|
|
|
monitorWindowResize={this.$data.monitor}
|
|
|
|
align={this.$data.align}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
width: '50px',
|
|
|
|
height: '50px',
|
|
|
|
background: 'yellow',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
source
|
|
|
|
</div>
|
|
|
|
</Align>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2017-12-12 07:05:45 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2017-12-12 07:05:45 +00:00
|
|
|
|
|
|
|
</script>
|