mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-18 12:08:59 +08:00
Merge pull request #9978 from asvetliakov/match-media-mock
Type definition for match-media-mock
This commit is contained in:
15
match-media-mock/match-media-mock-tests.ts
Normal file
15
match-media-mock/match-media-mock-tests.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="./match-media-mock.d.ts" />
|
||||
|
||||
import { create } from "match-media-mock";
|
||||
|
||||
const matchMediaMock = create();
|
||||
matchMediaMock.setConfig({type: 'screen', width: 1200})
|
||||
|
||||
matchMediaMock('(max-width: 991px)').matches // false
|
||||
matchMediaMock('(max-width: 1240px)').matches // true
|
||||
|
||||
const mediaQueryList = matchMediaMock('(max-width: 991px)');
|
||||
const listener = (mql: MediaQueryList) => { };
|
||||
|
||||
mediaQueryList.addListener(listener)
|
||||
mediaQueryList.removeListener(listener)
|
||||
35
match-media-mock/match-media-mock.d.ts
vendored
Normal file
35
match-media-mock/match-media-mock.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Type definitions for match-media-mock 0.1.0
|
||||
// Project: https://github.com/azazdeaz/match-media-mock
|
||||
// Definitions by: Alexey Svetliakov <https://github.com/asvetliakov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module "match-media-mock" {
|
||||
/**
|
||||
* Mock configuration options
|
||||
*/
|
||||
interface ConfigOptions {
|
||||
/**
|
||||
* Screen type
|
||||
*/
|
||||
type?: string;
|
||||
/**
|
||||
* Screen height
|
||||
*/
|
||||
height?: number;
|
||||
/**
|
||||
* Screen width
|
||||
*/
|
||||
width?: number;
|
||||
}
|
||||
interface MatchMediaMock {
|
||||
/**
|
||||
* Set configuration
|
||||
*/
|
||||
setConfig(config: ConfigOptions): void;
|
||||
/**
|
||||
* Execute query based on provided configuration
|
||||
*/
|
||||
(query: string): MediaQueryList;
|
||||
}
|
||||
export function create(): MatchMediaMock;
|
||||
}
|
||||
Reference in New Issue
Block a user