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

chore: update wds icon component #34950

Merged
merged 1 commit into from
Jul 22, 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

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion app/client/packages/design-system/headless/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// components
export * from "./components/Field";
export * from "./components/Icon";
export * from "./components/Tooltip";
export * from "./components/TextInput";
export * from "./components/TextArea";
Expand Down
2 changes: 1 addition & 1 deletion app/client/packages/design-system/widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@react-aria/visually-hidden": "^3.8.0",
"@react-types/actiongroup": "^3.4.6",
"@react-types/shared": "^3.23.1",
"@tabler/icons-react": "^2.45.0",
"@tabler/icons-react": "^3.10.0",
"clsx": "^2.0.0",
"colorjs.io": "^0.4.3",
"lodash": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
import type { Ref } from "react";
import type { Component, Ref } from "react";
import React, { Suspense, forwardRef, lazy, useMemo } from "react";
import { useThemeContext } from "@design-system/theming";
import { Icon as HeadlessIcon } from "@design-system/headless";

import { ICONS } from "./icons";
import styles from "./styles.module.css";
import type { IconProps } from "./types";
import { FallbackIcon } from "./FallbackIcon";

const _Icon = (props: IconProps, ref: Ref<SVGSVGElement>) => {
const { filled: filledProp, icon, name, size = "medium", ...rest } = props;
const _Icon = (props: IconProps, ref: Ref<Component>) => {
const { color, filled: filledProp, name, size = "medium", ...rest } = props;
const theme = useThemeContext();
const filled = theme.iconStyle === "filled" || filledProp;

const Icon = useMemo(() => {
let Icon: React.ComponentType | null;
const pascalName = ICONS[name];

if (icon !== undefined) {
Icon = icon as React.ComponentType;
} else if (name !== undefined) {
const pascalName = ICONS[name];
return lazy(async () =>
import("@tabler/icons-react").then((module) => {
if (Boolean(filled)) {
const filledVariant = `${pascalName}Filled`;

Icon = lazy(async () =>
import("@tabler/icons-react").then((module) => {
if (Boolean(filled)) {
const filledVariant = `${pascalName}Filled`;

if (filledVariant in module) {
return {
default: module[filledVariant] as React.ComponentType,
};
}
}

if (pascalName in module) {
if (filledVariant in module) {
return {
default: module[pascalName] as React.ComponentType,
default: module[filledVariant] as React.ComponentType,
};
}
}

if (pascalName in module) {
return {
default: module[pascalName] as React.ComponentType,
};
}

return { default: FallbackIcon };
}),
);
} else {
Icon = FallbackIcon;
}
return Icon;
}, [name, icon, filled]);
return { default: FallbackIcon };
}),
);
}, [name, filled]);
Comment on lines +18 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize icon loading logic.

The icon loading logic has been streamlined. However, the redundant Boolean calls should be removed.

-        if (Boolean(filled)) {
+        if (filled) {
-        if (Boolean(size)) {
+        if (size) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return lazy(async () =>
import("@tabler/icons-react").then((module) => {
if (Boolean(filled)) {
const filledVariant = `${pascalName}Filled`;
Icon = lazy(async () =>
import("@tabler/icons-react").then((module) => {
if (Boolean(filled)) {
const filledVariant = `${pascalName}Filled`;
if (filledVariant in module) {
return {
default: module[filledVariant] as React.ComponentType,
};
}
}
if (pascalName in module) {
if (filledVariant in module) {
return {
default: module[pascalName] as React.ComponentType,
default: module[filledVariant] as React.ComponentType,
};
}
}
if (pascalName in module) {
return {
default: module[pascalName] as React.ComponentType,
};
}
return { default: FallbackIcon };
}),
);
} else {
Icon = FallbackIcon;
}
return Icon;
}, [name, icon, filled]);
return { default: FallbackIcon };
}),
);
return lazy(async () =>
import("@tabler/icons-react").then((module) => {
if (filled) {
const filledVariant = `${pascalName}Filled`;
if (filledVariant in module) {
return {
default: module[filledVariant] as React.ComponentType,
};
}
}
if (pascalName in module) {
return {
default: module[pascalName] as React.ComponentType,
};
}
return { default: FallbackIcon };
}),
);
Tools
Biome

[error] 20-20: Avoid redundant Boolean call

It is not necessary to use Boolean call when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant Boolean call

(lint/complexity/noExtraBooleanCast)


return (
<Suspense
Expand All @@ -58,14 +48,14 @@ const _Icon = (props: IconProps, ref: Ref<SVGSVGElement>) => {
/>
}
>
<HeadlessIcon
<Icon
className={styles.icon}
data-color={color ? color : undefined}
data-icon=""
data-size={Boolean(size) ? size : undefined}
ref={ref}
{...rest}
>
<Icon />
</HeadlessIcon>
/>
</Suspense>
);
};
Expand Down
Loading
Loading