Bin
2025-12-17 2b99d77d73ba568beff0a549534017caaad8a6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import color from "chroma-js";
import { cn } from "../../../utils/bem";
import { colors } from "../../../utils/colors";
import "./Tag.scss";
 
const prepareColor = (colorString) => {
  const baseColor = color(colorString);
 
  return {
    color: baseColor,
    background: baseColor.desaturate(2).brighten(2.2),
    "shadow-color": baseColor.desaturate(1).brighten(1.22),
  };
};
 
const getColor = (colorString) => {
  if (colorString) {
    return colors[colorString] ?? colorString;
  }
  return colors.blue;
};
 
export const Tag = ({ className, style, size, color, children }) => {
  const finalColor = Object.entries(prepareColor(getColor(color))).reduce(
    (res, [key, color]) => ({ ...res, [`--${key}`]: color }),
    {},
  );
 
  const styles = { ...(style ?? {}), ...finalColor };
 
  return (
    <span className={cn("tag-dm").mod({ size }).mix(className).toClassName()} style={styles}>
      {children}
    </span>
  );
};