@@ -2,42 +2,22 @@ import kebabCase from 'lodash.kebabcase'
2
2
import camelCase from 'lodash.camelcase'
3
3
import {
4
4
propNames ,
5
- pseudoPropNames ,
6
5
StyleObjectOrFn ,
6
+ isStyleProp ,
7
7
} from '@chakra-ui/styled-system'
8
8
import { HTMLAttributes } from 'vue'
9
9
10
10
export type StyleAndHTMLAttibutes = StyleObjectOrFn &
11
11
Record < string , string | number | boolean | unknown > &
12
12
HTMLAttributes
13
13
14
- export const baseStylePropNames = propNames . reduce (
15
- ( acc : StyleAndHTMLAttibutes , curr : string ) => {
16
- acc [ curr ] = true
17
- acc [ kebabCase ( curr ) ] = true
18
- return acc
19
- } ,
20
- { }
21
- )
22
-
23
- export const pseudoStylePropNames = pseudoPropNames . reduce (
24
- ( acc : StyleAndHTMLAttibutes , curr : string ) => {
25
- acc [ curr ] = curr
26
- return acc
27
- } ,
28
- { }
29
- )
30
-
31
- export const allStylePropNames : StyleAndHTMLAttibutes = {
32
- ...baseStylePropNames ,
33
- ...pseudoStylePropNames ,
34
- }
35
-
36
14
interface ExtractedStyleAttrs {
37
15
styles : Partial < StyleAndHTMLAttibutes >
38
16
attrs : Partial < HTMLAttributes >
39
17
}
40
18
19
+ const camelCaseCache : any = { }
20
+
41
21
/** Extracts CSS style properties and HTML attributes from merged component attributs */
42
22
export const extractStyleAttrs = <
43
23
T extends StyleAndHTMLAttibutes ,
@@ -49,10 +29,15 @@ export const extractStyleAttrs = <
49
29
const attrs = { } as U
50
30
51
31
for ( const prop in styleProps ) {
52
- // TODO: Cache style prop names so that that camelCases is only computed once for each property
53
- // TODO: Is there another way to detect
54
- const _attr = ( pseudoStylePropNames [ prop ] as string ) || camelCase ( prop )
55
- if ( _attr in allStylePropNames ) {
32
+ const _isStyledProp = isStyleProp ( prop )
33
+ if ( _isStyledProp ) {
34
+ let _attr : string
35
+ if ( camelCaseCache [ prop ] ) {
36
+ _attr = camelCaseCache [ prop ]
37
+ } else {
38
+ _attr = camelCase ( prop )
39
+ camelCaseCache [ prop ] = _attr
40
+ }
56
41
// @ts -expect-error Not sure how to cast returned string into typeof key of U
57
42
styles [ _attr ] = styleProps [ prop ]
58
43
} else {
@@ -61,6 +46,11 @@ export const extractStyleAttrs = <
61
46
}
62
47
}
63
48
49
+ console . log ( {
50
+ styles,
51
+ attrs,
52
+ } )
53
+
64
54
return {
65
55
styles,
66
56
attrs,
0 commit comments