UNPKG

3.19 kBTypeScriptView Raw
1import { ComponentType, FunctionComponent } from 'react';
2import { ISystem } from './system';
3import { IThemeSettings } from './theme';
4export interface IComponentOptions<TProps extends object, TStyle> extends IStylingOptions<TProps, TStyle> {
5 passthrough?: boolean;
6}
7export interface IComponentFactoryOptions<TProps extends object, TStyle> extends IStylingOptions<TProps, TStyle> {
8 style?: TStyle | StylingFn<TProps, TStyle>;
9}
10export interface IComponentStylesRegistry<TStyle> {
11 [componentName: string]: Array<IStyler<any, TStyle>>;
12}
13export interface IDSComponent<TProps extends object> extends FunctionComponent<TProps> {
14 $$nprdds: boolean;
15}
16export declare type IDSProps<TStylerProps> = {
17 as?: string | ComponentType<any> | IDSComponent<any>;
18} & TStylerProps;
19export interface IStyleCache {
20 get<T = any>(name: string): T | void;
21 set<T = any>(name: string, value: T): T;
22}
23export interface IStylingOptions<TProps extends object, TStyle> {
24 cacheProps?: string[];
25 styles?: Array<IStyler<TProps, TStyle>>;
26 stripProps?: string[];
27}
28export interface IStyler<TProps extends object, TStyle = {}> {
29 apply: StylingFn<TProps, TStyle>;
30 propNames: Array<keyof TProps>;
31 stripProps: Array<keyof TProps>;
32}
33export declare type extractStylerProps<Type> = Type extends IStyler<infer x, any> ? x : object;
34export interface IInternalDSProps<TStyle> {
35 compPath?: string[];
36 stripProps?: string[];
37 stylers?: Array<IStyler<any, TStyle>>;
38}
39export interface IStyleApplicator<TStyleProps extends object, TStyle> {
40 apply<TProps extends object>(componentName: string, props: Partial<IInternalDSProps<TStyle> & TStyleProps> & TProps, system: ISystem, componentOptions: IComponentOptions<TProps, TStyle>): IInternalDSProps<TStyle> & TStyleProps & TProps;
41}
42export interface ITheme {
43 color(valueOrName: string, defaultValueOrName?: string): string;
44 get(attributeName: keyof IThemeSettings, defaultValue?: any): any;
45}
46export declare type ComponentFactory<TStyleProps extends object, TStyle = {}, TPropsDefault extends object = {}, TAsPropsDefault extends object = {}> = <TProps extends object = TPropsDefault, TAsProps extends object = TAsPropsDefault>(componentName: string, component: string | ComponentType<TAsProps> | IDSComponent<TAsProps>, options?: IComponentFactoryOptions<TProps, TStyle>) => IDSComponent<TProps & TAsProps & IDSProps<TStyleProps> & TStyleProps & {
47 [key: string]: any;
48}>;
49export declare type StyleCacheKeyFn = (props: object, cacheProps: string[], viewport: number, compPath?: string[], componentName?: string) => string;
50export declare type StyleApplicatorFactory<TStyle, TProps extends object = {}> = (options: {
51 cache: IStyleCache;
52 cacheKeyFn?: StyleCacheKeyFn;
53 componentStyles: IComponentStylesRegistry<TStyle>;
54 globalStyles: Array<IStyler<any, TStyle>>;
55}) => IStyleApplicator<TProps, TStyle>;
56export declare type StylerCreatorFn<TProps extends object, TStyle> = (propNames: string[], style: TStyle | StylingFn<TProps, TStyle>, stripProps?: string[]) => IStyler<TProps, TStyle>;
57export declare type StylingFn<TProps extends object, TStyle> = (props: TProps, designSystem: ISystem) => TStyle;