Skip to content

Instantly share code, notes, and snippets.

@HenriBeck
Created July 6, 2018 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenriBeck/438f0cbd6c6168ccced47287b0d61f0e to your computer and use it in GitHub Desktop.
Save HenriBeck/438f0cbd6c6168ccced47287b0d61f0e to your computer and use it in GitHub Desktop.
React JSS Typings
// @flow strict-local
import {
type ComponentType,
type ElementConfig
} from 'react';
import type Jss from '../../packages/webapp/node_modules/jss/src/Jss';
import type SheetsRegistry from '../../packages/webapp/node_modules/jss/src/SheetsRegistry';
import { type generateClassName } from '../../packages/webapp/node_modules/jss/src/types/jss';
declare module 'react-jss' {
declare type Options = { index?: number };
declare type ExtractReturnType = <R>(() => R) => R;
declare export type Styles = { [key: string]: string | number | Styles };
declare export type StaticStyles = { [key: string]: Styles };
declare export type ThemedStyles = (theme: {}) => StaticStyles;
declare export type StaticClasses<Styles: StaticStyles> = { [key: $Keys<Styles>]: string };
declare export type ThemedClasses<Styles: ThemedStyles> = {
[key: $Keys<$Call<Styles, ExtractReturnType>>]: string,
};
declare type HOC<Comp: ComponentType> = ComponentType<
$Diff<ElementConfig<Comp>, { classes: {} }>,
>;
declare export class JssProvider extends React$Component<{
registry: SheetsRegistry,
jss: Jss,
classNamePrefix: string,
generateClassName: generateClassName,
disableStylesGeneration: boolean,
}> {}
declare export default function injectSheet<
Styles: StaticStyles,
Props: { classes: StaticClasses<Styles> },
Comp: ComponentType<Props>,
>(styles: Styles, options?: Options): (comp: Comp) => HOC<Comp>;
declare export default function injectSheet<
Styles: ThemedStyles,
Props: { classes: ThemedClasses<Styles> },
Comp: ComponentType<Props>,
>(styles: Styles, options?: Options): (comp: Comp) => HOC<Comp>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment