|
--- |
|
title: "Migrate to 1.x" |
|
groupTitle: "Introduction" |
|
sort: 6 |
|
--- |
|
|
|
Drivers 1.x is a major release that introduces a new API and a new architecture. This page will help you migrate your code from 0.x to 1.x. |
|
|
|
> Change in how you import the library |
|
```diff |
|
- import Driver from 'driver.js'; |
|
- import 'driver.js/dist/driver.min.css'; |
|
+ import { driver } from 'driver.js'; |
|
+ import "driver.js/dist/driver.css"; |
|
``` |
|
|
|
> Change in how you initialize the library |
|
```diff |
|
- const driverObj = new Driver(config); |
|
- driverObj.setSteps(steps); |
|
|
|
+ |
|
+ const driverObj = driver({ |
|
+ ...config, |
|
+ steps |
|
+ }); |
|
``` |
|
|
|
> Changes in configuration |
|
|
|
```diff |
|
const config = { |
|
- overlayClickNext: false, |
|
- closeBtnText: 'Close', |
|
- scrollIntoViewOptions: {}, |
|
- opacity: 0.75, |
|
+ overlayOpacity: 0.75, |
|
- className: 'scoped-class', |
|
+ popoverClass: 'scoped-class', |
|
- padding: 10, |
|
+ stagePadding: 10, |
|
- showButtons: false, |
|
+ showButtons: ['next', 'prev', 'close'], |
|
- keyboardControl: true, |
|
+ allowKeyboardControl: true, |
|
- onHighlightStarted: (Element) {}, |
|
+ onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
- onHighlighted: (Element) {}, |
|
+ onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
- onDeselected: (Element) {}, |
|
+ onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
|
|
- onReset: (Element) {}, |
|
+ onDestroyStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
+ onDestroyed?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
+ onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
|
|
- onNext: (Element) => {}, |
|
- onPrevious: (Element) => {}, |
|
+ |
|
+ |
|
+ onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
+ onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
|
|
+ |
|
+ overlayColor?: string; |
|
+ stageRadius?: number; |
|
+ popoverOffset?: number; |
|
+ disableButtons?: ["next", "prev", "close"]; |
|
+ showProgress?: boolean; |
|
+ progressText?: string; |
|
+ onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State }) => void; |
|
} |
|
``` |
|
|
|
> Changes in step and popover definition |
|
|
|
```diff |
|
const stepDefinition = { |
|
popover: { |
|
- closeBtnText: 'Close', |
|
- element: '.some-element', |
|
+ element: '.some-element', |
|
- className: 'popover-class', |
|
+ popoverClass: string; |
|
- showButtons: false, |
|
+ showButtons: ["next", "previous", "close"]; |
|
- title: ''; |
|
+ title: ''; |
|
- description: ''; |
|
+ description: ''; |
|
|
|
- |
|
- |
|
- |
|
- position: 'left', |
|
+ |
|
+ side?: "top" | "right" | "bottom" | "left"; |
|
+ align?: "start" | "center" | "end"; |
|
|
|
+ // New options |
|
+ showProgress?: boolean; |
|
+ progressText?: string; |
|
+ onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State }) => void; |
|
+ onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void |
|
+ onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void |
|
+ onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void |
|
} |
|
|
|
+ |
|
+ onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
+ onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
+ onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void; |
|
}; |
|
``` |
|
|
|
> Changes in API methods. |
|
|
|
```diff |
|
- driverObj.preventMove(); |
|
- activeElement.getCalculatedPosition(); |
|
- activeElement.hidePopover(); |
|
- activeElement.showPopover(); |
|
- activeElement.getNode(); |
|
|
|
- const isActivated = driverObj.isActivated; |
|
+ const isActivated = driverObj.isActive(); |
|
|
|
- driverObj.start(stepNumber = 0); |
|
+ driverObj.drive(stepNumber = 0); |
|
|
|
- driverObj.highlight(string|stepDefinition); |
|
+ driverObj.highlight(stepDefinition) |
|
|
|
- driverObj.reset(); |
|
+ driverObj.destroy(); |
|
|
|
- driverObj.hasHighlightedElement(); |
|
+ typeof driverObj.getActiveElement() !== 'undefined'; |
|
|
|
- driverObj.getHighlightedElement(); |
|
+ driverObj.getActiveElement(); |
|
|
|
- driverObj.getLastHighlightedElement(); |
|
+ driverObj.getPreviousElement(); |
|
|
|
+ // New options added |
|
+ driverObj.moveTo(stepIndex) |
|
+ driverObj.getActiveStep(); // returns the configured step definition |
|
+ driverObj.getPreviousStep(); // returns the previous step definition |
|
+ driverObj.isLastStep(); |
|
+ driverObj.isFirstStep(); |
|
+ driverObj.getState(); |
|
+ driverObj.getConfig(); |
|
+ driverObj.setConfig(config); |
|
+ driverObj.refresh(); |
|
``` |
|
|
|
Please make sure to visit the [documentation](https://driverjs.com/docs/configuration) for more details. |