@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
36 lines (35 loc) • 1.67 kB
TypeScript
import { ESLMediaQuery } from './esl-media-query';
export type RulePayloadParser<T> = (val: string) => T | undefined;
/**
* ESL Media Rule
* @author Yuliya Adamskaya
*
* Helper class to wrap {@link ESLMediaQuery} with the payload value
* @see ESLMediaQuery
* @see ESLMediaRuleList
*/
export declare class ESLMediaRule<T = any> {
readonly query: ESLMediaQuery;
readonly payload: T;
constructor(payload: T, query?: string);
/** @returns if the inner {@link ESLMediaQuery} is matching current device configuration */
get matches(): boolean;
/** Subscribes on inner {@link ESLMediaQuery} changes */
addEventListener(callback: EventListener): void;
addEventListener(type: 'change', callback: EventListener): void;
/** Unsubscribes from inner {@link ESLMediaQuery} changes */
removeEventListener(callback: EventListener): void;
removeEventListener(type: 'change', callback: EventListener): void;
toString(): string;
/**
* Creates the {@link ESLMediaRule} instance from payload string, query and valueParser.
* If the payload parse result is undefined then rule will be undefined.
*/
static create<U>(payload: string, query: string, parser: RulePayloadParser<U>): ESLMediaRule<U> | undefined;
/** Parses the rule string to the {@link ESLMediaRule} instance */
static parse<U>(lex: string, parser: RulePayloadParser<U>): ESLMediaRule<U> | undefined;
/** Shortcut to create always active {@link ESLMediaRule} with passed value */
static all<U>(payload: U): ESLMediaRule<U>;
/** Shortcut to create always inactive {@link ESLMediaRule} */
static empty(): ESLMediaRule<undefined>;
}