@codeleap/styles 4.2.2 → 4.2.4
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/dist/lib/createTheme.js +29 -31
- package/dist/types/style.d.ts +1 -1
- package/dist/types/theme.d.ts +11 -6
- package/package.json +2 -2
- package/package.json.bak +1 -1
- package/src/lib/createTheme.ts +32 -16
- package/src/types/style.ts +7 -1
- package/src/types/theme.ts +16 -9
package/dist/lib/createTheme.js
CHANGED
|
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
13
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
25
|
exports.createTheme = void 0;
|
|
15
26
|
var borderCreator_1 = require("./borderCreator");
|
|
@@ -19,57 +30,44 @@ var defaultVariants_1 = require("./defaultVariants");
|
|
|
19
30
|
var spacing_1 = require("./spacing");
|
|
20
31
|
var themeStore_1 = require("./themeStore");
|
|
21
32
|
var createTheme = function (theme, colorSchemaPersistor) {
|
|
22
|
-
var _a
|
|
23
|
-
var
|
|
24
|
-
|
|
33
|
+
var _a;
|
|
34
|
+
var colors = theme.colors, breakpoints = theme.breakpoints, presets = theme.presets, borderRadius = theme.borderRadius, effects = theme.effects, typography = theme.typography, icons = theme.icons, values = theme.values, otherThemeValues = __rest(theme, ["colors", "breakpoints", "presets", "borderRadius", "effects", "typography", "icons", "values"]);
|
|
35
|
+
var themeObj = __assign(__assign({}, otherThemeValues), { get currentColorScheme() {
|
|
25
36
|
return themeStore_1.themeStore.getState().colorScheme;
|
|
26
|
-
},
|
|
27
|
-
breakpoints: (_a = theme.breakpoints) !== null && _a !== void 0 ? _a : {},
|
|
28
|
-
get colors() {
|
|
37
|
+
}, breakpoints: breakpoints !== null && breakpoints !== void 0 ? breakpoints : {}, get colors() {
|
|
29
38
|
var _a;
|
|
30
39
|
var colorScheme = themeStore_1.themeStore.getState().colorScheme;
|
|
31
40
|
if (colorScheme === 'default')
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
return colors;
|
|
42
|
+
var scheme = (_a = theme.alternateColors) === null || _a === void 0 ? void 0 : _a[colorScheme];
|
|
43
|
+
if (!scheme) {
|
|
44
|
+
console.warn("Color scheme ".concat(colorScheme, " not found in theme"));
|
|
45
|
+
}
|
|
46
|
+
return scheme !== null && scheme !== void 0 ? scheme : colors;
|
|
47
|
+
}, setColorScheme: function (colorScheme) {
|
|
36
48
|
themeStore_1.themeStore.setState({ colorScheme: colorScheme });
|
|
37
49
|
colorSchemaPersistor.set(colorScheme);
|
|
38
|
-
},
|
|
39
|
-
baseSpacing: theme.baseSpacing,
|
|
40
|
-
value: function (n) {
|
|
50
|
+
}, baseSpacing: theme.baseSpacing, value: function (n) {
|
|
41
51
|
if (n === void 0) { n = 1; }
|
|
42
52
|
return theme.baseSpacing * n;
|
|
43
|
-
},
|
|
44
|
-
spacing: __assign(__assign(__assign(__assign({ value: function (n) {
|
|
53
|
+
}, spacing: __assign(__assign(__assign(__assign({ value: function (n) {
|
|
45
54
|
if (n === void 0) { n = 1; }
|
|
46
55
|
return theme.baseSpacing * n;
|
|
47
|
-
}, gap: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'gap') }, (0, spacing_1.spacingFactory)(theme.baseSpacing, 'padding')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'margin')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'p', true)), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'm', true)),
|
|
48
|
-
inset: {
|
|
56
|
+
}, gap: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'gap') }, (0, spacing_1.spacingFactory)(theme.baseSpacing, 'padding')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'margin')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'p', true)), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'm', true)), inset: {
|
|
49
57
|
top: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'top'),
|
|
50
58
|
bottom: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'bottom'),
|
|
51
59
|
left: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'left'),
|
|
52
|
-
right: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'right')
|
|
53
|
-
},
|
|
54
|
-
presets: __assign(__assign({}, defaultVariants_1.defaultVariants), theme.presets),
|
|
55
|
-
borderRadius: (_b = theme.borderRadius) !== null && _b !== void 0 ? _b : {},
|
|
56
|
-
effects: (_c = theme.effects) !== null && _c !== void 0 ? _c : {},
|
|
57
|
-
media: (0, mediaQuery_1.createMediaQueries)(theme.breakpoints),
|
|
58
|
-
border: borderCreator_1.borderCreator,
|
|
59
|
-
typography: (_d = theme.typography) !== null && _d !== void 0 ? _d : {},
|
|
60
|
-
icons: theme.icons,
|
|
61
|
-
values: (_e = theme.values) !== null && _e !== void 0 ? _e : {},
|
|
62
|
-
sized: function (size) {
|
|
60
|
+
right: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'right'),
|
|
61
|
+
}, presets: __assign(__assign({}, defaultVariants_1.defaultVariants), presets), borderRadius: borderRadius !== null && borderRadius !== void 0 ? borderRadius : {}, effects: effects !== null && effects !== void 0 ? effects : {}, media: (0, mediaQuery_1.createMediaQueries)(breakpoints), border: borderCreator_1.borderCreator, typography: typography !== null && typography !== void 0 ? typography : {}, icons: icons, values: values !== null && values !== void 0 ? values : {}, sized: function (size) {
|
|
63
62
|
var value = typeof size == 'number' ? size * theme.baseSpacing : size;
|
|
64
63
|
return {
|
|
65
64
|
width: value,
|
|
66
65
|
height: value,
|
|
67
66
|
};
|
|
68
|
-
}
|
|
69
|
-
};
|
|
67
|
+
} });
|
|
70
68
|
themeStore_1.themeStore.setState({
|
|
71
69
|
current: themeObj,
|
|
72
|
-
colorScheme: (
|
|
70
|
+
colorScheme: (_a = colorSchemaPersistor.get()) !== null && _a !== void 0 ? _a : 'default',
|
|
73
71
|
});
|
|
74
72
|
return themeObj;
|
|
75
73
|
};
|
package/dist/types/style.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type Inset = `top:${Multiplier}` | `bottom:${Multiplier}` | `left:${Multiplier}`
|
|
|
6
6
|
export type CommonVariants = Spacing | Inset | DynamicVariants | keyof DefaultVariants | keyof IAppVariants | `effect:${keyof IEffects}`;
|
|
7
7
|
type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = string, HasComposition = string> = ICSS | Variants | CommonVariants | boolean | null | '' | (HasBreakpoints extends string ? {
|
|
8
8
|
'breakpoints': Partial<Record<keyof IBreakpoints, StyleAtom<Composition, Variants, boolean, string> | StyleAtom<Composition, Variants, boolean, string>[]>>;
|
|
9
|
-
} : null) | (HasComposition extends string ? Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>> : null) |
|
|
9
|
+
} : null) | (HasComposition extends string ? Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>> : null) | Array<Variants | ICSS | Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>>>;
|
|
10
10
|
export type StyleProp<Composition = AnyRecord, Variants = string> = StyleAtom<Composition, Variants> | StyleAtom<Composition, Variants>[];
|
|
11
11
|
export type VariantStyleSheet = Record<string, any>;
|
|
12
12
|
export type StyledProp<T extends string> = StyleProp<Record<T, ICSS>>;
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -40,23 +40,28 @@ export type Theme = {
|
|
|
40
40
|
};
|
|
41
41
|
export type DefaultColorSchemeName = 'default';
|
|
42
42
|
export type ColorScheme<T extends Theme = Theme> = DefaultColorSchemeName | keyof T['alternateColors'];
|
|
43
|
-
|
|
43
|
+
type PredefinedThemeDerivedValues<T extends Theme> = {
|
|
44
44
|
colors: T['colors'];
|
|
45
45
|
breakpoints: T['breakpoints'];
|
|
46
|
-
setColorScheme: (colorScheme: ColorScheme<T>) => void;
|
|
47
|
-
currentColorScheme: ColorScheme<T>;
|
|
48
|
-
spacing: SpacingMap;
|
|
49
46
|
presets: DefaultVariants & T['presets'];
|
|
50
47
|
borderRadius: T['borderRadius'];
|
|
51
|
-
media: MediaQueries;
|
|
52
48
|
effects: T['effects'];
|
|
53
|
-
border: BorderCreator;
|
|
54
49
|
typography: T['typography'];
|
|
55
50
|
icons: T['icons'];
|
|
56
51
|
values: T['values'];
|
|
52
|
+
};
|
|
53
|
+
type PredefinedAppTheme<T extends Theme> = PredefinedThemeDerivedValues<T> & {
|
|
54
|
+
setColorScheme: (colorScheme: ColorScheme<T>) => void;
|
|
55
|
+
currentColorScheme: ColorScheme<T>;
|
|
56
|
+
spacing: SpacingMap;
|
|
57
|
+
media: MediaQueries;
|
|
58
|
+
border: BorderCreator;
|
|
57
59
|
inset: InsetMap;
|
|
58
60
|
baseSpacing: number;
|
|
59
61
|
value: (multiplier: number) => number;
|
|
60
62
|
sized: (size: number | string) => ICSS;
|
|
61
63
|
};
|
|
64
|
+
export type AppTheme<T extends Theme> = PredefinedAppTheme<T> & {
|
|
65
|
+
[P in Exclude<keyof T, keyof PredefinedThemeDerivedValues<T>>]: T[P];
|
|
66
|
+
};
|
|
62
67
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"directory": "packages/styles"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@codeleap/config": "4.2.
|
|
13
|
+
"@codeleap/config": "4.2.4",
|
|
14
14
|
"ts-node-dev": "1.1.8"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
package/package.json.bak
CHANGED
package/src/lib/createTheme.ts
CHANGED
|
@@ -12,19 +12,35 @@ type ColorSchemaPersistor = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const createTheme = <T extends Theme>(theme: T, colorSchemaPersistor: ColorSchemaPersistor): AppTheme<T> => {
|
|
15
|
+
const {
|
|
16
|
+
colors,
|
|
17
|
+
breakpoints,
|
|
18
|
+
presets,
|
|
19
|
+
borderRadius,
|
|
20
|
+
effects,
|
|
21
|
+
typography,
|
|
22
|
+
icons,
|
|
23
|
+
values,
|
|
24
|
+
...otherThemeValues
|
|
25
|
+
} = theme
|
|
26
|
+
|
|
15
27
|
const themeObj:AppTheme<T> = {
|
|
28
|
+
...otherThemeValues,
|
|
16
29
|
get currentColorScheme(): string {
|
|
17
30
|
return themeStore.getState().colorScheme
|
|
18
31
|
},
|
|
19
32
|
|
|
20
|
-
breakpoints:
|
|
33
|
+
breakpoints: breakpoints ?? {},
|
|
21
34
|
|
|
22
35
|
get colors() {
|
|
23
36
|
const colorScheme = themeStore.getState().colorScheme
|
|
24
37
|
|
|
25
|
-
if (colorScheme === 'default') return
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
if (colorScheme === 'default') return colors
|
|
39
|
+
const scheme = theme.alternateColors?.[colorScheme]
|
|
40
|
+
if (!scheme) {
|
|
41
|
+
console.warn(`Color scheme ${colorScheme} not found in theme`)
|
|
42
|
+
}
|
|
43
|
+
return scheme ?? colors
|
|
28
44
|
},
|
|
29
45
|
|
|
30
46
|
setColorScheme(colorScheme: ColorScheme<Theme>) {
|
|
@@ -48,31 +64,31 @@ export const createTheme = <T extends Theme>(theme: T, colorSchemaPersistor: Col
|
|
|
48
64
|
top: multiplierProperty(theme.baseSpacing, 'top'),
|
|
49
65
|
bottom: multiplierProperty(theme.baseSpacing, 'bottom'),
|
|
50
66
|
left: multiplierProperty(theme.baseSpacing, 'left'),
|
|
51
|
-
right: multiplierProperty(theme.baseSpacing, 'right')
|
|
67
|
+
right: multiplierProperty(theme.baseSpacing, 'right'),
|
|
52
68
|
},
|
|
53
69
|
|
|
54
70
|
presets: {
|
|
55
71
|
...defaultVariants,
|
|
56
|
-
...
|
|
72
|
+
...presets,
|
|
57
73
|
},
|
|
58
74
|
|
|
59
|
-
borderRadius:
|
|
75
|
+
borderRadius: borderRadius ?? {},
|
|
60
76
|
|
|
61
|
-
effects:
|
|
77
|
+
effects: effects ?? {},
|
|
62
78
|
|
|
63
|
-
media: createMediaQueries(
|
|
79
|
+
media: createMediaQueries(breakpoints),
|
|
64
80
|
|
|
65
81
|
border: borderCreator,
|
|
66
82
|
|
|
67
|
-
typography:
|
|
83
|
+
typography: typography ?? {},
|
|
68
84
|
|
|
69
|
-
icons:
|
|
85
|
+
icons: icons,
|
|
70
86
|
|
|
71
|
-
values:
|
|
87
|
+
values: values ?? {},
|
|
72
88
|
|
|
73
89
|
sized: (size) => {
|
|
74
90
|
const value = typeof size == 'number' ? size * theme.baseSpacing : size
|
|
75
|
-
|
|
91
|
+
|
|
76
92
|
return {
|
|
77
93
|
width: value,
|
|
78
94
|
height: value,
|
|
@@ -80,9 +96,9 @@ export const createTheme = <T extends Theme>(theme: T, colorSchemaPersistor: Col
|
|
|
80
96
|
},
|
|
81
97
|
}
|
|
82
98
|
|
|
83
|
-
themeStore.setState({
|
|
84
|
-
current: themeObj,
|
|
85
|
-
colorScheme: colorSchemaPersistor.get() ?? 'default'
|
|
99
|
+
themeStore.setState({
|
|
100
|
+
current: themeObj,
|
|
101
|
+
colorScheme: colorSchemaPersistor.get() ?? 'default',
|
|
86
102
|
})
|
|
87
103
|
|
|
88
104
|
return themeObj
|
package/src/types/style.ts
CHANGED
|
@@ -41,7 +41,13 @@ type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = stri
|
|
|
41
41
|
>>
|
|
42
42
|
: null
|
|
43
43
|
)
|
|
44
|
-
|
|
|
44
|
+
| Array<Variants | ICSS | Partial<
|
|
45
|
+
Record<
|
|
46
|
+
keyof Composition,
|
|
47
|
+
StyleAtom<AnyRecord, Variants, boolean, boolean> |
|
|
48
|
+
StyleAtom<AnyRecord, Variants, boolean, boolean>[]
|
|
49
|
+
>
|
|
50
|
+
>>
|
|
45
51
|
|
|
46
52
|
export type StyleProp<
|
|
47
53
|
Composition = AnyRecord,
|
package/src/types/theme.ts
CHANGED
|
@@ -20,8 +20,8 @@ type EffectsMap = {
|
|
|
20
20
|
[key: string]: IEffect
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export type SpacingMap =
|
|
24
|
-
Spacings<'margin'> &
|
|
23
|
+
export type SpacingMap =
|
|
24
|
+
Spacings<'margin'> &
|
|
25
25
|
Spacings<'padding'> &
|
|
26
26
|
Spacings<'m', string> &
|
|
27
27
|
Spacings<'p', string> &
|
|
@@ -29,7 +29,7 @@ export type SpacingMap =
|
|
|
29
29
|
gap: MultiplierFunction
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export type InsetMap =
|
|
32
|
+
export type InsetMap =
|
|
33
33
|
{
|
|
34
34
|
bottom: MultiplierFunction
|
|
35
35
|
top: MultiplierFunction
|
|
@@ -56,22 +56,29 @@ export type DefaultColorSchemeName = 'default'
|
|
|
56
56
|
|
|
57
57
|
export type ColorScheme<T extends Theme = Theme> = DefaultColorSchemeName | keyof T['alternateColors']
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
type PredefinedThemeDerivedValues<T extends Theme> = {
|
|
60
60
|
colors: T['colors']
|
|
61
61
|
breakpoints: T['breakpoints']
|
|
62
|
-
setColorScheme: (colorScheme: ColorScheme<T>) => void
|
|
63
|
-
currentColorScheme: ColorScheme<T>
|
|
64
|
-
spacing: SpacingMap
|
|
65
62
|
presets: DefaultVariants & T['presets']
|
|
66
63
|
borderRadius: T['borderRadius']
|
|
67
|
-
media: MediaQueries
|
|
68
64
|
effects: T['effects']
|
|
69
|
-
border: BorderCreator
|
|
70
65
|
typography: T['typography']
|
|
71
66
|
icons: T['icons']
|
|
72
67
|
values: T['values']
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type PredefinedAppTheme<T extends Theme> = PredefinedThemeDerivedValues<T> & {
|
|
71
|
+
setColorScheme: (colorScheme: ColorScheme<T>) => void
|
|
72
|
+
currentColorScheme: ColorScheme<T>
|
|
73
|
+
spacing: SpacingMap
|
|
74
|
+
media: MediaQueries
|
|
75
|
+
border: BorderCreator
|
|
73
76
|
inset: InsetMap
|
|
74
77
|
baseSpacing: number
|
|
75
78
|
value: (multiplier: number) => number
|
|
76
79
|
sized: (size: number | string) => ICSS
|
|
77
80
|
}
|
|
81
|
+
|
|
82
|
+
export type AppTheme<T extends Theme> = PredefinedAppTheme<T> & {
|
|
83
|
+
[P in Exclude<keyof T, keyof PredefinedThemeDerivedValues<T>>]: T[P]
|
|
84
|
+
}
|