From c9713c715dfd5a0669d771b2c4fa9c02fef1f7f7 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 22 Jan 2025 18:19:16 +0100 Subject: [PATCH] feat: allow element to be type function that returns an element (#463) --- src/driver.ts | 2 +- src/highlight.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/driver.ts b/src/driver.ts index 8184fc2..1951c0c 100644 --- a/src/driver.ts +++ b/src/driver.ts @@ -8,7 +8,7 @@ import { getState, resetState, setState } from "./state"; import "./driver.css"; export type DriveStep = { - element?: string | Element; + element?: string | Element | (() => Element); onHighlightStarted?: DriverHook; onHighlighted?: DriverHook; onDeselected?: DriverHook; diff --git a/src/highlight.ts b/src/highlight.ts index ec55303..8bd1da9 100644 --- a/src/highlight.ts +++ b/src/highlight.ts @@ -29,7 +29,8 @@ function mountDummyElement(): Element { export function highlight(step: DriveStep) { const { element } = step; - let elemObj = typeof element === "string" ? document.querySelector(element) : element; + let elemObj = + typeof element === "function" ? element() : typeof element === "string" ? document.querySelector(element) : element; // If the element is not found, we mount a 1px div // at the center of the screen to highlight and show