elevate-rehab-v3

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

icon.tsx (4799B)


      1 import * as React from "react";
      2 import { ColorPickerInput } from "../../tina/fields/color";
      3 import { IconPickerInput } from "../../tina/fields/icon";
      4 import { useTheme } from "../layout";
      5 import * as BoxIcons from "react-icons/bi";
      6 
      7 export const IconOptions = {
      8   Tina: (props) => (
      9     <svg
     10       {...props}
     11       viewBox="0 0 66 80"
     12       fill="none"
     13       xmlns="http://www.w3.org/2000/svg"
     14     >
     15       <title>Tina</title>
     16       <path
     17         d="M39.4615 36.1782C42.763 33.4475 44.2259 17.3098 45.6551 11.5091C47.0843 5.70828 52.995 6.0025 52.995 6.0025C52.995 6.0025 51.4605 8.67299 52.0864 10.6658C52.7123 12.6587 57 14.4401 57 14.4401L56.0752 16.8781C56.0752 16.8781 54.1441 16.631 52.995 18.9297C51.8459 21.2283 53.7336 43.9882 53.7336 43.9882C53.7336 43.9882 46.8271 57.6106 46.8271 63.3621C46.8271 69.1136 49.5495 73.9338 49.5495 73.9338H45.7293C45.7293 73.9338 40.1252 67.2648 38.9759 63.9318C37.8266 60.5988 38.2861 57.2658 38.2861 57.2658C38.2861 57.2658 32.1946 56.921 26.7931 57.2658C21.3915 57.6106 17.7892 62.2539 17.1391 64.8512C16.4889 67.4486 16.2196 73.9338 16.2196 73.9338H13.1991C11.3606 68.2603 9.90043 66.2269 10.6925 63.3621C12.8866 55.4269 12.4557 50.9263 11.9476 48.9217C11.4396 46.9172 8 45.1676 8 45.1676C9.68492 41.7349 11.4048 40.0854 18.8029 39.9133C26.201 39.7413 36.1599 38.9088 39.4615 36.1782Z"
     18         fill="currentColor"
     19       />
     20       <path
     21         d="M20.25 63.03C20.25 63.03 21.0305 70.2533 25.1773 73.9342H28.7309C25.1773 69.9085 24.7897 59.415 24.7897 59.415C22.9822 60.0035 20.4799 62.1106 20.25 63.03Z"
     22         fill="currentColor"
     23       />
     24     </svg>
     25   ),
     26   ...BoxIcons,
     27 };
     28 
     29 const iconColorClass: {
     30   [name: string]: { regular: string; circle: string };
     31 } = {
     32   blue: {
     33     regular: "text-blue-400",
     34     circle: "bg-blue-400 dark:bg-blue-500 text-blue-50",
     35   },
     36   teal: {
     37     regular: "text-teal-400",
     38     circle: "bg-teal-400 dark:bg-teal-500 text-teal-50",
     39   },
     40   green: {
     41     regular: "text-green-400",
     42     circle: "bg-green-400 dark:bg-green-500 text-green-50",
     43   },
     44   red: {
     45     regular: "text-red-400",
     46     circle: "bg-red-400 dark:bg-red-500 text-red-50",
     47   },
     48   pink: {
     49     regular: "text-pink-400",
     50     circle: "bg-pink-400 dark:bg-pink-500 text-pink-50",
     51   },
     52   purple: {
     53     regular: "text-purple-400",
     54     circle: "bg-purple-400 dark:bg-purple-500 text-purple-50",
     55   },
     56   orange: {
     57     regular: "text-orange-400",
     58     circle: "bg-orange-400 dark:bg-orange-500 text-orange-50",
     59   },
     60   yellow: {
     61     regular: "text-yellow-400",
     62     circle: "bg-yellow-400 dark:bg-yellow-500 text-yellow-50",
     63   },
     64   white: {
     65     regular: "text-white opacity-80",
     66     circle: "bg-white-400 dark:bg-white-500 text-white-50",
     67   },
     68 };
     69 
     70 const iconSizeClass = {
     71   xs: "w-6 h-6 flex-shrink-0",
     72   small: "w-8 h-8 flex-shrink-0",
     73   medium: "w-12 h-12 flex-shrink-0",
     74   large: "w-14 h-14 flex-shrink-0",
     75   xl: "w-16 h-16 flex-shrink-0",
     76   custom: "",
     77 };
     78 
     79 export const Icon = ({
     80   data,
     81   parentColor = "",
     82   className = "",
     83   tinaField = "",
     84 }) => {
     85   const theme = useTheme();
     86   
     87   if (IconOptions[data.name] === null || IconOptions[data.name] === undefined) {
     88     return null;
     89   }
     90 
     91   const { name, color, size = "medium", style = "regular" } = data;
     92 
     93 
     94   const IconSVG = IconOptions[name];
     95 
     96   const iconSizeClasses =
     97     typeof size === "string"
     98       ? iconSizeClass[size]
     99       : iconSizeClass[Object.keys(iconSizeClass)[size]];
    100 
    101   const iconColor = color
    102     ? color === "primary"
    103       ? theme.color
    104       : color
    105     : theme.color;
    106 
    107   if (style == "circle") {
    108     return (
    109       <div
    110         data-tina-field={tinaField}
    111         className={`relative z-10 inline-flex items-center justify-center flex-shrink-0 ${iconSizeClasses} rounded-full ${iconColorClass[iconColor].circle} ${className}`}
    112       >
    113         <IconSVG className="w-2/3 h-2/3" />
    114       </div>
    115     );
    116   } else {
    117     const iconColorClasses =
    118       iconColorClass[
    119         parentColor === "primary" &&
    120         (iconColor === theme.color || iconColor === "primary")
    121           ? "white"
    122           : iconColor
    123       ].regular;
    124     return (
    125       <IconSVG
    126         data-tina-field={tinaField}
    127         className={`${iconSizeClasses} ${iconColorClasses} ${className}`}
    128       />
    129     );
    130   }
    131 };
    132 
    133 export const iconSchema = {
    134   type: "object",
    135   label: "Icon",
    136   name: "icon",
    137   fields: [
    138     {
    139       type: "string",
    140       label: "Icon",
    141       name: "name",
    142       ui: {
    143         component: IconPickerInput,
    144       },
    145     },
    146     {
    147       type: "string",
    148       label: "Color",
    149       name: "color",
    150       ui: {
    151         component: ColorPickerInput,
    152       },
    153     },
    154     {
    155       name: "style",
    156       label: "Style",
    157       type: "string",
    158       options: [
    159         {
    160           label: "Circle",
    161           value: "circle",
    162         },
    163         {
    164           label: "Float",
    165           value: "float",
    166         },
    167       ],
    168     },
    169   ],
    170 };