mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
[semantic-ui-nag] Add type definitions (#16944)
This commit is contained in:
committed by
Mohamed Hegazy
parent
0c2cd7d087
commit
277b8a1629
223
types/semantic-ui-nag/global.d.ts
vendored
Normal file
223
types/semantic-ui-nag/global.d.ts
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
interface JQuery {
|
||||
nag: SemanticUI.Nag;
|
||||
}
|
||||
|
||||
declare namespace SemanticUI {
|
||||
interface Nag {
|
||||
settings: NagSettings;
|
||||
|
||||
(behavior: 'show'): JQuery;
|
||||
(behavior: 'hide'): JQuery;
|
||||
/**
|
||||
* Clears cookie so nag shows again
|
||||
*/
|
||||
(behavior: 'clear'): JQuery;
|
||||
(behavior: 'destroy'): JQuery;
|
||||
<K extends keyof NagSettings>(behavior: 'setting', name: K, value?: undefined): NagSettings[K];
|
||||
<K extends keyof NagSettings>(behavior: 'setting', name: K, value: NagSettings[K]): JQuery;
|
||||
(behavior: 'setting', value: NagSettings.Param): JQuery;
|
||||
(settings?: NagSettings.Param): JQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link http://semantic-ui.com/modules/nag.html}
|
||||
*/
|
||||
interface NagSettings extends Pick<NagSettings._Impl, keyof NagSettings._Impl> { }
|
||||
|
||||
namespace NagSettings {
|
||||
type Param = NagSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
// region Behavior
|
||||
|
||||
/**
|
||||
* allows cookie to be overridden
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
persist: boolean;
|
||||
/**
|
||||
* set to zero to require manually dismissal, otherwise hides on its own
|
||||
*
|
||||
* @default 0
|
||||
*/
|
||||
displayTime: number;
|
||||
animation: Nag.AnimationSettings;
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
context: false | string | JQuery;
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
detachable: boolean;
|
||||
|
||||
/**
|
||||
* @default 30
|
||||
*/
|
||||
expires: number;
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
domain: false | string;
|
||||
/**
|
||||
* @default '/'
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* type of storage to use
|
||||
*
|
||||
* @default 'cookie'
|
||||
*/
|
||||
storageMethod: 'cookie' | 'localstorage' | 'sessionstorage';
|
||||
|
||||
/**
|
||||
* @default 'nag'
|
||||
*/
|
||||
key: any;
|
||||
/**
|
||||
* @default 'dismiss'
|
||||
*/
|
||||
value: any;
|
||||
|
||||
/**
|
||||
* @default 500
|
||||
*/
|
||||
speed: number;
|
||||
/**
|
||||
* @default 'easeOutQuad'
|
||||
*/
|
||||
easing: string;
|
||||
|
||||
// endregion
|
||||
|
||||
// region Callbacks
|
||||
|
||||
onHide(this: JQuery): void;
|
||||
|
||||
// endregion
|
||||
|
||||
// region DOM Settings
|
||||
|
||||
className: Nag.ClassNameSettings;
|
||||
selector: Nag.SelectorSettings;
|
||||
|
||||
// endregion
|
||||
|
||||
// region Debug Settings
|
||||
|
||||
error: Nag.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 Nag {
|
||||
interface AnimationSettings extends Pick<AnimationSettings._Impl, keyof AnimationSettings._Impl> { }
|
||||
|
||||
namespace AnimationSettings {
|
||||
type Param = AnimationSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
/**
|
||||
* @default 'slide'
|
||||
*/
|
||||
show: string;
|
||||
/**
|
||||
* @default 'slide'
|
||||
*/
|
||||
hide: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface ClassNameSettings extends Pick<ClassNameSettings._Impl, keyof ClassNameSettings._Impl> { }
|
||||
|
||||
namespace ClassNameSettings {
|
||||
type Param = ClassNameSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
/**
|
||||
* @default 'bottom'
|
||||
*/
|
||||
bottom: string;
|
||||
/**
|
||||
* @default 'fixed'
|
||||
*/
|
||||
fixed: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface SelectorSettings extends Pick<SelectorSettings._Impl, keyof SelectorSettings._Impl> { }
|
||||
|
||||
namespace SelectorSettings {
|
||||
type Param = SelectorSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
/**
|
||||
* @default '.close.icon'
|
||||
*/
|
||||
close: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface ErrorSettings extends Pick<ErrorSettings._Impl, keyof ErrorSettings._Impl> { }
|
||||
|
||||
namespace ErrorSettings {
|
||||
type Param = ErrorSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
/**
|
||||
* @default '$.cookie is not included. A storage solution is required.'
|
||||
*/
|
||||
noCookieStorage: string;
|
||||
/**
|
||||
* @default 'Neither $.cookie or store is defined. A storage solution is required for storing state'
|
||||
*/
|
||||
noStorage: string;
|
||||
/**
|
||||
* @default 'The method you called is not defined.'
|
||||
*/
|
||||
method: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
types/semantic-ui-nag/index.d.ts
vendored
Normal file
11
types/semantic-ui-nag/index.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// Type definitions for semantic-ui-nag 2.2
|
||||
// Project: http://www.semantic-ui.com
|
||||
// Definitions by: Leonard Thieu <https://github.com/leonard-thieu>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="jquery" />
|
||||
/// <reference path="global.d.ts" />
|
||||
|
||||
declare const nag: SemanticUI.Nag;
|
||||
export = nag;
|
||||
68
types/semantic-ui-nag/semantic-ui-nag-tests.ts
Normal file
68
types/semantic-ui-nag/semantic-ui-nag-tests.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
function test_nag_static() {
|
||||
$.fn.nag.settings.error.method = 'method';
|
||||
$.fn.nag.settings.namespace = 'namespace';
|
||||
$.fn.nag.settings.name = 'name';
|
||||
$.fn.nag.settings.silent = false;
|
||||
$.fn.nag.settings.debug = true;
|
||||
$.fn.nag.settings.performance = true;
|
||||
$.fn.nag.settings.verbose = true;
|
||||
}
|
||||
|
||||
function test_nag() {
|
||||
const selector = '.ui.nag';
|
||||
$(selector).nag('show') === $();
|
||||
$(selector).nag('hide') === $();
|
||||
$(selector).nag('clear') === $();
|
||||
$(selector).nag('destroy') === $();
|
||||
$(selector).nag('setting', 'debug', undefined) === false;
|
||||
$(selector).nag('setting', 'debug') === false;
|
||||
$(selector).nag('setting', 'debug', true) === $();
|
||||
$(selector).nag('setting', {
|
||||
namespace: 'namespace',
|
||||
name: 'name',
|
||||
silent: false,
|
||||
debug: true,
|
||||
performance: true,
|
||||
verbose: true
|
||||
}) === $();
|
||||
$(selector).nag({
|
||||
persist: true,
|
||||
displayTime: 0,
|
||||
animation: {
|
||||
show: 'slide',
|
||||
hide: 'slide'
|
||||
},
|
||||
context: $(),
|
||||
detachable: false,
|
||||
expires: 30,
|
||||
domain: 'domain',
|
||||
path: 'path',
|
||||
storageMethod: 'localstorage',
|
||||
key: 'nag',
|
||||
value: 'dismiss',
|
||||
speed: 500,
|
||||
easing: 'easeOutQuad',
|
||||
onHide() {
|
||||
this === $();
|
||||
},
|
||||
className: {
|
||||
bottom: 'bottom',
|
||||
fixed: 'fixed'
|
||||
},
|
||||
selector: {
|
||||
close: 'close'
|
||||
},
|
||||
error: {
|
||||
noCookieStorage: 'noCookieStorage',
|
||||
noStorage: 'noStorage',
|
||||
method: 'method'
|
||||
}
|
||||
}) === $();
|
||||
$(selector).nag() === $();
|
||||
}
|
||||
|
||||
import nag = require('semantic-ui-nag');
|
||||
|
||||
function test_module() {
|
||||
$.fn.nag = nag;
|
||||
}
|
||||
24
types/semantic-ui-nag/tsconfig.json
Normal file
24
types/semantic-ui-nag/tsconfig.json
Normal file
@@ -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-nag-tests.ts"
|
||||
]
|
||||
}
|
||||
7
types/semantic-ui-nag/tslint.json
Normal file
7
types/semantic-ui-nag/tslint.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-empty-interface": false,
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user