@codeleap/styles 4.3.7 → 4.3.8
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 +2 -2
- package/package.json.bak +1 -1
- package/src/lib/createStyles.ts +9 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.8",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/styles"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@codeleap/config": "4.3.
|
|
12
|
+
"@codeleap/config": "4.3.8",
|
|
13
13
|
"ts-node-dev": "1.1.8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
package/package.json.bak
CHANGED
package/src/lib/createStyles.ts
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import { ICSS, ITheme
|
|
1
|
+
import { AnyRecord, ICSS, ITheme } from '../types'
|
|
2
2
|
import { themeStore } from './themeStore'
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type Value = AnyRecord
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
styles: StylesShape<K, P> | ((theme: ITheme) => StylesShape<K, P>),
|
|
8
|
-
) {
|
|
6
|
+
type StylesShape<K extends string, V extends Value> = Partial<Record<K, ICSS & Partial<Omit<V, keyof ICSS>>>>
|
|
9
7
|
|
|
8
|
+
export function createStyles<K extends string, V extends Value = {}>(
|
|
9
|
+
styles: StylesShape<K, V> | ((theme: ITheme) => StylesShape<K, V>),
|
|
10
|
+
) {
|
|
10
11
|
const compute = () => {
|
|
11
|
-
let styleObj = {} as StylesShape<K, P>
|
|
12
12
|
const current = themeStore.getState().current
|
|
13
13
|
|
|
14
14
|
if (typeof styles === 'function') {
|
|
15
|
-
|
|
15
|
+
return !current ? {} as StylesShape<K, V> : styles(current)
|
|
16
16
|
} else {
|
|
17
|
-
|
|
17
|
+
return styles
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
return styleObj
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
// We use a proxy here so that the color scheme is recomputed every time the
|
|
24
22
|
// theme changes. This is necessary because the theme is a singleton which does not cause
|
|
25
23
|
// a re-render when it changes. The end-user will only have to worry about remounting the root component
|
|
26
24
|
// when the theme changes in order to get the new color scheme due to this proxy.
|
|
27
|
-
return new Proxy(compute() as StylesShape<K,
|
|
25
|
+
return new Proxy(compute() as StylesShape<K, V>, {
|
|
28
26
|
get(target, prop) {
|
|
29
27
|
return compute()[prop as string]
|
|
30
28
|
},
|