Skip to content
← ReactPalette Variants
import kleur from "@driangle/kleur";
import { useMemo } from "react";

function useVariants(hex, steps) {
  return useMemo(() => {
    const base = kleur(hex);
    const tints = [...base.tints(steps)];
    const shades = [...base.shades(steps)];

    return { tints, base, shades };
  }, [hex, steps]);
}

function Button({ variant, children }) {
  const { tints, base, shades } =
    useVariants("#3a6bd5", 5);

  const bg = variant === "light"
    ? tints[2].toHex()
    : variant === "dark"
      ? shades[2].toHex()
      : base.toHex();

  const color = kleur.isLight(bg)
    ? kleur(bg).darken(0.8).toHex()
    : kleur(bg).lighten(0.9).toHex();

  return (
    <button style={{ background: bg, color }}>
      {children}
    </button>
  );
}
#5b84dc
#7c9ce3
#9cb5ea
#bdcef1
#dee6f8
#3a6bd5
#2856ba
#204595
#183470
#10224a
#081125
Light
Default
Dark