add types for halfmoon (#46789)

* add types for Halfmoon

* add pageWrapper and stickyAlerts

* update halfmoon tests
This commit is contained in:
Jadie-Wadie 2020-08-21 14:42:36 +09:30 committed by GitHub
parent fd8aaff6bb
commit cd2a2ace59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,46 @@
import halfmoon = require('halfmoon');
halfmoon.pageWrapper; // $ExpectType Element
halfmoon.stickyAlerts; // $ExpectType Element
halfmoon.darkModeOn; // $ExpectType "yes" | "no"
halfmoon.createCookie('darkModeOn', 'yes'); // $ExpectType void
halfmoon.createCookie('darkModeOn', 'yes', 10); // $ExpectType void
halfmoon.readCookie('darkModeOn'); // $ExpectType string | null
halfmoon.eraseCookie('darkModeOn'); // $ExpectType void
halfmoon.toggleDarkMode(); // $ExpectType void
halfmoon.toggleSidebar(); // $ExpectType void
halfmoon.deactivateAllDropdownToggles(); // $ExpectType void
halfmoon.toggleModal('modal'); // $ExpectType void
halfmoon.makeId(16); // $ExpectType string
halfmoon.toastAlert('alert'); // $ExpectType void
halfmoon.toastAlert('alert', 1000); // $ExpectType void
const stickyAlert = {
content: '',
title: '',
alertType: '',
fillType: '',
hasDismissButton: true,
timeShown: 1000,
};
halfmoon.initStickyAlert(stickyAlert); // $ExpectType void
halfmoon.clickHandler = event => {
event.preventDefault();
};
halfmoon.keydownHandler = event => {
event.preventDefault();
};
halfmoon.onDOMContentLoaded(); // $ExpectType void

80
types/halfmoon/index.d.ts vendored Normal file
View File

@ -0,0 +1,80 @@
// Type definitions for halfmoon 1.0
// Project: https://github.com/halfmoonui/halfmoon#readme
// Definitions by: Jadie Wadie <https://github.com/Jadie-Wadie>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export const pageWrapper: Element;
export const stickyAlerts: Element;
/** The value of the `darkModeOn` cookie. */
export let darkModeOn: 'yes' | 'no';
/**
* Create a cookie.
* @param name The name of the cookie.
* @param value The value of the cookie.
* @param days The duration the cookie should expire after.
*/
export function createCookie(name: string, value: string, days?: number): void;
/**
* Read a cookie.
* @param name The name of the cookie.
*/
export function readCookie(name: string): string | null;
/**
* Erase a cookie.
* @param name The name of the cookie.
*/
export function eraseCookie(name: string): void;
/** Toggle dark mode. This also updates the cookie. */
export function toggleDarkMode(): void;
/** Toggle the sidebar. */
export function toggleSidebar(): void;
/** Deactivate all the dropdown toggles when another one is active. */
export function deactivateAllDropdownToggles(): void;
/**
* Toggle a modal.
* @param modalId The ID of the modal.
*/
export function toggleModal(modalId: string): void;
/**
* Make an ID for an element
* @param length The length of the ID.
*/
export function makeId(length: number): string;
/**
* Toast an alert.
* @param alertId The ID of the alert.
* @param timeShown The duration the toast should hide after.
*/
export function toastAlert(alertId: string, timeShown?: number): void;
/**
* Initialise a sticky alert.
* @param param Parameters for the sticky alert.
*/
export function initStickyAlert(param: {
content?: string;
title?: string;
alertType?: string;
fillType?: string;
hasDismissButton?: boolean;
timeShown?: number;
}): void;
/** An overridable click handler, to avoid adding another event listener to the DOM */
export function clickHandler(this: Document, event: MouseEvent): void;
/** An overridable keydown handler, to avoid adding another event listener to the DOM */
export function keydownHandler(this: Document, event: KeyboardEvent): void;
/** Manually initialise components that require JavaScript, such as dropdowns, custom file inputs, shortcuts, etc. */
export function onDOMContentLoaded(): void;

View File

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

View File

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