@codeleap/styles 5.7.1 → 5.8.2
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.2",
|
|
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.2",
|
|
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
|
@@ -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/hooks.ts
CHANGED
|
@@ -41,7 +41,7 @@ export const useTheme = <T = ThemeState>(
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function useCompositionStyles<T extends string, C extends string>(
|
|
44
|
-
composition: Array<T
|
|
44
|
+
composition: (T | Array<T>),
|
|
45
45
|
componentStyles: Partial<Record<C, ICSS>>
|
|
46
46
|
): Partial<Record<T, ICSS>> {
|
|
47
47
|
const styles = {
|
|
@@ -51,8 +51,12 @@ export function useCompositionStyles<T extends string, C extends string>(
|
|
|
51
51
|
return useMemo(() => {
|
|
52
52
|
const compositionStyles = {}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (Array.isArray(composition)) {
|
|
55
|
+
for (const element of composition) {
|
|
56
|
+
compositionStyles[element as string] = getNestedStylesByKey(element, styles)
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
compositionStyles[composition as string] = getNestedStylesByKey(composition, styles)
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
return compositionStyles
|
package/src/lib/themeStore.ts
CHANGED
|
@@ -53,7 +53,7 @@ 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
|
|
|
@@ -65,14 +65,14 @@ class ThemeStore {
|
|
|
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
|
}
|
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
|
}
|