mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 19:06:36 +08:00
feat(Popover): using popperjs
This commit is contained in:
parent
8f5a84ceec
commit
49a8d87845
@ -54,6 +54,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "7.x",
|
"@babel/runtime": "7.x",
|
||||||
|
"@popperjs/core": "^2.5.4",
|
||||||
"@vant/icons": "1.4.0",
|
"@vant/icons": "1.4.0",
|
||||||
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
|
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
|
||||||
"vue-lazyload": "1.2.3"
|
"vue-lazyload": "1.2.3"
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
<van-popover
|
<van-popover
|
||||||
v-model="show.basic"
|
v-model="show.basic"
|
||||||
:actions="t('actions')"
|
:actions="t('actions')"
|
||||||
placement="bottom-left"
|
placement="bottom"
|
||||||
>
|
>
|
||||||
<van-button @click="show.basic = true">
|
<van-button type="primary" @click="show.basic = true">
|
||||||
{{ t('showPopover') }}
|
{{ t('showPopover') }}
|
||||||
</van-button>
|
</van-button>
|
||||||
</van-popover>
|
</van-popover>
|
||||||
@ -17,9 +17,9 @@
|
|||||||
v-model="show.lightTheme"
|
v-model="show.lightTheme"
|
||||||
theme="light"
|
theme="light"
|
||||||
:actions="t('actions')"
|
:actions="t('actions')"
|
||||||
placement="bottom-left"
|
placement="bottom"
|
||||||
>
|
>
|
||||||
<van-button @click="show.lightTheme = true">
|
<van-button type="primary" @click="show.lightTheme = true">
|
||||||
{{ t('lightTheme') }}
|
{{ t('lightTheme') }}
|
||||||
</van-button>
|
</van-button>
|
||||||
</van-popover>
|
</van-popover>
|
||||||
@ -57,4 +57,10 @@ export default {
|
|||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@import '../../style/var';
|
@import '../../style/var';
|
||||||
|
|
||||||
|
.demo-popover {
|
||||||
|
.van-popover__wrapper {
|
||||||
|
margin-left: @padding-md;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
|
import { createPopper } from '@popperjs/core';
|
||||||
|
|
||||||
// Mixins
|
// Mixins
|
||||||
import { ClickOutsideMixin } from '../mixins/click-outside';
|
import { ClickOutsideMixin } from '../mixins/click-outside';
|
||||||
@ -21,9 +22,12 @@ export default createComponent({
|
|||||||
overlay: Boolean,
|
overlay: Boolean,
|
||||||
placement: String,
|
placement: String,
|
||||||
textColor: String,
|
textColor: String,
|
||||||
getContainer: [String, Function],
|
|
||||||
backgroundColor: String,
|
backgroundColor: String,
|
||||||
closeOnClickAction: Boolean,
|
closeOnClickAction: Boolean,
|
||||||
|
offset: {
|
||||||
|
type: Array,
|
||||||
|
default: [0, 0],
|
||||||
|
},
|
||||||
theme: {
|
theme: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'dark',
|
default: 'dark',
|
||||||
@ -32,9 +36,55 @@ export default createComponent({
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
|
getContainer: {
|
||||||
|
type: [String, Function],
|
||||||
|
default: 'body',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
location: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value(value) {
|
||||||
|
if (value) {
|
||||||
|
this.updateLocation();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
if (this.value) {
|
||||||
|
this.updateLocation();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
updateLocation() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
createPopper(this.$refs.wrapper, this.$refs.popover.$el, {
|
||||||
|
placement: this.placement,
|
||||||
|
modifiers: [
|
||||||
|
{
|
||||||
|
name: 'computeStyles',
|
||||||
|
options: {
|
||||||
|
adaptive: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'offset',
|
||||||
|
options: {
|
||||||
|
offset: this.offset,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
renderAction(action) {
|
renderAction(action) {
|
||||||
return <div class={bem('action')}>{action.text}</div>;
|
return <div class={bem('action')}>{action.text}</div>;
|
||||||
},
|
},
|
||||||
@ -60,10 +110,14 @@ export default createComponent({
|
|||||||
return (
|
return (
|
||||||
<span ref="wrapper" class={bem('wrapper')}>
|
<span ref="wrapper" class={bem('wrapper')}>
|
||||||
<Popup
|
<Popup
|
||||||
|
ref="popover"
|
||||||
value={this.value}
|
value={this.value}
|
||||||
|
style={this.location}
|
||||||
class={bem([this.theme])}
|
class={bem([this.theme])}
|
||||||
overlay={this.overlay}
|
overlay={this.overlay}
|
||||||
|
position=""
|
||||||
transition="van-popover-zoom"
|
transition="van-popover-zoom"
|
||||||
|
lockScroll={false}
|
||||||
getContainer={this.getContainer}
|
getContainer={this.getContainer}
|
||||||
onInput={this.onToggle}
|
onInput={this.onToggle}
|
||||||
>
|
>
|
||||||
|
@ -4,8 +4,11 @@
|
|||||||
.van-popover {
|
.van-popover {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border-radius: @border-radius-lg;
|
border-radius: @border-radius-lg;
|
||||||
transform: none;
|
transition-duration: 0s;
|
||||||
transition: all 0.3s;
|
|
||||||
|
&__wrapper {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
&__action {
|
&__action {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -53,9 +56,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&-zoom-enter,
|
// &-zoom-enter,
|
||||||
&-zoom-leave-active {
|
// &-zoom-leave-active {
|
||||||
transform: scale(0.8);
|
// transform: scale(0.8);
|
||||||
opacity: 0;
|
// opacity: 0;
|
||||||
}
|
// transition: all 0.3s;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -1524,6 +1524,11 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" ">= 8"
|
"@types/node" ">= 8"
|
||||||
|
|
||||||
|
"@popperjs/core@^2.5.4":
|
||||||
|
version "2.5.4"
|
||||||
|
resolved "https://registry.npm.taobao.org/@popperjs/core/download/@popperjs/core-2.5.4.tgz#de25b5da9f727985a3757fd59b5d028aba75841a"
|
||||||
|
integrity sha1-3iW12p9yeYWjdX/Vm10Cirp1hBo=
|
||||||
|
|
||||||
"@sindresorhus/is@^0.14.0":
|
"@sindresorhus/is@^0.14.0":
|
||||||
version "0.14.0"
|
version "0.14.0"
|
||||||
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
|
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user