UNPKG

@twstyled/core

Version:

twstyled -- the full-featured Tailwind CSS + CSS in JS solution with blazing fast build times and no runtime overhead

32 lines (31 loc) 2.16 kB
/** * This file contains an runtime version of `styled` component. Responsibilities of the component are: * - returns ReactElement based on HTML tag used with `styled` or custom React Component * - injects classNames for the returned component * - injects CSS variables used to define dynamic styles based on props */ import { FC } from 'react'; import type { CSSProperties, StyledMeta } from './types'; export type { CSSProperties } from './types'; export declare type NoInfer<A extends any> = [A][A extends any ? 0 : never]; declare function styled<TConstructor extends FC<any>>(tag: TConstructor extends FC<infer T> ? T extends { className?: string; } ? TConstructor : never : never): ComponentStyledTag<TConstructor>; declare function styled<T>(tag: T extends { className?: string; } ? React.ComponentType<T> : never): ComponentStyledTag<T>; declare function styled<TName extends keyof JSX.IntrinsicElements>(tag: TName): HtmlStyledTag<TName>; declare type StyledComponent<T> = StyledMeta & (T extends FC<any> ? T : FC<T & { as?: React.ElementType; }>); declare type StaticPlaceholder = string | number | CSSProperties | StyledMeta; declare type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <TAdditionalProps = {}>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>) => string | number)>) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>; declare type ComponentStyledTag<T> = <OwnProps = {}, TrgProps = T extends FC<infer TProps> ? TProps : T>(strings: TemplateStringsArray, ...exprs: TrgProps extends { style?: React.CSSProperties; } ? Array<StaticPlaceholder | ((props: NoInfer<OwnProps & TrgProps>) => string | number)> : StaticPlaceholder[]) => keyof OwnProps extends never ? T extends FC<any> ? StyledMeta & T : StyledComponent<TrgProps> : StyledComponent<OwnProps & TrgProps>; declare type StyledJSXIntrinsics = { readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>; }; export declare type Styled = typeof styled & StyledJSXIntrinsics; declare const _default: Styled; export default _default;