2017-12-12 07:05:45 +00:00
|
|
|
<script>
|
|
|
|
import Align from '../index'
|
2018-01-12 08:10:41 +00:00
|
|
|
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'],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getTarget () {
|
|
|
|
const ref = this.$refs.container
|
|
|
|
// if (!ref) {
|
|
|
|
// // parent ref not attached
|
|
|
|
// ref = document.getElementById('container')
|
|
|
|
// }
|
|
|
|
return ref
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleMonitor () {
|
|
|
|
this.setState({
|
|
|
|
monitor: !this.$data.monitor,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
forceAlign () {
|
|
|
|
this.setState({
|
|
|
|
align: Object.assign({}, this.$data.align),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
2017-12-26 11:04:28 +00:00
|
|
|
margin: '50px',
|
2017-12-12 07:05:45 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<p>
|
|
|
|
<button onClick={this.forceAlign}>force align</button>
|
|
|
|
|
|
|
|
<button onClick={this.toggleMonitor}>toggle monitor</button>
|
|
|
|
</p>
|
|
|
|
<div
|
|
|
|
ref='container'
|
|
|
|
id='container'
|
|
|
|
style={{
|
|
|
|
width: '80%',
|
|
|
|
height: '500px',
|
|
|
|
border: '1px solid red',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Align
|
|
|
|
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>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|