Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow spotlight styles to be updated from outside #954

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/components/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,56 @@ export default class JoyrideOverlay extends React.Component<OverlayProps, State>
const element = getElement(target);
const elementRect = getClientRect(element);
const isFixedTarget = hasPosition(element);
const top = getElementPosition(element, spotlightPadding, disableScrollParentFix);

let overriddenHeight;

if (styles.spotlight.height) {
overriddenHeight =
typeof styles.spotlight.height === 'number'
? styles.spotlight.height
: Number(parseInt(styles.spotlight.height, 10));
}

let overriddenWidth;

if (styles.spotlight.width) {
overriddenWidth =
typeof styles.spotlight.width === 'number'
? styles.spotlight.width
: Number(parseInt(styles.spotlight.width, 10));
}

let overriddenLeft;

if (styles.spotlight.left) {
overriddenLeft =
typeof styles.spotlight.left === 'number'
? styles.spotlight.left
: Number(parseInt(styles.spotlight.left, 10));
}

let overriddenTop;

if (styles.spotlight.top) {
overriddenTop =
typeof styles.spotlight.top === 'number'
? styles.spotlight.top
: Number(parseInt(styles.spotlight.top, 10));
}

const top =
overriddenTop ?? getElementPosition(element, spotlightPadding, disableScrollParentFix);

return {
...(isLegacy() ? styles.spotlightLegacy : styles.spotlight),
height: Math.round((elementRect?.height ?? 0) + spotlightPadding * 2),
left: Math.round((elementRect?.left ?? 0) - spotlightPadding),
height: Math.round((overriddenHeight ?? elementRect?.height ?? 0) + spotlightPadding * 2),
left: Math.round((overriddenLeft ?? elementRect?.left ?? 0) - spotlightPadding),
opacity: showSpotlight ? 1 : 0,
pointerEvents: spotlightClicks ? 'none' : 'auto',
position: isFixedTarget ? 'fixed' : 'absolute',
top,
transition: 'opacity 0.2s',
width: Math.round((elementRect?.width ?? 0) + spotlightPadding * 2),
width: overriddenWidth || Math.round((elementRect?.width ?? 0) + spotlightPadding * 2),
} satisfies React.CSSProperties;
}

Expand Down