diff --git a/types/semantic-ui-sidebar/global.d.ts b/types/semantic-ui-sidebar/global.d.ts new file mode 100644 index 0000000000..1217444f53 --- /dev/null +++ b/types/semantic-ui-sidebar/global.d.ts @@ -0,0 +1,424 @@ +interface JQuery { + sidebar: SemanticUI.Sidebar; +} + +declare namespace SemanticUI { + interface Sidebar { + settings: SidebarSettings; + + /** + * Attaches sidebar action to given selector. Default event if none specified is toggle + */ + (behavior: 'attach events', selector: string | JQuery, event?: string): JQuery; + /** + * Shows sidebar + */ + (behavior: 'show'): JQuery; + /** + * Hides sidebar + */ + (behavior: 'hide'): JQuery; + /** + * Toggles visibility of sidebar + */ + (behavior: 'toggle'): JQuery; + /** + * Returns whether sidebar is visible + */ + (behavior: 'is visible'): boolean; + /** + * Returns whether sidebar is hidden + */ + (behavior: 'is hidden'): boolean; + /** + * Pushes page content to be visible alongside sidebar + */ + (behavior: 'push page'): JQuery; + /** + * Returns direction of current sidebar + */ + (behavior: 'get direction'): string; + /** + * Returns page content to original position + */ + (behavior: 'pull page'): JQuery; + /** + * Adds stylesheet to page head to trigger sidebar animations + */ + (behavior: 'add body CSS'): JQuery; + /** + * Removes any inline stylesheets for sidebar animation + */ + (behavior: 'remove body CSS'): JQuery; + /** + * Returns vendor prefixed transition end event + */ + (behavior: 'get transition event'): string; + (behavior: 'destroy'): JQuery; + (behavior: 'setting', name: K, value?: undefined): SidebarSettings[K]; + (behavior: 'setting', name: K, value: SidebarSettings[K]): JQuery; + (behavior: 'setting', value: SidebarSettings.Param): JQuery; + (settings?: SidebarSettings.Param): JQuery; + } + + /** + * @see {@link http://semantic-ui.com/modules/sidebar.html#/settings} + */ + interface SidebarSettings extends Pick { } + + namespace SidebarSettings { + type Param = SidebarSettings | object; + + interface _Impl { + // region Behavior + + /** + * Context which sidebar will appear inside + * + * @default 'body' + */ + context: string | JQuery; + /** + * Whether multiple sidebars can be open at once + * + * @default false + */ + exclusive: boolean; + /** + * Whether sidebar can be closed by clicking on page + * + * @default true + */ + closable: boolean; + /** + * Whether to dim page contents when sidebar is visible + * + * @default true + */ + dimPage: boolean; + /** + * Whether to lock page scroll when sidebar is visible + * + * @default false + */ + scrollLock: boolean; + /** + * Whether to return to original scroll position when sidebar is hidden, automatically occurs with transition: scale + * + * @default false + */ + returnScroll: boolean; + /** + * When sidebar is initialized without the proper HTML, using this option will defer creation of DOM to use requestAnimationFrame. + * + * @default false + */ + delaySetup: boolean; + + // endregion + + // region Animation + + /** + * Named transition to use when animating sidebar. Defaults to 'auto' which selects transition from defaultTransition based on direction. + * + * @default 'auto' + */ + transition: string; + /** + * Named transition to use when animating when detecting mobile device. Defaults to 'auto' which selects transition from defaultTransition based on direction. + * + * @default 'auto' + */ + mobileTransition: string; + /** + * Default transitions for each direction and screen size, used with transition: auto + */ + defaultTransition: Sidebar.DefaultTransitionSettings; + /** + * Whether Javascript animations should be used. Defaults to false. Setting to auto will use legacy animations only for browsers that do not support CSS transforms + * + * @default false + */ + useLegacy: 'auto' | boolean; + /** + * Duration of sidebar animation when using legacy Javascript animation + * + * @default 500 + */ + duration: number; + /** + * Easing to use when using legacy Javascript animation + * + * @default 'easeInOutQuint' + */ + easing: string; + + // endregion + + // region Callbacks + + /** + * Is called when a sidebar begins animating in. + */ + onVisible(this: JQuery): void; + /** + * Is called when a sidebar has finished animating in. + */ + onShow(this: JQuery): void; + /** + * Is called when a sidebar begins to hide or show + */ + onChange(this: JQuery): void; + /** + * Is called before a sidebar begins to animate out. + */ + onHide(this: JQuery): void; + /** + * Is called after a sidebar has finished animating out. + */ + onHidden(this: JQuery): void; + + // endregion + + // region DOM Settings + + className: Sidebar.ClassNameSettings; + regExp: Sidebar.RegExpSettings; + selector: Sidebar.SelectorSettings; + + // endregion + + // region Debug Settings + + error: Sidebar.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 Sidebar { + interface DefaultTransitionSettings extends Pick { } + + namespace DefaultTransitionSettings { + type Param = DefaultTransitionSettings | object; + + interface _Impl { + computer: ComputerSettings; + mobile: MobileSettings; + } + + interface ComputerSettings extends Pick { } + + namespace ComputerSettings { + type Param = ComputerSettings | object; + + interface _Impl { + /** + * @default 'uncover' + */ + left: string; + /** + * @default 'uncover' + */ + right: string; + /** + * @default 'overlay' + */ + top: string; + /** + * @default 'overlay' + */ + bottom: string; + } + } + + interface MobileSettings extends Pick { } + + namespace MobileSettings { + type Param = MobileSettings | object; + + interface _Impl { + /** + * @default 'uncover' + */ + left: string; + /** + * @default 'uncover' + */ + right: string; + /** + * @default 'overlay' + */ + top: string; + /** + * @default 'overlay' + */ + bottom: string; + } + } + } + + interface ClassNameSettings extends Pick { } + + namespace ClassNameSettings { + type Param = ClassNameSettings | object; + + interface _Impl { + /** + * @default 'active' + */ + active: string; + /** + * @default 'animating' + */ + animating: string; + /** + * @default 'dimmed' + */ + dimmed: string; + /** + * @default 'ios' + */ + ios: string; + /** + * @default 'pushable' + */ + pushable: string; + /** + * @default 'pushed' + */ + pushed: string; + /** + * @default 'right' + */ + right: string; + /** + * @default 'top' + */ + top: string; + /** + * @default 'left' + */ + left: string; + /** + * @default 'bottom' + */ + bottom: string; + /** + * @default 'visible' + */ + visible: string; + } + } + + interface RegExpSettings extends Pick { } + + namespace RegExpSettings { + type Param = RegExpSettings | object; + + interface _Impl { + /** + * @default /(iPad|iPhone|iPod)/g + */ + ios: RegExp; + /** + * @default /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/g + */ + mobile: RegExp; + } + } + + interface SelectorSettings extends Pick { } + + namespace SelectorSettings { + type Param = SelectorSettings | object; + + interface _Impl { + /** + * @default '.fixed' + */ + fixed: string; + /** + * @default 'script, link, style, .ui.modal, .ui.dimmer, .ui.nag, .ui.fixed' + */ + omitted: string; + /** + * @default '.pusher' + */ + pusher: string; + /** + * @default '.ui.sidebar' + */ + sidebar: string; + } + } + + interface ErrorSettings extends Pick { } + + namespace ErrorSettings { + type Param = ErrorSettings | object; + + interface _Impl { + /** + * @default 'The method you called is not defined.' + */ + method: string; + /** + * @default 'Had to add pusher element. For optimal performance make sure body content is inside a pusher element' + */ + pusher: string; + /** + * @default 'Had to move sidebar. For optimal performance make sure sidebar and pusher are direct children of your body tag' + */ + movedSidebar: string; + /** + * @default 'The overlay setting is no longer supported, use animation: overlay' + */ + overlay: string; + /** + * @default 'There were no elements that matched the specified selector' + */ + notFound: string; + } + } + } +} diff --git a/types/semantic-ui-sidebar/index.d.ts b/types/semantic-ui-sidebar/index.d.ts new file mode 100644 index 0000000000..3a4ca1e23a --- /dev/null +++ b/types/semantic-ui-sidebar/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for semantic-ui-sidebar 2.2 +// Project: http://www.semantic-ui.com +// Definitions by: Leonard Thieu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// +/// + +declare const sidebar: SemanticUI.Sidebar; +export = sidebar; diff --git a/types/semantic-ui-sidebar/semantic-ui-sidebar-tests.ts b/types/semantic-ui-sidebar/semantic-ui-sidebar-tests.ts new file mode 100644 index 0000000000..c98b73b47c --- /dev/null +++ b/types/semantic-ui-sidebar/semantic-ui-sidebar-tests.ts @@ -0,0 +1,118 @@ +function test_sidebar_static() { + $.fn.sidebar.settings.error.method = 'method'; + $.fn.sidebar.settings.namespace = 'namespace'; + $.fn.sidebar.settings.name = 'name'; + $.fn.sidebar.settings.silent = false; + $.fn.sidebar.settings.debug = true; + $.fn.sidebar.settings.performance = true; + $.fn.sidebar.settings.verbose = true; +} + +function test_sidebar() { + const selector = '.ui.sidebar'; + $(selector).sidebar('attach events', $(), 'toggle') === $(); + $(selector).sidebar('show') === $(); + $(selector).sidebar('hide') === $(); + $(selector).sidebar('toggle') === $(); + $(selector).sidebar('is visible') === false; + $(selector).sidebar('is hidden') === true; + $(selector).sidebar('push page') === $(); + $(selector).sidebar('get direction') === 'top'; + $(selector).sidebar('pull page') === $(); + $(selector).sidebar('add body CSS') === $(); + $(selector).sidebar('remove body CSS') === $(); + $(selector).sidebar('get transition event') === 'transition'; + $(selector).sidebar('destroy') === $(); + $(selector).sidebar('setting', 'debug', undefined) === false; + $(selector).sidebar('setting', 'debug') === false; + $(selector).sidebar('setting', 'debug', true) === $(); + $(selector).sidebar('setting', { + namespace: 'namespace', + name: 'name', + silent: false, + debug: true, + performance: true, + verbose: true + }) === $(); + $(selector).sidebar({ + context: $(), + exclusive: false, + closable: true, + dimPage: false, + scrollLock: true, + returnScroll: false, + delaySetup: true, + transition: 'auto', + mobileTransition: 'auto', + defaultTransition: { + mobile: { + left: 'left', + right: 'right', + top: 'top', + bottom: 'bottom' + }, + computer: { + left: 'left', + right: 'right', + top: 'top', + bottom: 'bottom' + } + }, + useLegacy: false, + duration: 20, + easing: 'easeInOutQuint', + onVisible() { + this === $(); + }, + onShow() { + this === $(); + }, + onChange() { + this === $(); + }, + onHide() { + this === $(); + }, + onHidden() { + this === $(); + }, + className: { + active: 'active', + animating: 'animating', + dimmed: 'dimmed', + ios: 'ios', + pushable: 'pushable', + pushed: 'pushed', + right: 'right', + top: 'top', + left: 'left', + bottom: 'bottom', + visible: 'visible' + }, + regExp: { + ios: /(iPad|iPhone|iPod)/g, + mobile: /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/g, + }, + selector: { + fixed: 'fixed', + omitted: 'omitted', + pusher: 'pusher', + sidebar: 'sidebar' + }, + error: { + method: 'method', + pusher: 'pusher', + movedSidebar: 'movedSidebar', + animation: 'animation', + overlay: 'overlay', + notFound: 'notFound' + } + }) === $(); + $(selector).sidebar() === $(); +} + +import sidebar = require('semantic-ui-sidebar'); + +function test_module() { + $.fn.sidebar = sidebar; +} diff --git a/types/semantic-ui-sidebar/tsconfig.json b/types/semantic-ui-sidebar/tsconfig.json new file mode 100644 index 0000000000..250b2dfae1 --- /dev/null +++ b/types/semantic-ui-sidebar/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-sidebar-tests.ts" + ] +} diff --git a/types/semantic-ui-sidebar/tslint.json b/types/semantic-ui-sidebar/tslint.json new file mode 100644 index 0000000000..758e484744 --- /dev/null +++ b/types/semantic-ui-sidebar/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-empty-interface": false, + "unified-signatures": false + } +}