react-mcu 1.1.0 → 1.2.0
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 +21 -0
- package/dist/index.d.ts +22 -2
- package/dist/index.js +233 -64
- package/dist/tailwind.css +0 -19
- package/package.json +4 -4
- package/src/tailwind.css +0 -19
package/README.md
CHANGED
|
@@ -15,6 +15,27 @@ m3 references:
|
|
|
15
15
|
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
16
16
|
| [<img width="2836" height="2266" alt="CleanShot 2026-01-14 at 08 58 40@2x" src="https://github.com/user-attachments/assets/e4b47c00-716f-4b08-b393-de306d5ce302" />](https://material-foundation.github.io/material-theme-builder/) | [<img width="2836" height="2266" alt="CleanShot 2026-01-14 at 09 01 23@2x" src="https://github.com/user-attachments/assets/826e502d-e173-43c4-807a-53d0ba075a88" />](https://m3.material.io/styles/color/roles) |
|
|
17
17
|
|
|
18
|
+
Support for:
|
|
19
|
+
|
|
20
|
+
Base (like in the Builder):
|
|
21
|
+
|
|
22
|
+
- [x] light/dark mode
|
|
23
|
+
- [x] source color
|
|
24
|
+
- [x] scheme
|
|
25
|
+
- [x] contrast
|
|
26
|
+
- [x] core-colors overrides: primary, secondary, tertiary, error, neutral,
|
|
27
|
+
neutralVariant
|
|
28
|
+
- [x] custom-colors (aka. "Extended colors")
|
|
29
|
+
- [x] Harmonization (aka. `blend`) -- with effective color: `source` or
|
|
30
|
+
`primary` if defined
|
|
31
|
+
- [x] Shades (aka. "tonals")
|
|
32
|
+
- [ ] colorMatch
|
|
33
|
+
|
|
34
|
+
Extra:
|
|
35
|
+
|
|
36
|
+
- [x] `contrastAllColors`: contrast also applies to custom-colors and shades
|
|
37
|
+
(not only the core-colors)
|
|
38
|
+
|
|
18
39
|
# Usage
|
|
19
40
|
|
|
20
41
|
```tsx
|
package/dist/index.d.ts
CHANGED
|
@@ -28,10 +28,30 @@ type McuConfig = {
|
|
|
28
28
|
* When true, stays true to input colors without harmonization.
|
|
29
29
|
* When false (default), colors may be adjusted for better harmonization.
|
|
30
30
|
* Corresponds to "Color match - Stay true to my color inputs" in Material Theme Builder.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
* @deprecated Not yet implemented. This prop is currently ignored.
|
|
31
34
|
*/
|
|
32
35
|
colorMatch?: boolean;
|
|
33
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Array of custom colors to include in the generated palette.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* customColors={[
|
|
42
|
+
* { name: "brand", hex: "#FF5733", blend: true },
|
|
43
|
+
* { name: "success", hex: "#28A745", blend: false }
|
|
44
|
+
* ]}
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
34
47
|
customColors?: HexCustomColor[];
|
|
48
|
+
/**
|
|
49
|
+
* When true, applies the contrast level to all colors including custom colors and tonal palette shades.
|
|
50
|
+
* When false (default), only core colors are affected by the contrast level.
|
|
51
|
+
*
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
contrastAllColors?: boolean;
|
|
35
55
|
};
|
|
36
56
|
declare const schemesMap: {
|
|
37
57
|
readonly tonalSpot: typeof SchemeTonalSpot;
|
|
@@ -44,7 +64,7 @@ declare const schemesMap: {
|
|
|
44
64
|
};
|
|
45
65
|
declare const schemeNames: (keyof typeof schemesMap)[];
|
|
46
66
|
type SchemeName = (typeof schemeNames)[number];
|
|
47
|
-
declare function Mcu({ source, scheme, contrast, primary, secondary, tertiary, neutral, neutralVariant, error, colorMatch, customColors, children, }: McuConfig & {
|
|
67
|
+
declare function Mcu({ source, scheme, contrast, primary, secondary, tertiary, neutral, neutralVariant, error, colorMatch, customColors, contrastAllColors, children, }: McuConfig & {
|
|
48
68
|
children?: React.ReactNode;
|
|
49
69
|
}): react_jsx_runtime.JSX.Element;
|
|
50
70
|
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"];
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// src/Mcu.tsx
|
|
4
4
|
import {
|
|
5
5
|
argbFromHex,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Blend,
|
|
7
|
+
DynamicColor,
|
|
8
8
|
DynamicScheme,
|
|
9
9
|
Hct,
|
|
10
10
|
hexFromArgb as hexFromArgb2,
|
|
@@ -52,6 +52,7 @@ var McuProvider = ({
|
|
|
52
52
|
scheme: initialScheme,
|
|
53
53
|
contrast: initialContrast,
|
|
54
54
|
customColors: initialCustomColors,
|
|
55
|
+
contrastAllColors: initialContrastAllColors,
|
|
55
56
|
styleId,
|
|
56
57
|
children
|
|
57
58
|
}) => {
|
|
@@ -59,7 +60,8 @@ var McuProvider = ({
|
|
|
59
60
|
source: initialSource,
|
|
60
61
|
scheme: initialScheme,
|
|
61
62
|
contrast: initialContrast,
|
|
62
|
-
customColors: initialCustomColors
|
|
63
|
+
customColors: initialCustomColors,
|
|
64
|
+
contrastAllColors: initialContrastAllColors
|
|
63
65
|
}));
|
|
64
66
|
const [mcuConfig, setMcuConfig] = useState(initials);
|
|
65
67
|
const { css, mergedColorsLight, mergedColorsDark } = useMemo(
|
|
@@ -96,6 +98,16 @@ var McuProvider = ({
|
|
|
96
98
|
|
|
97
99
|
// src/Mcu.tsx
|
|
98
100
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
101
|
+
function adjustToneForContrast(baseTone, contrastLevel, isDark, adjustmentFactor = DEFAULT_CONTRAST_ADJUSTMENT_FACTOR) {
|
|
102
|
+
if (contrastLevel === 0) return baseTone;
|
|
103
|
+
let adjustedTone;
|
|
104
|
+
if (isDark) {
|
|
105
|
+
adjustedTone = baseTone + contrastLevel * (100 - baseTone) * adjustmentFactor;
|
|
106
|
+
} else {
|
|
107
|
+
adjustedTone = baseTone - contrastLevel * baseTone * adjustmentFactor;
|
|
108
|
+
}
|
|
109
|
+
return Math.max(0, Math.min(100, adjustedTone));
|
|
110
|
+
}
|
|
99
111
|
var schemesMap = {
|
|
100
112
|
tonalSpot: SchemeTonalSpot,
|
|
101
113
|
monochrome: SchemeMonochrome,
|
|
@@ -112,6 +124,9 @@ var DEFAULT_SCHEME = "tonalSpot";
|
|
|
112
124
|
var DEFAULT_CONTRAST = 0;
|
|
113
125
|
var DEFAULT_COLOR_MATCH = false;
|
|
114
126
|
var DEFAULT_CUSTOM_COLORS = [];
|
|
127
|
+
var DEFAULT_CONTRAST_ALL_COLORS = false;
|
|
128
|
+
var DEFAULT_BLEND = true;
|
|
129
|
+
var DEFAULT_CONTRAST_ADJUSTMENT_FACTOR = 0.2;
|
|
115
130
|
var STANDARD_TONES = [
|
|
116
131
|
0,
|
|
117
132
|
5,
|
|
@@ -165,6 +180,7 @@ function Mcu({
|
|
|
165
180
|
error,
|
|
166
181
|
colorMatch = DEFAULT_COLOR_MATCH,
|
|
167
182
|
customColors = DEFAULT_CUSTOM_COLORS,
|
|
183
|
+
contrastAllColors = DEFAULT_CONTRAST_ALL_COLORS,
|
|
168
184
|
children
|
|
169
185
|
}) {
|
|
170
186
|
const config = useMemo2(
|
|
@@ -179,7 +195,9 @@ function Mcu({
|
|
|
179
195
|
neutralVariant,
|
|
180
196
|
error,
|
|
181
197
|
colorMatch,
|
|
182
|
-
customColors
|
|
198
|
+
customColors,
|
|
199
|
+
// extras features
|
|
200
|
+
contrastAllColors
|
|
183
201
|
}),
|
|
184
202
|
[
|
|
185
203
|
contrast,
|
|
@@ -192,7 +210,8 @@ function Mcu({
|
|
|
192
210
|
neutral,
|
|
193
211
|
neutralVariant,
|
|
194
212
|
error,
|
|
195
|
-
colorMatch
|
|
213
|
+
colorMatch,
|
|
214
|
+
contrastAllColors
|
|
196
215
|
]
|
|
197
216
|
);
|
|
198
217
|
const { css } = useMemo2(() => generateCss(config), [config]);
|
|
@@ -270,22 +289,63 @@ function toRecord(arr, getEntry) {
|
|
|
270
289
|
{}
|
|
271
290
|
);
|
|
272
291
|
}
|
|
273
|
-
function
|
|
292
|
+
function getPalette(palettes, colorName) {
|
|
293
|
+
const palette = palettes[colorName];
|
|
294
|
+
if (!palette) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Custom color palette not found for '${colorName}'. This is likely a bug in the implementation.`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
return palette;
|
|
300
|
+
}
|
|
301
|
+
function mergeBaseAndCustomColors(scheme, customColors, colorPalettes, contrastAllColors) {
|
|
274
302
|
const baseVars = toRecord(tokenNames, (tokenName) => {
|
|
275
303
|
const dynamicColor = MaterialDynamicColors[tokenName];
|
|
276
304
|
const argb = dynamicColor.getArgb(scheme);
|
|
277
305
|
return [tokenName, argb];
|
|
278
306
|
});
|
|
279
307
|
const customVars = {};
|
|
280
|
-
const isDark = scheme.isDark;
|
|
281
308
|
customColors.forEach((color) => {
|
|
282
|
-
const customColorGroup = customColor(sourceArgb, color);
|
|
283
|
-
const colorGroup = isDark ? customColorGroup.dark : customColorGroup.light;
|
|
284
309
|
const colorname = color.name;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
310
|
+
const getPaletteForColor = (s) => getPalette(colorPalettes, colorname);
|
|
311
|
+
const getTone = (baseTone) => (s) => {
|
|
312
|
+
if (!contrastAllColors) return baseTone;
|
|
313
|
+
return adjustToneForContrast(baseTone, s.contrastLevel, s.isDark);
|
|
314
|
+
};
|
|
315
|
+
const colorDynamicColor = new DynamicColor(
|
|
316
|
+
colorname,
|
|
317
|
+
getPaletteForColor,
|
|
318
|
+
(s) => getTone(s.isDark ? 80 : 40)(s),
|
|
319
|
+
// Main color: lighter in dark mode, darker in light mode
|
|
320
|
+
true
|
|
321
|
+
// background
|
|
322
|
+
);
|
|
323
|
+
const onColorDynamicColor = new DynamicColor(
|
|
324
|
+
`on${upperFirst(colorname)}`,
|
|
325
|
+
getPaletteForColor,
|
|
326
|
+
(s) => getTone(s.isDark ? 20 : 100)(s),
|
|
327
|
+
// Text on main color: high contrast (dark on light, light on dark)
|
|
328
|
+
false
|
|
329
|
+
);
|
|
330
|
+
const containerDynamicColor = new DynamicColor(
|
|
331
|
+
`${colorname}Container`,
|
|
332
|
+
getPaletteForColor,
|
|
333
|
+
(s) => getTone(s.isDark ? 30 : 90)(s),
|
|
334
|
+
// Container: subtle variant (darker in dark mode, lighter in light mode)
|
|
335
|
+
true
|
|
336
|
+
// background
|
|
337
|
+
);
|
|
338
|
+
const onContainerDynamicColor = new DynamicColor(
|
|
339
|
+
`on${upperFirst(colorname)}Container`,
|
|
340
|
+
getPaletteForColor,
|
|
341
|
+
(s) => getTone(s.isDark ? 90 : 30)(s),
|
|
342
|
+
// Text on container: high contrast against container background
|
|
343
|
+
false
|
|
344
|
+
);
|
|
345
|
+
customVars[colorname] = colorDynamicColor.getArgb(scheme);
|
|
346
|
+
customVars[`on${upperFirst(colorname)}`] = onColorDynamicColor.getArgb(scheme);
|
|
347
|
+
customVars[`${colorname}Container`] = containerDynamicColor.getArgb(scheme);
|
|
348
|
+
customVars[`on${upperFirst(colorname)}Container`] = onContainerDynamicColor.getArgb(scheme);
|
|
289
349
|
});
|
|
290
350
|
return { ...baseVars, ...customVars };
|
|
291
351
|
}
|
|
@@ -294,12 +354,38 @@ var cssVar = (colorName, colorValue) => {
|
|
|
294
354
|
const value = hexFromArgb2(colorValue);
|
|
295
355
|
return `${name}:${value};`;
|
|
296
356
|
};
|
|
297
|
-
var generateTonalPaletteVars = (paletteName, palette) => {
|
|
357
|
+
var generateTonalPaletteVars = (paletteName, palette, scheme, applyContrast = false) => {
|
|
298
358
|
return STANDARD_TONES.map((tone) => {
|
|
299
|
-
|
|
359
|
+
let toneToUse = tone;
|
|
360
|
+
if (applyContrast && scheme) {
|
|
361
|
+
toneToUse = adjustToneForContrast(
|
|
362
|
+
tone,
|
|
363
|
+
scheme.contrastLevel,
|
|
364
|
+
scheme.isDark
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const color = palette.tone(toneToUse);
|
|
300
368
|
return cssVar(`${paletteName}-${tone}`, color);
|
|
301
369
|
}).join(" ");
|
|
302
370
|
};
|
|
371
|
+
function createColorPalette(colorDef, baseScheme, effectiveSourceForHarmonization) {
|
|
372
|
+
const colorArgb = argbFromHex(colorDef.hex);
|
|
373
|
+
const harmonizedArgb = colorDef.blend ? Blend.harmonize(colorArgb, effectiveSourceForHarmonization) : colorArgb;
|
|
374
|
+
const hct = Hct.fromInt(harmonizedArgb);
|
|
375
|
+
let targetChroma;
|
|
376
|
+
if (colorDef.core && colorDef.chromaSource) {
|
|
377
|
+
if (colorDef.chromaSource === "neutral") {
|
|
378
|
+
targetChroma = baseScheme.neutralPalette.chroma;
|
|
379
|
+
} else if (colorDef.chromaSource === "neutralVariant") {
|
|
380
|
+
targetChroma = baseScheme.neutralVariantPalette.chroma;
|
|
381
|
+
} else {
|
|
382
|
+
targetChroma = baseScheme.primaryPalette.chroma;
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
targetChroma = baseScheme.primaryPalette.chroma;
|
|
386
|
+
}
|
|
387
|
+
return TonalPalette.fromHueAndChroma(hct.hue, targetChroma);
|
|
388
|
+
}
|
|
303
389
|
var toCssVars = (mergedColors) => {
|
|
304
390
|
return Object.entries(mergedColors).map(([name, value]) => cssVar(name, value)).join(" ");
|
|
305
391
|
};
|
|
@@ -314,76 +400,159 @@ function generateCss({
|
|
|
314
400
|
neutralVariant,
|
|
315
401
|
error,
|
|
316
402
|
colorMatch = DEFAULT_COLOR_MATCH,
|
|
317
|
-
customColors: hexCustomColors = DEFAULT_CUSTOM_COLORS
|
|
403
|
+
customColors: hexCustomColors = DEFAULT_CUSTOM_COLORS,
|
|
404
|
+
contrastAllColors = DEFAULT_CONTRAST_ALL_COLORS
|
|
318
405
|
}) {
|
|
319
|
-
const hasCoreColors = primary ?? secondary ?? tertiary ?? neutral ?? neutralVariant ?? error;
|
|
320
406
|
const sourceArgb = argbFromHex(hexSource);
|
|
407
|
+
const effectiveSource = primary || hexSource;
|
|
408
|
+
const effectiveSourceArgb = argbFromHex(effectiveSource);
|
|
409
|
+
const effectiveSourceForHarmonization = primary ? argbFromHex(primary) : sourceArgb;
|
|
410
|
+
const SchemeClass = schemesMap[scheme];
|
|
411
|
+
const primaryHct = Hct.fromInt(effectiveSourceArgb);
|
|
412
|
+
const baseScheme = new SchemeClass(primaryHct, false, contrast);
|
|
413
|
+
const allColors = [
|
|
414
|
+
// Core colors (hex may be undefined)
|
|
415
|
+
{
|
|
416
|
+
name: "primary",
|
|
417
|
+
hex: primary,
|
|
418
|
+
core: true,
|
|
419
|
+
chromaSource: "primary"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: "secondary",
|
|
423
|
+
hex: secondary,
|
|
424
|
+
core: true,
|
|
425
|
+
chromaSource: "primary"
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
name: "tertiary",
|
|
429
|
+
hex: tertiary,
|
|
430
|
+
core: true,
|
|
431
|
+
chromaSource: "primary"
|
|
432
|
+
},
|
|
433
|
+
{ name: "error", hex: error, core: true, chromaSource: "primary" },
|
|
434
|
+
{
|
|
435
|
+
name: "neutral",
|
|
436
|
+
hex: neutral,
|
|
437
|
+
core: true,
|
|
438
|
+
chromaSource: "neutral"
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
name: "neutralVariant",
|
|
442
|
+
hex: neutralVariant,
|
|
443
|
+
core: true,
|
|
444
|
+
chromaSource: "neutralVariant"
|
|
445
|
+
},
|
|
446
|
+
//
|
|
447
|
+
// Custom colors
|
|
448
|
+
//
|
|
449
|
+
...hexCustomColors.map((c) => ({
|
|
450
|
+
name: c.name,
|
|
451
|
+
hex: c.hex,
|
|
452
|
+
blend: c.blend,
|
|
453
|
+
core: false
|
|
454
|
+
}))
|
|
455
|
+
];
|
|
456
|
+
const definedColors = allColors.filter(
|
|
457
|
+
(c) => c.hex !== void 0
|
|
458
|
+
);
|
|
459
|
+
const colorPalettes = Object.fromEntries(
|
|
460
|
+
definedColors.map((colorDef) => [
|
|
461
|
+
colorDef.name,
|
|
462
|
+
createColorPalette(colorDef, baseScheme, effectiveSourceForHarmonization)
|
|
463
|
+
])
|
|
464
|
+
);
|
|
321
465
|
const createSchemes = (baseConfig) => [
|
|
322
466
|
new DynamicScheme({ ...baseConfig, isDark: false }),
|
|
323
467
|
new DynamicScheme({ ...baseConfig, isDark: true })
|
|
324
468
|
];
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
sourceColorArgb: sourceArgb,
|
|
341
|
-
variant,
|
|
342
|
-
contrastLevel: contrast,
|
|
343
|
-
primaryPalette: corePalette.a1,
|
|
344
|
-
secondaryPalette: corePalette.a2,
|
|
345
|
-
tertiaryPalette: corePalette.a3,
|
|
346
|
-
neutralPalette: corePalette.n1,
|
|
347
|
-
neutralVariantPalette: corePalette.n2
|
|
348
|
-
});
|
|
349
|
-
} else {
|
|
350
|
-
const SchemeClass = schemesMap[scheme];
|
|
351
|
-
const hct = Hct.fromInt(sourceArgb);
|
|
352
|
-
lightScheme = new SchemeClass(hct, false, contrast);
|
|
353
|
-
darkScheme = new SchemeClass(hct, true, contrast);
|
|
354
|
-
corePalette = CorePalette.of(sourceArgb);
|
|
469
|
+
const variant = schemeToVariant[scheme];
|
|
470
|
+
const [lightScheme, darkScheme] = createSchemes({
|
|
471
|
+
sourceColorArgb: effectiveSourceArgb,
|
|
472
|
+
variant,
|
|
473
|
+
contrastLevel: contrast,
|
|
474
|
+
primaryPalette: colorPalettes["primary"] || baseScheme.primaryPalette,
|
|
475
|
+
secondaryPalette: colorPalettes["secondary"] || baseScheme.secondaryPalette,
|
|
476
|
+
tertiaryPalette: colorPalettes["tertiary"] || baseScheme.tertiaryPalette,
|
|
477
|
+
neutralPalette: colorPalettes["neutral"] || baseScheme.neutralPalette,
|
|
478
|
+
neutralVariantPalette: colorPalettes["neutralVariant"] || baseScheme.neutralVariantPalette
|
|
479
|
+
});
|
|
480
|
+
const errorPalette = colorPalettes["error"];
|
|
481
|
+
if (errorPalette) {
|
|
482
|
+
lightScheme.errorPalette = errorPalette;
|
|
483
|
+
darkScheme.errorPalette = errorPalette;
|
|
355
484
|
}
|
|
356
|
-
const customColors =
|
|
357
|
-
|
|
358
|
-
|
|
485
|
+
const customColors = definedColors.filter((c) => !c.core).map((c) => ({
|
|
486
|
+
name: c.name,
|
|
487
|
+
blend: c.blend ?? DEFAULT_BLEND,
|
|
488
|
+
value: argbFromHex(c.hex)
|
|
359
489
|
}));
|
|
360
490
|
const mergedColorsLight = mergeBaseAndCustomColors(
|
|
361
491
|
lightScheme,
|
|
362
492
|
customColors,
|
|
363
|
-
|
|
493
|
+
colorPalettes,
|
|
494
|
+
contrastAllColors
|
|
364
495
|
);
|
|
365
496
|
const mergedColorsDark = mergeBaseAndCustomColors(
|
|
366
497
|
darkScheme,
|
|
367
498
|
customColors,
|
|
368
|
-
|
|
499
|
+
colorPalettes,
|
|
500
|
+
contrastAllColors
|
|
369
501
|
);
|
|
370
502
|
const lightVars = toCssVars(mergedColorsLight);
|
|
371
503
|
const darkVars = toCssVars(mergedColorsDark);
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
generateTonalPaletteVars(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
504
|
+
const allTonalVars = [
|
|
505
|
+
// Core colors from the scheme
|
|
506
|
+
generateTonalPaletteVars(
|
|
507
|
+
"primary",
|
|
508
|
+
lightScheme.primaryPalette,
|
|
509
|
+
lightScheme,
|
|
510
|
+
contrastAllColors
|
|
511
|
+
),
|
|
512
|
+
generateTonalPaletteVars(
|
|
513
|
+
"secondary",
|
|
514
|
+
lightScheme.secondaryPalette,
|
|
515
|
+
lightScheme,
|
|
516
|
+
contrastAllColors
|
|
517
|
+
),
|
|
518
|
+
generateTonalPaletteVars(
|
|
519
|
+
"tertiary",
|
|
520
|
+
lightScheme.tertiaryPalette,
|
|
521
|
+
lightScheme,
|
|
522
|
+
contrastAllColors
|
|
523
|
+
),
|
|
524
|
+
generateTonalPaletteVars(
|
|
525
|
+
"error",
|
|
526
|
+
lightScheme.errorPalette,
|
|
527
|
+
lightScheme,
|
|
528
|
+
contrastAllColors
|
|
529
|
+
),
|
|
530
|
+
generateTonalPaletteVars(
|
|
531
|
+
"neutral",
|
|
532
|
+
lightScheme.neutralPalette,
|
|
533
|
+
lightScheme,
|
|
534
|
+
contrastAllColors
|
|
535
|
+
),
|
|
536
|
+
generateTonalPaletteVars(
|
|
537
|
+
"neutral-variant",
|
|
538
|
+
lightScheme.neutralVariantPalette,
|
|
539
|
+
lightScheme,
|
|
540
|
+
contrastAllColors
|
|
541
|
+
),
|
|
542
|
+
// Custom colors from our unified palette map
|
|
543
|
+
...customColors.map((customColorObj) => {
|
|
544
|
+
const palette = getPalette(colorPalettes, customColorObj.name);
|
|
545
|
+
return generateTonalPaletteVars(
|
|
546
|
+
kebabCase(customColorObj.name),
|
|
547
|
+
palette,
|
|
548
|
+
lightScheme,
|
|
549
|
+
contrastAllColors
|
|
550
|
+
);
|
|
551
|
+
})
|
|
379
552
|
].join(" ");
|
|
380
|
-
const customColorTonalVars = customColors.map((customColorObj) => {
|
|
381
|
-
const palette = TonalPalette.fromInt(customColorObj.value);
|
|
382
|
-
return generateTonalPaletteVars(kebabCase(customColorObj.name), palette);
|
|
383
|
-
}).join(" ");
|
|
384
553
|
return {
|
|
385
554
|
css: `
|
|
386
|
-
:root { ${lightVars} ${
|
|
555
|
+
:root { ${lightVars} ${allTonalVars} }
|
|
387
556
|
.dark { ${darkVars} }
|
|
388
557
|
`,
|
|
389
558
|
mergedColorsLight,
|
package/dist/tailwind.css
CHANGED
|
@@ -164,23 +164,4 @@
|
|
|
164
164
|
--color-myCustomColor2-800: var(--mcu-my-custom-color-2-20);
|
|
165
165
|
--color-myCustomColor2-900: var(--mcu-my-custom-color-2-10);
|
|
166
166
|
--color-myCustomColor2-950: var(--mcu-my-custom-color-2-5);
|
|
167
|
-
|
|
168
|
-
--color-myCustomColor3: var(--mcu-my-custom-color-3);
|
|
169
|
-
--color-on-myCustomColor3: var(--mcu-on-my-custom-color-3);
|
|
170
|
-
--color-myCustomColor3-container: var(--mcu-my-custom-color-3-container);
|
|
171
|
-
--color-on-myCustomColor3-container: var(
|
|
172
|
-
--mcu-on-my-custom-color-3-container
|
|
173
|
-
);
|
|
174
|
-
/* Shades */
|
|
175
|
-
--color-myCustomColor3-50: var(--mcu-my-custom-color-3-95);
|
|
176
|
-
--color-myCustomColor3-100: var(--mcu-my-custom-color-3-90);
|
|
177
|
-
--color-myCustomColor3-200: var(--mcu-my-custom-color-3-80);
|
|
178
|
-
--color-myCustomColor3-300: var(--mcu-my-custom-color-3-70);
|
|
179
|
-
--color-myCustomColor3-400: var(--mcu-my-custom-color-3-60);
|
|
180
|
-
--color-myCustomColor3-500: var(--mcu-my-custom-color-3-50);
|
|
181
|
-
--color-myCustomColor3-600: var(--mcu-my-custom-color-3-40);
|
|
182
|
-
--color-myCustomColor3-700: var(--mcu-my-custom-color-3-30);
|
|
183
|
-
--color-myCustomColor3-800: var(--mcu-my-custom-color-3-20);
|
|
184
|
-
--color-myCustomColor3-900: var(--mcu-my-custom-color-3-10);
|
|
185
|
-
--color-myCustomColor3-950: var(--mcu-my-custom-color-3-5);
|
|
186
167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-mcu",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A React component library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -66,14 +66,14 @@
|
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "tsup",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
69
|
+
"lgtm": "pnpm run build && pnpm run check-format && pnpm run check-exports && pnpm run typecheck && pnpm run test",
|
|
70
|
+
"typecheck": "tsc",
|
|
71
71
|
"test": "vitest run",
|
|
72
72
|
"format": "prettier --write .",
|
|
73
73
|
"check-format": "prettier --check .",
|
|
74
74
|
"check-exports": "attw --pack . --ignore-rules cjs-resolves-to-esm no-resolution",
|
|
75
75
|
"release": "pnpm run build && changeset publish",
|
|
76
|
-
"local-release": "pnpm run
|
|
76
|
+
"local-release": "pnpm run lgtm && changeset version && changeset publish",
|
|
77
77
|
"storybook": "storybook dev -p 6006",
|
|
78
78
|
"build-storybook": "storybook build",
|
|
79
79
|
"chromatic": "chromatic --project-token $CHROMATIC_PROJECT_TOKEN",
|
package/src/tailwind.css
CHANGED
|
@@ -164,23 +164,4 @@
|
|
|
164
164
|
--color-myCustomColor2-800: var(--mcu-my-custom-color-2-20);
|
|
165
165
|
--color-myCustomColor2-900: var(--mcu-my-custom-color-2-10);
|
|
166
166
|
--color-myCustomColor2-950: var(--mcu-my-custom-color-2-5);
|
|
167
|
-
|
|
168
|
-
--color-myCustomColor3: var(--mcu-my-custom-color-3);
|
|
169
|
-
--color-on-myCustomColor3: var(--mcu-on-my-custom-color-3);
|
|
170
|
-
--color-myCustomColor3-container: var(--mcu-my-custom-color-3-container);
|
|
171
|
-
--color-on-myCustomColor3-container: var(
|
|
172
|
-
--mcu-on-my-custom-color-3-container
|
|
173
|
-
);
|
|
174
|
-
/* Shades */
|
|
175
|
-
--color-myCustomColor3-50: var(--mcu-my-custom-color-3-95);
|
|
176
|
-
--color-myCustomColor3-100: var(--mcu-my-custom-color-3-90);
|
|
177
|
-
--color-myCustomColor3-200: var(--mcu-my-custom-color-3-80);
|
|
178
|
-
--color-myCustomColor3-300: var(--mcu-my-custom-color-3-70);
|
|
179
|
-
--color-myCustomColor3-400: var(--mcu-my-custom-color-3-60);
|
|
180
|
-
--color-myCustomColor3-500: var(--mcu-my-custom-color-3-50);
|
|
181
|
-
--color-myCustomColor3-600: var(--mcu-my-custom-color-3-40);
|
|
182
|
-
--color-myCustomColor3-700: var(--mcu-my-custom-color-3-30);
|
|
183
|
-
--color-myCustomColor3-800: var(--mcu-my-custom-color-3-20);
|
|
184
|
-
--color-myCustomColor3-900: var(--mcu-my-custom-color-3-10);
|
|
185
|
-
--color-myCustomColor3-950: var(--mcu-my-custom-color-3-5);
|
|
186
167
|
}
|