[Simplebar] Add typing for v5 (#42654)

* move old typings in v2

* add new typings

* fix linter errors

* move tests under v2

* add more classes

* revert original comments in v2
This commit is contained in:
Valikhan Akhmedov
2020-03-02 23:27:16 +06:00
committed by GitHub
parent 9d29adedf6
commit 9af68d8d95
7 changed files with 164 additions and 37 deletions

View File

@@ -1,14 +1,15 @@
// Type definitions for simplebar.js 2.4
// Type definitions for simplebar.js 5.1
// Project: https://github.com/Grsmto/simplebar, https://grsmto.github.io/simplebar
// Definitions by: Gregor Woiwode <https://github.com/gregonnet>, Leonard Thieu <https://github.com/leonard-thieu>
// Definitions by: Valikhan Akhmedov <https://github.com/val-o>, Gregor Woiwode <https://github.com/gregonnet>, Leonard Thieu <https://github.com/leonard-thieu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.8
export as namespace SimpleBar;
export = SimpleBar;
declare class SimpleBar {
static removeObserver(): void;
static instances: Pick<WeakMap<HTMLElement, SimpleBar>, 'get' | 'has'>;
constructor(element: HTMLElement, options?: SimpleBar.Options);
@@ -19,16 +20,32 @@ declare class SimpleBar {
declare namespace SimpleBar {
interface Options {
wrapContent?: boolean;
autoHide?: boolean;
scrollbarMinSize?: number;
classNames?: ClassNamesOptions;
forceVisible?: boolean | 'x' | 'y';
direction?: 'rtl' | 'ltr';
timeout?: number;
clickOnTrack?: boolean;
scrollbarMinSize?: number;
scrollbarMaxSize?: number;
}
interface ClassNamesOptions {
content?: string;
scrollContent?: string;
contentEl?: string;
contentWrapper?: string;
offset?: string;
mask?: string;
wrapper?: string;
placeholder?: string;
scrollbar?: string;
track?: string;
heightAutoObserverWrapperEl?: string;
heightAutoObserverEl?: string;
visible?: string;
horizontal?: string;
vertical?: string;
hover?: string;
dragging?: string;
[className: string]: string;
}
}

View File

@@ -1,17 +1,17 @@
function test_start() {
function test_constructorWithoutOpts() {
new SimpleBar(document.getElementById('myElement'));
}
function test_options_wrapContent() {
new SimpleBar(document.getElementById('myElement'), { wrapContent: false });
}
function test_options_autoHide() {
new SimpleBar(document.getElementById('myElement'), { autoHide: false });
}
function test_options_scrollbarMinSize() {
new SimpleBar(document.getElementById('myElement'), { scrollbarMinSize: 10 });
function test_constructor() {
new SimpleBar(document.getElementById('myElement'), {
autoHide: true,
clickOnTrack: true,
direction: 'ltr',
forceVisible: 'x',
scrollbarMaxSize: 20,
scrollbarMinSize: 10,
timeout: 300,
});
}
function test_options_classNames() {
@@ -21,31 +21,19 @@ function test_options_classNames() {
content: 'simplebar-content',
scrollContent: 'simplebar-scroll-content',
scrollbar: 'simplebar-scrollbar',
track: 'simplebar-track'
}
track: 'simplebar-track',
},
});
}
function test_recalculate() {
function test_instanceFunctions() {
const el = new SimpleBar(document.getElementById('myElement'));
el.recalculate();
const contentEl: Element = el.getContentElement();
const scrollEl: Element = el.getScrollElement();
}
function test_getScrollElement() {
const el = new SimpleBar(document.getElementById('myElement'));
el.getScrollElement();
}
function test_scrollEvent() {
const el = new SimpleBar(document.getElementById('myElement'));
el.getScrollElement().addEventListener('scroll', () => { });
}
function test_getContentElement() {
const el = new SimpleBar(document.getElementById('myElement'));
el.getContentElement();
}
function test_removeObserver() {
function test_staticFunctions() {
SimpleBar.removeObserver();
SimpleBar.instances.get(new HTMLDivElement());
}

34
types/simplebar/v2/index.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
// Type definitions for simplebar.js 2.4
// Project: https://github.com/Grsmto/simplebar, https://grsmto.github.io/simplebar
// Definitions by: Gregor Woiwode <https://github.com/gregonnet>, Leonard Thieu <https://github.com/leonard-thieu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export as namespace SimpleBar;
export = SimpleBar;
declare class SimpleBar {
static removeObserver(): void;
constructor(element: HTMLElement, options?: SimpleBar.Options);
recalculate(): void;
getScrollElement(): Element;
getContentElement(): Element;
}
declare namespace SimpleBar {
interface Options {
wrapContent?: boolean;
autoHide?: boolean;
scrollbarMinSize?: number;
classNames?: ClassNamesOptions;
}
interface ClassNamesOptions {
content?: string;
scrollContent?: string;
scrollbar?: string;
track?: string;
}
}

View File

@@ -0,0 +1,51 @@
function test_start() {
new SimpleBar(document.getElementById('myElement'));
}
function test_options_wrapContent() {
new SimpleBar(document.getElementById('myElement'), { wrapContent: false });
}
function test_options_autoHide() {
new SimpleBar(document.getElementById('myElement'), { autoHide: false });
}
function test_options_scrollbarMinSize() {
new SimpleBar(document.getElementById('myElement'), { scrollbarMinSize: 10 });
}
function test_options_classNames() {
new SimpleBar(document.getElementById('myElement'), {
classNames: {
// defaults
content: 'simplebar-content',
scrollContent: 'simplebar-scroll-content',
scrollbar: 'simplebar-scrollbar',
track: 'simplebar-track'
}
});
}
function test_recalculate() {
const el = new SimpleBar(document.getElementById('myElement'));
el.recalculate();
}
function test_getScrollElement() {
const el = new SimpleBar(document.getElementById('myElement'));
el.getScrollElement();
}
function test_scrollEvent() {
const el = new SimpleBar(document.getElementById('myElement'));
el.getScrollElement().addEventListener('scroll', () => { });
}
function test_getContentElement() {
const el = new SimpleBar(document.getElementById('myElement'));
el.getContentElement();
}
function test_removeObserver() {
SimpleBar.removeObserver();
}

View File

@@ -0,0 +1,4 @@
import SimpleBar = require('simplebar');
// $ExpectType typeof SimpleBar
SimpleBar;

View File

@@ -0,0 +1,30 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"paths": {
"simplebar": [
"simplebar/v2"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"simplebar-tests.ts",
"test/module-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}