You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. import React, {CSSProperties, useMemo} from "react";
  2. import {ColorValue} from "../models/Colors";
  3. import {kelvinToRgbHex} from "../helpers/kelvin";
  4. import {Icon} from "@iconify/react";
  5. import "./Elements.sass";
  6. import {LuciferIcon, toIconify} from "../models/Icons";
  7. function Element({children}: React.PropsWithChildren<{}>) {
  8. return (
  9. <div className="Element">{children}</div>
  10. )
  11. }
  12. interface IconProps {
  13. icon?: LuciferIcon
  14. color?: ColorValue | "hs-gradient" | "k-gradient"
  15. }
  16. export function IconBlock({icon, color}: IconProps) {
  17. const style: CSSProperties = useMemo(() => {
  18. const s: CSSProperties = {
  19. backgroundClip: "text",
  20. // @ts-ignore
  21. textFillColor: "transparent",
  22. };
  23. if (color !== undefined) {
  24. if (color === "hs-gradient") {
  25. s.backgroundImage = "linear-gradient(to bottom right, red, yellow, green, blue, violet)";
  26. } else if (color === "k-gradient") {
  27. s.backgroundImage = "linear-gradient(to bottom right, #ff9329, #ffd6aa, #fffaf4, #fff, #c9e2ff, #40a3ff)";
  28. } else if (color.kelvin !== undefined && color.kelvin > 0) {
  29. s.color = kelvinToRgbHex(color.kelvin);
  30. } else {
  31. const hue = color.h || 0;
  32. const sat = Math.floor((color.s || 0) * 100);
  33. s.color = `hsl(${hue}, ${sat}%, 50%)`;
  34. }
  35. }
  36. return s;
  37. }, [color]);
  38. return (
  39. <Icon icon={toIconify(icon || LuciferIcon.Square)}
  40. className="ColorElement-block"
  41. style={style}
  42. />
  43. );
  44. }
  45. interface IconElementProps extends IconProps {
  46. caption: string
  47. }
  48. export function IconElement({caption, color, icon}: IconElementProps) {
  49. return (
  50. <Element>
  51. <IconBlock icon={icon} color={color}/>
  52. {caption}
  53. </Element>
  54. );
  55. }