Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-3979] Encapsulated icons #487

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading