Add popover position example
Browse files- docs/src/components/CodeSample.tsx +8 -6
- docs/src/content/guides/animated-tour.mdx +1 -1
- docs/src/content/guides/async-tour.mdx +1 -1
- docs/src/content/guides/basic-usage.mdx +1 -1
- docs/src/content/guides/confirm-on-exit.mdx +1 -1
- docs/src/content/guides/popover-position.mdx +211 -0
- docs/src/content/guides/static-tour.mdx +1 -1
docs/src/components/CodeSample.tsx
CHANGED
@@ -4,7 +4,7 @@ import "driver.js/dist/driver.css";
|
|
4 |
import { useState } from "react";
|
5 |
|
6 |
type CodeSampleProps = {
|
7 |
-
heading
|
8 |
|
9 |
config?: Config;
|
10 |
highlight?: DriveStep;
|
@@ -12,7 +12,8 @@ type CodeSampleProps = {
|
|
12 |
|
13 |
id?: string;
|
14 |
className?: string;
|
15 |
-
children
|
|
|
16 |
};
|
17 |
|
18 |
function removeDummyElement() {
|
@@ -41,7 +42,7 @@ function mountDummyElement() {
|
|
41 |
|
42 |
export function CodeSample(props: CodeSampleProps) {
|
43 |
const [driverObj, setDriverObj] = useState<any>(null);
|
44 |
-
const { heading, id, children, className, config, highlight, tour } = props;
|
45 |
|
46 |
function onClick() {
|
47 |
if (highlight) {
|
@@ -97,10 +98,11 @@ export function CodeSample(props: CodeSampleProps) {
|
|
97 |
|
98 |
return (
|
99 |
<div id={id} className={className}>
|
100 |
-
<p className="text-lg -mt-0 font-medium text-black -mb-3 rounded-md">{heading}</p>
|
101 |
-
<div className="-mb-4">{children}</div>
|
|
|
102 |
<button onClick={onClick} className="w-full rounded-md bg-black p-2 text-white">
|
103 |
-
|
104 |
</button>
|
105 |
</div>
|
106 |
);
|
|
|
4 |
import { useState } from "react";
|
5 |
|
6 |
type CodeSampleProps = {
|
7 |
+
heading?: string;
|
8 |
|
9 |
config?: Config;
|
10 |
highlight?: DriveStep;
|
|
|
12 |
|
13 |
id?: string;
|
14 |
className?: string;
|
15 |
+
children?: any;
|
16 |
+
buttonText?: string;
|
17 |
};
|
18 |
|
19 |
function removeDummyElement() {
|
|
|
42 |
|
43 |
export function CodeSample(props: CodeSampleProps) {
|
44 |
const [driverObj, setDriverObj] = useState<any>(null);
|
45 |
+
const { heading, id, children, buttonText = "Show me an Example", className, config, highlight, tour } = props;
|
46 |
|
47 |
function onClick() {
|
48 |
if (highlight) {
|
|
|
98 |
|
99 |
return (
|
100 |
<div id={id} className={className}>
|
101 |
+
{heading && <p className="text-lg -mt-0 font-medium text-black -mb-3 rounded-md">{heading}</p>}
|
102 |
+
{children && <div className="-mb-4">{children}</div>}
|
103 |
+
{!children && <div className="mb-1"></div>}
|
104 |
<button onClick={onClick} className="w-full rounded-md bg-black p-2 text-white">
|
105 |
+
{buttonText}
|
106 |
</button>
|
107 |
</div>
|
108 |
);
|
docs/src/content/guides/animated-tour.mdx
CHANGED
@@ -45,6 +45,6 @@ The following example shows how to create a simple tour with a few steps. Click
|
|
45 |
]
|
46 |
});
|
47 |
|
48 |
-
|
49 |
```
|
50 |
</CodeSample>
|
|
|
45 |
]
|
46 |
});
|
47 |
|
48 |
+
driverObj.drive();
|
49 |
```
|
50 |
</CodeSample>
|
docs/src/content/guides/async-tour.mdx
CHANGED
@@ -75,7 +75,7 @@ You can also have async steps in your tour. This is useful when you want to load
|
|
75 |
|
76 |
});
|
77 |
|
78 |
-
|
79 |
|
80 |
```
|
81 |
</CodeSample>
|
|
|
75 |
|
76 |
});
|
77 |
|
78 |
+
driverObj.drive();
|
79 |
|
80 |
```
|
81 |
</CodeSample>
|
docs/src/content/guides/basic-usage.mdx
CHANGED
@@ -39,7 +39,7 @@ const driverObj = driver({
|
|
39 |
]
|
40 |
});
|
41 |
|
42 |
-
|
43 |
```
|
44 |
</CodeSample>
|
45 |
|
|
|
39 |
]
|
40 |
});
|
41 |
|
42 |
+
driverObj.drive();
|
43 |
```
|
44 |
</CodeSample>
|
45 |
|
docs/src/content/guides/confirm-on-exit.mdx
CHANGED
@@ -43,7 +43,7 @@ You can use the `onDestroyStarted` hook to add a confirmation dialog or some oth
|
|
43 |
},
|
44 |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title: "Popover Position"
|
3 |
+
groupTitle: "Examples"
|
4 |
+
sort: 6
|
5 |
+
---
|
6 |
+
|
7 |
+
import { CodeSample } from "../../components/CodeSample.tsx";
|
8 |
+
|
9 |
+
You can control the popover position using the `side` and `align` options. The `side` option controls the side of the element where the popover will be shown and the `align` option controls the alignment of the popover with the element.
|
10 |
+
|
11 |
+
> **Note:** Popover is intelligent enough to adjust itself to fit in the viewport. So, if you set `side` to `left` and `align` to `start`, but the popover doesn't fit in the viewport, it will automatically adjust itself to fit in the viewport. Consider highlighting and scrolling the browser to the element below to see this in action.
|
12 |
+
|
13 |
+
```js
|
14 |
+
import { driver } from "driver.js";
|
15 |
+
import "driver.js/dist/driver.css";
|
16 |
+
|
17 |
+
const driverObj = driver();
|
18 |
+
driverObj.highlight({
|
19 |
+
element: '#left-start',
|
20 |
+
popover: {
|
21 |
+
title: 'Animated Tour Example',
|
22 |
+
description: 'Here is the code example showing animated tour. Let\'s walk you through it.',
|
23 |
+
side: "left",
|
24 |
+
align: 'start'
|
25 |
+
}
|
26 |
+
});
|
27 |
+
```
|
28 |
+
|
29 |
+
<div id="sample-box" className='p-12 bg-gray-200 rounded-md flex items-center justify-center'>
|
30 |
+
<p>Use the buttons below to show the popover.</p>
|
31 |
+
</div>
|
32 |
+
|
33 |
+
<CodeSample
|
34 |
+
buttonText={"Left Start"}
|
35 |
+
highlight={{
|
36 |
+
element: '#sample-box',
|
37 |
+
popover: {
|
38 |
+
title: 'Left Start Example',
|
39 |
+
description: 'We have side set to <mark>left</mark> and align set to <mark>start</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
40 |
+
side: "left",
|
41 |
+
align: 'start'
|
42 |
+
}
|
43 |
+
}}
|
44 |
+
id={"left-start"}
|
45 |
+
client:load
|
46 |
+
/>
|
47 |
+
|
48 |
+
<CodeSample
|
49 |
+
buttonText={"Left Center"}
|
50 |
+
highlight={{
|
51 |
+
element: '#sample-box',
|
52 |
+
popover: {
|
53 |
+
title: 'Left Center Example',
|
54 |
+
description: 'We have side set to <mark>left</mark> and align set to <mark>center</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
55 |
+
side: "left",
|
56 |
+
align: 'center'
|
57 |
+
}
|
58 |
+
}}
|
59 |
+
id={"left-start"}
|
60 |
+
client:load
|
61 |
+
/>
|
62 |
+
|
63 |
+
<CodeSample
|
64 |
+
buttonText={"Left End"}
|
65 |
+
highlight={{
|
66 |
+
element: '#sample-box',
|
67 |
+
popover: {
|
68 |
+
title: 'Left End Example',
|
69 |
+
description: 'We have side set to <mark>left</mark> and align set to <mark>end</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
70 |
+
side: "left",
|
71 |
+
align: 'end'
|
72 |
+
}
|
73 |
+
}}
|
74 |
+
id={"left-start"}
|
75 |
+
client:load
|
76 |
+
/>
|
77 |
+
|
78 |
+
<CodeSample
|
79 |
+
buttonText={"Top Start"}
|
80 |
+
highlight={{
|
81 |
+
element: '#sample-box',
|
82 |
+
popover: {
|
83 |
+
title: 'Top Start Example',
|
84 |
+
description: 'We have side set to <mark>top</mark> and align set to <mark>start</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
85 |
+
side: "top",
|
86 |
+
align: 'start'
|
87 |
+
}
|
88 |
+
}}
|
89 |
+
id={"top-start"}
|
90 |
+
client:load
|
91 |
+
/>
|
92 |
+
|
93 |
+
<CodeSample
|
94 |
+
buttonText={"Top Center"}
|
95 |
+
highlight={{
|
96 |
+
element: '#sample-box',
|
97 |
+
popover: {
|
98 |
+
title: 'Top Center Example',
|
99 |
+
description: 'We have side set to <mark>top</mark> and align set to <mark>center</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
100 |
+
side: "top",
|
101 |
+
align: 'center'
|
102 |
+
}
|
103 |
+
}}
|
104 |
+
id={"top-start"}
|
105 |
+
client:load
|
106 |
+
/>
|
107 |
+
|
108 |
+
<CodeSample
|
109 |
+
buttonText={"Top End"}
|
110 |
+
highlight={{
|
111 |
+
element: '#sample-box',
|
112 |
+
popover: {
|
113 |
+
title: 'Top End Example',
|
114 |
+
description: 'We have side set to <mark>top</mark> and align set to <mark>end</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
115 |
+
side: "top",
|
116 |
+
align: 'end'
|
117 |
+
}
|
118 |
+
}}
|
119 |
+
id={"top-start"}
|
120 |
+
client:load
|
121 |
+
/>
|
122 |
+
|
123 |
+
<CodeSample
|
124 |
+
buttonText={"Right Start"}
|
125 |
+
highlight={{
|
126 |
+
element: '#sample-box',
|
127 |
+
popover: {
|
128 |
+
title: 'Right Start Example',
|
129 |
+
description: 'We have side set to <mark>right</mark> and align set to <mark>start</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
130 |
+
side: "right",
|
131 |
+
align: 'start'
|
132 |
+
}
|
133 |
+
}}
|
134 |
+
id={"right-start"}
|
135 |
+
client:load
|
136 |
+
/>
|
137 |
+
|
138 |
+
<CodeSample
|
139 |
+
buttonText={"Right Center"}
|
140 |
+
highlight={{
|
141 |
+
element: '#sample-box',
|
142 |
+
popover: {
|
143 |
+
title: 'Right Center Example',
|
144 |
+
description: 'We have side set to <mark>right</mark> and align set to <mark>center</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
145 |
+
side: "right",
|
146 |
+
align: 'center'
|
147 |
+
}
|
148 |
+
}}
|
149 |
+
id={"right-start"}
|
150 |
+
client:load
|
151 |
+
/>
|
152 |
+
|
153 |
+
<CodeSample
|
154 |
+
buttonText={"Right End"}
|
155 |
+
highlight={{
|
156 |
+
element: '#sample-box',
|
157 |
+
popover: {
|
158 |
+
title: 'Right End Example',
|
159 |
+
description: 'We have side set to <mark>right</mark> and align set to <mark>end</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
160 |
+
side: "right",
|
161 |
+
align: 'end'
|
162 |
+
}
|
163 |
+
}}
|
164 |
+
id={"right-start"}
|
165 |
+
client:load
|
166 |
+
/>
|
167 |
+
|
168 |
+
<CodeSample
|
169 |
+
buttonText={"Bottom Start"}
|
170 |
+
highlight={{
|
171 |
+
element: '#sample-box',
|
172 |
+
popover: {
|
173 |
+
title: 'Bottom Start Example',
|
174 |
+
description: 'We have side set to <mark>bottom</mark> and align set to <mark>start</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
175 |
+
side: "bottom",
|
176 |
+
align: 'start'
|
177 |
+
}
|
178 |
+
}}
|
179 |
+
id={"bottom-start"}
|
180 |
+
client:load
|
181 |
+
/>
|
182 |
+
|
183 |
+
<CodeSample
|
184 |
+
buttonText={"Bottom Center"}
|
185 |
+
highlight={{
|
186 |
+
element: '#sample-box',
|
187 |
+
popover: {
|
188 |
+
title: 'Bottom Center Example',
|
189 |
+
description: 'We have side set to <mark>bottom</mark> and align set to <mark>center</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
190 |
+
side: "bottom",
|
191 |
+
align: 'center'
|
192 |
+
}
|
193 |
+
}}
|
194 |
+
id={"bottom-start"}
|
195 |
+
client:load
|
196 |
+
/>
|
197 |
+
|
198 |
+
<CodeSample
|
199 |
+
buttonText={"Bottom End"}
|
200 |
+
highlight={{
|
201 |
+
element: '#sample-box',
|
202 |
+
popover: {
|
203 |
+
title: 'Bottom End Example',
|
204 |
+
description: 'We have side set to <mark>bottom</mark> and align set to <mark>end</mark>. PS, we can use HTML in the title and descriptions of popover.',
|
205 |
+
side: "bottom",
|
206 |
+
align: 'end'
|
207 |
+
}
|
208 |
+
}}
|
209 |
+
id={"right-start"}
|
210 |
+
client:load
|
211 |
+
/>
|
docs/src/content/guides/static-tour.mdx
CHANGED
@@ -47,6 +47,6 @@ You can simply set `animate` option to `false` to make the tour static. This wil
|
|
47 |
]
|
48 |
});
|
49 |
|
50 |
-
|
51 |
```
|
52 |
</CodeSample>
|
|
|
47 |
]
|
48 |
});
|
49 |
|
50 |
+
driverObj.drive();
|
51 |
```
|
52 |
</CodeSample>
|