88 PropType ,
99 PublicProps ,
1010 reactive ,
11+ ref ,
1112 SlotsType ,
1213 watch ,
1314} from 'vue'
@@ -65,14 +66,26 @@ function baseStyled<P extends Record<string, any>>(target: string | InstanceType
6566 const componentName = generateComponentName ( type )
6667 return defineComponent (
6768 ( props , { slots } ) => {
68- const myAttrs = { ...attributes }
69+ const tailwindClasses = ref < string [ ] > ( [ ] )
70+ const myAttrs = ref ( { ...attributes } )
6971 const theme = inject < Record < string , string | number > > ( '$theme' , reactive ( { } ) )
7072 let context = {
7173 theme,
7274 ...props ,
7375 }
7476
75- myAttrs . class = generateClassName ( )
77+ const defaultClassName = generateClassName ( )
78+
79+ myAttrs . value . class = defaultClassName
80+
81+ // Inject the tailwind classes to the class attribute
82+ watch (
83+ tailwindClasses ,
84+ ( classNames ) => {
85+ myAttrs . value . class = `${ defaultClassName } ${ classNames . join ( ' ' ) } `
86+ } ,
87+ { deep : true } ,
88+ )
7689
7790 watch (
7891 [ theme , props ] ,
@@ -81,19 +94,19 @@ function baseStyled<P extends Record<string, any>>(target: string | InstanceType
8194 theme,
8295 ...props ,
8396 }
84- injectStyle < T & { theme : DefaultTheme } > ( myAttrs . class , cssWithExpression , context )
97+ tailwindClasses . value = injectStyle < T & { theme : DefaultTheme } > ( defaultClassName , cssWithExpression , context )
8598 } ,
8699 {
87100 deep : true ,
88101 } ,
89102 )
90103
91104 onMounted ( ( ) => {
92- injectStyle < T & { theme : DefaultTheme } > ( myAttrs . class , cssWithExpression , context )
105+ tailwindClasses . value = injectStyle < T & { theme : DefaultTheme } > ( defaultClassName , cssWithExpression , context )
93106 } )
94107
95108 onUnmounted ( ( ) => {
96- removeStyle ( myAttrs . class )
109+ removeStyle ( myAttrs . value . class )
97110 } )
98111
99112 // Return the render function
@@ -102,7 +115,7 @@ function baseStyled<P extends Record<string, any>>(target: string | InstanceType
102115 return h (
103116 node ,
104117 {
105- ...myAttrs ,
118+ ...myAttrs . value ,
106119 } ,
107120 slots ,
108121 )
0 commit comments