ant-design-vue/components/trigger/demo/simple.vue

280 lines
6.2 KiB
Vue
Raw Normal View History

2017-12-26 19:04:28 +08:00
<script>
import Trigger from '../index'
import '../assets/index.less'
import { Input, Button, Checkbox } from 'antd'
function getPopupAlign (state) {
return {
offset: [state.offsetX, state.offsetY],
overflow: {
adjustX: 1,
adjustY: 1,
},
}
}
const builtinPlacements = {
left: {
points: ['cr', 'cl'],
},
right: {
points: ['cl', 'cr'],
},
top: {
points: ['bc', 'tc'],
},
bottom: {
points: ['tc', 'bc'],
},
topLeft: {
points: ['bl', 'tl'],
},
topRight: {
points: ['br', 'tr'],
},
bottomRight: {
points: ['tr', 'br'],
},
bottomLeft: {
points: ['tl', 'bl'],
},
}
function preventDefault (e) {
e.preventDefault()
}
function getPopupContainer (trigger) {
return trigger.parentNode
}
export default {
data () {
return {
mask: false,
maskClosable: false,
placement: 'right',
trigger: {
hover: 1,
},
offsetX: undefined,
offsetY: undefined,
transitionName: '',
destroyPopupOnHide: false,
}
},
methods: {
setState (state, callback) {
Object.assign(this.$data, state)
this.$nextTick(() => {
callback && callback()
})
},
onPlacementChange (e) {
this.setState({
placement: e.target.value,
})
},
onTransitionChange (e) {
this.setState({
transitionName: e.target.checked ? e.target.value : '',
})
},
onTriggerChange (e) {
const trigger = Object.assign({}, this.$data.trigger)
if (e.target.checked) {
trigger[e.target.value] = 1
} else {
delete trigger[e.target.value]
}
this.setState({
trigger,
})
},
onOffsetXChange (e) {
const targetValue = e.target.value
this.setState({
offsetX: targetValue || undefined,
})
},
onOffsetYChange (e) {
const targetValue = e.target.value
this.setState({
offsetY: targetValue || undefined,
})
},
onVisibleChange (visible) {
console.log('tooltip', visible)
},
onMask (e) {
this.setState({
mask: e.target.checked,
})
},
onMaskClosable (e) {
this.setState({
maskClosable: e.target.checked,
})
},
destroy () {
this.setState({
destroyed: true,
})
},
handleDestroyPopupOnHide (e) {
this.setState({
destroyPopupOnHide: e.target.checked,
})
},
},
render () {
const state = this.$data
const trigger = state.trigger
if (state.destroyed) {
return null
}
return (<div >
<div style={{ margin: '10px 20px' }}>
<label>
placement:
<select value={state.placement} onChange={this.onPlacementChange}>
<option>right</option>
<option>left</option>
<option>top</option>
<option>bottom</option>
<option>topLeft</option>
<option>topRight</option>
<option>bottomRight</option>
<option>bottomLeft</option>
</select>
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
value='rc-trigger-popup-zoom'
onChange={this.onTransitionChange}
checked={state.transitionName === 'rc-trigger-popup-zoom'}
/>
transitionName
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
trigger:
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
value='hover'
checked={!!trigger.hover}
onChange={this.onTriggerChange}
/>
hover
</label>
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
value='focus'
checked={!!trigger.focus}
onChange={this.onTriggerChange}
/>
focus
</label>
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
value='click'
checked={!!trigger.click}
onChange={this.onTriggerChange}
/>
click
</label>
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
value='contextMenu'
checked={!!trigger.contextMenu}
onChange={this.onTriggerChange}
/>
contextMenu
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
checked={!!state.destroyPopupOnHide}
onChange={this.handleDestroyPopupOnHide}
/>
destroyPopupOnHide
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
checked={!!state.mask}
onChange={this.onMask}
/>
mask
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
2018-01-23 18:55:39 +08:00
a-checkbox
2017-12-26 19:04:28 +08:00
checked={!!state.maskClosable}
onChange={this.onMaskClosable}
/>
maskClosable
</label>
<br />
<label>
offsetX:
<Input
type='text'
onChange={this.onOffsetXChange}
style={{ width: '50px' }}
/>
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
offsetY:
<Input
type='text'
onChange={this.onOffsetYChange}
style={{ width: '50px' }}
/>
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<Button onClick={this.destroy}>destroy</Button>
</div>
<div style={{ margin: '100px', position: 'relative' }}>
<Trigger
getPopupContainer={undefined && getPopupContainer}
popupAlign={getPopupAlign(state)}
popupPlacement={state.placement}
destroyPopupOnHide={state.destroyPopupOnHide}
// zIndex={40}
mask={state.mask}
maskClosable={state.maskClosable}
// maskAnimation="fade"
// mouseEnterDelay={0.1}
// mouseLeaveDelay={0.1}
action={Object.keys(state.trigger)}
builtinPlacements={builtinPlacements}
2018-01-04 19:06:54 +08:00
popupAnimation={state.transitionName}
2017-12-26 19:04:28 +08:00
>
<div slot='popup' style={{ border: '1px solid red', padding: '10px', background: 'white' }}>
i am a popup
</div>
<a href='#' style={{ margin: '20px' }} onClick={preventDefault}>trigger</a>
</Trigger>
</div>
</div>)
},
}
</script>