11import { css , CSSAttribute } from "goober" ;
2- import { assignProps , createContext , useContext } from "solid-js" ;
2+ import { assignProps , splitProps , createContext , useContext } from "solid-js" ;
33import { spread , createComponent } from "solid-js/dom" ;
44
55export { css , glob , extractCss } from "goober" ;
@@ -25,34 +25,33 @@ type StyledTemplateArgs<T> = [
2525] ;
2626
2727export function styled < T extends keyof JSX . IntrinsicElements > ( tag : T | ( ( props : any ) => any ) ) {
28- return < P > ( ...args : StyledTemplateArgs < P & { theme ?: any ; className ?: any } > ) => {
28+ return < P > ( ...args : StyledTemplateArgs < P & { theme ?: any ; as ?: keyof JSX . IntrinsicElements ; className ?: any } > ) => {
2929 return (
30- props : P & JSX . IntrinsicElements [ T ] & { theme ?: any ; className ?: any }
30+ props : P & JSX . IntrinsicElements [ T ] & { theme ?: any ; as ?: keyof JSX . IntrinsicElements ; className ?: any }
3131 ) : JSX . Element => {
32- const newProps = assignProps ( { } , props ) ;
33- props . theme = useContext ( ThemeContext ) ;
34- Object . defineProperty ( newProps , "className" , {
35- get ( ) {
32+ const clone = assignProps ( { } , props , {
33+ theme : useContext ( ThemeContext ) ,
34+ get className ( ) : string {
3635 const pClassName = props . className ,
3736 append = "className" in props && / ^ g o [ 0 - 9 ] + / . test ( pClassName ! ) ;
3837
3938 // Call `css` with the append flag and pass the props
4039 let className = css . apply (
41- { target : this . target , o : append , p : props } ,
40+ { target : ( this as any ) . target , o : append , p : newProps } ,
4241 args as [ any , ...any [ ] ]
4342 ) ;
4443
4544 return [ pClassName , className ] . filter ( Boolean ) . join ( " " ) ;
46- } ,
47- configurable : true ,
48- enumerable : true
45+ }
4946 } ) ;
47+ const [ local , newProps ] = splitProps ( clone , [ "as" ] ) ;
48+ const createTag = local . as || tag ;
5049
5150 let el ;
52- if ( typeof tag === "function" ) {
53- el = tag ( newProps ) ;
51+ if ( typeof createTag === "function" ) {
52+ el = createTag ( newProps ) ;
5453 } else {
55- el = document . createElement ( tag ) ;
54+ el = document . createElement ( createTag as any ) ;
5655 spread ( el , newProps ) ;
5756 }
5857
0 commit comments