Add examples for styling
Browse files
docs/package.json
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
"@types/react": "^18.0.21",
|
17 |
"@types/react-dom": "^18.0.6",
|
18 |
"astro": "^2.7.0",
|
19 |
-
"driver.js": "1.1.
|
20 |
"react": "^18.0.0",
|
21 |
"react-dom": "^18.0.0",
|
22 |
"react-fast-marquee": "^1.6.0",
|
|
|
16 |
"@types/react": "^18.0.21",
|
17 |
"@types/react-dom": "^18.0.6",
|
18 |
"astro": "^2.7.0",
|
19 |
+
"driver.js": "1.1.11-next.0",
|
20 |
"react": "^18.0.0",
|
21 |
"react-dom": "^18.0.0",
|
22 |
"react-fast-marquee": "^1.6.0",
|
docs/pnpm-lock.yaml
CHANGED
@@ -24,8 +24,8 @@ dependencies:
|
|
24 |
specifier: ^2.7.0
|
25 |
version: 2.7.0
|
26 |
driver.js:
|
27 |
-
specifier: 1.1.
|
28 |
-
version: 1.1.
|
29 |
react:
|
30 |
specifier: ^18.0.0
|
31 |
version: 18.0.0
|
@@ -1386,8 +1386,8 @@ packages:
|
|
1386 | |
1387 |
resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==}
|
1388 |
|
1389 |
-
/[email protected].
|
1390 |
-
resolution: {integrity: sha512-
|
1391 |
dev: false
|
1392 |
|
1393 |
|
|
24 |
specifier: ^2.7.0
|
25 |
version: 2.7.0
|
26 |
driver.js:
|
27 |
+
specifier: 1.1.11-next.0
|
28 |
+
version: 1.1.11-next.0
|
29 |
react:
|
30 |
specifier: ^18.0.0
|
31 |
version: 18.0.0
|
|
|
1386 | |
1387 |
resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==}
|
1388 |
|
1389 |
+
/[email protected].11-next.0:
|
1390 |
+
resolution: {integrity: sha512-9Yyk79pqzoFE+NfNZf3vMx7/GHV9mkHhi9C48Xy9XUWSne9J96yrC4oDgc6Wr1aCVrR3uH5IEDmuc/fJjF7LWw==}
|
1391 |
dev: false
|
1392 |
|
1393 |
docs/src/components/CodeSample.tsx
CHANGED
@@ -43,12 +43,11 @@ function mountDummyElement() {
|
|
43 |
|
44 |
function attachFirstButton(popover: PopoverDOM) {
|
45 |
const firstButton = document.createElement("button");
|
46 |
-
firstButton.innerText = "First";
|
47 |
popover.footerButtons.appendChild(firstButton);
|
48 |
|
49 |
-
console.log(firstButton);
|
50 |
firstButton.addEventListener("click", () => {
|
51 |
-
|
52 |
});
|
53 |
}
|
54 |
|
|
|
43 |
|
44 |
function attachFirstButton(popover: PopoverDOM) {
|
45 |
const firstButton = document.createElement("button");
|
46 |
+
firstButton.innerText = "Go to First";
|
47 |
popover.footerButtons.appendChild(firstButton);
|
48 |
|
|
|
49 |
firstButton.addEventListener("click", () => {
|
50 |
+
window.driverObj.drive(0);
|
51 |
});
|
52 |
}
|
53 |
|
docs/src/content/guides/buttons.mdx
CHANGED
@@ -229,6 +229,77 @@ You can use the `onNextClick`, `onPreviousClick` and `onCloseClick` callbacks to
|
|
229 |
]
|
230 |
});
|
231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
driverObj.drive();
|
233 |
```
|
234 |
</CodeSample>
|
|
|
229 |
]
|
230 |
});
|
231 |
|
232 |
+
driverObj.drive();
|
233 |
+
```
|
234 |
+
</CodeSample>
|
235 |
+
|
236 |
+
## Custom Buttons
|
237 |
+
|
238 |
+
You can add custom buttons using `onPopoverRendered` callback. This callback is called every time a popover is rendered. In the following example, we are adding a custom button that takes the user to the first step.
|
239 |
+
|
240 |
+
|
241 |
+
<CodeSample
|
242 |
+
buttonText={"Run Example"}
|
243 |
+
config={{
|
244 |
+
prevBtnText: '← Previous',
|
245 |
+
nextBtnText: 'Next →',
|
246 |
+
doneBtnText: 'Done',
|
247 |
+
showButtons: ['next', 'previous'],
|
248 |
+
}}
|
249 |
+
tour={[
|
250 |
+
{
|
251 |
+
element: '#demo-hook-theme',
|
252 |
+
popover: {
|
253 |
+
align: 'start',
|
254 |
+
side: 'left',
|
255 |
+
title: 'More Control with Hooks',
|
256 |
+
description: 'You can use onPopoverRendered hook to modify the popover DOM. Here we are adding a custom button to the popover which takes the user to the first step.'
|
257 |
+
}
|
258 |
+
},
|
259 |
+
{
|
260 |
+
element: 'h1',
|
261 |
+
popover: {
|
262 |
+
align: 'start',
|
263 |
+
side: 'bottom',
|
264 |
+
title: 'Style However You Want',
|
265 |
+
description: 'You can use the default class names and override the styles or you can pass a custom class name to the popoverClass option either globally or per step.'
|
266 |
+
}
|
267 |
+
},
|
268 |
+
{
|
269 |
+
element: 'p a',
|
270 |
+
popover: {
|
271 |
+
align: 'start',
|
272 |
+
side: 'left',
|
273 |
+
title: 'Style However You Want',
|
274 |
+
description: 'You can use the default class names and override the styles or you can pass a custom class name to the popoverClass option either globally or per step.'
|
275 |
+
}
|
276 |
+
}
|
277 |
+
]}
|
278 |
+
id={"demo-hook-theme"}
|
279 |
+
client:load
|
280 |
+
>
|
281 |
+
```js
|
282 |
+
import { driver } from "driver.js";
|
283 |
+
import "driver.js/dist/driver.css";
|
284 |
+
|
285 |
+
const driverObj = driver({
|
286 |
+
// Get full control over the popover rendering.
|
287 |
+
// Here we are adding a custom button that takes
|
288 |
+
// user to the first step.
|
289 |
+
onPopoverRendered: (popover, { config, state }) => {
|
290 |
+
const firstButton = document.createElement("button");
|
291 |
+
firstButton.innerText = "Go to First";
|
292 |
+
popover.footerButtons.appendChild(firstButton);
|
293 |
+
|
294 |
+
firstButton.addEventListener("click", () => {
|
295 |
+
driverObj.drive(0);
|
296 |
+
});
|
297 |
+
},
|
298 |
+
steps: [
|
299 |
+
// ..
|
300 |
+
]
|
301 |
+
});
|
302 |
+
|
303 |
driverObj.drive();
|
304 |
```
|
305 |
</CodeSample>
|
docs/src/content/guides/configuration.mdx
CHANGED
@@ -63,7 +63,7 @@ type Popover = {
|
|
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) => void;
|
67 |
|
68 |
// Callbacks for button clicks. You can use
|
69 |
// these to add custom behavior to the buttons.
|
@@ -166,7 +166,7 @@ type Config = {
|
|
166 |
// PopoverDOM is an object with references to
|
167 |
// the popover DOM elements such as buttons
|
168 |
// title, descriptions, body, container etc.
|
169 |
-
onPopoverRendered?: (popover: PopoverDOM) => void;
|
170 |
|
171 |
// Hooks to run before and after highlighting
|
172 |
// each step. Each hook receives the following
|
|
|
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.
|
|
|
166 |
// PopoverDOM is an object with references to
|
167 |
// the popover DOM elements such as buttons
|
168 |
// title, descriptions, body, container etc.
|
169 |
+
onPopoverRendered?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
|
170 |
|
171 |
// Hooks to run before and after highlighting
|
172 |
// each step. Each hook receives the following
|
docs/src/content/guides/styling-popover.mdx
CHANGED
@@ -72,11 +72,76 @@ We have added a few examples below but have a look at the [theming section](/doc
|
|
72 |
```
|
73 |
</CodeSample>
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
<br/>
|
76 |
|
77 |
<CodeSample
|
78 |
-
heading="Using Hook"
|
79 |
-
buttonText={"
|
80 |
config={{
|
81 |
prevBtnText: '← Previous',
|
82 |
nextBtnText: 'Next →',
|
@@ -89,8 +154,8 @@ We have added a few examples below but have a look at the [theming section](/doc
|
|
89 |
popover: {
|
90 |
align: 'start',
|
91 |
side: 'left',
|
92 |
-
title: '
|
93 |
-
description: 'You can use
|
94 |
}
|
95 |
},
|
96 |
{
|
@@ -120,15 +185,23 @@ We have added a few examples below but have a look at the [theming section](/doc
|
|
120 |
import "driver.js/dist/driver.css";
|
121 |
|
122 |
const driverObj = driver({
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
```
|
134 |
</CodeSample>
|
|
|
72 |
```
|
73 |
</CodeSample>
|
74 |
|
75 |
+
Here is the CSS used for the above example:
|
76 |
+
|
77 |
+
```css
|
78 |
+
.driver-popover.driverjs-theme {
|
79 |
+
background-color: #fde047;
|
80 |
+
color: #000;
|
81 |
+
}
|
82 |
+
|
83 |
+
.driver-popover.driverjs-theme .driver-popover-title {
|
84 |
+
font-size: 20px;
|
85 |
+
}
|
86 |
+
|
87 |
+
.driver-popover.driverjs-theme .driver-popover-title,
|
88 |
+
.driver-popover.driverjs-theme .driver-popover-description,
|
89 |
+
.driver-popover.driverjs-theme .driver-popover-progress-text {
|
90 |
+
color: #000;
|
91 |
+
}
|
92 |
+
|
93 |
+
.driver-popover.driverjs-theme button {
|
94 |
+
flex: 1;
|
95 |
+
text-align: center;
|
96 |
+
background-color: #000;
|
97 |
+
color: #ffffff;
|
98 |
+
border: 2px solid #000;
|
99 |
+
text-shadow: none;
|
100 |
+
font-size: 14px;
|
101 |
+
padding: 5px 8px;
|
102 |
+
border-radius: 6px;
|
103 |
+
}
|
104 |
+
|
105 |
+
.driver-popover.driverjs-theme button:hover {
|
106 |
+
background-color: #000;
|
107 |
+
color: #ffffff;
|
108 |
+
}
|
109 |
+
|
110 |
+
.driver-popover.driverjs-theme .driver-popover-navigation-btns {
|
111 |
+
justify-content: space-between;
|
112 |
+
gap: 3px;
|
113 |
+
}
|
114 |
+
|
115 |
+
.driver-popover.driverjs-theme .driver-popover-close-btn {
|
116 |
+
color: #9b9b9b;
|
117 |
+
}
|
118 |
+
|
119 |
+
.driver-popover.driverjs-theme .driver-popover-close-btn:hover {
|
120 |
+
color: #000;
|
121 |
+
}
|
122 |
+
|
123 |
+
.driver-popover.driverjs-theme .driver-popover-arrow-side-left.driver-popover-arrow {
|
124 |
+
border-left-color: #fde047;
|
125 |
+
}
|
126 |
+
|
127 |
+
.driver-popover.driverjs-theme .driver-popover-arrow-side-right.driver-popover-arrow {
|
128 |
+
border-right-color: #fde047;
|
129 |
+
}
|
130 |
+
|
131 |
+
.driver-popover.driverjs-theme .driver-popover-arrow-side-top.driver-popover-arrow {
|
132 |
+
border-top-color: #fde047;
|
133 |
+
}
|
134 |
+
|
135 |
+
.driver-popover.driverjs-theme .driver-popover-arrow-side-bottom.driver-popover-arrow {
|
136 |
+
border-bottom-color: #fde047;
|
137 |
+
}
|
138 |
+
```
|
139 |
+
|
140 |
<br/>
|
141 |
|
142 |
<CodeSample
|
143 |
+
heading="Using Hook to Modify"
|
144 |
+
buttonText={"Manipulating Popover DOM"}
|
145 |
config={{
|
146 |
prevBtnText: '← Previous',
|
147 |
nextBtnText: 'Next →',
|
|
|
154 |
popover: {
|
155 |
align: 'start',
|
156 |
side: 'left',
|
157 |
+
title: 'More Control with Hooks',
|
158 |
+
description: 'You can use onPopoverRendered hook to modify the popover DOM. Here we are adding a custom button to the popover which takes the user to the first step.'
|
159 |
}
|
160 |
},
|
161 |
{
|
|
|
185 |
import "driver.js/dist/driver.css";
|
186 |
|
187 |
const driverObj = driver({
|
188 |
+
// Get full control over the popover rendering.
|
189 |
+
// Here we are adding a custom button that takes
|
190 |
+
// the user to the first step.
|
191 |
+
onPopoverRendered: (popover, { config, state }) => {
|
192 |
+
const firstButton = document.createElement("button");
|
193 |
+
firstButton.innerText = "Go to First";
|
194 |
+
popover.footerButtons.appendChild(firstButton);
|
195 |
+
|
196 |
+
firstButton.addEventListener("click", () => {
|
197 |
+
driverObj.drive(0);
|
198 |
+
});
|
199 |
+
},
|
200 |
+
steps: [
|
201 |
+
// ..
|
202 |
+
]
|
203 |
+
});
|
204 |
+
|
205 |
+
driverObj.drive();
|
206 |
```
|
207 |
</CodeSample>
|
docs/src/content/guides/theming.mdx
CHANGED
@@ -53,6 +53,10 @@ Here is the list of classes applied to the popover which you can use in conjunct
|
|
53 |
.driver-popover-next-btn {}
|
54 |
```
|
55 |
|
|
|
|
|
|
|
|
|
56 |
Alternatively, you can also use the `onPopoverRendered` hook to modify the popover DOM before it is displayed. The hook is called with the popover DOM as the first argument.
|
57 |
|
58 |
```typescript
|
|
|
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 |
+
|
60 |
Alternatively, you can also use the `onPopoverRendered` hook to modify the popover DOM before it is displayed. The hook is called with the popover DOM as the first argument.
|
61 |
|
62 |
```typescript
|
src/popover.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import { bringInView } from "./utils";
|
2 |
-
import { DriverHook, getConfig } from "./config";
|
3 |
-
import { getState, setState } from "./state";
|
4 |
import { DriveStep } from "./driver";
|
5 |
import { onDriverClick } from "./events";
|
6 |
import { emit } from "./emitter";
|
@@ -28,7 +28,7 @@ export type Popover = {
|
|
28 |
prevBtnText?: string;
|
29 |
|
30 |
// Called after the popover is rendered
|
31 |
-
onPopoverRendered?: (popover: PopoverDOM) => void;
|
32 |
|
33 |
// Button callbacks
|
34 |
onNextClick?: DriverHook;
|
@@ -208,7 +208,10 @@ export function renderPopover(element: Element, step: DriveStep) {
|
|
208 |
|
209 |
const onPopoverRendered = step.popover?.onPopoverRendered || getConfig("onPopoverRendered");
|
210 |
if (onPopoverRendered) {
|
211 |
-
onPopoverRendered(popover
|
|
|
|
|
|
|
212 |
}
|
213 |
}
|
214 |
|
|
|
1 |
import { bringInView } from "./utils";
|
2 |
+
import { Config, DriverHook, getConfig } from "./config";
|
3 |
+
import { getState, setState, State } from "./state";
|
4 |
import { DriveStep } from "./driver";
|
5 |
import { onDriverClick } from "./events";
|
6 |
import { emit } from "./emitter";
|
|
|
28 |
prevBtnText?: string;
|
29 |
|
30 |
// Called after the popover is rendered
|
31 |
+
onPopoverRendered?: (popover: PopoverDOM, opts: { config: Config; state: State }) => void;
|
32 |
|
33 |
// Button callbacks
|
34 |
onNextClick?: DriverHook;
|
|
|
208 |
|
209 |
const onPopoverRendered = step.popover?.onPopoverRendered || getConfig("onPopoverRendered");
|
210 |
if (onPopoverRendered) {
|
211 |
+
onPopoverRendered(popover, {
|
212 |
+
config: getConfig(),
|
213 |
+
state: getState(),
|
214 |
+
});
|
215 |
}
|
216 |
}
|
217 |
|