@codeleap/styles 5.7.0 → 5.8.1
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/StaleControl.ts +1 -1
- package/src/lib/borderCreator.ts +1 -1
- package/src/lib/createTheme.ts +11 -0
- package/src/lib/dynamicVariants.ts +6 -3
- package/src/lib/themeStore.ts +21 -9
- package/src/lib/validateTheme.ts +19 -2
- package/src/types/theme.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.1",
|
|
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": "5.
|
|
12
|
+
"@codeleap/config": "5.8.1",
|
|
13
13
|
"ts-node-dev": "^1.1.8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
package/package.json.bak
CHANGED
package/src/lib/StaleControl.ts
CHANGED
package/src/lib/borderCreator.ts
CHANGED
package/src/lib/createTheme.ts
CHANGED
|
@@ -95,6 +95,17 @@ export const createTheme = <T extends Theme>(theme: T, themePersistor: ThemePers
|
|
|
95
95
|
|
|
96
96
|
themePersistor.set(alternateColorsKey, unpersistedAlternateColors)
|
|
97
97
|
},
|
|
98
|
+
ejectColorScheme(name) {
|
|
99
|
+
themeStore.ejectColorScheme(name)
|
|
100
|
+
|
|
101
|
+
const persistedAlternateColors = themePersistor.get(alternateColorsKey)
|
|
102
|
+
|
|
103
|
+
if (name in persistedAlternateColors) {
|
|
104
|
+
delete persistedAlternateColors[name]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
themePersistor.set(alternateColorsKey, persistedAlternateColors)
|
|
108
|
+
},
|
|
98
109
|
|
|
99
110
|
baseSpacing: theme.baseSpacing,
|
|
100
111
|
|
|
@@ -22,6 +22,9 @@ export type Value =
|
|
|
22
22
|
| number
|
|
23
23
|
| ''
|
|
24
24
|
|
|
25
|
+
// @note
|
|
26
|
+
// Typing has been removed because figma's new color organization is extremely heavy,
|
|
27
|
+
// perhaps in a future typescript update
|
|
25
28
|
type Color = string // keyof IColors
|
|
26
29
|
|
|
27
30
|
export type DynamicVariants =
|
|
@@ -44,7 +47,7 @@ export const createDynamicVariants = () => {
|
|
|
44
47
|
|
|
45
48
|
colorVariants.forEach(variant => {
|
|
46
49
|
createVariant(variant, (theme, color: Color) => ({
|
|
47
|
-
[variant]: theme.
|
|
50
|
+
[variant]: theme.colors[color],
|
|
48
51
|
}))
|
|
49
52
|
})
|
|
50
53
|
|
|
@@ -63,7 +66,7 @@ export const createDynamicVariants = () => {
|
|
|
63
66
|
const variant = `border${capitalize(direction)}${capitalize(property)}`
|
|
64
67
|
|
|
65
68
|
createVariant(variant, (theme, value: string) => ({
|
|
66
|
-
[variant]: property == 'color' ? theme.
|
|
69
|
+
[variant]: property == 'color' ? theme.colors[value] : theme.radius[value],
|
|
67
70
|
}))
|
|
68
71
|
})
|
|
69
72
|
})
|
|
@@ -71,7 +74,7 @@ export const createDynamicVariants = () => {
|
|
|
71
74
|
createVariant('cursor', (theme, cursor: typeof cursorTypes[number]) => ({ cursor }))
|
|
72
75
|
|
|
73
76
|
createVariant('bg', (theme, color: Color) => ({
|
|
74
|
-
backgroundColor: theme.
|
|
77
|
+
backgroundColor: theme.colors[color],
|
|
75
78
|
}))
|
|
76
79
|
|
|
77
80
|
createVariant('effect', (theme, effect: keyof IEffects) => theme.effects[effect])
|
package/src/lib/themeStore.ts
CHANGED
|
@@ -53,41 +53,53 @@ class ThemeStore {
|
|
|
53
53
|
|
|
54
54
|
// utils
|
|
55
55
|
|
|
56
|
-
private
|
|
56
|
+
private getBaseSchemeColors(): ColorMap {
|
|
57
57
|
const alternateColors = this.alternateColorsScheme ?? {}
|
|
58
58
|
const colorSchemeKeys = Object.keys(alternateColors)
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
if (colorSchemeKeys.length === 0) {
|
|
61
61
|
return {}
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
return alternateColors[colorSchemeKeys[0]] ?? {}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
injectColorScheme(name: string, colors: ColorMap) {
|
|
68
|
-
const
|
|
68
|
+
const baseSchemeColors = this.getBaseSchemeColors()
|
|
69
69
|
const currentAlternateColors = this.alternateColorsScheme ?? {}
|
|
70
70
|
|
|
71
71
|
const alternateColors = {
|
|
72
72
|
...currentAlternateColors,
|
|
73
73
|
|
|
74
74
|
[name]: {
|
|
75
|
-
...
|
|
75
|
+
...baseSchemeColors,
|
|
76
76
|
...colors,
|
|
77
|
-
}
|
|
77
|
+
},
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
this.setAlternateColorsScheme(alternateColors)
|
|
81
81
|
|
|
82
82
|
return alternateColors
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
ejectColorScheme(name:string) {
|
|
86
|
+
const currentAlternateColors = this.alternateColorsScheme ?? {}
|
|
87
|
+
|
|
88
|
+
if (name in currentAlternateColors) {
|
|
89
|
+
delete currentAlternateColors[name]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.setAlternateColorsScheme(currentAlternateColors)
|
|
93
|
+
|
|
94
|
+
return currentAlternateColors
|
|
95
|
+
}
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
export const themeStore = new ThemeStore()
|
|
87
99
|
|
|
88
100
|
export const themeStoreComputed = computed([
|
|
89
|
-
themeStore
|
|
90
|
-
themeStore
|
|
101
|
+
themeStore.themeStore,
|
|
102
|
+
themeStore.colorSchemeStore,
|
|
91
103
|
], (theme, colorScheme) => ({
|
|
92
104
|
theme: theme as unknown as AppTheme<Theme>,
|
|
93
105
|
colorScheme,
|
package/src/lib/validateTheme.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Theme } from '../types/theme'
|
|
2
2
|
|
|
3
3
|
export function validateTheme<T extends Theme>(theme: T) {
|
|
4
|
+
const baseColors = theme.baseColors
|
|
5
|
+
|
|
4
6
|
const colors = theme.colors
|
|
5
|
-
const requiredColors = Object.keys(colors)
|
|
6
7
|
|
|
7
8
|
const alternateColors = theme.alternateColors
|
|
9
|
+
|
|
10
|
+
const requiredColors = Object.keys(colors)
|
|
11
|
+
|
|
12
|
+
const mergedAlternateColors = {}
|
|
8
13
|
|
|
9
14
|
if (alternateColors) {
|
|
10
15
|
for (const [colorSchemeName, colorSchemeColors] of Object.entries(alternateColors)) {
|
|
@@ -15,8 +20,20 @@ export function validateTheme<T extends Theme>(theme: T) {
|
|
|
15
20
|
throw new Error(`Alternate color scheme ${colorSchemeName} is missing color ${requiredColor}`)
|
|
16
21
|
}
|
|
17
22
|
}
|
|
23
|
+
|
|
24
|
+
mergedAlternateColors[colorSchemeName] = {
|
|
25
|
+
...baseColors,
|
|
26
|
+
...colorSchemeColors,
|
|
27
|
+
}
|
|
18
28
|
}
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
...theme,
|
|
33
|
+
alternateColors: mergedAlternateColors,
|
|
34
|
+
colors: {
|
|
35
|
+
...baseColors,
|
|
36
|
+
...colors,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
22
39
|
}
|
package/src/types/theme.ts
CHANGED
|
@@ -78,6 +78,7 @@ type PredefinedAppTheme<T extends Theme> = PredefinedThemeDerivedValues<T> & {
|
|
|
78
78
|
setColorScheme: (colorScheme: string) => void
|
|
79
79
|
currentColorScheme: () => ColorScheme<T>
|
|
80
80
|
injectColorScheme: (name: string, colorMap: ColorMap) => void
|
|
81
|
+
ejectColorScheme: (name: string) => void
|
|
81
82
|
spacing: SpacingMap
|
|
82
83
|
media: MediaQueries
|
|
83
84
|
border: BorderCreator
|