smbls 0.15.33 → 0.15.35
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 -5
- package/src/atoms/Picture.js +18 -0
- 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
|
}
|
|
@@ -48,7 +53,8 @@ const applyMediaProps = (key, props, result, element) => {
|
|
|
48
53
|
const { context } = element
|
|
49
54
|
console.log(context, element)
|
|
50
55
|
if (!context.SYSTEM || !context.SYSTEM.MEDIA) return
|
|
51
|
-
const
|
|
56
|
+
const globalTheme = getSystemTheme(element)
|
|
57
|
+
const { MEDIA } = context.SYSTEM
|
|
52
58
|
const mediaName = MEDIA[key.slice(1)]
|
|
53
59
|
const generatedClass = convertPropsToClass(props, result, element)
|
|
54
60
|
|
|
@@ -113,7 +119,8 @@ const beforeClassAssign = (element, s) => {
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
export const initUpdate = element => {
|
|
116
|
-
const { props,
|
|
122
|
+
const { props, class: className } = element
|
|
123
|
+
const globalTheme = getSystemTheme(element)
|
|
117
124
|
|
|
118
125
|
const parentProps = element.parent.props
|
|
119
126
|
if (parentProps && parentProps.spacingRatio && parentProps.inheritSpacingRatio) {
|
|
@@ -126,8 +133,6 @@ export const initUpdate = element => {
|
|
|
126
133
|
})
|
|
127
134
|
}
|
|
128
135
|
|
|
129
|
-
const { globalTheme } = context.SYSTEM
|
|
130
|
-
|
|
131
136
|
if (globalTheme) {
|
|
132
137
|
const CLASS_NAMES = {
|
|
133
138
|
media: {},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export const Picture = {
|
|
4
|
+
tag: 'picture',
|
|
5
|
+
|
|
6
|
+
childExtend: {
|
|
7
|
+
tag: 'source',
|
|
8
|
+
attr: {
|
|
9
|
+
media: ({ props, key, context }) => {
|
|
10
|
+
const { MEDIA } = context.SYSTEM
|
|
11
|
+
return MEDIA[(props.media || key).slice(1)]
|
|
12
|
+
},
|
|
13
|
+
srcset: ({ props }) => props.srcset
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
Img: ({ props }) => ({ src: props.src })
|
|
18
|
+
}
|
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
|
|