Islam Attrash commited on
Commit
cfadc6c
·
1 Parent(s): 6eba7f5

[FEATURE] Adding Scoped classNames in Driver and Popover level (#138)

Browse files

This PR is related to adding scoped classNames into the driver-popover-item.
I temporary wrapped it in a React Component which handles this isolation in order to protect
from getting to the style css collision problem since the selectors are shared between all usages.

You can specifiy the className in the Driver instance options and at the popover options level. classNames of popover will
be merged with the general driver className if exist.

demo/index.html CHANGED
@@ -208,6 +208,7 @@ driver.defineSteps([
208
  {
209
  element: '#first-element-introduction',
210
  popover: {
 
211
  title: 'Title on Popover',
212
  description: 'Body of the popover',
213
  position: 'left'
@@ -273,6 +274,7 @@ driver.highlight({
273
  <h4>Driver Definition</h4>
274
  <p>Here are the options that Driver understands</p>
275
  <pre><code class="javascript">const driver = new Driver({
 
276
  animate: true, // Animate while changing highlighted element
277
  opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
278
  padding: 10, // Distance of element from around the edges
@@ -301,14 +303,15 @@ driver.highlight({
301
  <p>Here are the set of options that you can pass in each step i.e. an item in array of steps or the object that
302
  you pass to <code>highlight</code> method</p>
303
  <pre><code class="javascript">const stepDefinition = {
304
- element: '#some-item', // Query selector string or Node to be highlighted
305
- popover: { // There will be no popover if empty or not given
306
- title: 'Title', // Title on the popover
 
307
  description: 'Description', // Body of the popover
308
- showButtons: false, // Do not show control buttons in footer
309
- closeBtnText: 'Close', // Text on the close button for this step
310
- nextBtnText: 'Next', // Next button text for this step
311
- prevBtnText: 'Previous', // Previous button text for this step
312
  }
313
  };
314
  </code></pre>
 
208
  {
209
  element: '#first-element-introduction',
210
  popover: {
211
+ className: 'first-step-popover-class',
212
  title: 'Title on Popover',
213
  description: 'Body of the popover',
214
  position: 'left'
 
274
  <h4>Driver Definition</h4>
275
  <p>Here are the options that Driver understands</p>
276
  <pre><code class="javascript">const driver = new Driver({
277
+ className: 'scoped-class', // className to wrap driver.js popover
278
  animate: true, // Animate while changing highlighted element
279
  opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
280
  padding: 10, // Distance of element from around the edges
 
303
  <p>Here are the set of options that you can pass in each step i.e. an item in array of steps or the object that
304
  you pass to <code>highlight</code> method</p>
305
  <pre><code class="javascript">const stepDefinition = {
306
+ element: '#some-item', // Query selector string or Node to be highlighted
307
+ popover: { // There will be no popover if empty or not given
308
+ className: 'popover-class', // className to wrap this specific step popover in addition to the general className in Driver options
309
+ title: 'Title', // Title on the popover
310
  description: 'Description', // Body of the popover
311
+ showButtons: false, // Do not show control buttons in footer
312
+ closeBtnText: 'Close', // Text on the close button for this step
313
+ nextBtnText: 'Next', // Next button text for this step
314
+ prevBtnText: 'Previous', // Previous button text for this step
315
  }
316
  };
317
  </code></pre>
demo/scripts/demo.js CHANGED
@@ -6,6 +6,7 @@ document.addEventListener('DOMContentLoaded', function () {
6
  {
7
  element: document.getElementById('driver-demo-head'),
8
  popover: {
 
9
  title: 'Before we start',
10
  description: 'This is just one use-case, make sure to check out the rest of the docs below.',
11
  nextBtnText: 'Okay, Start!',
@@ -101,7 +102,8 @@ document.addEventListener('DOMContentLoaded', function () {
101
  animate: false,
102
  opacity: 0.8,
103
  padding: 5,
104
- showButtons: true
 
105
  });
106
 
107
  boringTourDriver.defineSteps(tourSteps);
 
6
  {
7
  element: document.getElementById('driver-demo-head'),
8
  popover: {
9
+ className: 'scoped-driver-popover',
10
  title: 'Before we start',
11
  description: 'This is just one use-case, make sure to check out the rest of the docs below.',
12
  nextBtnText: 'Okay, Start!',
 
102
  animate: false,
103
  opacity: 0.8,
104
  padding: 5,
105
+ showButtons: true,
106
+ className: 'boring-scope'
107
  });
108
 
109
  boringTourDriver.defineSteps(tourSteps);
readme.md CHANGED
@@ -146,6 +146,7 @@ driver.defineSteps([
146
  {
147
  element: '#first-element-introduction',
148
  popover: {
 
149
  title: 'Title on Popover',
150
  description: 'Body of the popover',
151
  position: 'left'
@@ -238,6 +239,7 @@ Here are the options that Driver understands:
238
 
239
  ```javascript
240
  const driver = new Driver({
 
241
  animate: true, // Whether to animate or not
242
  opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
243
  padding: 10, // Distance of element from around the edges
@@ -270,6 +272,7 @@ const stepDefinition = {
270
  element: '#some-item', // Query selector string or Node to be highlighted
271
  stageBackground: '#ffffff', // This will override the one set in driver
272
  popover: { // There will be no popover if empty or not given
 
273
  title: 'Title', // Title on the popover
274
  description: 'Description', // Body of the popover
275
  showButtons: false, // Do not show control buttons in footer
 
146
  {
147
  element: '#first-element-introduction',
148
  popover: {
149
+ className: 'first-step-popover-class',
150
  title: 'Title on Popover',
151
  description: 'Body of the popover',
152
  position: 'left'
 
239
 
240
  ```javascript
241
  const driver = new Driver({
242
+ className: 'scoped-class', // className to wrap driver.js popover
243
  animate: true, // Whether to animate or not
244
  opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
245
  padding: 10, // Distance of element from around the edges
 
272
  element: '#some-item', // Query selector string or Node to be highlighted
273
  stageBackground: '#ffffff', // This will override the one set in driver
274
  popover: { // There will be no popover if empty or not given
275
+ className: 'popover-class', // className to wrap this specific step popover in addition to the general className in Driver options
276
  title: 'Title', // Title on the popover
277
  description: 'Description', // Body of the popover
278
  showButtons: false, // Do not show control buttons in footer
src/common/constants.js CHANGED
@@ -32,8 +32,8 @@ export const CLASS_BTN_DISABLED = 'driver-disabled';
32
  export const ANIMATION_DURATION_MS = 400;
33
 
34
  // language=HTML
35
- export const POPOVER_HTML = `
36
- <div id="${ID_POPOVER}">
37
  <div class="${CLASS_POPOVER_TIP}"></div>
38
  <div class="${CLASS_POPOVER_TITLE}">Popover Title</div>
39
  <div class="${CLASS_POPOVER_DESCRIPTION}">Popover Description</div>
 
32
  export const ANIMATION_DURATION_MS = 400;
33
 
34
  // language=HTML
35
+ export const POPOVER_HTML = (className = '') => `
36
+ <div id="${ID_POPOVER} ${className}">
37
  <div class="${CLASS_POPOVER_TIP}"></div>
38
  <div class="${CLASS_POPOVER_TITLE}">Popover Title</div>
39
  <div class="${CLASS_POPOVER_DESCRIPTION}">Popover Description</div>
src/core/popover.js CHANGED
@@ -54,7 +54,7 @@ export default class Popover extends Element {
54
  attachNode() {
55
  let popover = this.document.getElementById(ID_POPOVER);
56
  if (!popover) {
57
- popover = createNodeFromString(POPOVER_HTML);
58
  document.body.appendChild(popover);
59
  }
60
 
 
54
  attachNode() {
55
  let popover = this.document.getElementById(ID_POPOVER);
56
  if (!popover) {
57
+ popover = createNodeFromString(POPOVER_HTML(this.options.className));
58
  document.body.appendChild(popover);
59
  }
60
 
src/index.js CHANGED
@@ -370,9 +370,15 @@ export default class Driver {
370
 
371
  let popover = null;
372
  if (elementOptions.popover && elementOptions.popover.title) {
 
 
 
 
 
373
  const popoverOptions = {
374
  ...this.options,
375
  ...elementOptions.popover,
 
376
  totalCount: allSteps.length,
377
  currentIndex: index,
378
  isFirst: index === 0,
 
370
 
371
  let popover = null;
372
  if (elementOptions.popover && elementOptions.popover.title) {
373
+ const mergedClassNames = [
374
+ this.options.className,
375
+ elementOptions.popover.className,
376
+ ].filter(c => c).join(' ');
377
+
378
  const popoverOptions = {
379
  ...this.options,
380
  ...elementOptions.popover,
381
+ className: mergedClassNames,
382
  totalCount: allSteps.length,
383
  currentIndex: index,
384
  isFirst: index === 0,