forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
71 lines (61 loc) · 1.53 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Utils
import { createNamespace, isDef, noop } from '../utils';
import { inherit } from '../utils/functional';
import { preventDefault } from '../utils/dom/event';
// Types
import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/types';
export type OverlayProps = {
show?: boolean;
zIndex?: number | string;
duration: number | string | null;
className?: any;
lockScroll?: boolean;
customStyle?: object;
};
export type OverlayEvents = {
click(event: Event): void;
};
const [createComponent, bem] = createNamespace('overlay');
function preventTouchMove(event: TouchEvent) {
preventDefault(event, true);
}
function Overlay(
h: CreateElement,
props: OverlayProps,
slots: DefaultSlots,
ctx: RenderContext<OverlayProps>
) {
const style: { [key: string]: any } = {
zIndex: props.zIndex,
...props.customStyle,
};
if (isDef(props.duration)) {
style.animationDuration = `${props.duration}s`;
}
return (
<transition name="van-fade">
<div
vShow={props.show}
style={style}
class={[bem(), props.className]}
onTouchmove={props.lockScroll ? preventTouchMove : noop}
{...inherit(ctx, true)}
>
{slots.default?.()}
</div>
</transition>
);
}
Overlay.props = {
show: Boolean,
zIndex: [Number, String],
duration: [Number, String],
className: null as any,
customStyle: Object,
lockScroll: {
type: Boolean,
default: true,
},
};
export default createComponent<OverlayProps, OverlayEvents>(Overlay);