smbls 0.15.32 → 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 +11 -8
- package/src/atoms/Theme.js +39 -8
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
|
}
|
|
@@ -45,13 +50,13 @@ const convertPropsToClass = (props, result, element) => {
|
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
const applyMediaProps = (key, props, result, element) => {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
const { context } = element
|
|
54
|
+
if (!context.SYSTEM || !context.SYSTEM.MEDIA) return
|
|
55
|
+
const globalTheme = getSystemTheme(element)
|
|
56
|
+
const { MEDIA } = context.SYSTEM
|
|
50
57
|
const mediaName = MEDIA[key.slice(1)]
|
|
51
58
|
const generatedClass = convertPropsToClass(props, result, element)
|
|
52
59
|
|
|
53
|
-
const rootState = element.__root ? element.__root.state : element.state
|
|
54
|
-
const { globalTheme } = rootState
|
|
55
60
|
const name = key.slice(1)
|
|
56
61
|
const isTheme = ['dark', 'light'].includes(name)
|
|
57
62
|
const matchesGlobal = name === globalTheme
|
|
@@ -114,7 +119,7 @@ const beforeClassAssign = (element, s) => {
|
|
|
114
119
|
|
|
115
120
|
export const initUpdate = element => {
|
|
116
121
|
const { props, class: className } = element
|
|
117
|
-
const
|
|
122
|
+
const globalTheme = getSystemTheme(element)
|
|
118
123
|
|
|
119
124
|
const parentProps = element.parent.props
|
|
120
125
|
if (parentProps && parentProps.spacingRatio && parentProps.inheritSpacingRatio) {
|
|
@@ -127,8 +132,6 @@ export const initUpdate = element => {
|
|
|
127
132
|
})
|
|
128
133
|
}
|
|
129
134
|
|
|
130
|
-
const { globalTheme } = rootState
|
|
131
|
-
|
|
132
135
|
if (globalTheme) {
|
|
133
136
|
const CLASS_NAMES = {
|
|
134
137
|
media: {},
|
package/src/atoms/Theme.js
CHANGED
|
@@ -36,29 +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)
|
|
56
64
|
},
|
|
57
65
|
|
|
58
|
-
color: (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
color: (element) => {
|
|
67
|
+
const { props } = element
|
|
68
|
+
const globalTheme = getSystemTheme(element)
|
|
69
|
+
if (!props.color) return
|
|
70
|
+
return getMediaColor(props.color, 'color', globalTheme)
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
background: (element) => {
|
|
74
|
+
const { props } = element
|
|
75
|
+
const globalTheme = getSystemTheme(element)
|
|
76
|
+
if (!props.background) return
|
|
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)
|
|
92
|
+
},
|
|
62
93
|
backgroundSize: ({ props }) => props.backgroundSize ? ({ backgroundSize: props.backgroundSize }) : null,
|
|
63
94
|
backgroundPosition: ({ props }) => props.backgroundPosition ? ({ backgroundPosition: props.backgroundPosition }) : null,
|
|
64
95
|
|