Skip to content

Commit 12535c2

Browse files
feat: make theme injection reactive
1 parent a07004f commit 12535c2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/models/StyledComponent.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, inject } from 'vue'
1+
import { computed, h, inject } from 'vue'
22
import css from '../constructors/css'
33
import isVueComponent from '../utils/isVueComponent'
44
import normalizeProps from '../utils/normalizeProps'
@@ -30,8 +30,10 @@ export default (ComponentStyle) => {
3030
setup (props, { slots, attrs, emit }) {
3131
const theme = inject('theme')
3232

33+
const finalTheme = computed(() => theme && theme.value ? theme.value : theme)
34+
3335
return () => {
34-
const styleClass = componentStyle.generateAndInjectStyles({ theme, ...props, ...attrs })
36+
const styleClass = componentStyle.generateAndInjectStyles({ theme: finalTheme.value, ...props, ...attrs })
3537
const classes = [styleClass]
3638

3739
if (attrs.class) {

src/providers/ThemeProvider.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { h, provide } from 'vue'
1+
import { h, provide, toRefs } from 'vue'
22

33
export default {
44
props: {
55
theme: Object
66
},
7-
setup (props, { slots }) {
8-
provide('theme', props.theme)
7+
setup (props) {
8+
const { theme } = toRefs(props)
9+
10+
provide('theme', theme)
911
},
1012

1113
render () {

0 commit comments

Comments
 (0)