File tree 4 files changed +47
-5
lines changed
4 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,6 @@ export {
65
65
} from './components/BaseTransition'
66
66
// For using custom directives
67
67
export { withDirectives } from './directives'
68
- // SFC CSS Modules
69
- export { useCSSModule } from './helpers/useCssModule'
70
68
// SSR context
71
69
export { useSSRContext , ssrContextKey } from './helpers/useSsrContext'
72
70
Original file line number Diff line number Diff line change 1
- import { getCurrentInstance } from '../component '
1
+ import { warn , getCurrentInstance } from '@vue/runtime-core '
2
2
import { EMPTY_OBJ } from '@vue/shared'
3
- import { warn } from '../warning'
4
3
5
- export const useCSSModule = ( name = '$style' ) : Record < string , string > = > {
4
+ export function useCSSModule ( name = '$style' ) : Record < string , string > {
6
5
if ( ! __GLOBAL__ ) {
7
6
const instance = getCurrentInstance ( ) !
8
7
if ( ! instance ) {
Original file line number Diff line number Diff line change
1
+ import {
2
+ ComponentPublicInstance ,
3
+ getCurrentInstance ,
4
+ onMounted ,
5
+ watchEffect ,
6
+ warn ,
7
+ VNode ,
8
+ Fragment
9
+ } from '@vue/runtime-core'
10
+ import { ShapeFlags } from '@vue/shared/src'
11
+
12
+ export function useCSSVars (
13
+ getter : ( ctx : ComponentPublicInstance ) => Record < string , string >
14
+ ) {
15
+ const instance = getCurrentInstance ( )
16
+ if ( ! instance ) {
17
+ __DEV__ &&
18
+ warn ( `useCssVars is called without current active component instance.` )
19
+ return
20
+ }
21
+ onMounted ( ( ) => {
22
+ watchEffect ( ( ) => {
23
+ setVarsOnVNode ( instance . vnode , getter ( instance . proxy ! ) )
24
+ } )
25
+ } )
26
+ }
27
+
28
+ function setVarsOnVNode ( vnode : VNode , vars : Record < string , string > ) {
29
+ // drill down HOCs until it's a non-component vnode
30
+ while ( vnode . component ) {
31
+ vnode = vnode . component . subTree
32
+ }
33
+ if ( vnode . shapeFlag & ShapeFlags . ELEMENT && vnode . el ) {
34
+ const style = vnode . el . style
35
+ for ( const key in vars ) {
36
+ style . setProperty ( `--${ key } ` , vars [ key ] )
37
+ }
38
+ } else if ( vnode . type === Fragment ) {
39
+ ; ( vnode . children as VNode [ ] ) . forEach ( c => setVarsOnVNode ( c , vars ) )
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -113,6 +113,10 @@ function normalizeContainer(container: Element | string): Element | null {
113
113
return container
114
114
}
115
115
116
+ // SFC CSS utilities
117
+ export { useCSSModule } from './helpers/useCssModule'
118
+ export { useCSSVars } from './helpers/useCssVars'
119
+
116
120
// DOM-only components
117
121
export { Transition , TransitionProps } from './components/Transition'
118
122
export {
You can’t perform that action at this time.
0 commit comments