Skip to content

Commit cb6b3d6

Browse files
committed
Add a support for reactive theme
1 parent 0ddd6e3 commit cb6b3d6

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ export default StyledButton;
155155

156156
`vue-styled-components` has full theming support by exporting a `<ThemeProvider>` wrapper component. This component provides a theme to all `Vue` components underneath itself via the context API. In the render tree all `vue-styled-components` will have access to the provided theme, even when they are multiple levels deep.
157157

158+
ThemeProvider supports reactive theme, i.e. it can be derived via vuex and changed over the time.
159+
158160
Remember to register `ThemeProvider` locally.
159161

160162
```JSX

src/models/StyledComponent.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ export default (ComponentStyle) => {
88
const componentStyle = new ComponentStyle(rules)
99

1010
const StyledComponent = {
11-
inject: {
12-
theme: {
13-
default: {}
14-
}
15-
},
11+
inject: ['$theme'],
1612
props: mergedProps,
1713
render: function (createElement) {
1814
const children = []
@@ -47,6 +43,13 @@ export default (ComponentStyle) => {
4743
generatedClassName () {
4844
const componentProps = Object.assign({ theme: this.theme }, this.$props)
4945
return this.generateAndInjectStyles(componentProps)
46+
},
47+
theme () {
48+
return this.$theme
49+
? this.$theme()
50+
: {
51+
default: {}
52+
}
5053
}
5154
},
5255
extend (extendedRules) {

src/providers/ThemeProvider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
},
66
provide () {
77
return {
8-
theme: this.theme
8+
$theme: () => this.theme
99
}
1010
},
1111
render: function (createElement) {

0 commit comments

Comments
 (0)