smbls 0.15.33 → 0.15.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/atoms/Media.js +10 -6
- package/src/atoms/Theme.js +37 -11
package/package.json
CHANGED
package/src/atoms/Media.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { merge, isArray } from '@domql/utils'
|
|
4
|
+
import { getSystemTheme } from './Theme'
|
|
4
5
|
|
|
5
6
|
const keySetters = {
|
|
6
7
|
'@': (key, props, result, element, isSubtree) => applyMediaProps(key, props, isSubtree ? result : result.media, element),
|
|
@@ -16,7 +17,11 @@ const execClass = (key, props, result, element) => {
|
|
|
16
17
|
|
|
17
18
|
if (typeof classnameExec !== 'function') return
|
|
18
19
|
|
|
19
|
-
let classExec = classnameExec({
|
|
20
|
+
let classExec = classnameExec({
|
|
21
|
+
props,
|
|
22
|
+
context: element.context,
|
|
23
|
+
state: element.state
|
|
24
|
+
})
|
|
20
25
|
if (isArray(classExec)) {
|
|
21
26
|
classExec = classExec.reduce((a, c) => merge(a, c), {})
|
|
22
27
|
}
|
|
@@ -46,9 +51,9 @@ const convertPropsToClass = (props, result, element) => {
|
|
|
46
51
|
|
|
47
52
|
const applyMediaProps = (key, props, result, element) => {
|
|
48
53
|
const { context } = element
|
|
49
|
-
console.log(context, element)
|
|
50
54
|
if (!context.SYSTEM || !context.SYSTEM.MEDIA) return
|
|
51
|
-
const
|
|
55
|
+
const globalTheme = getSystemTheme(element)
|
|
56
|
+
const { MEDIA } = context.SYSTEM
|
|
52
57
|
const mediaName = MEDIA[key.slice(1)]
|
|
53
58
|
const generatedClass = convertPropsToClass(props, result, element)
|
|
54
59
|
|
|
@@ -113,7 +118,8 @@ const beforeClassAssign = (element, s) => {
|
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
export const initUpdate = element => {
|
|
116
|
-
const { props,
|
|
121
|
+
const { props, class: className } = element
|
|
122
|
+
const globalTheme = getSystemTheme(element)
|
|
117
123
|
|
|
118
124
|
const parentProps = element.parent.props
|
|
119
125
|
if (parentProps && parentProps.spacingRatio && parentProps.inheritSpacingRatio) {
|
|
@@ -126,8 +132,6 @@ export const initUpdate = element => {
|
|
|
126
132
|
})
|
|
127
133
|
}
|
|
128
134
|
|
|
129
|
-
const { globalTheme } = context.SYSTEM
|
|
130
|
-
|
|
131
135
|
if (globalTheme) {
|
|
132
136
|
const CLASS_NAMES = {
|
|
133
137
|
media: {},
|
package/src/atoms/Theme.js
CHANGED
|
@@ -36,34 +36,60 @@ const transformShadow = shadows => shadows.split('|').map(shadow => {
|
|
|
36
36
|
}).join(' ')
|
|
37
37
|
}).join(',')
|
|
38
38
|
|
|
39
|
-
const transformBackgroundImage = (backgroundImage, ctx) => ({
|
|
39
|
+
const transformBackgroundImage = (backgroundImage, ctx, globalTheme) => ({
|
|
40
40
|
backgroundImage: backgroundImage.split(', ').map(v => {
|
|
41
41
|
if (v.includes('url') || v.includes('gradient')) return v
|
|
42
42
|
else if (ctx.SYSTEM.GRADIENT[backgroundImage]) {
|
|
43
|
-
return getMediaColor(backgroundImage, 'backgroundImage')
|
|
43
|
+
return getMediaColor(backgroundImage, 'backgroundImage', globalTheme)
|
|
44
44
|
}
|
|
45
45
|
return `url(${v})`
|
|
46
46
|
}).join(' ')
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
+
export const getSystemTheme = (element, state) => {
|
|
50
|
+
const { context } = element
|
|
51
|
+
const rootState = element.__root ? element.__root.state : element.state
|
|
52
|
+
return rootState.globalTheme || context.SYSTEM.globalTheme
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
export const Theme = {
|
|
50
56
|
class: {
|
|
51
57
|
depth: ({ props }) => depth[props.depth],
|
|
52
58
|
|
|
53
|
-
theme: (
|
|
59
|
+
theme: (element) => {
|
|
60
|
+
const { props } = element
|
|
61
|
+
const globalTheme = getSystemTheme(element)
|
|
54
62
|
if (!props.theme) return
|
|
55
|
-
return getMediaTheme(props.theme, props.themeModifier ||
|
|
63
|
+
return getMediaTheme(props.theme, props.themeModifier || globalTheme)
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
color: (element) => {
|
|
67
|
+
const { props } = element
|
|
68
|
+
const globalTheme = getSystemTheme(element)
|
|
69
|
+
if (!props.color) return
|
|
70
|
+
return getMediaColor(props.color, 'color', globalTheme)
|
|
56
71
|
},
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
background: ({ props, context }) => {
|
|
73
|
+
background: (element) => {
|
|
74
|
+
const { props } = element
|
|
75
|
+
const globalTheme = getSystemTheme(element)
|
|
62
76
|
if (!props.background) return
|
|
63
|
-
return getMediaColor(props.background, 'background',
|
|
77
|
+
return getMediaColor(props.background, 'background', globalTheme)
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
backgroundColor: (element) => {
|
|
81
|
+
const { props } = element
|
|
82
|
+
const globalTheme = getSystemTheme(element)
|
|
83
|
+
if (!props.backgroundColor) return
|
|
84
|
+
return getMediaColor(props.backgroundColor, 'backgroundColor', globalTheme)
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
backgroundImage: (element) => {
|
|
88
|
+
const { props, context } = element
|
|
89
|
+
const globalTheme = getSystemTheme(element)
|
|
90
|
+
if (!props.backgroundImage) return
|
|
91
|
+
return transformBackgroundImage(props.backgroundImage, context, globalTheme)
|
|
64
92
|
},
|
|
65
|
-
backgroundColor: ({ props, context }) => (props.backgroundColor) && getMediaColor(props.backgroundColor, 'backgroundColor', context.SYSTEM.globalTheme),
|
|
66
|
-
backgroundImage: ({ props, context }) => (props.backgroundImage) && transformBackgroundImage(props.backgroundImage, context),
|
|
67
93
|
backgroundSize: ({ props }) => props.backgroundSize ? ({ backgroundSize: props.backgroundSize }) : null,
|
|
68
94
|
backgroundPosition: ({ props }) => props.backgroundPosition ? ({ backgroundPosition: props.backgroundPosition }) : null,
|
|
69
95
|
|