kamrify commited on
Commit
42aa4be
·
1 Parent(s): 4e75205

Rename onPopoverRendered to onPopoverRender

Browse files
docs/src/content/guides/buttons.mdx CHANGED
@@ -235,7 +235,7 @@ You can use the `onNextClick`, `onPreviousClick` and `onCloseClick` callbacks to
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
@@ -253,7 +253,7 @@ You can add custom buttons using `onPopoverRendered` callback. This callback is
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
  {
@@ -286,7 +286,7 @@ You can add custom buttons using `onPopoverRendered` callback. This callback is
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);
 
235
 
236
  ## Custom Buttons
237
 
238
+ You can add custom buttons using `onPopoverRender` callback. This callback is called before the 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
 
253
  align: 'start',
254
  side: 'left',
255
  title: 'More Control with Hooks',
256
+ description: 'You can use onPopoverRender 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
  {
 
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
+ onPopoverRender: (popover, { config, state }) => {
290
  const firstButton = document.createElement("button");
291
  firstButton.innerText = "Go to First";
292
  popover.footerButtons.appendChild(firstButton);
docs/src/content/guides/configuration.mdx CHANGED
@@ -69,7 +69,7 @@ type Config = {
69
  // PopoverDOM is an object with references to
70
  // the popover DOM elements such as buttons
71
  // title, descriptions, body, container etc.
72
- onPopoverRendered?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
73
 
74
  // Hooks to run before and after highlighting
75
  // each step. Each hook receives the following
@@ -163,7 +163,7 @@ type Popover = {
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.
 
69
  // PopoverDOM is an object with references to
70
  // the popover DOM elements such as buttons
71
  // title, descriptions, body, container etc.
72
+ onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
73
 
74
  // Hooks to run before and after highlighting
75
  // each step. Each hook receives the following
 
163
  // Parameter is an object with references to
164
  // the popover DOM elements such as buttons
165
  // title, descriptions, body, etc.
166
+ onPopoverRender?: (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.
docs/src/content/guides/styling-popover.mdx CHANGED
@@ -8,7 +8,7 @@ import { CodeSample } from "../../components/CodeSample.tsx";
8
 
9
  You can either 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.
10
 
11
- Alternatively, if want to modify the Popover DOM, you can use the `onPopoverRendered` callback to get the popover DOM element and do whatever you want with it.
12
 
13
  We have added a few examples below but have a look at the [theming section](/docs/theming#styling-popover) for detailed guide including class names to target etc.
14
 
@@ -155,7 +155,7 @@ Here is the CSS used for the above example:
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
  {
@@ -188,7 +188,7 @@ Here is the CSS used for the above example:
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);
 
8
 
9
  You can either 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.
10
 
11
+ Alternatively, if want to modify the Popover DOM, you can use the `onPopoverRender` callback to get the popover DOM element and do whatever you want with it before popover is rendered.
12
 
13
  We have added a few examples below but have a look at the [theming section](/docs/theming#styling-popover) for detailed guide including class names to target etc.
14
 
 
155
  align: 'start',
156
  side: 'left',
157
  title: 'More Control with Hooks',
158
+ description: 'You can use onPopoverRender 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
  {
 
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
+ onPopoverRender: (popover, { config, state }) => {
192
  const firstButton = document.createElement("button");
193
  firstButton.innerText = "Go to First";
194
  popover.footerButtons.appendChild(firstButton);
docs/src/content/guides/theming.mdx CHANGED
@@ -57,7 +57,7 @@ Visit the [example page](/docs/styling-popover) for an example that modifies the
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
63
  type PopoverDOM = {
@@ -73,7 +73,7 @@ type PopoverDOM = {
73
  footerButtons: HTMLElement;
74
  };
75
 
76
- onPopoverRendered?: (popover: PopoverDOM) => void;
77
  ```
78
 
79
  ## Styling Page
 
57
 
58
  ## Modifying Popover DOM
59
 
60
+ Alternatively, you can also use the `onPopoverRender` 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
63
  type PopoverDOM = {
 
73
  footerButtons: HTMLElement;
74
  };
75
 
76
+ onPopoverRender?: (popover: PopoverDOM) => void;
77
  ```
78
 
79
  ## Styling Page
index.html CHANGED
@@ -452,10 +452,9 @@ npm install driver.js</pre
452
  steps: basicTourSteps,
453
  showProgress: true,
454
  progressText: "{{current}} of {{total}} done",
455
- onPopoverRendered: (popover) => {
456
  popover.title.innerHTML = `${driverObj.getActiveIndex()} ${driverObj.hasNextStep() ? 'Yes' : 'No'} ${driverObj.hasPreviousStep() ? 'Yes' : 'No'}`
457
  popover.description.innerHTML = `${driverObj.isFirstStep() ? 'Yes' : 'No'} ${driverObj.isLastStep() ? 'Yes' : 'No'}`
458
- driverObj.refresh();
459
  }
460
  });
461
 
@@ -662,7 +661,7 @@ npm install driver.js</pre
662
 
663
  document.getElementById("popover-hook").addEventListener("click", () => {
664
  const driverObj = driver({
665
- onPopoverRendered: popover => {
666
  popover.title.innerText = "Modified Parent";
667
  },
668
  });
@@ -673,7 +672,7 @@ npm install driver.js</pre
673
  description: "Body of the popover",
674
  side: "bottom",
675
  align: "start",
676
- onPopoverRendered: popover => {
677
  popover.title.innerText = "Modified";
678
  },
679
  },
@@ -694,7 +693,7 @@ npm install driver.js</pre
694
  description: "Body of the popover",
695
  side: "bottom",
696
  align: "start",
697
- onPopoverRendered: popover => {
698
  popover.title.innerText = "Modified";
699
  },
700
  },
@@ -777,7 +776,7 @@ npm install driver.js</pre
777
 
778
  document.getElementById("popover-hook-config").addEventListener("click", () => {
779
  const driverObj = driver({
780
- onPopoverRendered: popover => {
781
  const firstButton = document.createElement("button");
782
  firstButton.innerText = "First";
783
  popover.footerButtons.appendChild(firstButton);
 
452
  steps: basicTourSteps,
453
  showProgress: true,
454
  progressText: "{{current}} of {{total}} done",
455
+ onPopoverRender: (popover) => {
456
  popover.title.innerHTML = `${driverObj.getActiveIndex()} ${driverObj.hasNextStep() ? 'Yes' : 'No'} ${driverObj.hasPreviousStep() ? 'Yes' : 'No'}`
457
  popover.description.innerHTML = `${driverObj.isFirstStep() ? 'Yes' : 'No'} ${driverObj.isLastStep() ? 'Yes' : 'No'}`
 
458
  }
459
  });
460
 
 
661
 
662
  document.getElementById("popover-hook").addEventListener("click", () => {
663
  const driverObj = driver({
664
+ onPopoverRender: popover => {
665
  popover.title.innerText = "Modified Parent";
666
  },
667
  });
 
672
  description: "Body of the popover",
673
  side: "bottom",
674
  align: "start",
675
+ onPopoverRender: popover => {
676
  popover.title.innerText = "Modified";
677
  },
678
  },
 
693
  description: "Body of the popover",
694
  side: "bottom",
695
  align: "start",
696
+ onPopoverRender: popover => {
697
  popover.title.innerText = "Modified";
698
  },
699
  },
 
776
 
777
  document.getElementById("popover-hook-config").addEventListener("click", () => {
778
  const driverObj = driver({
779
+ onPopoverRender: popover => {
780
  const firstButton = document.createElement("button");
781
  firstButton.innerText = "First";
782
  popover.footerButtons.appendChild(firstButton);
package.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "driver.js",
3
  "private": false,
4
- "version": "1.0.2",
5
  "main": "./dist/driver.js.cjs",
6
  "module": "./dist/driver.js.mjs",
7
  "types": "./dist/driver.js.d.ts",
 
1
  {
2
  "name": "driver.js",
3
  "private": false,
4
+ "version": "1.0.3",
5
  "main": "./dist/driver.js.cjs",
6
  "module": "./dist/driver.js.mjs",
7
  "types": "./dist/driver.js.d.ts",
src/config.ts CHANGED
@@ -31,7 +31,7 @@ export type Config = {
31
  doneBtnText?: string;
32
 
33
  // Called after the popover is rendered
34
- onPopoverRendered?: (popover: PopoverDOM) => void;
35
 
36
  // State based callbacks, called upon state changes
37
  onHighlightStarted?: DriverHook;
 
31
  doneBtnText?: string;
32
 
33
  // Called after the popover is rendered
34
+ onPopoverRender?: (popover: PopoverDOM) => void;
35
 
36
  // State based callbacks, called upon state changes
37
  onHighlightStarted?: DriverHook;
src/popover.ts CHANGED
@@ -28,7 +28,7 @@ export type Popover = {
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;
@@ -203,16 +203,16 @@ export function renderPopover(element: Element, step: DriveStep) {
203
 
204
  setState("popover", popover);
205
 
206
- repositionPopover(element, step);
207
- bringInView(popoverWrapper);
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
 
218
  type PopoverDimensions = {
 
28
  prevBtnText?: string;
29
 
30
  // Called after the popover is rendered
31
+ onPopoverRender?: (popover: PopoverDOM, opts: { config: Config; state: State }) => void;
32
 
33
  // Button callbacks
34
  onNextClick?: DriverHook;
 
203
 
204
  setState("popover", popover);
205
 
206
+ const onPopoverRender = step.popover?.onPopoverRender || getConfig("onPopoverRender");
207
+ if (onPopoverRender) {
208
+ onPopoverRender(popover, {
 
 
 
209
  config: getConfig(),
210
  state: getState(),
211
  });
212
  }
213
+
214
+ repositionPopover(element, step);
215
+ bringInView(popoverWrapper);
216
  }
217
 
218
  type PopoverDimensions = {