material-color-utilities
Algorithms and utilities that power the Material Design 3 (M3) color system,
including choosing theme colors from images and creating tones of colors; all in
a new color space.
See the main
README
for more information.
Getting started
npm i @material/material-color-utilities
or yarn add @material/material-color-utilities
import { HCT } from "@material/material-color-utilities";
const color = HCT.fromInt(0xff4285f4);
console.log(`Hue: ${color.hue}`);
console.log(`Chrome: ${color.chroma}`);
console.log(`Tone: ${color.tone}`);
Theming
import { argbFromHex, themeFromSourceColor, applyTheme } from "@material/material-color-utilities";
const theme = themeFromSourceColor(argbFromHex('#f82506'), [
{
name: "custom-1",
value: argbFromHex("#ff0000"),
blend: true,
},
]);
console.log(JSON.stringify(theme, null, 2));
const systemDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
applyTheme(theme, {target: document.body, dark: systemDark});
Troubleshooting
If using node make sure to use the following flag:
node --experimental-specifier-resolution=node
Contributing
This repo is not accepting external contributions, but feature requests and bug
reports are welcome on
GitHub.