mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(Popover): use tsx (#8166)
This commit is contained in:
parent
68555aa29a
commit
6c89575946
@ -59,7 +59,7 @@
|
|||||||
"@babel/runtime": "7.x",
|
"@babel/runtime": "7.x",
|
||||||
"@vant/icons": "^1.5.2",
|
"@vant/icons": "^1.5.2",
|
||||||
"@vant/lazyload": "^1.0.2",
|
"@vant/lazyload": "^1.0.2",
|
||||||
"@vant/popperjs": "^1.0.2",
|
"@vant/popperjs": "^1.0.4",
|
||||||
"@vant/use": "^1.0.5"
|
"@vant/use": "^1.0.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
import { ref, watch, nextTick, onMounted, onBeforeUnmount } from 'vue';
|
import {
|
||||||
import { createPopper, offsetModifier } from '@vant/popperjs';
|
ref,
|
||||||
|
watch,
|
||||||
|
nextTick,
|
||||||
|
PropType,
|
||||||
|
onMounted,
|
||||||
|
TeleportProps,
|
||||||
|
onBeforeUnmount,
|
||||||
|
} from 'vue';
|
||||||
|
import { Instance, createPopper, offsetModifier } from '@vant/popperjs';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { createNamespace } from '../utils';
|
import { ComponentInstance, createNamespace } from '../utils';
|
||||||
import { BORDER_BOTTOM } from '../utils/constant';
|
import { BORDER_BOTTOM } from '../utils/constant';
|
||||||
|
|
||||||
// Composition
|
// Composition
|
||||||
@ -14,32 +22,56 @@ import Popup from '../popup';
|
|||||||
|
|
||||||
const [createComponent, bem] = createNamespace('popover');
|
const [createComponent, bem] = createNamespace('popover');
|
||||||
|
|
||||||
|
export type PopoverTheme = 'light' | 'dark';
|
||||||
|
export type PopoverTrigger = 'manual' | 'click';
|
||||||
|
export type PopoverPlacement =
|
||||||
|
| 'top'
|
||||||
|
| 'top-start'
|
||||||
|
| 'top-end'
|
||||||
|
| 'left'
|
||||||
|
| 'left-start'
|
||||||
|
| 'left-end'
|
||||||
|
| 'right'
|
||||||
|
| 'right-start'
|
||||||
|
| 'right-end'
|
||||||
|
| 'bottom'
|
||||||
|
| 'bottom-start'
|
||||||
|
| 'bottom-end';
|
||||||
|
|
||||||
|
export type PopoverAction = {
|
||||||
|
text: string;
|
||||||
|
icon?: string;
|
||||||
|
color?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
overlay: Boolean,
|
overlay: Boolean,
|
||||||
offset: {
|
offset: {
|
||||||
type: Array,
|
type: (Array as unknown) as PropType<[number, number]>,
|
||||||
default: () => [0, 8],
|
default: () => [0, 8],
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
type: String,
|
type: String as PropType<PopoverTheme>,
|
||||||
default: 'light',
|
default: 'light',
|
||||||
},
|
},
|
||||||
trigger: {
|
trigger: {
|
||||||
type: String,
|
type: String as PropType<PopoverTrigger>,
|
||||||
default: 'click',
|
default: 'click',
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
type: Array,
|
type: Array as PropType<PopoverAction[]>,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
placement: {
|
placement: {
|
||||||
type: String,
|
type: String as PropType<PopoverPlacement>,
|
||||||
default: 'bottom',
|
default: 'bottom',
|
||||||
},
|
},
|
||||||
teleport: {
|
teleport: {
|
||||||
type: [String, Object],
|
type: [String, Object] as PropType<TeleportProps['to']>,
|
||||||
default: 'body',
|
default: 'body',
|
||||||
},
|
},
|
||||||
closeOnClickAction: {
|
closeOnClickAction: {
|
||||||
@ -51,12 +83,13 @@ export default createComponent({
|
|||||||
emits: ['select', 'touchstart', 'update:show'],
|
emits: ['select', 'touchstart', 'update:show'],
|
||||||
|
|
||||||
setup(props, { emit, slots, attrs }) {
|
setup(props, { emit, slots, attrs }) {
|
||||||
let popper;
|
let popper: Instance | null;
|
||||||
const wrapperRef = ref();
|
|
||||||
const popoverRef = ref();
|
const wrapperRef = ref<HTMLElement>();
|
||||||
|
const popoverRef = ref<ComponentInstance>();
|
||||||
|
|
||||||
const createPopperInstance = () => {
|
const createPopperInstance = () => {
|
||||||
return createPopper(wrapperRef.value, popoverRef.value.popupRef.value, {
|
return createPopper(wrapperRef.value!, popoverRef.value!.popupRef.value, {
|
||||||
placement: props.placement,
|
placement: props.placement,
|
||||||
modifiers: [
|
modifiers: [
|
||||||
{
|
{
|
||||||
@ -92,7 +125,7 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggle = (value) => {
|
const toggle = (value: boolean) => {
|
||||||
emit('update:show', value);
|
emit('update:show', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,12 +135,12 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onTouchstart = (event) => {
|
const onTouchstart = (event: TouchEvent) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
emit('touchstart', event);
|
emit('touchstart', event);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickAction = (action, index) => {
|
const onClickAction = (action: PopoverAction, index: number) => {
|
||||||
if (action.disabled) {
|
if (action.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -123,7 +156,7 @@ export default createComponent({
|
|||||||
toggle(false);
|
toggle(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderAction = (action, index) => {
|
const renderAction = (action: PopoverAction, index: number) => {
|
||||||
const { icon, text, color, disabled, className } = action;
|
const { icon, text, color, disabled, className } = action;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -160,7 +193,7 @@ export default createComponent({
|
|||||||
show={props.show}
|
show={props.show}
|
||||||
class={bem([props.theme])}
|
class={bem([props.theme])}
|
||||||
overlay={props.overlay}
|
overlay={props.overlay}
|
||||||
position={null}
|
position={''}
|
||||||
teleport={props.teleport}
|
teleport={props.teleport}
|
||||||
transition="van-popover-zoom"
|
transition="van-popover-zoom"
|
||||||
lockScroll={false}
|
lockScroll={false}
|
@ -25,7 +25,7 @@ import { useLazyRender } from '../composables/use-lazy-render';
|
|||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import Overlay from '../overlay';
|
import Overlay from '../overlay';
|
||||||
|
|
||||||
export type PopupPosition = 'top' | 'left' | 'bottom' | 'right' | 'center';
|
export type PopupPosition = 'top' | 'left' | 'bottom' | 'right' | 'center' | '';
|
||||||
|
|
||||||
export type PopupCloseIconPosition =
|
export type PopupCloseIconPosition =
|
||||||
| 'top-left'
|
| 'top-left'
|
||||||
|
@ -1961,10 +1961,10 @@
|
|||||||
fast-glob "^3.2.2"
|
fast-glob "^3.2.2"
|
||||||
fs-extra "^9.0.0"
|
fs-extra "^9.0.0"
|
||||||
|
|
||||||
"@vant/popperjs@^1.0.2":
|
"@vant/popperjs@^1.0.4":
|
||||||
version "1.0.2"
|
version "1.0.4"
|
||||||
resolved "https://registry.npm.taobao.org/@vant/popperjs/download/@vant/popperjs-1.0.2.tgz#522d71656235125a3ae08e9c701a3bae6fd88d7b"
|
resolved "https://registry.npm.taobao.org/@vant/popperjs/download/@vant/popperjs-1.0.4.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vant%2Fpopperjs%2Fdownload%2F%40vant%2Fpopperjs-1.0.4.tgz#49c20809a3828e7b036e23d50fb56121e997618f"
|
||||||
integrity sha1-Ui1xZWI1Elo64I6ccBo7rm/YjXs=
|
integrity sha1-ScIICaOCjnsDbiPVD7VhIemXYY8=
|
||||||
dependencies:
|
dependencies:
|
||||||
"@popperjs/core" "^2.5.4"
|
"@popperjs/core" "^2.5.4"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user