// Type definitions for jss 9.3 // Project: https://github.com/cssinjs/jss#readme // Definitions by: Brenton Simpson // Oleg Slobodskoi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 export interface Rule { className: string; selector: string; applyTo(element: HTMLElement): void; prop(key: string): string; prop(key: string, value: any): this; toJSON(): string; } export interface StyleSheet { // Gives auto-completion on the rules declared in `createStyleSheet` without // causing errors for rules added dynamically after creation. classes: { [K in keyof T]: string; } & { [key: string]: string }; options: any; linked: boolean; attached: boolean; /** * Attach renderable to the render tree. */ attach(): this; /** * Remove renderable from render tree. */ detach(): this; /** * Add a rule to the current stylesheet. * Will insert a rule also after the stylesheet has been rendered first time. */ addRule(style: Style, options?: Partial): Rule; addRule(name: string, style: Style, options?: Partial): Rule; /** * Create and add rules. * Will render also after Style Sheet was rendered the first time. */ addRules(styles: { [key: string]: Style }, options?: Partial): Rule[]; /** * Get a rule by name. */ getRule(name: string): Rule; /** * Delete a rule by name. * Returns `true`: if rule has been deleted from the DOM. */ deleteRule(name: string): boolean; /** * Get index of a rule. */ indexOf(rule: Rule): number; /** * Update the function values with a new data. */ update(data?: {}): this; update(name: string, data: {}): this; /** * Convert rules to a CSS string. */ toString(options?: { indent?: number }): string; } export type GenerateClassName = (rule: Rule, sheet?: StyleSheet) => string; export interface Style { [key: string]: any; } export interface JSSPlugin { [key: string]: () => Partial<{ onCreateRule(name: string, style: Style, options: RuleOptions): Rule, onProcessRule(rule: Rule, sheet: StyleSheet): void, onProcessStyle(style: Style, rule: Rule, sheet: StyleSheet): Style, onProcessSheet(sheet: StyleSheet): void, onChangeValue(value: any, prop: string, rule: Rule): any, onUpdate(data: {}, rule: Rule, sheet: StyleSheet): void, }>; } export interface JSSOptions { createGenerateClassName(): GenerateClassName; plugins: ReadonlyArray; virtual: boolean; insertionPoint: string | HTMLElement; } export interface RuleFactoryOptions { selector: string; classes: { [key: string]: string }; sheet: StyleSheet; index: number; jss: JSS; generateClassName: GenerateClassName; } export interface RuleOptions { index: number; className: string; } declare class JSS { constructor(options?: Partial); createStyleSheet( styles: T, options?: Partial<{ media: string, meta: string, link: boolean, element: HTMLStyleElement, index: number, generateClassName: GenerateClassName, classNamePrefix: string, }>, ): StyleSheet; removeStyleSheet(sheet: StyleSheet): this; setup(options?: Partial): this; use(plugin: JSSPlugin): this; createRule(style: Style, options?: Partial): Rule; createRule(name: string, style: Style, options?: Partial): Rule; } /** * Creates a new instance of JSS. */ export function create(options?: Partial): JSS; declare const sharedInstance: JSS; /** * A global JSS instance. */ export default sharedInstance;