From 6928294983ed95369e299af92714b01800d9250d Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Mon, 10 Aug 2015 11:33:46 -0400 Subject: [PATCH] Added first draft typing for Shepherd Tour library. Not all overloads are fully typed out, but this should provide user with some helpful intellisense and a few compile checks. https://github.com/HubSpot/shepherd/ --- shepherd/shepherd.d.ts | 165 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 shepherd/shepherd.d.ts diff --git a/shepherd/shepherd.d.ts b/shepherd/shepherd.d.ts new file mode 100644 index 000000000..979c7bc81 --- /dev/null +++ b/shepherd/shepherd.d.ts @@ -0,0 +1,165 @@ +declare module shepherd { + + interface ShepherdStatic { + on(eventName, handler, context?): any; + off(eventName, handler?): any; + once(eventName, handler, context?): any; + + activeTour: IShepherdTour; + Tour: IShepherdTour; + } + + interface IShepherdTourOptions { + steps?: IShepherdTourStep[]; + defaults?: IShepherdTourStepOptions; + } + + interface IShepherdTour { + new (options?: IShepherdTourOptions): IShepherdTour + + /** + * Creates a new Step object with options, and returns the Tour object for convenient chaining when creating multiple steps. If you'd like you can also just pass an options hash which includes id as a key. If the options hash doesn't include an id, one will be generated. You can also pass an existing Step instance rather than options, but note that Shepherd does not support a Step being attached to multiple Tours. + */ + addStep(id: string, options: IShepherdTourStepOptions); + addStep(id: string, options: IShepherdTourStep); + + /** + * Return a step with a specific id + */ + getById(id: string): IShepherdTourStep; + + /** + * Advance to the next step, in the order they were added + */ + next(): void; + + /** + * Show the previous step, in the order they were added + */ + back(): void; + + /** + * Trigger cancel on the current step, hiding it without advancing + */ + cancel(): void; + + /** + * Hide the current step + */ + hide(): void; + + /** + * Show the step specified by id (if it's a string), or index (if it's a number) provided. Defaults to the first step. + */ + show(): void; + show(id: number): void; + show(id: string): void; + + /** + * Show the first step and begin the tour + */ + start(): void; + + /** + * Returns the currently shown step + */ + getCurrentStep(): IShepherdTourStep; + + /** + * Bind an event + */ + on(eventName, handler, context?): any; + + /** + * Unbind an event + */ + off(eventName, handler?): any; + + /** + * Bind just the next instance of an event + */ + once(eventName, handler, context?): any; + } + + interface IShepherdTourStep { + /** + * Show this step + */ + show(): void; + + /** + * Hide this step + */ + hide(): void; + + /** + * Hide this step and trigger the cancel event + */ + cancel(): void; + + /** + * Hide this step and trigger the complete event + */ + complete(): void; + + /** + * Scroll to this step's element + */ + scrollTo(): void; + + /** + * Returns true if the step is currently shown + */ + isOpen(): boolean; + + /** + * Remove the element + */ + destroy(): void; + + /** + * Bind an event + */ + on(eventName, handler, context?): any; + + /** + * Unbind an event + */ + off(eventName, handler?): any; + + /** + * Bind just the next instance of an event + */ + once(eventName, handler, context?): any; + } + + interface IShepherdTourStepOptions { + text?: any; + title?: string; + attachTo?: any; + beforeShowPromise?: any; + classes?: any; + buttons?: IShepherdTourButton[]; + advanceOn?: any; + showCancelLink?: boolean; + scrollTo?: boolean; + when?: any; + + // TODO: Tie this in with the tether.d.ts + tetherOptions?: any; + } + + interface IShepherdTourButton { + text: string; + classes: string[]; + action?: any; + events?: any; + } + + interface IShepherdTourAttachProperties { + element: string; + on: string; + } +} + +declare var Shepherd: shepherd.ShepherdStatic; \ No newline at end of file