UNPKG

13.8 kBTypeScriptView Raw
1import { E as EmotionCache, I as Interpolation, C as CSSInterpolation, S as SerializedStyles, K as Keyframes, a as ComponentSelector, b as StorybookTheme, T as Typography, c as Color, B as Background, d as ThemeVars, F as FunctionInterpolation } from './create-e8afafc2.js';
2export { A as Animation, l as Brand, e as CSSObject, j as Easing, k as TextSize, i as ThemeVarsColors, h as ThemeVarsPartial, g as background, f as color, n as create, m as themes, t as typography } from './create-e8afafc2.js';
3import * as React$1 from 'react';
4import { Provider, ReactElement, createElement, ReactNode } from 'react';
5
6// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
7// TypeScript Version: 2.2
8
9
10interface StylisElement {
11 type: string
12 value: string
13 props: Array<string> | string
14 root: StylisElement | null
15 parent: StylisElement | null
16 children: Array<StylisElement> | string
17 line: number
18 column: number
19 length: number
20 return: string
21}
22type StylisPluginCallback = (
23 element: StylisElement,
24 index: number,
25 children: Array<StylisElement>,
26 callback: StylisPluginCallback
27) => string | void
28
29type StylisPlugin = (
30 element: StylisElement,
31 index: number,
32 children: Array<StylisElement>,
33 callback: StylisPluginCallback
34) => string | void
35
36interface Options {
37 nonce?: string
38 stylisPlugins?: Array<StylisPlugin>
39 key: string
40 container?: Node
41 speedy?: boolean
42 /** @deprecate use `insertionPoint` instead */
43 prepend?: boolean
44 insertionPoint?: HTMLElement
45}
46
47declare function createCache(options: Options): EmotionCache
48
49type WithConditionalCSSProp<P> = 'className' extends keyof P
50 ? string extends P['className' & keyof P]
51 ? { css?: Interpolation<Theme> }
52 : {}
53 : {}
54
55// unpack all here to avoid infinite self-referencing when defining our own JSX namespace
56type ReactJSXElement = JSX.Element
57type ReactJSXElementClass = JSX.ElementClass
58type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty
59type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute
60type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>
61type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes
62type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>
63type ReactJSXIntrinsicElements = JSX.IntrinsicElements
64
65// based on the code from @types/react@18.2.8
66// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13
67type ReactJSXElementType = string | React.JSXElementConstructor<any>
68
69declare namespace EmotionJSX {
70 type ElementType = ReactJSXElementType
71 interface Element extends ReactJSXElement {}
72 interface ElementClass extends ReactJSXElementClass {}
73 interface ElementAttributesProperty
74 extends ReactJSXElementAttributesProperty {}
75 interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}
76
77 type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
78 ReactJSXLibraryManagedAttributes<C, P>
79
80 interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
81 interface IntrinsicClassAttributes<T>
82 extends ReactJSXIntrinsicClassAttributes<T> {}
83
84 type IntrinsicElements = {
85 [K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
86 css?: Interpolation<Theme>
87 }
88 }
89}
90
91/**
92 * @desc Utility type for getting props type of React component.
93 * It takes `defaultProps` into an account - making props with defaults optional.
94 */
95type PropsOf<
96 C extends keyof JSX.IntrinsicElements | React$1.JSXElementConstructor<any>
97> = JSX.LibraryManagedAttributes<C, React$1.ComponentProps<C>>
98
99// We need to use this version of Omit as it's distributive (Will preserve unions)
100type DistributiveOmit<T, U> = T extends any
101 ? Pick<T, Exclude<keyof T, U>>
102 : never
103
104// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
105// TypeScript Version: 3.1
106
107
108
109interface ThemeProviderProps {
110 theme: Partial<Theme> | ((outerTheme: Theme) => Theme)
111 children: React$1.ReactNode
112}
113
114declare function useTheme(): Theme
115
116interface ThemeProvider {
117 (props: ThemeProviderProps): React$1.ReactElement
118}
119
120declare const ThemeProvider: ThemeProvider
121
122type withTheme = <
123 C extends React$1.ComponentType<React$1.ComponentProps<C>>
124>(
125 component: C
126) => React$1.FC<DistributiveOmit<PropsOf<C>, 'theme'> & { theme?: Theme }>
127
128declare const withTheme: withTheme
129
130// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
131// TypeScript Version: 3.4
132
133
134
135// tslint:disable-next-line: no-empty-interface
136interface Theme {}
137declare const CacheProvider: Provider<EmotionCache>
138
139declare function css(
140 template: TemplateStringsArray,
141 ...args: Array<CSSInterpolation>
142): SerializedStyles
143declare function css(...args: Array<CSSInterpolation>): SerializedStyles
144
145interface GlobalProps {
146 styles: Interpolation<Theme>
147}
148
149/**
150 * @desc
151 * JSX generic are supported only after TS@2.9
152 */
153declare function Global(props: GlobalProps): ReactElement
154
155declare function keyframes(
156 template: TemplateStringsArray,
157 ...args: Array<CSSInterpolation>
158): Keyframes
159declare function keyframes(...args: Array<CSSInterpolation>): Keyframes
160
161interface ArrayClassNamesArg extends Array<ClassNamesArg> {}
162type ClassNamesArg =
163 | undefined
164 | null
165 | string
166 | boolean
167 | { [className: string]: boolean | null | undefined }
168 | ArrayClassNamesArg
169
170interface ClassNamesContent {
171 css(template: TemplateStringsArray, ...args: Array<CSSInterpolation>): string
172 css(...args: Array<CSSInterpolation>): string
173 cx(...args: Array<ClassNamesArg>): string
174 theme: Theme
175}
176interface ClassNamesProps {
177 children(content: ClassNamesContent): ReactNode
178}
179/**
180 * @desc
181 * JSX generic are supported only after TS@2.9
182 */
183declare function ClassNames(props: ClassNamesProps): ReactElement
184
185declare const jsx: typeof createElement
186declare namespace jsx {
187 namespace JSX {
188 type ElementType = EmotionJSX.ElementType
189 interface Element extends EmotionJSX.Element {}
190 interface ElementClass extends EmotionJSX.ElementClass {}
191 interface ElementAttributesProperty
192 extends EmotionJSX.ElementAttributesProperty {}
193 interface ElementChildrenAttribute
194 extends EmotionJSX.ElementChildrenAttribute {}
195 type LibraryManagedAttributes<C, P> = EmotionJSX.LibraryManagedAttributes<
196 C,
197 P
198 >
199 interface IntrinsicAttributes extends EmotionJSX.IntrinsicAttributes {}
200 interface IntrinsicClassAttributes<T>
201 extends EmotionJSX.IntrinsicClassAttributes<T> {}
202 type IntrinsicElements = EmotionJSX.IntrinsicElements
203 }
204}
205
206// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
207// TypeScript Version: 3.2
208
209
210
211/** Same as StyledOptions but shouldForwardProp must be a type guard */
212interface FilteringStyledOptions<
213 Props = Record<string, any>,
214 ForwardedProps extends keyof Props & string = keyof Props & string
215> {
216 label?: string
217 shouldForwardProp?: (propName: string) => propName is ForwardedProps
218 target?: string
219}
220
221interface StyledOptions<Props = Record<string, any>> {
222 label?: string
223 shouldForwardProp?: (propName: string) => boolean
224 target?: string
225}
226
227/**
228 * @typeparam ComponentProps Props which will be included when withComponent is called
229 * @typeparam SpecificComponentProps Props which will *not* be included when withComponent is called
230 */
231interface StyledComponent<
232 ComponentProps extends {},
233 SpecificComponentProps extends {} = {},
234 JSXProps extends {} = {}
235> extends React$1.FC<ComponentProps & SpecificComponentProps & JSXProps>,
236 ComponentSelector {
237 withComponent<C extends React$1.ComponentClass<React$1.ComponentProps<C>>>(
238 component: C
239 ): StyledComponent<
240 ComponentProps & PropsOf<C>,
241 {},
242 { ref?: React$1.Ref<InstanceType<C>> }
243 >
244 withComponent<C extends React$1.ComponentType<React$1.ComponentProps<C>>>(
245 component: C
246 ): StyledComponent<ComponentProps & PropsOf<C>>
247 withComponent<Tag extends keyof JSX.IntrinsicElements>(
248 tag: Tag
249 ): StyledComponent<ComponentProps, JSX.IntrinsicElements[Tag]>
250}
251
252/**
253 * @typeparam ComponentProps Props which will be included when withComponent is called
254 * @typeparam SpecificComponentProps Props which will *not* be included when withComponent is called
255 */
256interface CreateStyledComponent<
257 ComponentProps extends {},
258 SpecificComponentProps extends {} = {},
259 JSXProps extends {} = {}
260> {
261 /**
262 * @typeparam AdditionalProps Additional props to add to your styled component
263 */
264 <AdditionalProps extends {} = {}>(
265 ...styles: Array<
266 Interpolation<
267 ComponentProps &
268 SpecificComponentProps &
269 AdditionalProps & { theme: Theme }
270 >
271 >
272 ): StyledComponent<
273 ComponentProps & AdditionalProps,
274 SpecificComponentProps,
275 JSXProps
276 >
277
278 (
279 template: TemplateStringsArray,
280 ...styles: Array<
281 Interpolation<ComponentProps & SpecificComponentProps & { theme: Theme }>
282 >
283 ): StyledComponent<ComponentProps, SpecificComponentProps, JSXProps>
284
285 /**
286 * @typeparam AdditionalProps Additional props to add to your styled component
287 */
288 <AdditionalProps extends {}>(
289 template: TemplateStringsArray,
290 ...styles: Array<
291 Interpolation<
292 ComponentProps &
293 SpecificComponentProps &
294 AdditionalProps & { theme: Theme }
295 >
296 >
297 ): StyledComponent<
298 ComponentProps & AdditionalProps,
299 SpecificComponentProps,
300 JSXProps
301 >
302}
303
304/**
305 * @desc
306 * This function accepts a React component or tag ('div', 'a' etc).
307 *
308 * @example styled(MyComponent)({ width: 100 })
309 * @example styled(MyComponent)(myComponentProps => ({ width: myComponentProps.width })
310 * @example styled('div')({ width: 100 })
311 * @example styled('div')<Props>(props => ({ width: props.width })
312 */
313interface CreateStyled$1 {
314 <
315 C extends React$1.ComponentClass<React$1.ComponentProps<C>>,
316 ForwardedProps extends keyof React$1.ComponentProps<C> &
317 string = keyof React$1.ComponentProps<C> & string
318 >(
319 component: C,
320 options: FilteringStyledOptions<React$1.ComponentProps<C>, ForwardedProps>
321 ): CreateStyledComponent<
322 Pick<PropsOf<C>, ForwardedProps> & {
323 theme?: Theme
324 },
325 {},
326 {
327 ref?: React$1.Ref<InstanceType<C>>
328 }
329 >
330
331 <C extends React$1.ComponentClass<React$1.ComponentProps<C>>>(
332 component: C,
333 options?: StyledOptions<React$1.ComponentProps<C>>
334 ): CreateStyledComponent<
335 PropsOf<C> & {
336 theme?: Theme
337 },
338 {},
339 {
340 ref?: React$1.Ref<InstanceType<C>>
341 }
342 >
343
344 <
345 C extends React$1.ComponentType<React$1.ComponentProps<C>>,
346 ForwardedProps extends keyof React$1.ComponentProps<C> &
347 string = keyof React$1.ComponentProps<C> & string
348 >(
349 component: C,
350 options: FilteringStyledOptions<React$1.ComponentProps<C>, ForwardedProps>
351 ): CreateStyledComponent<
352 Pick<PropsOf<C>, ForwardedProps> & {
353 theme?: Theme
354 }
355 >
356
357 <C extends React$1.ComponentType<React$1.ComponentProps<C>>>(
358 component: C,
359 options?: StyledOptions<React$1.ComponentProps<C>>
360 ): CreateStyledComponent<
361 PropsOf<C> & {
362 theme?: Theme
363 }
364 >
365
366 <
367 Tag extends keyof JSX.IntrinsicElements,
368 ForwardedProps extends keyof JSX.IntrinsicElements[Tag] &
369 string = keyof JSX.IntrinsicElements[Tag] & string
370 >(
371 tag: Tag,
372 options: FilteringStyledOptions<JSX.IntrinsicElements[Tag], ForwardedProps>
373 ): CreateStyledComponent<
374 { theme?: Theme; as?: React$1.ElementType },
375 Pick<JSX.IntrinsicElements[Tag], ForwardedProps>
376 >
377
378 <Tag extends keyof JSX.IntrinsicElements>(
379 tag: Tag,
380 options?: StyledOptions<JSX.IntrinsicElements[Tag]>
381 ): CreateStyledComponent<
382 { theme?: Theme; as?: React$1.ElementType },
383 JSX.IntrinsicElements[Tag]
384 >
385}
386
387// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
388// TypeScript Version: 3.2
389
390
391
392type StyledTags = {
393 [Tag in keyof JSX.IntrinsicElements]: CreateStyledComponent<
394 {
395 theme?: Theme
396 as?: React.ElementType
397 },
398 JSX.IntrinsicElements[Tag]
399 >
400}
401
402interface CreateStyled extends CreateStyled$1, StyledTags {}
403
404declare const styled: CreateStyled
405
406declare module '@emotion/react' {
407 type StorybookTheme = StorybookTheme;
408 export interface Theme extends StorybookTheme {}
409}
410
411// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
412// TypeScript Version: 2.1
413
414declare function isPropValid(prop: string): boolean
415
416type Value = string | number;
417interface Return {
418 [key: string]: {
419 [key: string]: Value;
420 };
421}
422declare const createReset: ({ typography }: {
423 typography: Typography;
424}) => Return;
425declare const createGlobal: ({ color, background, typography, }: {
426 color: Color;
427 background: Background;
428 typography: Typography;
429}) => Return;
430
431declare const convert: (inherit?: ThemeVars) => StorybookTheme;
432
433declare const ensure: (input: ThemeVars) => StorybookTheme;
434
435declare const lightenColor: (color: string) => string;
436declare const darkenColor: (color: string) => string;
437
438type FunctionInterpolationEnhanced<T = {}> = FunctionInterpolation<T & {
439 theme: StorybookTheme;
440}>;
441type InterpolationEnhanced<T = {}> = Interpolation<T & {
442 theme: StorybookTheme;
443}>;
444
445declare const ignoreSsrWarning = "/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */";
446
447export { Background, CacheProvider, ClassNames, Color, FunctionInterpolationEnhanced as FunctionInterpolation, Global, InterpolationEnhanced as Interpolation, Keyframes, StorybookTheme, StyledComponent, ThemeProvider, ThemeVars, Typography, convert, createCache, createGlobal, createReset, css, darkenColor as darken, ensure, ignoreSsrWarning, isPropValid, jsx, keyframes, lightenColor as lighten, styled, useTheme, withTheme };
448
449interface Theme extends StorybookTheme {}
450export type { Theme };
\No newline at end of file