Skip to content

Commit

Permalink
feat: add EncapsulatedIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehenson committed Sep 19, 2024
1 parent 1f2d132 commit d3f3c70
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 243 deletions.
2 changes: 1 addition & 1 deletion src/core/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconName } from "./Icon/types";
import { ColorClass } from "./styles/colors/types";
import { convertTailwindClassToVar } from "./styles/colors/utils";

type IconProps = {
export type IconProps = {
name: IconName;
size?: string;
color?: ColorClass;
Expand Down
35 changes: 35 additions & 0 deletions src/core/Icon/EncapsulatedIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";
import Icon, { IconProps } from "../Icon";
import { determineThemeColor } from "../styles/colors/utils";
import { ColorClass, Theme } from "../styles/colors/types";

type EncapsulatedIconProps = {
theme?: Theme;
className?: string;
} & IconProps;

const EncapsulatedIcon = ({
theme = "dark",
size = "40px",
className,
...iconProps
}: EncapsulatedIconProps) => {
const t = (color: ColorClass) => determineThemeColor("dark", theme, color);
const numericalSize = parseInt(size, 10);

return (
<div
className={`p-1 rounded-lg ${theme === "light" ? "bg-gradient-to-t" : "bg-gradient-to-b"} ${t("from-neutral-900")} ${className ?? ""}`}
style={{ width: numericalSize, height: numericalSize }}
>
<div
className={`flex items-center justify-center rounded-lg ${t("bg-neutral-1100")}`}
style={{ height: numericalSize - 2 }}
>
<Icon size={`${numericalSize - 12}`} {...iconProps} />
</div>
</div>
);
};

export default EncapsulatedIcon;
32 changes: 25 additions & 7 deletions src/core/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from "react";
import Icon from "../Icon";
import EncapsulatedIcon from "./EncapsulatedIcon";
import loadIcons from "../icons";
import { IconName, iconNames } from "./types";
import { Theme } from "../styles/colors/types";

export default {
title: "JS Components/Icon",
Expand All @@ -12,7 +14,11 @@ export default {
tags: ["autodocs"],
};

const renderIcons = (iconSet: IconName[]) => {
const renderIcons = (
iconSet: IconName[],
encapsulated?: boolean,
theme?: Theme,
) => {
loadIcons();

return (
Expand All @@ -25,12 +31,16 @@ const renderIcons = (iconSet: IconName[]) => {
<code className="ui-text-code mb-8 block">{icon}</code>
<div className="border inline-flex flex-0">
<div className="flex pi-checkered-bg">
<Icon
name={icon}
additionalCSS="hover:text-active-orange"
color="text-cool-black"
size="1.5rem"
/>
{encapsulated ? (
<EncapsulatedIcon name={icon} theme={theme ?? "dark"} />
) : (
<Icon
name={icon}
additionalCSS="hover:text-active-orange"
color="text-cool-black"
size="1.5rem"
/>
)}
</div>
</div>
</div>
Expand Down Expand Up @@ -88,3 +98,11 @@ export const IconWithSecondaryColor = {
},
},
};

export const DarkEncapsulatedIcons = {
render: () => renderIcons([...iconNames.product], true),
};

export const LightEncapsulatedIcons = {
render: () => renderIcons([...iconNames.product], true, "light"),
};
Loading

0 comments on commit d3f3c70

Please sign in to comment.