File size: 1,734 Bytes
70d8f15
fe7906f
70d8f15
66a740c
 
a688e23
82a88c5
4c98241
e3d3deb
edd7dca
 
c7a3398
 
9bde4cc
fe7906f
70d8f15
93af367
 
 
 
 
9a49612
e0443d1
eb375ea
 
 
e0443d1
9a49612
 
 
d0e0b03
9a49612
66a740c
 
 
 
 
 
 
4c98241
e3d3deb
c38b220
edd7dca
 
9bde4cc
9a49612
a688e23
66a740c
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { DriveStep } from "./driver";
import { AllowedButtons } from "./popover";

export type Config = {
  animate?: boolean;
  backdropColor?: string;
  smoothScroll?: boolean;
  allowClose?: boolean;
  opacity?: number;
  stagePadding?: number;
  stageRadius?: number;
  allowKeyboardControl?: boolean;

  popoverOffset?: number;
  showButtons?: AllowedButtons[];

  // Button texts
  nextBtnText?: string;
  prevBtnText?: string;
  closeBtnText?: string;

  // State based callbacks, called upon state changes
  onOverlayClick?: (element: Element | undefined, step: DriveStep) => void;
  onHighlightStarted?: (element: Element | undefined, step: DriveStep) => void;
  onHighlighted?: (element: Element | undefined, step: DriveStep) => void;
  onDeselected?: (element: Element | undefined, step: DriveStep) => void;
  onDestroyed?: (element: Element | undefined, step: DriveStep) => void;

  // Event based callbacks, called upon events
  onNextClick?: (element: Element | undefined, step: DriveStep) => void;
  onPrevClick?: (element: Element | undefined, step: DriveStep) => void;
  onCloseClick?: (element: Element | undefined, step: DriveStep) => void;
};

let currentConfig: Config = {};

export function configure(config: Config = {}) {
  currentConfig = {
    animate: true,
    allowClose: true,
    opacity: 0.7,
    smoothScroll: false,
    stagePadding: 10,
    stageRadius: 5,
    popoverOffset: 10,
    showButtons: ["next", "previous", "close"],
    backdropColor: "#000",
    ...config,
  };
}

export function getConfig(): Config;
export function getConfig<K extends keyof Config>(key: K): Config[K];
export function getConfig<K extends keyof Config>(key?: K) {
  return key ? currentConfig[key] : currentConfig;
}