1- import { defineComponent , DefineSetupFnComponent , h , inject , onMounted , PropType , PublicProps , reactive , SlotsType , watch } from 'vue'
1+ import {
2+ defineComponent ,
3+ DefineSetupFnComponent ,
4+ h ,
5+ inject ,
6+ onMounted ,
7+ onUnmounted ,
8+ PropType ,
9+ PublicProps ,
10+ reactive ,
11+ SlotsType ,
12+ watch ,
13+ } from 'vue'
214import domElements , { type SupportedHTMLElements } from '@/constants/domElements'
3- import { type ExpressionType , generateClassName , generateComponentName , insertExpressions } from '@/utils'
4- import { injectStyle } from '@/utils/injectStyle'
15+ import { type ExpressionType , generateClassName , generateComponentName , insertExpressions , injectStyle , removeStyle } from '@/utils'
516import { isStyledComponent , isValidElementType , isVueComponent } from '@/helper'
6- import { useStyledClassName } from '@/hooks'
717
818interface IProps {
919 as ?: SupportedHTMLElements
@@ -51,13 +61,7 @@ function baseStyled(target: string | InstanceType<any>, propsDefinition: Record<
5161 type = 'styled-component'
5262 }
5363
54- // Generate a unique class name
55- const className = generateClassName ( )
5664 const componentName = generateComponentName ( type )
57-
58- const { styledClassNameMap } = useStyledClassName ( )
59- styledClassNameMap [ componentName ] = className
60-
6165 return defineComponent (
6266 ( props , { slots } ) => {
6367 const myAttrs = { ...attributes }
@@ -66,18 +70,23 @@ function baseStyled(target: string | InstanceType<any>, propsDefinition: Record<
6670 theme,
6771 ...props ,
6872 }
69- myAttrs . class = className
73+
74+ myAttrs . class = generateClassName ( )
7075
7176 watch ( [ theme , props ] , ( ) => {
7277 context = {
7378 theme,
7479 ...props ,
7580 }
76- injectStyle < T > ( className , cssWithExpression , context )
81+ injectStyle < T > ( myAttrs . class , cssWithExpression , context )
7782 } )
7883
7984 onMounted ( ( ) => {
80- injectStyle < T > ( className , cssWithExpression , context )
85+ injectStyle < T > ( myAttrs . class , cssWithExpression , context )
86+ } )
87+
88+ onUnmounted ( ( ) => {
89+ removeStyle ( myAttrs . class )
8190 } )
8291
8392 // Return the render function
0 commit comments