🤖 Merge PR #65730 [minimasonry] Initial types for minimasonry by @plbstl

* add types for minimasonry 1.3

* update minimasonry types to be used through a default ESM import

* update minimasonry types to allow use as a browser script

* remove dtslint errors

- strict-export-declare-modifiers
- npm-naming
This commit is contained in:
Paul Ebose
2023-06-20 19:42:35 +01:00
committed by GitHub
parent c04d34a236
commit 56fbb35fb4
4 changed files with 129 additions and 0 deletions

85
types/minimasonry/index.d.ts vendored Normal file
View File

@@ -0,0 +1,85 @@
// Type definitions for minimasonry 1.3
// Project: https://spope.github.io/MiniMasonry.js/
// Definitions by: Paul Ebose <https://github.com/plbstl>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyType
export interface MiniMasonryOptions {
/**
* Target width of elements.
* @default 255
*/
baseWidth?: number;
/**
* Container's selector or element.
*/
container: string | HTMLElement;
/**
* Width / height of gutter between elements. Use gutterX / gutterY to set different values.
* @default 10
*/
gutter?: number;
/**
* Width of gutter between elements. Need gutterY to work, fallback to `gutter`.
*/
gutterX?: number;
/**
* Height of gutter between elements. Need gutterX to work, fallback to `gutter`.
*/
gutterY?: number;
/**
* Whether or not MiniMasonry places elements on the shortest column or keeps exact order of the list.
* @default true
*/
minify?: boolean;
/**
* Set left gutter on first columns and right gutter on last.
* @default true
*/
surroundingGutter?: boolean;
/**
* Gutter applied when only 1 column can be displayed.
* @default 5
*/
ultimateGutter?: number;
/**
* Sorting direction, "ltr" or "rtl".
* @default "ltr"
*/
direction?: 'ltr' | 'rtl';
/**
* False will start to sort from center, true will start from left or right according to direction parameter.
* @default false
*/
wedge?: boolean;
}
/**
* You should have a container **relatively positioned** with your elements as children. Those children elements must be **absolutely positioned**.
*
* MiniMasonry will add a "resize" event listener on the window to redraw the masonry on window resize. This listener is throttled to *66ms (15fps)*.
*
* @example
* import MiniMasonry from "minimasonry";
* const masonry = new MiniMasonry({
* container: '.masonry_transition'
* });
*/
// tslint:disable-next-line:npm-naming
export default class MiniMasonry {
constructor(options: MiniMasonryOptions);
/**
* If list has changed, trigger a re-layout of the masonry.
*/
layout(): void;
/**
* Remove the resize listener and set back container as it was before initialization.
*/
destroy(): void;
}
// browser global variable `MiniMasonry`
declare global {
interface Window {
MiniMasonry: MiniMasonry;
}
}

View File

@@ -0,0 +1,19 @@
import MiniMasonry from 'minimasonry';
// $ExpectType MiniMasonry
const masonry0 = window.MiniMasonry;
// $ExpectType MiniMasonry
const masonry = new MiniMasonry({ container: '' });
// @ts-expect-error
const masonry1 = new MiniMasonry(); // needs an argument
// @ts-expect-error
const masonry2 = new MiniMasonry(''); // wrong argument type
// @ts-expect-error
const masonry3 = new MiniMasonry({}); // `container` is required
// @ts-expect-error
const masonry4 = new MiniMasonry({ baseWidth: 255 }); // `container` is required

View File

@@ -0,0 +1,24 @@
{
"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",
"minimasonry-tests.ts"
]
}

View File

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