From f391463294d8196fd506cb52f0d01e7616f4d76c Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Fri, 2 Jun 2017 20:00:42 -0400 Subject: [PATCH] [semantic-ui-accordion] Add type definitions. (#16926) --- types/semantic-ui-accordion/global.d.ts | 239 ++++++++++++++++++ types/semantic-ui-accordion/index.d.ts | 11 + .../semantic-ui-accordion-tests.ts | 74 ++++++ types/semantic-ui-accordion/tsconfig.json | 24 ++ types/semantic-ui-accordion/tslint.json | 7 + 5 files changed, 355 insertions(+) create mode 100644 types/semantic-ui-accordion/global.d.ts create mode 100644 types/semantic-ui-accordion/index.d.ts create mode 100644 types/semantic-ui-accordion/semantic-ui-accordion-tests.ts create mode 100644 types/semantic-ui-accordion/tsconfig.json create mode 100644 types/semantic-ui-accordion/tslint.json diff --git a/types/semantic-ui-accordion/global.d.ts b/types/semantic-ui-accordion/global.d.ts new file mode 100644 index 0000000000..33e3080dfb --- /dev/null +++ b/types/semantic-ui-accordion/global.d.ts @@ -0,0 +1,239 @@ +interface JQuery { + accordion: SemanticUI.Accordion; +} + +declare namespace SemanticUI { + interface Accordion { + settings: AccordionSettings; + + /** + * Refreshes all cached selectors and data + */ + (behavior: 'refresh'): JQuery; + /** + * Opens accordion content at index + */ + (behavior: 'open', index: number): JQuery; + /** + * Closes accordion content that are not active + */ + (behavior: 'close others'): JQuery; + /** + * Closes accordion content at index + */ + (behavior: 'close', index: number): JQuery; + /** + * Toggles accordion content at index + */ + (behavior: 'toggle', index: number): JQuery; + (behavior: 'destroy'): JQuery; + (behavior: 'setting', name: K, value?: undefined): AccordionSettings[K]; + (behavior: 'setting', name: K, value: AccordionSettings[K]): JQuery; + (behavior: 'setting', value: AccordionSettings.Param): JQuery; + (settings?: AccordionSettings.Param): JQuery; + } + + /** + * @see {@link http://semantic-ui.com/modules/accordion.html#/settings} + */ + interface AccordionSettings extends Pick { } + + namespace AccordionSettings { + type Param = AccordionSettings | object; + + interface _Impl { + // region Behavior + + /** + * Only allow one section open at a time + * + * @default true + */ + exclusive: boolean; + /** + * Event on title that will cause accordion to open + * + * @default 'click' + */ + on: string; + /** + * Whether child content opacity should be animated (may cause performance issues with many child elements) + * + * @default true + */ + animateChildren: boolean; + /** + * Close open nested accordion content when an element closes + * + * @default true + */ + closeNested: boolean; + /** + * Allow active sections to collapse + * + * @default true + */ + collapsible: boolean; + /** + * Duration in ms of opening animation + * + * @default 500 + */ + duration: number; + /** + * Easing of opening animation. EaseInOutQuint is included with accordion, for additional options you must include easing equations. + * + * @default 'easeInOutQuint' + * @see {@link http://gsgd.co.uk/sandbox/jquery/easing/} + */ + easing: string; + /** + * whether accordion should automatically refresh on DOM insertion + * + * @default true + */ + observeChanges: boolean; + + // endregion + + // region Callbacks + + /** + * Callback before element opens + */ + onOpening(this: JQuery): void; + /** + * Callback after element is open + */ + onOpen(this: JQuery): void; + /** + * Callback before element closes + */ + onClosing(this: JQuery): void; + /** + * Callback after element is closed + */ + onClose(this: JQuery): void; + /** + * Callback on element open or close + */ + onChange(this: JQuery): void; + + // endregion + + // region DOM Settings + + /** + * Selectors used to find parts of a module + */ + selector: Accordion.SelectorSettings; + /** + * Class names used to determine element state + */ + className: Accordion.ClassNameSettings; + + // endregion + + // region Debug Settings + + error: Accordion.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 Accordion { + interface SelectorSettings extends Pick { } + + namespace SelectorSettings { + type Param = SelectorSettings | object; + + interface _Impl { + /** + * @default '.accordion' + */ + accordion: string; + /** + * @default '.title' + */ + title: string; + /** + * @default '.title' + */ + trigger: string; + /** + * @default '.content' + */ + content: string; + } + } + + interface ClassNameSettings extends Pick { } + + namespace ClassNameSettings { + type Param = ClassNameSettings | object; + + interface _Impl { + /** + * @default 'active' + */ + active: string; + /** + * @default 'animating' + */ + animating: string; + } + } + + interface ErrorSettings extends Pick { } + + namespace ErrorSettings { + type Param = ErrorSettings | object; + + interface _Impl { + /** + * @default 'The method you called is not defined.' + */ + method: string; + } + } + } +} diff --git a/types/semantic-ui-accordion/index.d.ts b/types/semantic-ui-accordion/index.d.ts new file mode 100644 index 0000000000..d4367cb93f --- /dev/null +++ b/types/semantic-ui-accordion/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for semantic-ui-accordion 2.2 +// Project: http://www.semantic-ui.com +// Definitions by: Leonard Thieu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// +/// + +declare const accordion: SemanticUI.Accordion; +export = accordion; diff --git a/types/semantic-ui-accordion/semantic-ui-accordion-tests.ts b/types/semantic-ui-accordion/semantic-ui-accordion-tests.ts new file mode 100644 index 0000000000..7ab192f847 --- /dev/null +++ b/types/semantic-ui-accordion/semantic-ui-accordion-tests.ts @@ -0,0 +1,74 @@ +function test_static() { + $.fn.accordion.settings.namespace = 'namespace'; + $.fn.accordion.settings.name = 'name'; + $.fn.accordion.settings.silent = false; + $.fn.accordion.settings.debug = true; + $.fn.accordion.settings.performance = true; + $.fn.accordion.settings.verbose = true; +} + +function test_accordion() { + const selector = '.ui.accordion'; + $(selector).accordion('refresh') === $(); + $(selector).accordion('open', 3) === $(); + $(selector).accordion('close others') === $(); + $(selector).accordion('close', 10) === $(); + $(selector).accordion('toggle', 5) === $(); + $(selector).accordion('destroy') === $(); + $(selector).accordion('setting', 'debug', undefined) === false; + $(selector).accordion('setting', 'debug') === false; + $(selector).accordion('setting', 'debug', true) === $(); + $(selector).accordion('setting', { + namespace: 'namespace', + name: 'name', + silent: false, + debug: true, + performance: true, + verbose: true + }) === $(); + $(selector).accordion({ + exclusive: true, + on: 'on', + animateChildren: false, + closeNested: true, + collapsible: false, + duration: 500, + easing: 'easeInOutQuint', + observeChanges: true, + onOpening() { + this === $(); + }, + onOpen() { + this === $(); + }, + onClosing() { + this === $(); + }, + onClose() { + this === $(); + }, + onChange() { + this === $(); + }, + selector: { + accordion: 'accordion', + title: 'title', + trigger: 'trigger', + content: 'content' + }, + className: { + active: 'active', + animating: 'animating' + }, + error: { + method: 'method' + } + }) === $(); + $(selector).accordion() === $(); +} + +import accordion = require('semantic-ui-accordion'); + +function test_module() { + $.fn.accordion = accordion; +} diff --git a/types/semantic-ui-accordion/tsconfig.json b/types/semantic-ui-accordion/tsconfig.json new file mode 100644 index 0000000000..1cf2dd2ed4 --- /dev/null +++ b/types/semantic-ui-accordion/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-accordion-tests.ts" + ] +} diff --git a/types/semantic-ui-accordion/tslint.json b/types/semantic-ui-accordion/tslint.json new file mode 100644 index 0000000000..758e484744 --- /dev/null +++ b/types/semantic-ui-accordion/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-empty-interface": false, + "unified-signatures": false + } +}