From dc2dbe4bf06f35701a4868037423884602d41fad Mon Sep 17 00:00:00 2001 From: Alexandre Teixeira Date: Thu, 22 Jun 2017 14:33:20 +0200 Subject: [PATCH 1/2] New typing for askmethat-rating plugin --- .../askmethat-rating-tests.ts | 15 ++ types/askmethat-rating/index.d.ts | 131 ++++++++++++++++++ types/askmethat-rating/tsconfig.json | 23 +++ types/askmethat-rating/tslint.json | 1 + 4 files changed, 170 insertions(+) create mode 100644 types/askmethat-rating/askmethat-rating-tests.ts create mode 100644 types/askmethat-rating/index.d.ts create mode 100644 types/askmethat-rating/tsconfig.json create mode 100644 types/askmethat-rating/tslint.json diff --git a/types/askmethat-rating/askmethat-rating-tests.ts b/types/askmethat-rating/askmethat-rating-tests.ts new file mode 100644 index 0000000000..36ed72c1ee --- /dev/null +++ b/types/askmethat-rating/askmethat-rating-tests.ts @@ -0,0 +1,15 @@ +import { AskmethatRating, AskmethatRatingSteps } from "askmethat-rating"; + +var options = { + backgroundColor: "#e5e500", + hoverColor: "#ffff66", + fontClass: "fa fa-star", + minRating: 1, + maxRating: 5, + readonly: false, + step: AskmethatRatingSteps["OnePerOneStep"], + inputName: "AskmethatRating" +}; + +var div = document.createElement("div"); +var amcRating = new AskmethatRating(div, 2, options); \ No newline at end of file diff --git a/types/askmethat-rating/index.d.ts b/types/askmethat-rating/index.d.ts new file mode 100644 index 0000000000..b52f16febe --- /dev/null +++ b/types/askmethat-rating/index.d.ts @@ -0,0 +1,131 @@ +// Type definitions for askmethat-rating 0.3 +// Project: https://alexteixeira.github.io/Askmethat-Rating/ +// Definitions by: Alexandre Teixeira +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export declare enum AskmethatRatingSteps { + /** + * Step 0.1 per 0.1 + */ + DecimalStep = 0, + /** + * Step 0.5 per 0.5 + */ + HalfStep = 1, + /** + * Step 1 per 1 + */ + OnePerOneStep = 2, +} +export interface AskmethatRatingOptions { + hoverColor?: string; + /** + * Color when the rating is not hovered + */ + backgroundColor?: string; + /** + * Mininmum rating that the user can set + */ + minRating?: number; + /** + * Maximum rating that the plugin display + */ + maxRating?: number; + /** + * Class to display as rating (FontAwesome or Rating for exemple) + */ + fontClass: string; + /** + * Set the rating to readonly + */ + readonly: boolean; + /** + * The stepping for the rating + */ + step: AskmethatRatingSteps; + /** + * Input name (Default is AskmethatRating) + */ + inputName: string; +} +export declare class AskmethatRating { + private parentElement; + private pValue; + private styleSheet; + private changeEvent; + private ratingClick; + private mouseMove; + /** + * @function get the current value for the rating + */ + /** + * @function set a new value for the rating + * + * @param _value this is the new value you want to set to the rating + * @returns the current number + */ + value: number; + /** + * Default option base on @type IAskmethatRatingOptions + */ + private _defaultOptions; + /** + * @function get the default option for the rating + * + * @return options based on @type AskmethatRatingOptions + */ + readonly defaultOptions: any; + /** + * constructor with div element, default rating value & default options + * + * @param element This is the html container for the rating elements + * @param defaultValue Default value set when the plugin render the rating + * @param options Default option base on AskmethatRatingOptions type + */ + constructor(element: HTMLDivElement, defaultValue?: number, options?: any); + /** + * render a new rating, by default value is the minRating + * + * @param value this is the default value set when the plugin is rendered, by default IAskmethatRatingOptions.minRating + */ + render(value?: number): void; + /** + * @function when a rating is clicked + * @param {type} event : Event {event object} + */ + private onRatingClick(event?); + /** + * @function Calculate the value according to the step provided in options + * @param {Number} value:number the current value + * @return {Number} the new value according to step + */ + protected getValueAccordingToStep(value: number): number; + /** + * @function mouse event enter in rating + * @param {type} event?: Event {event} + */ + private onMouseMove(event?); + /** + * @function mouse out event in rating + * @param {type} event?: Event {event} + */ + private onMouseLeave(event?); + /** + * @function set or unset the active class and color + * @param {HTMLSpanElement} current : current span element + * @param {number} current : value needed for the if + */ + protected setOrUnsetActive(value: number): void; + /** + * Check if disabled attribute is added or removed from the input + * Update readonly status if needed for the rating + */ + private mutationEvent(); + /** + * @function static method to retrieve with identifier the value + * @param {string} identifier: string container identifier + * @return {number} current rating + */ + static value(identifier: string): number; +} diff --git a/types/askmethat-rating/tsconfig.json b/types/askmethat-rating/tsconfig.json new file mode 100644 index 0000000000..fd5ef4ae50 --- /dev/null +++ b/types/askmethat-rating/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "askmethat-rating-tests.ts" + ] +} diff --git a/types/askmethat-rating/tslint.json b/types/askmethat-rating/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/askmethat-rating/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From e1d40e693c67b00f826d558b4e7ffa97db2d2b09 Mon Sep 17 00:00:00 2001 From: Alexandre Teixeira Date: Thu, 22 Jun 2017 16:46:57 +0200 Subject: [PATCH 2/2] Correcting TSLINT issues --- .../askmethat-rating-tests.ts | 6 +-- types/askmethat-rating/index.d.ts | 54 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/types/askmethat-rating/askmethat-rating-tests.ts b/types/askmethat-rating/askmethat-rating-tests.ts index 36ed72c1ee..2f17ad0b62 100644 --- a/types/askmethat-rating/askmethat-rating-tests.ts +++ b/types/askmethat-rating/askmethat-rating-tests.ts @@ -1,6 +1,6 @@ import { AskmethatRating, AskmethatRatingSteps } from "askmethat-rating"; -var options = { +let options = { backgroundColor: "#e5e500", hoverColor: "#ffff66", fontClass: "fa fa-star", @@ -11,5 +11,5 @@ var options = { inputName: "AskmethatRating" }; -var div = document.createElement("div"); -var amcRating = new AskmethatRating(div, 2, options); \ No newline at end of file +let div = document.createElement("div"); +let amcRating = new AskmethatRating(div, 2 , options); diff --git a/types/askmethat-rating/index.d.ts b/types/askmethat-rating/index.d.ts index b52f16febe..ff31f81747 100644 --- a/types/askmethat-rating/index.d.ts +++ b/types/askmethat-rating/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -export declare enum AskmethatRatingSteps { +export enum AskmethatRatingSteps { /** * Step 0.1 per 0.1 */ @@ -25,8 +25,8 @@ export interface AskmethatRatingOptions { */ backgroundColor?: string; /** - * Mininmum rating that the user can set - */ + * Mininmum rating that the user can set + */ minRating?: number; /** * Maximum rating that the plugin display @@ -41,15 +41,15 @@ export interface AskmethatRatingOptions { */ readonly: boolean; /** - * The stepping for the rating - */ + * The stepping for the rating + */ step: AskmethatRatingSteps; /** * Input name (Default is AskmethatRating) */ inputName: string; } -export declare class AskmethatRating { +export class AskmethatRating { private parentElement; private pValue; private styleSheet; @@ -91,31 +91,31 @@ export declare class AskmethatRating { */ render(value?: number): void; /** - * @function when a rating is clicked - * @param {type} event : Event {event object} - */ + * @function when a rating is clicked + * @param {type} event : Event {event object} + */ private onRatingClick(event?); /** - * @function Calculate the value according to the step provided in options - * @param {Number} value:number the current value - * @return {Number} the new value according to step - */ + * @function Calculate the value according to the step provided in options + * @param {Number} value:number the current value + * @return {Number} the new value according to step + */ protected getValueAccordingToStep(value: number): number; /** - * @function mouse event enter in rating - * @param {type} event?: Event {event} - */ + * @function mouse event enter in rating + * @param {type} event?: Event {event} + */ private onMouseMove(event?); /** - * @function mouse out event in rating - * @param {type} event?: Event {event} - */ + * @function mouse out event in rating + * @param {type} event?: Event {event} + */ private onMouseLeave(event?); /** - * @function set or unset the active class and color - * @param {HTMLSpanElement} current : current span element - * @param {number} current : value needed for the if - */ + * @function set or unset the active class and color + * @param {HTMLSpanElement} current : current span element + * @param {number} current : value needed for the if + */ protected setOrUnsetActive(value: number): void; /** * Check if disabled attribute is added or removed from the input @@ -123,9 +123,9 @@ export declare class AskmethatRating { */ private mutationEvent(); /** - * @function static method to retrieve with identifier the value - * @param {string} identifier: string container identifier - * @return {number} current rating - */ + * @function static method to retrieve with identifier the value + * @param {string} identifier: string container identifier + * @return {number} current rating + */ static value(identifier: string): number; }