Sticky sidebar and highlight
Browse files
docs/src/components/CodeSample.tsx
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
import type { Config, DriveStep, PopoverDOM } from "driver.js";
|
2 |
import { driver } from "driver.js";
|
3 |
import "driver.js/dist/driver.css";
|
4 |
-
import { useState } from "react";
|
5 |
-
import { onDriverClick } from "../../../src/events";
|
6 |
|
7 |
type CodeSampleProps = {
|
8 |
heading?: string;
|
|
|
1 |
import type { Config, DriveStep, PopoverDOM } from "driver.js";
|
2 |
import { driver } from "driver.js";
|
3 |
import "driver.js/dist/driver.css";
|
|
|
|
|
4 |
|
5 |
type CodeSampleProps = {
|
6 |
heading?: string;
|
docs/src/components/FormHelp.tsx
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useEffect } from "react";
|
2 |
+
import { driver } from "driver.js";
|
3 |
+
import "driver.js/dist/driver.css";
|
4 |
+
|
5 |
+
export function FormHelp() {
|
6 |
+
useEffect(() => {
|
7 |
+
const driverObj = driver({
|
8 |
+
popoverClass: "driverjs-theme",
|
9 |
+
stagePadding: 0,
|
10 |
+
onDestroyed: () => {
|
11 |
+
(document?.activeElement as any)?.blur();
|
12 |
+
}
|
13 |
+
});
|
14 |
+
|
15 |
+
const nameEl = document.getElementById("name");
|
16 |
+
const educationEl = document.getElementById("education");
|
17 |
+
const ageEl = document.getElementById("age");
|
18 |
+
const addressEl = document.getElementById("address");
|
19 |
+
const submitEl = document.getElementById("submit-btn");
|
20 |
+
|
21 |
+
nameEl!.addEventListener("focus", () => {
|
22 |
+
driverObj.highlight({
|
23 |
+
element: nameEl!,
|
24 |
+
popover: {
|
25 |
+
title: "Name",
|
26 |
+
description: "Enter your name here",
|
27 |
+
},
|
28 |
+
});
|
29 |
+
});
|
30 |
+
|
31 |
+
educationEl!.addEventListener("focus", () => {
|
32 |
+
driverObj.highlight({
|
33 |
+
element: educationEl!,
|
34 |
+
popover: {
|
35 |
+
title: "Education",
|
36 |
+
description: "Enter your education here",
|
37 |
+
},
|
38 |
+
});
|
39 |
+
});
|
40 |
+
|
41 |
+
ageEl!.addEventListener("focus", () => {
|
42 |
+
driverObj.highlight({
|
43 |
+
element: ageEl!,
|
44 |
+
popover: {
|
45 |
+
title: "Age",
|
46 |
+
description: "Enter your age here",
|
47 |
+
},
|
48 |
+
});
|
49 |
+
});
|
50 |
+
|
51 |
+
addressEl!.addEventListener("focus", () => {
|
52 |
+
driverObj.highlight({
|
53 |
+
element: addressEl!,
|
54 |
+
popover: {
|
55 |
+
title: "Address",
|
56 |
+
description: "Enter your address here",
|
57 |
+
},
|
58 |
+
});
|
59 |
+
});
|
60 |
+
|
61 |
+
submitEl!.addEventListener("focus", (e) => {
|
62 |
+
e.preventDefault();
|
63 |
+
driverObj.destroy();
|
64 |
+
});
|
65 |
+
});
|
66 |
+
|
67 |
+
return <></>;
|
68 |
+
}
|
docs/src/components/Sidebar.astro
CHANGED
@@ -18,23 +18,26 @@ const groupedGuides = sortedGuides.reduce((acc, curr) => {
|
|
18 |
const { activePath } = Astro.props;
|
19 |
---
|
20 |
<div class="w-[300px] border-r border-gray-200 text-right min-h-screen py-5 flex-shrink-0">
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
</div>
|
|
|
18 |
const { activePath } = Astro.props;
|
19 |
---
|
20 |
<div class="w-[300px] border-r border-gray-200 text-right min-h-screen py-5 flex-shrink-0">
|
21 |
+
<div class="sticky top-[100px]">
|
22 |
+
{Object.keys(groupedGuides).map(groupTitle => {
|
23 |
+
const guides = groupedGuides[groupTitle];
|
24 |
|
25 |
+
return (
|
26 |
+
<>
|
27 |
+
<h2 class="text-xl font-bold mb-2 pr-5 relative">{groupTitle}</h2>
|
28 |
+
<ul class="text-gray-400 mb-5">
|
29 |
+
{guides.map(guide => {
|
30 |
+
const guidePath = `/docs/${guide.slug}`;
|
31 |
+
return (
|
32 |
+
<li class="mb-2">
|
33 |
+
<a href={guidePath}
|
34 |
+
class:list={["hover:text-black pr-5 py-2", { "text-black": activePath === guidePath }]}>{guide.data.title}</a>
|
35 |
+
</li>
|
36 |
+
);
|
37 |
+
})}
|
38 |
+
</ul>
|
39 |
+
</>
|
40 |
+
);
|
41 |
+
})}
|
42 |
+
</div>
|
43 |
</div>
|
docs/src/content/guides/simple-highlight.mdx
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: "Simple Highlight"
|
3 |
+
groupTitle: "Examples"
|
4 |
+
sort: 11
|
5 |
+
---
|
6 |
+
|
7 |
+
import { FormHelp } from "../../components/FormHelp.tsx";
|
8 |
+
import { CodeSample } from "../../components/CodeSample.tsx";
|
9 |
+
|
10 |
+
Product tours is not the only usecase for Driver.js. You can use it to highlight any element on the page and show a popover with a description. This is useful for providing contextual help to the user e.g. help the user fill a form or explain a feature.
|
11 |
+
|
12 |
+
Example below shows how to highlight an element and simply show a popover.
|
13 |
+
|
14 |
+
<CodeSample
|
15 |
+
id={"highlight-me"}
|
16 |
+
buttonText={"Highlight Me"}
|
17 |
+
config={{
|
18 |
+
popoverClass: "driverjs-theme",
|
19 |
+
stagePadding: 4,
|
20 |
+
}}
|
21 |
+
highlight={{
|
22 |
+
element: "#highlight-me",
|
23 |
+
popover: {
|
24 |
+
side: "bottom",
|
25 |
+
title: "This is a title",
|
26 |
+
description: "This is a description",
|
27 |
+
},
|
28 |
+
}}
|
29 |
+
client:load
|
30 |
+
/>
|
31 |
+
|
32 |
+
Here is the code for above example:
|
33 |
+
|
34 |
+
```js
|
35 |
+
const driverObj = driver({
|
36 |
+
popoverClass: "driverjs-theme",
|
37 |
+
stagePadding: 4,
|
38 |
+
});
|
39 |
+
|
40 |
+
driverObj.highlight({
|
41 |
+
element: "#highlight-me",
|
42 |
+
popover: {
|
43 |
+
side: "bottom",
|
44 |
+
title: "This is a title",
|
45 |
+
description: "This is a description",
|
46 |
+
}
|
47 |
+
})
|
48 |
+
```
|
49 |
+
|
50 |
+
You can also use it to show a simple modal without highlighting any element.
|
51 |
+
|
52 |
+
<CodeSample
|
53 |
+
id={"highlight-me"}
|
54 |
+
buttonText={"Show Popover"}
|
55 |
+
highlight={{
|
56 |
+
popover: {
|
57 |
+
side: "bottom",
|
58 |
+
description: "<img src='https://i.imgur.com/EAQhHu5.gif' style='height: 202.5px; width: 270px;' /><span style='font-size: 15px; display: block; margin-top: 10px; text-align: center;'>Yet another highlight example.</span>",
|
59 |
+
},
|
60 |
+
}}
|
61 |
+
client:load
|
62 |
+
/>
|
63 |
+
|
64 |
+
Here is the code for above example:
|
65 |
+
|
66 |
+
```js
|
67 |
+
const driverObj = driver();
|
68 |
+
|
69 |
+
driverObj.highlight({
|
70 |
+
popover: {
|
71 |
+
description: "<img src='https://i.imgur.com/EAQhHu5.gif' style='height: 202.5px; width: 270px;' /><span style='font-size: 15px; display: block; margin-top: 10px; text-align: center;'>Yet another highlight example.</span>",
|
72 |
+
}
|
73 |
+
})
|
74 |
+
```
|
75 |
+
|
76 |
+
Focus on the input below and see how the popover is shown.
|
77 |
+
|
78 |
+
<form action="#" className='flex flex-col gap-2'>
|
79 |
+
<input id="name" type="text" placeholder="Enter your Name" className='block w-full border rounded-md py-2 px-3 focus:outline-0' />
|
80 |
+
<input id="education" type="text" placeholder="Your Education" className='block w-full border rounded-md py-2 px-3 focus:outline-0' />
|
81 |
+
<input id="age" type="number" placeholder="Your Age" className='block w-full border rounded-md py-2 px-3 focus:outline-0' />
|
82 |
+
<textarea id="address" placeholder="Your Address" className='block w-full border rounded-md py-2 px-3 focus:outline-0' />
|
83 |
+
<button id="submit-btn" className='w-full rounded-md bg-black p-2 text-white'>Submit</button>
|
84 |
+
</form>
|
85 |
+
|
86 |
+
<FormHelp client:only />
|
87 |
+
|
88 |
+
Here is the code for the above example.
|
89 |
+
|
90 |
+
```js
|
91 |
+
const driverObj = driver({
|
92 |
+
popoverClass: "driverjs-theme",
|
93 |
+
stagePadding: 0,
|
94 |
+
onDestroyed: () => {
|
95 |
+
document?.activeElement?.blur();
|
96 |
+
}
|
97 |
+
});
|
98 |
+
|
99 |
+
const nameEl = document.getElementById("name");
|
100 |
+
const educationEl = document.getElementById("education");
|
101 |
+
const ageEl = document.getElementById("age");
|
102 |
+
const addressEl = document.getElementById("address");
|
103 |
+
const formEl = document.querySelector("form");
|
104 |
+
|
105 |
+
nameEl.addEventListener("focus", () => {
|
106 |
+
driverObj.highlight({
|
107 |
+
element: nameEl,
|
108 |
+
popover: {
|
109 |
+
title: "Name",
|
110 |
+
description: "Enter your name here",
|
111 |
+
},
|
112 |
+
});
|
113 |
+
});
|
114 |
+
|
115 |
+
educationEl.addEventListener("focus", () => {
|
116 |
+
driverObj.highlight({
|
117 |
+
element: educationEl,
|
118 |
+
popover: {
|
119 |
+
title: "Education",
|
120 |
+
description: "Enter your education here",
|
121 |
+
},
|
122 |
+
});
|
123 |
+
});
|
124 |
+
|
125 |
+
ageEl.addEventListener("focus", () => {
|
126 |
+
driverObj.highlight({
|
127 |
+
element: ageEl,
|
128 |
+
popover: {
|
129 |
+
title: "Age",
|
130 |
+
description: "Enter your age here",
|
131 |
+
},
|
132 |
+
});
|
133 |
+
});
|
134 |
+
|
135 |
+
addressEl.addEventListener("focus", () => {
|
136 |
+
driverObj.highlight({
|
137 |
+
element: addressEl,
|
138 |
+
popover: {
|
139 |
+
title: "Address",
|
140 |
+
description: "Enter your address here",
|
141 |
+
},
|
142 |
+
});
|
143 |
+
});
|
144 |
+
|
145 |
+
formEl.addEventListener("blur", () => {
|
146 |
+
driverObj.destroy();
|
147 |
+
});
|
148 |
+
```
|
docs/src/content/guides/styling-popover.mdx
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
---
|
2 |
title: "Styling Popover"
|
3 |
groupTitle: "Examples"
|
4 |
-
sort:
|
5 |
---
|
6 |
|
7 |
import { CodeSample } from "../../components/CodeSample.tsx";
|
@@ -62,7 +62,7 @@ We have added a few examples below but have a look at the [theming section](/doc
|
|
62 |
popoverClass: 'driverjs-theme'
|
63 |
});
|
64 |
|
65 |
-
|
66 |
element: '#demo-theme',
|
67 |
popover: {
|
68 |
title: 'Style However You Want',
|
|
|
1 |
---
|
2 |
title: "Styling Popover"
|
3 |
groupTitle: "Examples"
|
4 |
+
sort: 2
|
5 |
---
|
6 |
|
7 |
import { CodeSample } from "../../components/CodeSample.tsx";
|
|
|
62 |
popoverClass: 'driverjs-theme'
|
63 |
});
|
64 |
|
65 |
+
driverObj.highlight({
|
66 |
element: '#demo-theme',
|
67 |
popover: {
|
68 |
title: 'Style However You Want',
|