Skip to content

Commit

Permalink
Fix some TypeScript issues (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner authored Aug 2, 2019
1 parent 324ff20 commit 9466a97
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 118 deletions.
20 changes: 12 additions & 8 deletions src/types/shepherd.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Tour from './tour';
import Evented from './evented';
import Step from './step';

declare abstract class Shepherd extends Evented {
static Tour: { new(options?: Tour.TourOptions): Tour };
static Step: { new(tour: Tour, options: Step.StepOptions): Step };
static Evented: { new(): Evented };
import _Evented from './evented';
import _Step from './step';
import _Tour from './tour';

declare class Shepherd extends _Evented {
activeTour?: _Tour;
}

declare namespace Shepherd {
export import Step = _Step;
export import Tour = _Tour;
}

export default Shepherd;

153 changes: 79 additions & 74 deletions src/types/step.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,78 @@
import Tour from './tour';
import Evented from './evented';

/**
* Class representing steps to be added to a tour
* @extends {Evented}
*/
declare class Step extends Evented {
/**
* Create a step
* @param tour The tour for the step
* @param options The options for the step
* @return The newly created Step instance
*/
constructor(tour: Tour, options: Step.StepOptions);//TODO superheri Note: Return on constructor is not possible in typescript. Could this be possible to make this the same for the constructor of the Step class?

/**
* Returns the tour for the step
* @return The tour instance
*/
getTour(): Tour;

/**
* Cancel the tour
* Triggers the `cancel` event
*/
cancel(): void;

/**
* Complete the tour
* Triggers the `complete` event
*/
complete(): void;

/**
* Remove the step, delete the step's element, and destroy the tippy instance for the step
* Triggers `destroy` event
*/
destroy(): void;

/**
* Hide the step and destroy the tippy instance
*/
hide(): void;

/**
* Check if the step is open and visible
* @return True if the step is open and visible
*/
isOpen(): boolean;

/**
* Create the element and set up the tippy instance
*/
setupElements(): void;

/**
* If a custom scrollToHandler is defined, call that, otherwise do the generic
* scrollIntoView call.
*/
scrollTo(): void;

/**
* Sets the options for the step, maps `when` to events, sets up buttons
* @param options The options for the step default is `{}`
*/
setOptions(options?: Step.StepOptions): void;

/**
* Wraps `_show` and ensures `beforeShowPromise` resolves before calling show
* @return Promise
*/
show(): Promise<void> | void;
}

declare namespace Step {
/**
* The options for the step
Expand Down Expand Up @@ -47,6 +119,11 @@ declare namespace Step {
*/
highlightClass?: string;

/**
* The string to use as the `id` for the step.
*/
id?: string;

/**
* Extra [options to pass to tippy.js]{@link https://atomiks.github.io/tippyjs/#all-options}
*/
Expand Down Expand Up @@ -137,15 +214,15 @@ declare namespace Step {
* }
* ```
*/
events?: StepOptoonsButtonEvent;
events?: StepOptionsButtonEvent;

/**
* The HTML text of the button
*/
text?: string;
}

interface StepOptoonsButtonEvent {
interface StepOptionsButtonEvent {
[key: string]: (() => void);
}

Expand All @@ -154,76 +231,4 @@ declare namespace Step {
}
}

/**
* Class representing steps to be added to a tour
* @extends {Evented}
*/
declare class Step extends Evented {
/**
* Create a step
* @param tour The tour for the step
* @param options The options for the step
* @return The newly created Step instance
*/
constructor(tour: Tour, options: Step.StepOptions);//TODO superheri Note: Return on constructor is not possible in typescript. Could this be possible to make this the same for the constructor of the Step class?

/**
* Returns the tour for the step
* @return The tour instance
*/
getTour(): Tour;

/**
* Cancel the tour
* Triggers the `cancel` event
*/
cancel(): void;

/**
* Complete the tour
* Triggers the `complete` event
*/
complete(): void;

/**
* Remove the step, delete the step's element, and destroy the tippy instance for the step
* Triggers `destroy` event
*/
destroy(): void;

/**
* Hide the step and destroy the tippy instance
*/
hide(): void;

/**
* Check if the step is open and visible
* @return True if the step is open and visible
*/
isOpen(): boolean;

/**
* Create the element and set up the tippy instance
*/
setupElements(): void;

/**
* If a custom scrollToHandler is defined, call that, otherwise do the generic
* scrollIntoView call.
*/
scrollTo(): void;

/**
* Sets the options for the step, maps `when` to events, sets up buttons
* @param options The options for the step default is `{}`
*/
setOptions(options?: Step.StepOptions): void;

/**
* Wraps `_show` and ensures `beforeShowPromise` resolves before calling show
* @return Promise
*/
show(): Promise<void> | void;
}

export default Step;
72 changes: 36 additions & 36 deletions src/types/tour.d.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
import Evented from './evented';
import Step from './step';

declare namespace Tour {
interface TourOptions {
/**
* If true, will issue a `window.confirm` before cancelling
*/
confirmCancel?: boolean;
/**
* The message to display in the confirm dialog
*/
confirmCancelMessage?: string;
/**
* Default options for Steps created through `addStep`
*/
defaultStepOptions?: Step.StepOptions;

/**
* An array of Step instances to initialize the tour with
*/
steps?: Step[];

/**
* An optional "name" for the tour. This will be appended to the the tour's
* dynamically generated `id` property -- which is also set on the `body` element as the `data-shepherd-active-tour` attribute
* whenever the tour becomes active.
*/
tourName?: string;

/**
* Whether or not steps should be placed above a darkened
* modal overlay. If true, the overlay will create an opening around the target element so that it
* can remain interactive
*/
useModalOverlay?: string | boolean;
}
}

/**
* Class representing the site tour
* @extends {Evented}
Expand Down Expand Up @@ -135,4 +99,40 @@ declare class Tour extends Evented {
start(): void;
}

declare namespace Tour {
interface TourOptions {
/**
* If true, will issue a `window.confirm` before cancelling
*/
confirmCancel?: boolean;
/**
* The message to display in the confirm dialog
*/
confirmCancelMessage?: string;
/**
* Default options for Steps created through `addStep`
*/
defaultStepOptions?: Step.StepOptions;

/**
* An array of Step instances to initialize the tour with
*/
steps?: Step[];

/**
* An optional "name" for the tour. This will be appended to the the tour's
* dynamically generated `id` property -- which is also set on the `body` element as the `data-shepherd-active-tour` attribute
* whenever the tour becomes active.
*/
tourName?: string;

/**
* Whether or not steps should be placed above a darkened
* modal overlay. If true, the overlay will create an opening around the target element so that it
* can remain interactive
*/
useModalOverlay?: string | boolean;
}
}

export default Tour;

0 comments on commit 9466a97

Please sign in to comment.