tailwind-styled-components
Advanced tools
Comparing version 2.1.2 to 2.1.4
import React from "react"; | ||
export declare type IntrinsicElementsKeys = keyof JSX.IntrinsicElements; | ||
declare const isTwElement: unique symbol; | ||
declare type IntrinsicElementsKeys = keyof JSX.IntrinsicElements; | ||
export declare const mergeArrays: (template: TemplateStringsArray, templateElements: (string | undefined | null)[]) => (string | null | undefined)[]; | ||
export declare const cleanTemplate: (template: (string | undefined | null)[], inheritedClasses?: string) => string; | ||
declare type TransientProps = Record<`$${string}`, any>; | ||
declare type NoInfer<T> = [T][T extends any ? 0 : never]; | ||
declare type StripCallSignature<T> = { | ||
[K in keyof T]: T[K]; | ||
}; | ||
export interface TailwindComponent<P extends {}> extends StripCallSignature<React.ForwardRefExoticComponent<P>> { | ||
(props: P & { | ||
export declare type TailwindComponentProps<E extends React.ComponentType<any> | IntrinsicElementsKeys, K extends object> = K extends any ? React.ComponentPropsWithoutRef<E> & React.RefAttributes<React.ComponentRef<E> | undefined> & K : never; | ||
declare type TailwindComponentPropsWith$As<E extends React.ComponentType<any> | IntrinsicElementsKeys, K extends object, As extends IntrinsicElementsKeys | React.ComponentType<any> = E> = TailwindComponentProps<E, K> & InnerTailwindComponentAllProps<As> & { | ||
$as?: As; | ||
}; | ||
export declare type TailwindExoticComponent<E extends React.ComponentType<any> | IntrinsicElementsKeys, K extends object> = StripCallSignature<React.ForwardRefExoticComponent<TailwindComponentProps<E, K>>>; | ||
export interface TailwindComponent<E extends React.ComponentType<any> | IntrinsicElementsKeys, K extends object> extends TailwindExoticComponent<E, K> { | ||
(props: TailwindComponentProps<E, K> & { | ||
$as?: never | undefined; | ||
}): React.ReactElement<any> | null; | ||
<As extends IntrinsicElementsKeys>(props: P & { | ||
$as?: As; | ||
} & JSX.IntrinsicElements[As]): React.ReactElement<any> | null; | ||
<P2 extends {}>(props: P & { | ||
$as?: React.ComponentType<P2>; | ||
} & NoInfer<P2>): React.ReactElement<any> | null; | ||
}): React.ReactElement<TailwindComponentProps<E, K>> | null; | ||
<As extends IntrinsicElementsKeys | React.ComponentType<any> = E>(props: TailwindComponentPropsWith$As<E, K, As>): React.ReactElement<TailwindComponentPropsWith$As<E, K, As>> | null; | ||
[isTwElement]: boolean; | ||
} | ||
export declare type TemplateFunction<P, E> = <K extends TransientProps = {}>(template: TemplateStringsArray, ...templateElements: ((props: P & K) => string | undefined | null)[]) => TailwindComponent<React.PropsWithoutRef<P & K> & React.RefAttributes<E>>; | ||
interface ClassNameProp { | ||
className?: string; | ||
declare type NoInfer<T> = [T][T extends any ? 0 : never]; | ||
export interface TemplateFunction<E extends React.ComponentType<any> | IntrinsicElementsKeys, K2 extends object = {}> { | ||
<K extends object = {}>(template: TemplateStringsArray, ...templateElements: ((props: NoInfer<React.ComponentPropsWithRef<E> & K2> & K) => string | undefined | null)[]): TailwindComponent<E, K & K2>; | ||
} | ||
interface AsProp { | ||
$as?: keyof JSX.IntrinsicElements | React.ComponentType<any>; | ||
declare type InnerTailwindComponent<E extends React.ComponentType<any> | IntrinsicElementsKeys | TailwindComponent<any, any>> = E extends TailwindComponent<infer E2, any> ? E2 : E; | ||
declare type InnerTailwindComponentOtherProps<E extends React.ComponentType<any> | IntrinsicElementsKeys | TailwindComponent<any, any>> = E extends TailwindComponent<any, infer K2> ? K2 : {}; | ||
declare type InnerTailwindComponentAllProps<E extends React.ComponentType<any> | IntrinsicElementsKeys | TailwindComponent<any, any>> = E extends TailwindComponent<infer E2, infer K2> ? React.ComponentPropsWithoutRef<E2> & K2 & React.RefAttributes<React.ComponentRef<E2> | undefined> : React.ComponentPropsWithoutRef<E> & React.RefAttributes<React.ComponentRef<E> | undefined>; | ||
export interface TemplateFunctionFactory { | ||
<E extends TailwindComponent<E2, K2>, E2 extends IntrinsicElementsKeys, K2 extends object = {}>(Element: E): TemplateFunction<E2, K2>; | ||
<E extends TailwindComponent<any, any>>(Element: E): TemplateFunction<InnerTailwindComponent<E>, InnerTailwindComponentOtherProps<E>>; | ||
<E extends IntrinsicElementsKeys>(Element: E): TemplateFunction<E>; | ||
<E extends React.ComponentType<any>>(Element: E): TemplateFunction<E>; | ||
} | ||
declare function templateFunction<P extends ClassNameProp & AsProp, E = any>(Element: React.ComponentType<P>): TemplateFunction<P, E>; | ||
export declare type IntrinsicElements = { | ||
[key in keyof JSX.IntrinsicElements]: TemplateFunction<JSX.IntrinsicElements[key], React.ElementRef<key> | undefined>; | ||
export declare type IntrinsicElementsTemplateFunctionsMap = { | ||
[key in IntrinsicElementsKeys]: TemplateFunction<key>; | ||
}; | ||
declare const tw: typeof templateFunction & IntrinsicElements; | ||
declare const tw: TemplateFunctionFactory & IntrinsicElementsTemplateFunctionsMap; | ||
export default tw; |
@@ -30,28 +30,28 @@ "use strict"; | ||
exports.cleanTemplate = cleanTemplate; | ||
const filter$FromProps = ([key]) => key.charAt(0) !== "$"; | ||
function templateFunction(Element) { | ||
const removeTransientProps = ([key]) => key.charAt(0) !== "$"; | ||
const templateFunctionFactory = (Element) => { | ||
return (template, ...templateElements) => { | ||
const result = react_1.default.forwardRef(({ $as, ...props }, ref) => { | ||
const TwComponent = react_1.default.forwardRef(({ $as, ...props }, ref) => { | ||
const FinalElement = $as || Element; | ||
const filteredProps = FinalElement[isTwElement] === true | ||
? props | ||
: Object.fromEntries(Object.entries(props).filter(filter$FromProps)); | ||
: Object.fromEntries(Object.entries(props).filter(removeTransientProps)); | ||
return (react_1.default.createElement(FinalElement, { ...filteredProps, ref: ref, className: (0, exports.cleanTemplate)((0, exports.mergeArrays)(template, templateElements.map((t) => t({ ...props, $as }))), props.className) })); | ||
}); | ||
result[isTwElement] = true; | ||
TwComponent[isTwElement] = true; | ||
if (typeof Element !== "string") { | ||
result.displayName = Element.displayName || Element.name || "tw.Component"; | ||
TwComponent.displayName = Element.displayName || Element.name || "tw.Component"; | ||
} | ||
else { | ||
result.displayName = "tw." + Element; | ||
TwComponent.displayName = "tw." + Element; | ||
} | ||
return result; | ||
return TwComponent; | ||
}; | ||
} | ||
const intrinsicElements = domElements_1.default.reduce((acc, DomElement) => ({ | ||
}; | ||
const intrinsicElementsMap = domElements_1.default.reduce((acc, DomElement) => ({ | ||
...acc, | ||
[DomElement]: templateFunction(DomElement) | ||
[DomElement]: templateFunctionFactory(DomElement) | ||
}), {}); | ||
const tw = Object.assign(templateFunction, intrinsicElements); | ||
const tw = Object.assign(templateFunctionFactory, intrinsicElementsMap); | ||
exports.default = tw; | ||
//# sourceMappingURL=tailwind.js.map |
{ | ||
"name": "tailwind-styled-components", | ||
"version": "2.1.2", | ||
"version": "2.1.4", | ||
"keywords": [ | ||
@@ -17,2 +17,3 @@ "react", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -23,6 +24,8 @@ "dist/**/*" | ||
"build": "tsc", | ||
"postbuild": "yarn run test", | ||
"dev": "tsc -w", | ||
"clean": "rimraf dist", | ||
"test": "jest", | ||
"posttest": "tsc -p ./src/typing-tests/tsconfig.json", | ||
"test:types": "tsc -p ./src/typing-tests/tsconfig.json", | ||
"posttest": "yarn run test:types", | ||
"prepublishOnly": "npm run clean && npm run build" | ||
@@ -43,2 +46,3 @@ }, | ||
"@typescript-eslint/parser": "^5.9.0", | ||
"esbuild": "^0.14.11", | ||
"eslint": "^8.6.0", | ||
@@ -45,0 +49,0 @@ "eslint-config-prettier": "^8.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40408
245
17