diff --git a/types/semantic-ui-shape/global.d.ts b/types/semantic-ui-shape/global.d.ts new file mode 100644 index 0000000000..cfd6cc689e --- /dev/null +++ b/types/semantic-ui-shape/global.d.ts @@ -0,0 +1,260 @@ +interface JQuery { + shape: SemanticUI.Shape; +} + +declare namespace SemanticUI { + interface Shape { + settings: ShapeSettings; + + /** + * Flips the shape upward + */ + (behavior: 'flip up'): JQuery; + /** + * Flips the shape downward + */ + (behavior: 'flip down'): JQuery; + /** + * Flips the shape right + */ + (behavior: 'flip right'): JQuery; + /** + * Flips the shape left + */ + (behavior: 'flip left'): JQuery; + /** + * Flips the shape over clock-wise + */ + (behavior: 'flip over'): JQuery; + /** + * Flips the shape over counter-clockwise + */ + (behavior: 'flip back'): JQuery; + /** + * Set the next side to a specific selector + */ + (behavior: 'set next side', selector: string | JQuery): JQuery; + /** + * Returns whether shape is currently animating + */ + (behavior: 'is animating'): boolean; + /** + * Removes all inline styles + */ + (behavior: 'reset'): JQuery; + /** + * Queues an animation until after current animation + */ + (behavior: 'queue', animation: string): JQuery; + /** + * Forces a reflow on element + */ + (behavior: 'repaint'): JQuery; + /** + * Set the next side to next sibling to active element + */ + (behavior: 'set default side'): JQuery; + /** + * Sets shape to the content size of the next side + */ + (behavior: 'set stage size'): JQuery; + /** + * Refreshes the selector cache for element sides + */ + (behavior: 'refresh'): JQuery; + /** + * Returns translation for next side staged below + */ + (behavior: 'get transform down'): Shape.Translation; + /** + * Returns translation for next side staged left + */ + (behavior: 'get transform left'): Shape.Translation; + /** + * Returns translation for next side staged right + */ + (behavior: 'get transform right'): Shape.Translation; + /** + * Returns translation for next side staged up + */ + (behavior: 'get transform up'): Shape.Translation; + /** + * Returns translation for next side staged down + */ + (behavior: 'get transform down'): Shape.Translation; + (behavior: 'destroy'): JQuery; + (behavior: 'setting', name: K, value?: undefined): ShapeSettings[K]; + (behavior: 'setting', name: K, value: ShapeSettings[K]): JQuery; + (behavior: 'setting', value: ShapeSettings.Param): JQuery; + (settings?: ShapeSettings.Param): JQuery; + } + + /** + * @see {@link http://semantic-ui.com/modules/shape.html#/settings} + */ + interface ShapeSettings extends Pick { } + + namespace ShapeSettings { + type Param = ShapeSettings | object; + + interface _Impl { + // region Shape Settings + + /** + * Duration of side change animation + * + * @default 700 + */ + duration: number; + /** + * When set to next will use the width of the next side during the shape's animation. + * When set to initial it will use the width of the shape at initialization. + * When set to a specific pixel height, will force the width to that height. + * + * @default 'initial' + * @since 2.2 + */ + width: 'next' | 'initial' | number; + /** + * When set to next will use the height of the next side during the shape's animation. + * When set to initial it will use the height of the shape at initialization. + * When set to a specific pixel height, will force the height to that height. + * + * @default 'initial' + * @since 2.2 + */ + height: 'next' | 'initial' | number; + + // endregion + + // region Callbacks + + /** + * Is called before side change + */ + beforeChange(this: JQuery): void; + /** + * Is called after visible side change + */ + onChange(this: JQuery): void; + + // endregion + + // region DOM Settings + + selector: Shape.SelectorSettings; + className: Shape.ClassNameSettings; + + // endregion + + // region Debug Settings + + error: Shape.ErrorSettings; + + // endregion + + // region Component Settings + + // region DOM Settings + + /** + * Event namespace. Makes sure module teardown does not effect other events attached to an element. + */ + namespace: string; + + // endregion + + // region Debug Settings + + /** + * Name used in log statements + */ + name: string; + /** + * Silences all console output including error messages, regardless of other debug settings. + */ + silent: boolean; + /** + * Debug output to console + */ + debug: boolean; + /** + * Show console.table output with performance metrics + */ + performance: boolean; + /** + * Debug output includes all internal behaviors + */ + verbose: boolean; + + // endregion + + // endregion + } + } + + namespace Shape { + interface Translation { + transform: string; + } + + interface SelectorSettings extends Pick { } + + namespace SelectorSettings { + type Param = SelectorSettings | object; + + interface _Impl { + /** + * @default '.sides' + */ + sides: string; + /** + * @default '.side' + */ + side: string; + } + } + + interface ClassNameSettings extends Pick { } + + namespace ClassNameSettings { + type Param = ClassNameSettings | object; + + interface _Impl { + /** + * @default 'animating' + */ + animating: string; + /** + * @default 'hidden' + */ + hidden: string; + /** + * @default 'loading' + */ + loading: string; + /** + * @default 'active' + */ + active: string; + } + } + + interface ErrorSettings extends Pick { } + + namespace ErrorSettings { + type Param = ErrorSettings | object; + + interface _Impl { + /** + * @default 'You tried to switch to a side that does not exist.' + */ + side: string; + /** + * @default 'The method you called is not defined' + */ + method: string; + } + } + } +} diff --git a/types/semantic-ui-shape/index.d.ts b/types/semantic-ui-shape/index.d.ts new file mode 100644 index 0000000000..715a8af1bd --- /dev/null +++ b/types/semantic-ui-shape/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for semantic-ui-shape 2.2 +// Project: http://www.semantic-ui.com +// Definitions by: Leonard Thieu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// +/// + +declare const shape: SemanticUI.Shape; +export = shape; diff --git a/types/semantic-ui-shape/semantic-ui-shape-tests.ts b/types/semantic-ui-shape/semantic-ui-shape-tests.ts new file mode 100644 index 0000000000..994909085a --- /dev/null +++ b/types/semantic-ui-shape/semantic-ui-shape-tests.ts @@ -0,0 +1,76 @@ +function test_shape_static() { + $.fn.shape.settings.error.method = 'method'; + $.fn.shape.settings.namespace = 'namespace'; + $.fn.shape.settings.name = 'name'; + $.fn.shape.settings.silent = false; + $.fn.shape.settings.debug = true; + $.fn.shape.settings.performance = true; + $.fn.shape.settings.verbose = true; +} + +function test_shape() { + const selector = '.ui.shape'; + $(selector).shape('flip up') === $(); + $(selector).shape('flip down') === $(); + $(selector).shape('flip right') === $(); + $(selector).shape('flip left') === $(); + $(selector).shape('flip over') === $(); + $(selector).shape('flip back') === $(); + $(selector).shape('set next side', $()) === $(); + $(selector).shape('is animating') === false; + $(selector).shape('reset') === $(); + $(selector).shape('queue', 'animation') === $(); + $(selector).shape('repaint') === $(); + $(selector).shape('set default side') === $(); + $(selector).shape('set stage size') === $(); + $(selector).shape('refresh') === $(); + $(selector).shape('get transform down') === { transform: 'transform' }; + $(selector).shape('get transform left') === { transform: 'transform' }; + $(selector).shape('get transform right') === { transform: 'transform' }; + $(selector).shape('get transform up') === { transform: 'transform' }; + $(selector).shape('get transform down') === { transform: 'transform' }; + $(selector).shape('destroy') === $(); + $(selector).shape('setting', 'debug', undefined) === false; + $(selector).shape('setting', 'debug') === false; + $(selector).shape('setting', 'debug', true) === $(); + $(selector).shape('setting', { + namespace: 'namespace', + name: 'name', + silent: false, + debug: true, + performance: true, + verbose: true + }) === $(); + $(selector).shape({ + duration: 700, + width: 'next', + height: 200, + beforeChange() { + this === $(); + }, + onChange() { + this === $(); + }, + selector: { + sides: 'sides', + side: 'side' + }, + className: { + animating: 'animating', + hidden: 'hidden', + loading: 'loading', + active: 'active' + }, + error: { + side: 'side', + method: 'method' + } + }) === $(); + $(selector).shape() === $(); +} + +import shape = require('semantic-ui-shape'); + +function test_module() { + $.fn.shape = shape; +} diff --git a/types/semantic-ui-shape/tsconfig.json b/types/semantic-ui-shape/tsconfig.json new file mode 100644 index 0000000000..80aca84e86 --- /dev/null +++ b/types/semantic-ui-shape/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "global.d.ts", + "semantic-ui-shape-tests.ts" + ] +} diff --git a/types/semantic-ui-shape/tslint.json b/types/semantic-ui-shape/tslint.json new file mode 100644 index 0000000000..758e484744 --- /dev/null +++ b/types/semantic-ui-shape/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-empty-interface": false, + "unified-signatures": false + } +}