kamrify commited on
Commit
80a2c0d
·
1 Parent(s): 3d04f71

Add API configuration page

Browse files
docs/src/content/guides/api.mdx ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "API Reference"
3
+ groupTitle: "Introduction"
4
+ sort: 4
5
+ ---
6
+
7
+ Here is the list of methods provided by `driver` when you initialize it.
8
+
9
+ > **Note:** We have omitted the configuration options for brevity. Please look at the configuration section for the options. Links are provided in the description below.
10
+
11
+ ```javascript
12
+ import { driver } from "driver.js";
13
+ import "driver.js/dist/driver.css";
14
+
15
+ // Look at the configuration section for the options
16
+ // https://driverjs.com/docs/configuration#driver-configuration
17
+ const driverObj = driver({ /* ... */ });
18
+
19
+ // --------------------------------------------------
20
+ // driverObj is an object with the following methods
21
+ // --------------------------------------------------
22
+
23
+ // Start the tour using `steps` given in the configuration
24
+ driverObj.drive(); // Starts at step 0
25
+ driverObj.drive(4); // Starts at step 4
26
+
27
+ driverObj.moveNext(); // Move to the next step
28
+ driverObj.movePrevious(); // Move to the previous step
29
+ driverObj.moveTo(4); // Move to the step 4
30
+ driverObj.hasNextStep(); // Is there a next step
31
+ driverObj.hasPreviousStep() // Is there a previous step
32
+
33
+ driverObj.getActiveIndex(); // Gets the active step index
34
+
35
+ driverObj.getActiveStep(); // Gets the active step configuration
36
+ driverObj.getPreviousStep(); // Gets the previous step configuration
37
+ driverObj.getActiveElement(); // Gets the active HTML element
38
+ driverObj.getPreviousElement(); // Gets the previous HTML element
39
+
40
+ // Is the tour or highlight currently active
41
+ driverObj.isActive();
42
+
43
+ // Recalculate and redraw the highlight
44
+ driverObj.refresh();
45
+
46
+ // Look at the configuration section for configuration options
47
+ // https://driverjs.com/docs/configuration#driver-configuration
48
+ driverObj.getConfig();
49
+ driverObj.setConfig({ /* ... */ });
50
+
51
+ // Look at the state section of configuration for format of the state
52
+ // https://driverjs.com/docs/configuration#state
53
+ driverObj.getState();
54
+
55
+ // Look at the DriveStep section of configuration for format of the step
56
+ // https://driverjs.com/docs/configuration/#drive-step-configuration
57
+ driverObj.highlight({ /* ... */ }); // Highlight an element
58
+ ```
docs/src/content/guides/configuration.mdx CHANGED
@@ -10,104 +10,7 @@ Driver.js is built to be highly configurable. You can configure the driver globa
10
 
11
  > Driver.js is written in TypeScript. Configuration options are mostly self-explanatory. Also, if you're using an IDE like WebStorm or VSCode, you'll get autocomplete and documentation for all the configuration options.
12
 
13
- ## Popover Configuration
14
-
15
- The popover is the main UI element of Driver.js. It's the element that highlights the target element, and shows the step content. You can configure the popover globally, or per step. Given below are some of the available configuration options.
16
-
17
- ```typescript
18
- type Popover = {
19
- // Title and descriptions shown in the popover.
20
- // You can use HTML in these. Also, you can
21
- // omit one of these to show only the other.
22
- title?: string;
23
- description?: string;
24
-
25
- // The position and alignment of the popover
26
- // relative to the target element.
27
- side?: "top" | "right" | "bottom" | "left";
28
- align?: "start" | "center" | "end";
29
-
30
- // Array of buttons to show in the popover.
31
- // When highlighting a single element, there
32
- // are no buttons by default. When showing
33
- // a tour, the default buttons are "next",
34
- // "previous" and "close".
35
- showButtons?: ("next" | "previous" | "close")[];
36
- // An array of buttons to disable. This is
37
- // useful when you want to show some of the
38
- // buttons, but disable some of them.
39
- disableButtons?: ("next" | "previous" | "close")[];
40
-
41
- // Text to show in the buttons. `doneBtnText`
42
- // is used on the last step of a tour.
43
- nextBtnText?: string;
44
- prevBtnText?: string;
45
- doneBtnText?: string;
46
-
47
- // Whether to show the progress text in popover.
48
- showProgress?: boolean;
49
- // Template for the progress text. You can use
50
- // the following placeholders in the template:
51
- // - {{current}}: The current step number
52
- // - {{total}}: Total number of steps
53
- // Defaults to following if `showProgress` is true:
54
- // - "{{current}} of {{total}}"
55
- progressText?: string;
56
-
57
- // Custom class to add to the popover element.
58
- // This can be used to style the popover.
59
- popoverClass?: string;
60
-
61
- // Hook to run after the popover is rendered.
62
- // You can modify the popover element here.
63
- // Parameter is an object with references to
64
- // the popover DOM elements such as buttons
65
- // title, descriptions, body, etc.
66
- onPopoverRendered?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
67
-
68
- // Callbacks for button clicks. You can use
69
- // these to add custom behavior to the buttons.
70
- // Each callback receives the following parameters:
71
- // - element: The current DOM element of the step
72
- // - step: The step object configured for the step
73
- // - options.config: The current configuration options
74
- // - options.state: The current state of the driver
75
- onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
76
- onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
77
- onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
78
- }
79
- ```
80
-
81
- ## Drive Step Configuration
82
-
83
- Drive step is the configuration object passed to the `highlight` method or the `steps` array of the `drive` method. You can configure the popover and the target element for each step. Given below are some of the available configuration options.
84
-
85
- ```typescript
86
- type DriveStep = {
87
- // The target element to highlight.
88
- // This can be a DOM element, or a CSS selector.
89
- // If this is a selector, the first matching
90
- // element will be highlighted.
91
- element: Element | string;
92
-
93
- // The popover configuration for this step.
94
- // Look at the Popover Configuration section
95
- popover?: Popover;
96
-
97
- // Callback when the current step is deselected,
98
- // about to be highlighted or highlighted.
99
- // Each callback receives the following parameters:
100
- // - element: The current DOM element of the step
101
- // - step: The step object configured for the step
102
- // - options.config: The current configuration options
103
- // - options.state: The current state of the driver
104
- onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
105
- onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
106
- onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
107
- }
108
- ```
109
-
110
- ## Global Configuration
111
 
112
  You can configure the driver globally by passing the configuration object to the `driver` call or by using the `setConfig` method. Given below are some of the available configuration options.
113
 
@@ -207,6 +110,103 @@ type Config = {
207
  >
208
  > `onNextClick` and `onPrevClick` hooks can be configured at the step level as well. When configured at the driver level, you control the navigation for all the steps. When configured at the step level, you control the navigation for that particular step only.
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  ## State
211
 
212
  You can access the current state of the driver by calling the `getState` method. It's also passed to the hooks and callbacks.
 
10
 
11
  > Driver.js is written in TypeScript. Configuration options are mostly self-explanatory. Also, if you're using an IDE like WebStorm or VSCode, you'll get autocomplete and documentation for all the configuration options.
12
 
13
+ ## Driver Configuration
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  You can configure the driver globally by passing the configuration object to the `driver` call or by using the `setConfig` method. Given below are some of the available configuration options.
16
 
 
110
  >
111
  > `onNextClick` and `onPrevClick` hooks can be configured at the step level as well. When configured at the driver level, you control the navigation for all the steps. When configured at the step level, you control the navigation for that particular step only.
112
 
113
+ ## Popover Configuration
114
+
115
+ The popover is the main UI element of Driver.js. It's the element that highlights the target element, and shows the step content. You can configure the popover globally, or per step. Given below are some of the available configuration options.
116
+
117
+ ```typescript
118
+ type Popover = {
119
+ // Title and descriptions shown in the popover.
120
+ // You can use HTML in these. Also, you can
121
+ // omit one of these to show only the other.
122
+ title?: string;
123
+ description?: string;
124
+
125
+ // The position and alignment of the popover
126
+ // relative to the target element.
127
+ side?: "top" | "right" | "bottom" | "left";
128
+ align?: "start" | "center" | "end";
129
+
130
+ // Array of buttons to show in the popover.
131
+ // When highlighting a single element, there
132
+ // are no buttons by default. When showing
133
+ // a tour, the default buttons are "next",
134
+ // "previous" and "close".
135
+ showButtons?: ("next" | "previous" | "close")[];
136
+ // An array of buttons to disable. This is
137
+ // useful when you want to show some of the
138
+ // buttons, but disable some of them.
139
+ disableButtons?: ("next" | "previous" | "close")[];
140
+
141
+ // Text to show in the buttons. `doneBtnText`
142
+ // is used on the last step of a tour.
143
+ nextBtnText?: string;
144
+ prevBtnText?: string;
145
+ doneBtnText?: string;
146
+
147
+ // Whether to show the progress text in popover.
148
+ showProgress?: boolean;
149
+ // Template for the progress text. You can use
150
+ // the following placeholders in the template:
151
+ // - {{current}}: The current step number
152
+ // - {{total}}: Total number of steps
153
+ // Defaults to following if `showProgress` is true:
154
+ // - "{{current}} of {{total}}"
155
+ progressText?: string;
156
+
157
+ // Custom class to add to the popover element.
158
+ // This can be used to style the popover.
159
+ popoverClass?: string;
160
+
161
+ // Hook to run after the popover is rendered.
162
+ // You can modify the popover element here.
163
+ // Parameter is an object with references to
164
+ // the popover DOM elements such as buttons
165
+ // title, descriptions, body, etc.
166
+ onPopoverRendered?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
167
+
168
+ // Callbacks for button clicks. You can use
169
+ // these to add custom behavior to the buttons.
170
+ // Each callback receives the following parameters:
171
+ // - element: The current DOM element of the step
172
+ // - step: The step object configured for the step
173
+ // - options.config: The current configuration options
174
+ // - options.state: The current state of the driver
175
+ onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
176
+ onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
177
+ onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
178
+ }
179
+ ```
180
+
181
+ ## Drive Step Configuration
182
+
183
+ Drive step is the configuration object passed to the `highlight` method or the `steps` array of the `drive` method. You can configure the popover and the target element for each step. Given below are some of the available configuration options.
184
+
185
+ ```typescript
186
+ type DriveStep = {
187
+ // The target element to highlight.
188
+ // This can be a DOM element, or a CSS selector.
189
+ // If this is a selector, the first matching
190
+ // element will be highlighted.
191
+ element: Element | string;
192
+
193
+ // The popover configuration for this step.
194
+ // Look at the Popover Configuration section
195
+ popover?: Popover;
196
+
197
+ // Callback when the current step is deselected,
198
+ // about to be highlighted or highlighted.
199
+ // Each callback receives the following parameters:
200
+ // - element: The current DOM element of the step
201
+ // - step: The step object configured for the step
202
+ // - options.config: The current configuration options
203
+ // - options.state: The current state of the driver
204
+ onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
205
+ onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
206
+ onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
207
+ }
208
+ ```
209
+
210
  ## State
211
 
212
  You can access the current state of the driver by calling the `getState` method. It's also passed to the hooks and callbacks.
docs/src/content/guides/theming.mdx CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: "Theming"
3
  groupTitle: "Introduction"
4
- sort: 3
5
  ---
6
 
7
  You can customize the look and feel of the driver by adding custom class to popover or applying CSS to different classes used by driver.js.
@@ -53,7 +53,7 @@ Here is the list of classes applied to the popover which you can use in conjunct
53
  .driver-popover-next-btn {}
54
  ```
55
 
56
- Visit the [example page](/docs/styling-popover) for a demo that modifies the popover styles.
57
 
58
  ## Modifying Popover DOM
59
 
 
1
  ---
2
  title: "Theming"
3
  groupTitle: "Introduction"
4
+ sort: 5
5
  ---
6
 
7
  You can customize the look and feel of the driver by adding custom class to popover or applying CSS to different classes used by driver.js.
 
53
  .driver-popover-next-btn {}
54
  ```
55
 
56
+ Visit the [example page](/docs/styling-popover) for an example that modifies the popover styles.
57
 
58
  ## Modifying Popover DOM
59
 
src/driver.ts CHANGED
@@ -56,6 +56,16 @@ export function driver(options: Config = {}) {
56
  }
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
59
  function handleArrowLeft() {
60
  const isTransitioning = getState("__transitionCallback");
61
  if (isTransitioning) {
@@ -253,8 +263,14 @@ export function driver(options: Config = {}) {
253
  setConfig: configure,
254
  getConfig,
255
  getState,
 
 
 
 
 
256
  moveNext,
257
  movePrevious,
 
258
  hasNextStep: () => {
259
  const steps = getConfig("steps") || [];
260
  const activeIndex = getState("activeIndex");
 
56
  }
57
  }
58
 
59
+ function moveTo(index: number) {
60
+ const steps = getConfig("steps") || [];
61
+
62
+ if (steps[index]) {
63
+ drive(index);
64
+ } else {
65
+ destroy();
66
+ }
67
+ }
68
+
69
  function handleArrowLeft() {
70
  const isTransitioning = getState("__transitionCallback");
71
  if (isTransitioning) {
 
263
  setConfig: configure,
264
  getConfig,
265
  getState,
266
+ getActiveIndex: () => getState("activeIndex"),
267
+ getActiveStep: () => getState("activeStep"),
268
+ getActiveElement: () => getState("activeElement"),
269
+ getPreviousElement: () => getState("previousElement"),
270
+ getPreviousStep: () => getState("previousStep"),
271
  moveNext,
272
  movePrevious,
273
+ moveTo,
274
  hasNextStep: () => {
275
  const steps = getConfig("steps") || [];
276
  const activeIndex = getState("activeIndex");