mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(Popup): use tsx (#8110)
* types(Popup): use tsx * types: add PopupCloseIconPosition
This commit is contained in:
parent
85da57e583
commit
b50cd43921
@ -4,9 +4,12 @@ import {
|
|||||||
watch,
|
watch,
|
||||||
Teleport,
|
Teleport,
|
||||||
computed,
|
computed,
|
||||||
|
PropType,
|
||||||
onMounted,
|
onMounted,
|
||||||
Transition,
|
Transition,
|
||||||
onActivated,
|
onActivated,
|
||||||
|
CSSProperties,
|
||||||
|
TeleportProps,
|
||||||
onDeactivated,
|
onDeactivated,
|
||||||
onBeforeUnmount,
|
onBeforeUnmount,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
@ -22,16 +25,15 @@ 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 PopupCloseIconPosition =
|
||||||
|
| 'top-left'
|
||||||
|
| 'top-right'
|
||||||
|
| 'botttom-left'
|
||||||
|
| 'bottom-right';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('popup');
|
const [createComponent, bem] = createNamespace('popup');
|
||||||
|
|
||||||
const context = {
|
let globalZIndex = 2000;
|
||||||
zIndex: 2000,
|
|
||||||
lockCount: 0,
|
|
||||||
stack: [],
|
|
||||||
find(vm) {
|
|
||||||
return this.stack.filter((item) => item.vm === vm)[0];
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const popupSharedProps = {
|
export const popupSharedProps = {
|
||||||
// whether to show popup
|
// whether to show popup
|
||||||
@ -41,7 +43,7 @@ export const popupSharedProps = {
|
|||||||
// transition duration
|
// transition duration
|
||||||
duration: [Number, String],
|
duration: [Number, String],
|
||||||
// teleport
|
// teleport
|
||||||
teleport: [String, Object],
|
teleport: [String, Object] as PropType<TeleportProps['to']>,
|
||||||
// overlay custom style
|
// overlay custom style
|
||||||
overlayStyle: Object,
|
overlayStyle: Object,
|
||||||
// overlay custom class name
|
// overlay custom class name
|
||||||
@ -89,7 +91,7 @@ export default createComponent({
|
|||||||
default: 'cross',
|
default: 'cross',
|
||||||
},
|
},
|
||||||
closeIconPosition: {
|
closeIconPosition: {
|
||||||
type: String,
|
type: String as PropType<PopupCloseIconPosition>,
|
||||||
default: 'top-right',
|
default: 'top-right',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -106,10 +108,10 @@ export default createComponent({
|
|||||||
],
|
],
|
||||||
|
|
||||||
setup(props, { emit, attrs, slots }) {
|
setup(props, { emit, attrs, slots }) {
|
||||||
let opened;
|
let opened: boolean;
|
||||||
let shouldReopen;
|
let shouldReopen: boolean;
|
||||||
|
|
||||||
const zIndex = ref();
|
const zIndex = ref<number>();
|
||||||
const popupRef = ref();
|
const popupRef = ref();
|
||||||
|
|
||||||
const [lockScroll, unlockScroll] = useLockScroll(
|
const [lockScroll, unlockScroll] = useLockScroll(
|
||||||
@ -120,7 +122,7 @@ export default createComponent({
|
|||||||
const lazyRender = useLazyRender(() => props.show || !props.lazyRender);
|
const lazyRender = useLazyRender(() => props.show || !props.lazyRender);
|
||||||
|
|
||||||
const style = computed(() => {
|
const style = computed(() => {
|
||||||
const style = {
|
const style: CSSProperties = {
|
||||||
zIndex: zIndex.value,
|
zIndex: zIndex.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -138,12 +140,12 @@ export default createComponent({
|
|||||||
const open = () => {
|
const open = () => {
|
||||||
if (!opened) {
|
if (!opened) {
|
||||||
if (props.zIndex !== undefined) {
|
if (props.zIndex !== undefined) {
|
||||||
context.zIndex = props.zIndex;
|
globalZIndex = +props.zIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
opened = true;
|
opened = true;
|
||||||
lockScroll();
|
lockScroll();
|
||||||
zIndex.value = ++context.zIndex;
|
zIndex.value = ++globalZIndex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickOverlay = (event) => {
|
const onClickOverlay = (event: MouseEvent) => {
|
||||||
emit('click-overlay', event);
|
emit('click-overlay', event);
|
||||||
|
|
||||||
if (props.closeOnClickOverlay) {
|
if (props.closeOnClickOverlay) {
|
||||||
@ -178,7 +180,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickCloseIcon = (event) => {
|
const onClickCloseIcon = (event: MouseEvent) => {
|
||||||
emit('click-close-icon', event);
|
emit('click-close-icon', event);
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
@ -188,7 +190,7 @@ export default createComponent({
|
|||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex={0}
|
||||||
name={props.closeIcon}
|
name={props.closeIcon}
|
||||||
class={bem('close-icon', props.closeIconPosition)}
|
class={bem('close-icon', props.closeIconPosition)}
|
||||||
onClick={onClickCloseIcon}
|
onClick={onClickCloseIcon}
|
||||||
@ -197,7 +199,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClick = (event) => emit('click', event);
|
const onClick = (event: MouseEvent) => emit('click', event);
|
||||||
const onOpened = () => emit('opened');
|
const onOpened = () => emit('opened');
|
||||||
const onClosed = () => emit('closed');
|
const onClosed = () => emit('closed');
|
||||||
|
|
3
src/vue-shim.d.ts
vendored
3
src/vue-shim.d.ts
vendored
@ -6,6 +6,9 @@ import 'vue';
|
|||||||
// https://github.com/vuejs/vue-next/issues/3029
|
// https://github.com/vuejs/vue-next/issues/3029
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
interface ComponentCustomProps {
|
interface ComponentCustomProps {
|
||||||
|
role?: string;
|
||||||
|
tabindex?: number;
|
||||||
onClick?: (event: MouseEvent) => void;
|
onClick?: (event: MouseEvent) => void;
|
||||||
|
onClosed?: () => void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user