Skip to content

Commit

Permalink
overlayLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
binrysearch committed Sep 4, 2024
1 parent 7e278ec commit f52d74b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/packages/tour/addOverlayLayer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { style } from "../../util/style";
import { Tour } from "./tour";
import { overlayClassName } from "./classNames";
import van from "../dom/van";

const { div } = van.tags;
import { OverlayLayer } from "./overlayLayer";

/**
* Add overlay layer to the page
Expand All @@ -13,25 +10,14 @@ const { div } = van.tags;
export default function addOverlayLayer(tour: Tour) {
const exitOnOverlayClick = tour.getOption("exitOnOverlayClick") === true;

const overlayLayer = div({
className: overlayClassName,
style: style({
top: 0,
bottom: 0,
left: 0,
right: 0,
position: "fixed",
cursor: exitOnOverlayClick ? "pointer" : "auto",
}),
const overlayLayer = OverlayLayer({
exitOnOverlayClick,
onExitTour: async () => {
return tour.exit();
},
});

van.add(tour.getRoot(), overlayLayer);

if (exitOnOverlayClick) {
overlayLayer.onclick = async () => {
await tour.exit();
};
}

return true;
}
36 changes: 36 additions & 0 deletions src/packages/tour/overlayLayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { style } from "../../util/style";
import { overlayClassName } from "./classNames";
import van from "../dom/van";
import { Tour } from "./tour";

const { div } = van.tags;

export type OverlayLayerProps = {
exitOnOverlayClick: boolean;
onExitTour: () => Promise<Tour>;
};

export const OverlayLayer = ({
exitOnOverlayClick,
onExitTour,
}: OverlayLayerProps) => {
const overlayLayer = div({
className: overlayClassName,
style: style({
top: 0,
bottom: 0,
left: 0,
right: 0,
position: "fixed",
cursor: exitOnOverlayClick ? "pointer" : "auto",
}),
});

if (exitOnOverlayClick) {
overlayLayer.onclick = async () => {
await onExitTour();
};
}

return overlayLayer;
};

0 comments on commit f52d74b

Please sign in to comment.