Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript support #3

Open
Dan503 opened this issue Sep 3, 2021 · 0 comments
Open

Add TypeScript support #3

Dan503 opened this issue Sep 3, 2021 · 0 comments

Comments

@Dan503
Copy link
Owner

Dan503 commented Sep 3, 2021

The world is moving to TypeScript.

This is still a useful library so it needs to keep up.

I've already made a start on writing out the Types needed for this:

type Callback = (screenSize: number) => void

type SimpleMq<BP> = (bp: keyof BP, cb?: Callback) => boolean
type ComplexMq<BP> = (bp1: keyof BP, bp2: keyof BP, cb?: Callback) => boolean
type ReactToCB = (isActive: boolean, screenSize: number) => void

export interface MqJs<BP extends object> {
	/** Returns `true` if the window size is **less than** the breakpoint size */
	min: SimpleMq<BP>,
	/** Returns `true` if the window size is **greater than** the breakpoint size */
	max: SimpleMq<BP>,
	/** Returns `true` if the window size is **greater than smaller** breakpoint but **less than the larger** breakpoint */
	inside: ComplexMq<BP>,
	/** Returns `true` if the window size is **less than the smaller breakpoint** or **greater than the larger** breakpoint */
	outside: ComplexMq<BP>,
	/** Runs a callback function every time `testMQ` changes from returning `true` to returning `false` */
	reactTo: (testMQ: () => boolean, cb: ReactToCB) => void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant