Skip to content

Commit

Permalink
disableInteraction
Browse files Browse the repository at this point in the history
  • Loading branch information
binrysearch committed Sep 4, 2024
1 parent 0643c7d commit 718c4fd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 58 deletions.
43 changes: 43 additions & 0 deletions src/packages/tour/disableInteraction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import van, { State } from "../dom/van";
import { disableInteractionClassName } from "./classNames";
import { setPositionRelativeToStep } from "./position";
import { TourStep } from "./steps";

const { div } = van.tags;

export type HelperLayerProps = {
currentStep: State<number>;
steps: TourStep[];
targetElement: HTMLElement;
helperElementPadding: number;
};

export const DisableInteraction = ({
currentStep,
steps,
targetElement,
helperElementPadding,
}: HelperLayerProps) => {
const step = van.derive(() =>
currentStep.val !== undefined ? steps[currentStep.val] : null
);

return () => {
if (!step.val) {
return null;
}

const disableInteraction = div({
className: disableInteractionClassName,
});

setPositionRelativeToStep(
targetElement,
disableInteraction,
step.val,
helperElementPadding
);

return disableInteraction;
};
};
36 changes: 18 additions & 18 deletions src/packages/tour/exitIntro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export default async function exitIntro(
if (!force && continueExit === false) return false;

// remove overlay layers from the page
const overlayLayers = Array.from(
queryElementsByClassName(overlayClassName, targetElement)
);
// const overlayLayers = Array.from(
// queryElementsByClassName(overlayClassName, targetElement)
// );

if (overlayLayers && overlayLayers.length) {
for (const overlayLayer of overlayLayers) {
removeChild(overlayLayer);
}
}
// if (overlayLayers && overlayLayers.length) {
// for (const overlayLayer of overlayLayers) {
// removeChild(overlayLayer);
// }
// }

//const referenceLayer = queryElementByClassName(
// tooltipReferenceLayerClassName,
Expand All @@ -53,11 +53,11 @@ export default async function exitIntro(
//removeChild(referenceLayer);

//remove disableInteractionLayer
const disableInteractionLayer = queryElementByClassName(
disableInteractionClassName,
targetElement
);
removeChild(disableInteractionLayer);
// const disableInteractionLayer = queryElementByClassName(
// disableInteractionClassName,
// targetElement
// );
// removeChild(disableInteractionLayer);

//remove intro floating element
const floatingElement = queryElementByClassName(
Expand All @@ -69,11 +69,11 @@ export default async function exitIntro(
removeShowElement();

//remove all helper layers
const helperLayer = queryElementByClassName(
helperLayerClassName,
targetElement
);
await removeAnimatedChild(helperLayer);
// const helperLayer = queryElementByClassName(
// helperLayerClassName,
// targetElement
// );
// await removeAnimatedChild(helperLayer);

//check if any callback is defined
await tour.callback("exit")?.call(tour);
Expand Down
54 changes: 14 additions & 40 deletions src/packages/tour/showElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,7 @@ import getPropValue from "../../util/getPropValue";
import van from "../dom/van";
import { HelperLayer } from "./helperLayer";
import { ReferenceLayer } from "../tooltip/referenceLayer";

/**
* Add disableinteraction layer and adjust the size and position of the layer
*
* @api private
*/
export const _disableInteraction = (tour: Tour, step: TourStep) => {
let disableInteractionLayer = queryElementByClassName(
disableInteractionClassName
);

if (disableInteractionLayer === null) {
disableInteractionLayer = createElement("div", {
className: disableInteractionClassName,
});

tour.getTargetElement().appendChild(disableInteractionLayer);
}

setPositionRelativeToStep(
tour.getTargetElement(),
disableInteractionLayer,
step,
tour.getOption("helperElementPadding")
);
};
import { DisableInteraction } from "./disableInteraction";

/**
* To set the show element
Expand Down Expand Up @@ -88,29 +63,28 @@ export default async function _showElement(tour: Tour, step: TourStep) {
});

const referenceLayer = ReferenceLayer({
tour
tour,
});

//add helper layer to target element
van.add(tour.getRoot(), helperLayer);
van.add(tour.getRoot(), referenceLayer);
}

// removing previous disable interaction layer
const disableInteractionLayer = queryElementByClassName(
disableInteractionClassName,
tour.getTargetElement()
);
if (disableInteractionLayer && disableInteractionLayer.parentNode) {
disableInteractionLayer.parentNode.removeChild(disableInteractionLayer);
// disable interaction
if (step.disableInteraction) {
van.add(
tour.getRoot(),
DisableInteraction({
currentStep: tour.currentStepSignal,
steps: tour.getSteps(),
targetElement: tour.getTargetElement(),
helperElementPadding: tour.getOption("helperElementPadding"),
})
);
}
}

setShowElement(step.element as HTMLElement);

//disable interaction
if (step.disableInteraction) {
_disableInteraction(tour, step);
}

await tour.callback("afterChange")?.call(tour, step.element);
}

0 comments on commit 718c4fd

Please sign in to comment.