1
1
import clsx from 'clsx'
2
- import { CSSInterpolation , Interpolation , serializeStyles } from '@emotion/serialize'
2
+ import { mergeProps , SetupContext , h , Fragment } from 'vue'
3
+ import { CSSInterpolation , serializeStyles } from '@emotion/serialize'
4
+ import { extractStyleAttrs } from '@chakra-ui/vue-utils'
3
5
import { getRegisteredStyles , insertStyles , SerializedStyles } from '@emotion/utils'
6
+ import camelCase from 'lodash.camelcase'
7
+ import { CreateStyled , PrivateStyledComponent , StyledOptions } from './types'
4
8
import { defaultCache , __unusafe_useEmotionCache } from './cache'
5
9
import { useEmotionTheme } from './theming'
6
- import { CreateStyled , PrivateStyledComponent , StyledOptions } from './types'
7
- import camelCase from 'lodash.camelcase'
8
- import { mergeProps , SetupContext , h , Fragment } from 'vue'
10
+ import memoize from 'lodash.memoize'
9
11
10
12
const ILLEGAL_ESCAPE_SEQUENCE_ERROR = `You have illegal escape sequence in your template literal, most likely inside content's property value.
11
13
Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example "content: '\\00d7';" should become "content: '\\\\00d7';".
@@ -17,6 +19,8 @@ let isBrowser = typeof document !== 'undefined'
17
19
const Noop = ( ) => null
18
20
const camelCaseCache : any = { }
19
21
22
+ const _camelCase = memoize ( ( key ) => camelCase ( key ) )
23
+
20
24
// @ts -ignore
21
25
export const createStyled : CreateStyled = ( tag : any , options ?: StyledOptions ) => {
22
26
if ( process . env . NODE_ENV !== 'production' ) {
@@ -33,7 +37,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
33
37
let identifierName : string
34
38
let targetClassName : string
35
39
if ( options !== undefined ) {
36
- identifierName = options . label as string
40
+ identifierName = options . __label as string
37
41
targetClassName = options . target as string
38
42
}
39
43
@@ -71,7 +75,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
71
75
72
76
let mergedProps = { ...props , ...restAttrs }
73
77
74
- let className = attrs . staticClass ? `${ attrs . staticClass } ` : ''
78
+ let className = options ?. __label ? `${ cache . key } - ${ options ?. __label || typeof tag === 'string' ? tag : 'element' } ` : ``
75
79
const FinalTag = as || baseTag
76
80
const classInterpolations = [ ] as string [ ]
77
81
@@ -80,7 +84,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
80
84
if ( camelCaseCache [ key ] ) {
81
85
mergedProps [ key ] = camelCaseCache [ key ]
82
86
} else {
83
- const attr = camelCase ( key )
87
+ const attr = _camelCase ( key )
84
88
camelCaseCache [ attr ] = props [ key ]
85
89
mergedProps [ attr ] = props [ key ]
86
90
}
@@ -120,11 +124,14 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
120
124
className += ` ${ targetClassName } `
121
125
}
122
126
127
+
128
+ const { attrs : htmlAttrs } = extractStyleAttrs ( mergedProps )
123
129
const vnodeProps = {
124
- ...attrs ,
125
- ...restAttrs ,
130
+ ...htmlAttrs ,
126
131
class : className ,
127
132
}
133
+ // @ts -expect-error
134
+ delete vnodeProps ?. theme
128
135
129
136
const StyledElement = (
130
137
< FinalTag { ...vnodeProps } >
0 commit comments