mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
[semantic-ui-accordion] Add type definitions. (#16926)
This commit is contained in:
committed by
Mohamed Hegazy
parent
d99d02d39d
commit
f391463294
+239
@@ -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;
|
||||
<K extends keyof AccordionSettings>(behavior: 'setting', name: K, value?: undefined): AccordionSettings[K];
|
||||
<K extends keyof AccordionSettings>(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<AccordionSettings._Impl, keyof AccordionSettings._Impl> { }
|
||||
|
||||
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<SelectorSettings._Impl, keyof SelectorSettings._Impl> { }
|
||||
|
||||
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<ClassNameSettings._Impl, keyof ClassNameSettings._Impl> { }
|
||||
|
||||
namespace ClassNameSettings {
|
||||
type Param = ClassNameSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
/**
|
||||
* @default 'active'
|
||||
*/
|
||||
active: string;
|
||||
/**
|
||||
* @default 'animating'
|
||||
*/
|
||||
animating: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface ErrorSettings extends Pick<ErrorSettings._Impl, keyof ErrorSettings._Impl> { }
|
||||
|
||||
namespace ErrorSettings {
|
||||
type Param = ErrorSettings | object;
|
||||
|
||||
interface _Impl {
|
||||
/**
|
||||
* @default 'The method you called is not defined.'
|
||||
*/
|
||||
method: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// Type definitions for semantic-ui-accordion 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 accordion: SemanticUI.Accordion;
|
||||
export = accordion;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-empty-interface": false,
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user