-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
styled-components.d.ts
117 lines (85 loc) 路 4.8 KB
/
styled-components.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import * as React from "react";
import { StatelessComponent, ComponentClass, PureComponent, ReactElement } from "react";
import { HTMLTags, SVGTags } from "./tags";
type Component<P> = ComponentClass<P> | StatelessComponent<P>;
export interface ThemeProps<T> {
theme: T;
}
export type ThemedStyledProps<P, T> = P & ThemeProps<T>;
export type StyledProps<P> = ThemedStyledProps<P, any>;
export type ThemedOuterStyledProps<P, T> = P & {
theme?: T;
innerRef?: (instance: any) => void;
};
export type OuterStyledProps<P> = ThemedOuterStyledProps<P, any>;
export type Interpolation<P> = FlattenInterpolation<P> | ReadonlyArray<FlattenInterpolation<P> | ReadonlyArray<FlattenInterpolation<P>>>;
export type FlattenInterpolation<P> = InterpolationValue | InterpolationFunction<P>;
export type InterpolationValue = string | number | StyledComponentClass<any, any>;
export type SimpleInterpolation = InterpolationValue | ReadonlyArray<InterpolationValue | ReadonlyArray<InterpolationValue>>;
export interface InterpolationFunction<P> {
(props: P): Interpolation<P>;
}
type Attrs<P, A extends Partial<P>, T> = {
[K in keyof A]: ((props: ThemedStyledProps<P, T>) => A[K]) | A[K];
};
export interface StyledComponentClass<P, T, O = P> extends ComponentClass<ThemedOuterStyledProps<O, T>> {
extend: ThemedStyledFunction<P, T, O>;
withComponent<K extends keyof HTMLTags>(tag: K): StyledComponentClass<React.HTMLProps<HTMLTags[K]>, T, O>;
withComponent<K extends keyof SVGTags>(tag: K): StyledComponentClass<React.SVGAttributes<SVGTags[K]>, T, O>;
withComponent(element: ComponentClass<P>): StyledComponentClass<P, T, O>;
}
export interface ThemedStyledFunction<P, T, O = P> {
(strings: TemplateStringsArray, ...interpolations: Interpolation<ThemedStyledProps<P, T>>[]): StyledComponentClass<P, T, O>;
<U>(strings: TemplateStringsArray, ...interpolations: Interpolation<ThemedStyledProps<P & U, T>>[]): StyledComponentClass<P & U, T, O & U>;
attrs<U, A extends Partial<P & U> = {}>(attrs: Attrs<P & U, A, T>): ThemedStyledFunction<P & A & U, T, O & U>;
}
export type StyledFunction<P> = ThemedStyledFunction<P, any>;
export type ThemedHtmlStyledFunction<E, T> = ThemedStyledFunction<React.HTMLProps<E>, T>;
export type HtmlStyledFunction<E> = ThemedHtmlStyledFunction<E, any>;
export type ThemedSvgStyledFunction<E extends SVGElement, T> = ThemedStyledFunction<React.SVGAttributes<E>, T>;
export type SvgStyledFunction<E extends SVGElement> = ThemedSvgStyledFunction<E, any>;
type ThemedStyledComponentFactoriesHTML<T> = {
[K in keyof HTMLTags]: ThemedHtmlStyledFunction<HTMLTags[K], T>;
};
type ThemedStyledComponentFactoriesSVG<T> = {
[K in keyof SVGTags]: ThemedSvgStyledFunction<SVGTags[K], T>;
};
type ThemedStyledComponentFactories<T> = ThemedStyledComponentFactoriesHTML<T> & ThemedStyledComponentFactoriesHTML<T>;
export interface ThemedBaseStyledInterface<T> extends ThemedStyledComponentFactories<T> {
<P>(component: Component<P>): ThemedStyledFunction<P, T>;
}
export type BaseStyledInterface = ThemedBaseStyledInterface<any>;
export type ThemedStyledInterface<T> = ThemedBaseStyledInterface<T>;
export type StyledInterface = ThemedStyledInterface<any>;
export interface ThemeProviderProps<T> {
theme?: T | ((theme: T) => T);
}
export type ThemeProviderComponent<T> = ComponentClass<ThemeProviderProps<T>>;
export interface ThemedCssFunction<T> {
(strings: TemplateStringsArray, ...interpolations: SimpleInterpolation[]): InterpolationValue[];
<P>(strings: TemplateStringsArray, ...interpolations: Interpolation<ThemedStyledProps<P, T>>[]): FlattenInterpolation<ThemedStyledProps<P, T>>[];
}
export interface ThemedStyledComponentsModule<T> {
default: ThemedStyledInterface<T>;
css: ThemedCssFunction<T>;
keyframes(strings: TemplateStringsArray, ...interpolations: SimpleInterpolation[]): string;
injectGlobal(strings: TemplateStringsArray, ...interpolations: SimpleInterpolation[]): void;
withTheme<P extends { theme?: T; }, T>(component: Component<P>): ComponentClass<P>;
ThemeProvider: ThemeProviderComponent<T>;
}
declare const styled: StyledInterface;
export const css: ThemedCssFunction<any>;
export function withTheme<P extends { theme?: T; }, T>(component: Component<P>): ComponentClass<P>;
export function keyframes(strings: TemplateStringsArray, ...interpolations: SimpleInterpolation[]): string;
export function injectGlobal(strings: TemplateStringsArray, ...interpolations: SimpleInterpolation[]): void;
export const ThemeProvider: ThemeProviderComponent<object>;
interface StylesheetComponentProps {
sheet: ServerStyleSheet;
}
export class StyleSheetManager extends React.Component<StylesheetComponentProps, {}> { }
export class ServerStyleSheet {
collectStyles(tree: React.ReactNode): ReactElement<StylesheetComponentProps>;
getStyleTags(): string;
getStyleElement(): ReactElement<{}>[];
}
export default styled;