Skip to content

Spotlight Overlay API Reference

Composable: useSpotlightOverlay

The useSpotlightOverlay composable provides all the functionality for managing spotlight overlays.

State Properties

PropertyTypeDescription
positionXNumberX coordinate of the instruction bar position
positionYNumberY coordinate of the instruction bar position
previousPositionXNumberPrevious X coordinate for animation purposes
previousPositionYNumberPrevious Y coordinate for animation purposes
arrowPositionStringCurrent arrow position (see Arrow Positions below)
previousArrowPositionStringPrevious arrow position for animation
showFloatingInstructionBarBooleanWhether the instruction bar is visible
barConfigObjectConfiguration object for the instruction bar
highlightXNumberX coordinate of the highlight center
highlightYNumberY coordinate of the highlight center
highlightRadiusNumberRadius of the highlight area
clipPathXNumberX coordinate of the clip path area
clipPathYNumberY coordinate of the clip path area
clipPathHeightNumberHeight of the clip path area
clipPathWidthNumberWidth of the clip path area
highlightedElementsArrayArray of currently highlighted elements
highlightAreaBorderStylesObjectBorder styles for the highlight area
isAnimatingBooleanWhether the component is currently animating
animationDurationNumberDuration of animations in milliseconds

Methods

setInstructionBarConfigByElementId(data)

Main method for configuring and showing the spotlight overlay.

Parameters:

  • data (Object) - Configuration object

Data Object Properties:

PropertyTypeRequiredDescription
elementIdStringYesID of the element to highlight
arrowPositionStringYesPosition of the arrow (see Arrow Positions)
isVisibleBooleanYesWhether to show the instruction bar
configObjectNoConfiguration for the instruction bar
elementToHighLightIdStringNoAlternative element ID to highlight (overrides elementId)
elementHighlightClassNameStringNoCSS class to add to highlighted element (default: 'tour-highlight')

Config Object Properties:

PropertyTypeDescription
titleStringText to display in the instruction bar
buttonObjectButton configuration
hideArrowIconBooleanWhether to hide the arrow icon
allowInteractionWithOtherElementsBooleanAllow interaction with other page elements
closeButtonCallBackFunctionCallback when close button is clicked
onBlurFunctionCallback when instruction bar loses focus

Button Object Properties:

PropertyTypeDescription
labelStringText to display on the button
callbackFunctionFunction to call when button is clicked

Example:

javascript
setInstructionBarConfigByElementId({
  elementId: 'my-button',
  arrowPosition: 'top',
  isVisible: true,
  config: {
    title: 'Click this button to continue',
    button: {
      label: 'Got it',
      callback: () => console.log('Button clicked!')
    },
    hideArrowIcon: false,
    allowInteractionWithOtherElements: true,
    closeButtonCallBack: () => console.log('Closed'),
    onBlur: () => console.log('Lost focus')
  }
})

resetInstructionBarConfig()

Resets the spotlight overlay to its initial state, hiding the instruction bar and clearing all configurations.

Example:

javascript
resetInstructionBarConfig()

setInstructionBarConfig(data)

Low-level method for setting instruction bar configuration directly.

Parameters:

  • data (Object) - Configuration object with position, clipPath, highlight, arrowPosition, isVisible, config, and elementId properties

highlightElement({ elementId, className })

Adds a CSS class to a specific element to highlight it.

Parameters:

  • elementId (String) - ID of the element to highlight
  • className (String) - CSS class to add to the element

setPosition(data)

Sets the position of the instruction bar.

Parameters:

  • data (Object) - Object with positionX and positionY properties

setPositionWithAnimation(data)

Sets the position of the instruction bar with animation.

Parameters:

  • data (Object) - Object with positionX and positionY properties

setHighlight(data)

Sets the highlight area properties.

Parameters:

  • data (Object) - Object with highlightX, highlightY, and highlightRadius properties

setClipPath(data)

Sets the clip path area properties.

Parameters:

  • data (Object) - Object with clipPathX, clipPathY, clipPathHeight, and clipPathWidth properties

addHighlightedElements({ elementId, className })

Adds an element to the list of highlighted elements.

Parameters:

  • elementId (String) - ID of the element to add
  • className (String) - CSS class to apply to the element

resetHighlightedElements()

Removes all highlighted elements and clears the highlighted elements array.

Arrow Positions

The component supports the following arrow positions:

PositionDescription
topArrow pointing down from above, centered
topLeftArrow pointing down from above, positioned left
topRightArrow pointing down from above, positioned right
topExtremeLeftArrow pointing down from above, extreme left position
topExtremeRightArrow pointing down from above, extreme right position
bottomArrow pointing up from below, centered
bottomLeftArrow pointing up from below, positioned left
bottomRightArrow pointing up from below, positioned right
bottomExtremeLeftArrow pointing up from below, extreme left position
bottomExtremeRightArrow pointing up from below, extreme right position
leftArrow pointing right from the left side
rightArrow pointing left from the right side

Usage Examples

Basic Highlight

javascript
import { useSpotlightOverlay } from '@/composables/useSpotlightOverlay'

const { setInstructionBarConfigByElementId } = useSpotlightOverlay()

// Simple highlight with title
setInstructionBarConfigByElementId({
  elementId: 'welcome-button',
  arrowPosition: 'top',
  isVisible: true,
  config: {
    title: 'Welcome! Click here to get started.'
  }
})

With Action Button

javascript
setInstructionBarConfigByElementId({
  elementId: 'submit-form',
  arrowPosition: 'bottom',
  isVisible: true,
  config: {
    title: 'Ready to submit your form?',
    button: {
      label: 'Submit Now',
      callback: () => {
        document.getElementById('submit-form').click()
        console.log('Form submitted!')
      }
    }
  }
})

Advanced Configuration

javascript
setInstructionBarConfigByElementId({
  elementId: 'settings-panel',
  arrowPosition: 'right',
  isVisible: true,
  config: {
    title: 'Configure your settings here',
    button: {
      label: 'Open Settings',
      callback: () => {
        // Custom action
        openSettingsPanel()
      }
    },
    hideArrowIcon: false,
    allowInteractionWithOtherElements: true,
    closeButtonCallBack: () => {
      console.log('Settings spotlight closed')
    },
    onBlur: () => {
      console.log('Settings spotlight lost focus')
    }
  },
  elementHighlightClassName: 'custom-highlight'
})

Multi-step Tour

javascript
const tourSteps = [
  {
    elementId: 'step1-button',
    arrowPosition: 'top',
    title: 'Step 1: Click here to begin',
    button: { label: 'Next', callback: () => showNextStep(1) }
  },
  {
    elementId: 'step2-input',
    arrowPosition: 'bottom',
    title: 'Step 2: Fill in your information',
    button: { label: 'Next', callback: () => showNextStep(2) }
  },
  {
    elementId: 'step3-submit',
    arrowPosition: 'top',
    title: 'Step 3: Submit when ready',
    button: { label: 'Finish', callback: () => completeTour() }
  }
]

let currentStep = 0

const showNextStep = (stepIndex) => {
  if (stepIndex < tourSteps.length) {
    setInstructionBarConfigByElementId({
      ...tourSteps[stepIndex],
      isVisible: true
    })
  }
}

const completeTour = () => {
  resetInstructionBarConfig()
  console.log('Tour completed!')
}

CSS Classes

The component automatically adds CSS classes to highlighted elements:

  • tour-highlight - Default class added to highlighted elements
  • Custom classes can be specified via elementHighlightClassName parameter

Animation and Transitions

The component includes several built-in animations:

  • Position Changes: Smooth transitions when moving between elements
  • Clip Path Animation: Close-in effect when highlighting new areas
  • Arrow Position Changes: Smooth transitions when arrow position changes
  • Content Updates: Fade effects for content changes

Animation duration can be controlled via the animationDuration property (default: 300ms).