// Type definitions for styletron-react 5.0 // Project: https://github.com/styletron/styletron // Definitions by: Eric Taylor // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 import * as React from 'react'; import { driver, StandardEngine, StyleObject } from 'styletron-standard'; export { StyleObject, StandardEngine }; // From styletron-react types export interface Reducer { // Static reducer = no props, dynamic requires props object (style: StyleObject, props?: object): StyleObject; } export interface AssignmentCommutativeReducerContainer { assignmentCommutative: true; reducer: Reducer; style: StyleObject; factory: (style: StyleObject) => AssignmentCommutativeReducerContainer; } export interface NonAssignmentCommutativeReducerContainer { assignmentCommutative: false; reducer: Reducer; } export type ReducerContainer = AssignmentCommutativeReducerContainer | NonAssignmentCommutativeReducerContainer; export type StackIndex = number; // See addDebugMetadata in dev-tool.js export interface StackInfo { stack: string | undefined; stacktrace: any; message: string; } export type StyletronBase = React.ElementType; export type StyletronDriver = typeof driver; export type StyletronGetInitialStyle = () => StyleObject; export type StyletronWrapper = (fc: React.FC) => React.ComponentType; export interface Styletron { reducers: ReadonlyArray; base: StyletronBase; driver: StyletronDriver; wrapper: StyletronWrapper; getInitialStyle: StyletronGetInitialStyle; debug?: { stackIndex: StackIndex; stackInfo: StackInfo; }; } export type StyleObjectFn

= (props: P) => StyleObject; export type $StyleProp

= StyleObject | StyleObjectFn

; export interface StyletronComponentInjectedProps

{ $as?: StyletronBase; $style?: $StyleProp

; } export type StyletronComponent

= React.FC

> & { __STYLETRON__: Styletron; }; export interface StyledFn { , P extends object>( component: C, style: (props: P) => StyleObject, ): StyletronComponent< Pick, Exclude, { className: string }>> & P >; >( component: C, style: StyleObject, ): StyletronComponent, Exclude, { className: string }>>>; } export interface WithStyleFn { , P extends object>( component: C, style: (props: P) => StyleObject, ): StyletronComponent & P>; >(component: C, style: StyleObject): StyletronComponent>; } export interface WithTransformFn { , P extends object>( component: C, style: (style: StyleObject, props: P) => StyleObject, ): StyletronComponent & P>; } export interface WithWrapperFn { , P extends object>( component: C, wrapper: (component: C) => React.ComponentType

, ): StyletronComponent & P>; } // ^^^^^^^^^^^^^^^^^^^^^^^^^ // End of style-types export class BrowserDebugEngine { debug(stack: { stackIndex: StackIndex; stackInfo: StackInfo }): string; } export class NoopDebugEngine { debug(): void; } export const DebugEngine: typeof BrowserDebugEngine | typeof NoopDebugEngine; export type DebugEngine = BrowserDebugEngine | NoopDebugEngine; export interface DevProviderProps { children: React.ReactNode; value: StandardEngine; debugAfterHydration?: boolean; /** DebugEngineContext */ debug?: DebugEngine; } export class DevProvider extends React.Component {} export const Provider: typeof DevProvider | React.Provider; export function DevConsumer(props: { children: (styletronEngine: StandardEngine, debugEngine: DebugEngine, hydrating: boolean) => React.ReactNode; }): JSX.Element; /** * @param style the StyleObject * @returns string to be used in className prop of JSX.Element */ export type CSSFn = (style: StyleObject) => string; export function useStyletron(): Readonly<[CSSFn]>; export interface CreateStyledOptions { getInitialStyle: StyletronGetInitialStyle; driver: StyletronDriver; wrapper: StyletronWrapper; } export function createStyled(options: CreateStyledOptions): StyledFn; export const styled: ReturnType; export function createStyledElementComponent(styletron: Styletron): StyletronComponent; export const withTransform: WithTransformFn; export const withStyleDeep: WithStyleFn; /** * Aliases to withStyleDeep() * @deprecated use withStyleDeep() */ export const withStyle: typeof withStyleDeep; export const withWrapper: WithWrapperFn; export function composeStatic(styletron: Styletron, reducerContainer: ReducerContainer): Styletron; export function composeDynamic( styletron: Styletron, reducer: (style: StyleObject, props: object) => StyleObject, ): Styletron; export function staticComposeShallow(styletron: Styletron, style: StyleObject): ReturnType; export function staticComposeDeep(styletron: Styletron, style: StyleObject): ReturnType; export function dynamicComposeShallow( styletron: Styletron, styleArg: (props: object) => StyleObject, ): ReturnType; export function dynamicComposeDeep( styletron: Styletron, styleArg: (props: object) => StyleObject, ): ReturnType; export function autoComposeShallow( styletron: Styletron, styleArg: StyleObject | ((props: object) => StyleObject), ): ReturnType; export function autoComposeDeep(styletron: Styletron, styleArg: StyleObject): ReturnType; export function autoComposeDeep( styletron: Styletron, styleArg: (props: object) => StyleObject, ): ReturnType; export function createShallowMergeReducer(style: StyleObject): AssignmentCommutativeReducerContainer; export function createDeepMergeReducer(style: StyleObject): AssignmentCommutativeReducerContainer; // Utility functions export function resolveStyle( getInitialStyle: () => StyleObject, reducers: ReadonlyArray, props: object, ): StyleObject;