Overlay.mjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { withDirectives as _withDirectives, createVNode as _createVNode, vShow as _vShow } from "vue";
  2. import { ref, Transition, defineComponent } from "vue";
  3. import { isDef, extend, truthProp, numericProp, unknownProp, preventDefault, createNamespace, getZIndexStyle } from "../utils/index.mjs";
  4. import { useEventListener } from "@vant/use";
  5. import { useLazyRender } from "../composables/use-lazy-render.mjs";
  6. const [name, bem] = createNamespace("overlay");
  7. const overlayProps = {
  8. show: Boolean,
  9. zIndex: numericProp,
  10. duration: numericProp,
  11. className: unknownProp,
  12. lockScroll: truthProp,
  13. lazyRender: truthProp,
  14. customStyle: Object
  15. };
  16. var stdin_default = defineComponent({
  17. name,
  18. props: overlayProps,
  19. setup(props, {
  20. slots
  21. }) {
  22. const root = ref();
  23. const lazyRender = useLazyRender(() => props.show || !props.lazyRender);
  24. const onTouchMove = (event) => {
  25. if (props.lockScroll) {
  26. preventDefault(event, true);
  27. }
  28. };
  29. const renderOverlay = lazyRender(() => {
  30. var _a;
  31. const style = extend(getZIndexStyle(props.zIndex), props.customStyle);
  32. if (isDef(props.duration)) {
  33. style.animationDuration = `${props.duration}s`;
  34. }
  35. return _withDirectives(_createVNode("div", {
  36. "ref": root,
  37. "style": style,
  38. "class": [bem(), props.className]
  39. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]), [[_vShow, props.show]]);
  40. });
  41. useEventListener("touchmove", onTouchMove, {
  42. target: root
  43. });
  44. return () => _createVNode(Transition, {
  45. "name": "van-fade",
  46. "appear": true
  47. }, {
  48. default: renderOverlay
  49. });
  50. }
  51. });
  52. export {
  53. stdin_default as default
  54. };