@@ -3,16 +3,32 @@ import type { YakTheme } from "./index.d.ts";
33
44export const yakComponentSymbol = Symbol ( "yak" ) ;
55
6- type ComponentStyles < TProps > = ( props : TProps ) => {
6+ export type ComponentStyles < TProps > = ( props : TProps ) => {
77 className : string ;
88 style ?: {
99 [ key : string ] : string ;
1010 } ;
1111} ;
1212
13- export type StaticCSSProp = {
14- className : string ;
15- style ?: CSSProperties ;
13+ /**
14+ * Convenience type to specify the CSS prop type.
15+ * This type is used to allow the css prop on components.
16+ *
17+ * @example
18+ * ```tsx
19+ * const ComponentThatTakesCssProp = (p: CSSProp) =>
20+ * <div {...p}>anything</div>;
21+ * ```
22+ */
23+ export type CSSProp = {
24+ /** This prop is transformed during compilation and doesn't exist at runtime. */
25+ css ?: ComponentStyles < Record < keyof any , never > > ;
26+ /** The css prop will return the name of the class and automatically merged with an existing class */
27+ className ?: string ;
28+ /** The css prop will return the style object and automatically merged with an existing style */
29+ style ?: {
30+ [ key : string ] : string ;
31+ } ;
1632} ;
1733
1834export type CSSInterpolation < TProps > =
@@ -22,7 +38,6 @@ export type CSSInterpolation<TProps> =
2238 | null
2339 | false
2440 | ComponentStyles < TProps >
25- | StaticCSSProp
2641 | {
2742 // type only identifier to allow targeting components
2843 // e.g. styled.svg`${Button}:hover & { fill: red; }`
@@ -61,10 +76,8 @@ export type PropsToClassNameFn = (props: unknown) =>
6176export function css < TProps > (
6277 styles : TemplateStringsArray ,
6378 ...values : CSSInterpolation < NoInfer < TProps > & { theme : YakTheme } > [ ]
64- ) : TProps extends object ? ComponentStyles < TProps > : StaticCSSProp ;
65- export function css < TProps > (
66- ...args : Array < any >
67- ) : TProps extends object ? ComponentStyles < TProps > : StaticCSSProp {
79+ ) : ComponentStyles < TProps > ;
80+ export function css < TProps > ( ...args : Array < any > ) : ComponentStyles < TProps > {
6881 const classNames : string [ ] = [ ] ;
6982 const dynamicCssFunctions : PropsToClassNameFn [ ] = [ ] ;
7083 const style : Record < string , string > = { } ;
@@ -109,11 +122,9 @@ export function css<TProps>(
109122 // Non Dynamic CSS
110123 if ( dynamicCssFunctions . length === 0 ) {
111124 const className = classNames . join ( " " ) ;
112- // @ts -expect-error - Conditional return types are tricky in the implementation and generate false positives
113125 return ( ) => ( { className, style } ) ;
114126 }
115127
116- // @ts -expect-error - Conditional return types are tricky in the implementation and generate false positives
117128 return ( props : unknown ) => {
118129 const allClassNames : string [ ] = [ ...classNames ] ;
119130 const allStyles : Record < string , string > = { ...style } ;
0 commit comments