react-mcu 1.0.4 → 1.0.6
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/README.md +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +37 -15
- package/dist/tailwind.css +26 -1
- package/package.json +1 -1
- package/src/tailwind.css +26 -1
package/README.md
CHANGED
|
@@ -17,8 +17,9 @@ import { Mcu } from "react-mcu";
|
|
|
17
17
|
scheme="vibrant"
|
|
18
18
|
contrast={0.5}
|
|
19
19
|
customColors={[
|
|
20
|
-
{ name: "myCustomColor1", hex: "#
|
|
21
|
-
{ name: "myCustomColor2", hex: "#
|
|
20
|
+
{ name: "myCustomColor1", hex: "#6C8A0C", blend: true },
|
|
21
|
+
{ name: "myCustomColor2", hex: "#E126C6", blend: true },
|
|
22
|
+
{ name: "myCustomColor3", hex: "#E126C6", blend: false },
|
|
22
23
|
]}
|
|
23
24
|
>
|
|
24
25
|
<p style={{
|
|
@@ -26,7 +27,7 @@ import { Mcu } from "react-mcu";
|
|
|
26
27
|
color: "var(--mcu-on-surface)",
|
|
27
28
|
}}>
|
|
28
29
|
Hello, MCU <span style={{
|
|
29
|
-
backgroundColor: "var(--mcu-my-custom-
|
|
30
|
+
backgroundColor: "var(--mcu-my-custom-color-1)",
|
|
30
31
|
color: "var(--mcu-my-custom-color2)",
|
|
31
32
|
}}>colors<span>!
|
|
32
33
|
</p>
|
|
@@ -54,7 +55,7 @@ return (
|
|
|
54
55
|
Compatible with Tailwind through
|
|
55
56
|
[theme variables](https://tailwindcss.com/docs/theme):
|
|
56
57
|
|
|
57
|
-
https://github.com/abernier/react-mcu/blob/
|
|
58
|
+
https://github.com/abernier/react-mcu/blob/f981087651d77f6b11fc76cb783a5220a1b56e87/src/tailwind.css#L3-L76
|
|
58
59
|
|
|
59
60
|
Or simply:
|
|
60
61
|
|
|
@@ -62,6 +63,9 @@ Or simply:
|
|
|
62
63
|
@import "react-mcu/tailwind.css";
|
|
63
64
|
```
|
|
64
65
|
|
|
66
|
+
> [!IMPORTANT] Do not forget to manually add your custom colors, as in:
|
|
67
|
+
> https://github.com/abernier/react-mcu/blob/f981087651d77f6b11fc76cb783a5220a1b56e87/src/tailwind.css#L52-L75
|
|
68
|
+
|
|
65
69
|
# Dev
|
|
66
70
|
|
|
67
71
|
## INSTALL
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,14 @@ type HexCustomColor = Omit<CustomColor, "value"> & {
|
|
|
5
5
|
hex: string;
|
|
6
6
|
};
|
|
7
7
|
type McuConfig = {
|
|
8
|
+
/** Source color in hex format (e.g., "#6750A4") used to generate the color scheme */
|
|
8
9
|
source: string;
|
|
9
|
-
scheme:
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** Color scheme variant. Default: "tonalSpot" */
|
|
11
|
+
scheme?: SchemeName;
|
|
12
|
+
/** Contrast level from -1.0 (reduced) to 1.0 (increased). Default: 0 (standard) */
|
|
13
|
+
contrast?: number;
|
|
14
|
+
/** Array of custom colors to include in the generated palette */
|
|
15
|
+
customColors?: HexCustomColor[];
|
|
12
16
|
};
|
|
13
17
|
declare const schemesMap: {
|
|
14
18
|
readonly tonalSpot: typeof SchemeTonalSpot;
|
|
@@ -22,7 +26,7 @@ declare const schemesMap: {
|
|
|
22
26
|
declare const schemeNames: (keyof typeof schemesMap)[];
|
|
23
27
|
type SchemeName = (typeof schemeNames)[number];
|
|
24
28
|
declare function Mcu({ source, scheme, contrast, customColors, children, }: McuConfig & {
|
|
25
|
-
children
|
|
29
|
+
children?: React.ReactNode;
|
|
26
30
|
}): react_jsx_runtime.JSX.Element;
|
|
27
31
|
declare const tokenNames: readonly ["background", "onBackground", "surface", "surfaceDim", "surfaceBright", "surfaceContainerLowest", "surfaceContainerLow", "surfaceContainer", "surfaceContainerHigh", "surfaceContainerHighest", "onSurface", "onSurfaceVariant", "outline", "outlineVariant", "inverseSurface", "inverseOnSurface", "primary", "onPrimary", "primaryContainer", "onPrimaryContainer", "primaryFixed", "primaryFixedDim", "onPrimaryFixed", "onPrimaryFixedVariant", "inversePrimary", "primaryFixed", "primaryFixedDim", "onPrimaryFixed", "onPrimaryFixedVariant", "secondary", "onSecondary", "secondaryContainer", "onSecondaryContainer", "secondaryFixed", "secondaryFixedDim", "onSecondaryFixed", "onSecondaryFixedVariant", "tertiary", "onTertiary", "tertiaryContainer", "onTertiaryContainer", "tertiaryFixed", "tertiaryFixedDim", "onTertiaryFixed", "onTertiaryFixedVariant", "error", "onError", "errorContainer", "onErrorContainer", "scrim", "shadow"];
|
|
28
32
|
type TokenName = (typeof tokenNames)[number];
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/Mcu.tsx
|
|
2
2
|
import {
|
|
3
3
|
argbFromHex,
|
|
4
|
+
Blend,
|
|
4
5
|
Hct,
|
|
5
6
|
hexFromArgb as hexFromArgb2,
|
|
6
7
|
MaterialDynamicColors,
|
|
@@ -10,9 +11,10 @@ import {
|
|
|
10
11
|
SchemeMonochrome,
|
|
11
12
|
SchemeNeutral,
|
|
12
13
|
SchemeTonalSpot,
|
|
13
|
-
SchemeVibrant
|
|
14
|
+
SchemeVibrant,
|
|
15
|
+
TonalPalette
|
|
14
16
|
} from "@material/material-color-utilities";
|
|
15
|
-
import { kebabCase } from "lodash-es";
|
|
17
|
+
import { kebabCase, upperFirst } from "lodash-es";
|
|
16
18
|
import { useMemo as useMemo2 } from "react";
|
|
17
19
|
|
|
18
20
|
// src/Mcu.context.tsx
|
|
@@ -102,12 +104,15 @@ var schemesMap = {
|
|
|
102
104
|
var schemeNames = Object.keys(
|
|
103
105
|
schemesMap
|
|
104
106
|
);
|
|
107
|
+
var DEFAULT_SCHEME = "tonalSpot";
|
|
108
|
+
var DEFAULT_CONTRAST = 0;
|
|
109
|
+
var DEFAULT_CUSTOM_COLORS = [];
|
|
105
110
|
var mcuStyleId = "mcu-styles";
|
|
106
111
|
function Mcu({
|
|
107
112
|
source,
|
|
108
|
-
scheme,
|
|
109
|
-
contrast,
|
|
110
|
-
customColors,
|
|
113
|
+
scheme = DEFAULT_SCHEME,
|
|
114
|
+
contrast = DEFAULT_CONTRAST,
|
|
115
|
+
customColors = DEFAULT_CUSTOM_COLORS,
|
|
111
116
|
children
|
|
112
117
|
}) {
|
|
113
118
|
const config = useMemo2(
|
|
@@ -194,16 +199,25 @@ function toRecord(arr, getEntry) {
|
|
|
194
199
|
{}
|
|
195
200
|
);
|
|
196
201
|
}
|
|
197
|
-
function mergeBaseAndCustomColors(scheme, customColors) {
|
|
202
|
+
function mergeBaseAndCustomColors(scheme, customColors, sourceArgb) {
|
|
198
203
|
const baseVars = toRecord(tokenNames, (tokenName) => {
|
|
199
204
|
const dynamicColor = MaterialDynamicColors[tokenName];
|
|
200
205
|
const argb = dynamicColor.getArgb(scheme);
|
|
201
206
|
return [tokenName, argb];
|
|
202
207
|
});
|
|
203
|
-
const customVars =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
208
|
+
const customVars = {};
|
|
209
|
+
const isDark = scheme.isDark;
|
|
210
|
+
customColors.forEach((color) => {
|
|
211
|
+
const colorValue = color.blend ? Blend.harmonize(color.value, sourceArgb) : color.value;
|
|
212
|
+
const palette = TonalPalette.fromInt(colorValue);
|
|
213
|
+
const colorname = color.name;
|
|
214
|
+
customVars[colorname] = palette.tone(isDark ? 80 : 40);
|
|
215
|
+
customVars[`on${upperFirst(colorname)}`] = palette.tone(isDark ? 20 : 100);
|
|
216
|
+
customVars[`${colorname}Container`] = palette.tone(isDark ? 30 : 90);
|
|
217
|
+
customVars[`on${upperFirst(colorname)}Container`] = palette.tone(
|
|
218
|
+
isDark ? 90 : 10
|
|
219
|
+
);
|
|
220
|
+
});
|
|
207
221
|
return { ...baseVars, ...customVars };
|
|
208
222
|
}
|
|
209
223
|
var cssVar = (colorName, colorValue) => {
|
|
@@ -216,9 +230,9 @@ var toCssVars = (mergedColors) => {
|
|
|
216
230
|
};
|
|
217
231
|
function generateCss({
|
|
218
232
|
source: hexSource,
|
|
219
|
-
customColors: hexCustomColors,
|
|
220
|
-
scheme,
|
|
221
|
-
contrast
|
|
233
|
+
customColors: hexCustomColors = DEFAULT_CUSTOM_COLORS,
|
|
234
|
+
scheme = DEFAULT_SCHEME,
|
|
235
|
+
contrast = DEFAULT_CONTRAST
|
|
222
236
|
}) {
|
|
223
237
|
console.log("MCU generateCss");
|
|
224
238
|
const sourceArgb = argbFromHex(hexSource);
|
|
@@ -230,8 +244,16 @@ function generateCss({
|
|
|
230
244
|
...rest,
|
|
231
245
|
value: argbFromHex(hex)
|
|
232
246
|
}));
|
|
233
|
-
const mergedColorsLight = mergeBaseAndCustomColors(
|
|
234
|
-
|
|
247
|
+
const mergedColorsLight = mergeBaseAndCustomColors(
|
|
248
|
+
lightScheme,
|
|
249
|
+
customColors,
|
|
250
|
+
sourceArgb
|
|
251
|
+
);
|
|
252
|
+
const mergedColorsDark = mergeBaseAndCustomColors(
|
|
253
|
+
darkScheme,
|
|
254
|
+
customColors,
|
|
255
|
+
sourceArgb
|
|
256
|
+
);
|
|
235
257
|
const lightVars = toCssVars(mergedColorsLight);
|
|
236
258
|
const darkVars = toCssVars(mergedColorsDark);
|
|
237
259
|
return {
|
package/dist/tailwind.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
2
|
|
|
3
|
-
@theme {
|
|
3
|
+
@theme inline {
|
|
4
4
|
--color-background: var(--mcu-background);
|
|
5
5
|
--color-on-background: var(--mcu-on-background);
|
|
6
6
|
--color-surface: var(--mcu-surface);
|
|
@@ -48,4 +48,29 @@
|
|
|
48
48
|
--color-on-error-container: var(--mcu-on-error-container);
|
|
49
49
|
--color-scrim: var(--mcu-scrim);
|
|
50
50
|
--color-shadow: var(--mcu-shadow);
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Custom colors
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
--color-myCustomColor1: var(--mcu-my-custom-color-1);
|
|
57
|
+
--color-on-myCustomColor1: var(--mcu-on-my-custom-color-1);
|
|
58
|
+
--color-myCustomColor1-container: var(--mcu-my-custom-color-1-container);
|
|
59
|
+
--color-on-myCustomColor1-container: var(
|
|
60
|
+
--mcu-on-my-custom-color-1-container
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
--color-myCustomColor2: var(--mcu-my-custom-color-2);
|
|
64
|
+
--color-on-myCustomColor2: var(--mcu-on-my-custom-color-2);
|
|
65
|
+
--color-myCustomColor2-container: var(--mcu-my-custom-color-2-container);
|
|
66
|
+
--color-on-myCustomColor2-container: var(
|
|
67
|
+
--mcu-on-my-custom-color-2-container
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
--color-myCustomColor3: var(--mcu-my-custom-color-3);
|
|
71
|
+
--color-on-myCustomColor3: var(--mcu-on-my-custom-color-3);
|
|
72
|
+
--color-myCustomColor3-container: var(--mcu-my-custom-color-3-container);
|
|
73
|
+
--color-on-myCustomColor3-container: var(
|
|
74
|
+
--mcu-on-my-custom-color-3-container
|
|
75
|
+
);
|
|
51
76
|
}
|
package/package.json
CHANGED
package/src/tailwind.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
2
|
|
|
3
|
-
@theme {
|
|
3
|
+
@theme inline {
|
|
4
4
|
--color-background: var(--mcu-background);
|
|
5
5
|
--color-on-background: var(--mcu-on-background);
|
|
6
6
|
--color-surface: var(--mcu-surface);
|
|
@@ -48,4 +48,29 @@
|
|
|
48
48
|
--color-on-error-container: var(--mcu-on-error-container);
|
|
49
49
|
--color-scrim: var(--mcu-scrim);
|
|
50
50
|
--color-shadow: var(--mcu-shadow);
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Custom colors
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
--color-myCustomColor1: var(--mcu-my-custom-color-1);
|
|
57
|
+
--color-on-myCustomColor1: var(--mcu-on-my-custom-color-1);
|
|
58
|
+
--color-myCustomColor1-container: var(--mcu-my-custom-color-1-container);
|
|
59
|
+
--color-on-myCustomColor1-container: var(
|
|
60
|
+
--mcu-on-my-custom-color-1-container
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
--color-myCustomColor2: var(--mcu-my-custom-color-2);
|
|
64
|
+
--color-on-myCustomColor2: var(--mcu-on-my-custom-color-2);
|
|
65
|
+
--color-myCustomColor2-container: var(--mcu-my-custom-color-2-container);
|
|
66
|
+
--color-on-myCustomColor2-container: var(
|
|
67
|
+
--mcu-on-my-custom-color-2-container
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
--color-myCustomColor3: var(--mcu-my-custom-color-3);
|
|
71
|
+
--color-on-myCustomColor3: var(--mcu-on-my-custom-color-3);
|
|
72
|
+
--color-myCustomColor3-container: var(--mcu-my-custom-color-3-container);
|
|
73
|
+
--color-on-myCustomColor3-container: var(
|
|
74
|
+
--mcu-on-my-custom-color-3-container
|
|
75
|
+
);
|
|
51
76
|
}
|