From 67394c255956035b446e1008c6e3185612a8bc26 Mon Sep 17 00:00:00 2001
From: physicsSorcererKing
Date: Sun, 5 May 2024 20:45:17 +0800
Subject: [PATCH 1/6] Revert "fix: merge icon and icon v2"
This reverts commit bb5db829
---
components/shared/Button/v2/Button.tsx | 9 +-
components/shared/Icon/icons/index.ts | 43 ---------
components/shared/Icon/icons/svgs/arcade.svg | 2 +-
.../shared/Icon/icons/svgs/archery-match.svg | 2 +-
components/shared/Icon/icons/svgs/archery.svg | 2 +-
.../Icon/icons/svgs/arrow-left-circle.svg | 2 +-
.../shared/Icon/icons/svgs/arrow-left.svg | 2 +-
.../Icon/icons/svgs/arrow-right-circle.svg | 2 +-
.../shared/Icon/icons/svgs/arrow-right.svg | 2 +-
.../shared/Icon/icons/svgs/bounce-right.svg | 2 +-
.../shared/Icon/icons/svgs/bright-crown.svg | 2 +-
.../shared/Icon/icons/svgs/bright-star.svg | 2 +-
components/shared/Icon/icons/svgs/cellar.svg | 2 +-
.../shared/Icon/icons/svgs/chat-lines.svg | 2 +-
components/shared/Icon/icons/svgs/check.svg | 2 +-
.../shared/Icon/icons/svgs/chess-rook.svg | 2 +-
.../shared/Icon/icons/svgs/collectbook.svg | 2 +-
.../shared/Icon/icons/svgs/community.svg | 2 +-
components/shared/Icon/icons/svgs/crown.svg | 2 +-
components/shared/Icon/icons/svgs/discord.svg | 4 +-
components/shared/Icon/icons/svgs/droplet.svg | 2 +-
.../shared/Icon/icons/svgs/edit-pencil.svg | 2 +-
components/shared/Icon/icons/svgs/edit.svg | 4 +-
components/shared/Icon/icons/svgs/emoji.svg | 2 +-
components/shared/Icon/icons/svgs/error.svg | 2 +-
components/shared/Icon/icons/svgs/explore.svg | 2 +-
.../shared/Icon/icons/svgs/gamepad-simple.svg | 2 +-
components/shared/Icon/icons/svgs/gamepad.svg | 4 +-
components/shared/Icon/icons/svgs/github.svg | 4 +-
components/shared/Icon/icons/svgs/globe.svg | 2 +-
components/shared/Icon/icons/svgs/google.svg | 7 +-
components/shared/Icon/icons/svgs/heart.svg | 4 +-
components/shared/Icon/icons/svgs/home.svg | 2 +-
.../Icon/icons/svgs/hot-air-balloon.svg | 4 +-
.../shared/Icon/icons/svgs/kick_user.svg | 2 +-
components/shared/Icon/icons/svgs/label.svg | 2 +-
components/shared/Icon/icons/svgs/layout.svg | 2 +-
.../shared/Icon/icons/svgs/leaderboard.svg | 2 +-
components/shared/Icon/icons/svgs/lens.svg | 2 +-
.../shared/Icon/icons/svgs/linkedin.svg | 5 +-
components/shared/Icon/icons/svgs/logo.svg | 2 +-
.../shared/Icon/icons/svgs/nav-arrow-left.svg | 2 +-
.../Icon/icons/svgs/nav-arrow-right.svg | 2 +-
.../shared/Icon/icons/svgs/neighbourhood.svg | 2 +-
.../shared/Icon/icons/svgs/page-left.svg | 2 +-
.../shared/Icon/icons/svgs/page-right.svg | 2 +-
components/shared/Icon/icons/svgs/pending.svg | 2 +-
.../shared/Icon/icons/svgs/planimetry.svg | 2 +-
components/shared/Icon/icons/svgs/play.svg | 2 +-
components/shared/Icon/icons/svgs/player.svg | 2 +-
components/shared/Icon/icons/svgs/players.svg | 2 +-
components/shared/Icon/icons/svgs/search.svg | 2 +-
.../shared/Icon/icons/svgs/send-diagonal.svg | 2 +-
components/shared/Icon/icons/svgs/sent.svg | 2 +-
.../shared/Icon/icons/svgs/sleeper-chair.svg | 2 +-
components/shared/Icon/icons/svgs/spiral.svg | 2 +-
.../shared/Icon/icons/svgs/star-dashed.svg | 2 +-
.../Icon/icons/svgs/star-half-dashed.svg | 2 +-
components/shared/Icon/icons/svgs/star.svg | 2 +-
components/shared/Icon/icons/svgs/tower.svg | 2 +-
components/shared/Icon/icons/svgs/trophy.svg | 2 +-
components/shared/Icon/icons/svgs/tunnel.svg | 2 +-
components/shared/Icon/v2/Icon.tsx | 30 ++++++
components/shared/Icon/v2/icon.stories.tsx | 88 +++++++++++++++++
components/shared/Icon/v2/icon.test.tsx | 27 ++++++
components/shared/Icon/v2/icons/index.ts | 95 +++++++++++++++++++
.../shared/Icon/v2/icons/svgs/arcade.svg | 7 ++
.../shared/Icon/v2/icons/svgs/archery.svg | 3 +
.../shared/Icon/v2/icons/svgs/arrow-left.svg | 3 +
.../shared/Icon/v2/icons/svgs/arrow-right.svg | 3 +
.../Icon/v2/icons/svgs/bright-crown.svg | 15 +++
.../Icon/{ => v2}/icons/svgs/calendar.svg | 0
.../Icon/{ => v2}/icons/svgs/chat-default.svg | 0
.../Icon/{ => v2}/icons/svgs/chat-updates.svg | 0
.../shared/Icon/v2/icons/svgs/chess-rook.svg | 3 +
.../shared/Icon/{ => v2}/icons/svgs/clock.svg | 0
.../shared/Icon/v2/icons/svgs/collectbook.svg | 7 ++
.../shared/Icon/v2/icons/svgs/discord.svg | 3 +
.../Icon/{ => v2}/icons/svgs/edit-mode.svg | 0
components/shared/Icon/v2/icons/svgs/edit.svg | 3 +
.../shared/Icon/v2/icons/svgs/explore.svg | 5 +
.../shared/Icon/{ => v2}/icons/svgs/frame.svg | 0
.../shared/Icon/v2/icons/svgs/gamepad.svg | 4 +
.../shared/Icon/v2/icons/svgs/github.svg | 3 +
.../shared/Icon/v2/icons/svgs/google.svg | 6 ++
.../shared/Icon/v2/icons/svgs/heart.svg | 3 +
.../Icon/{ => v2}/icons/svgs/help-circle.svg | 0
components/shared/Icon/v2/icons/svgs/home.svg | 3 +
.../Icon/v2/icons/svgs/hot-air-balloon.svg | 5 +
.../Icon/{ => v2}/icons/svgs/house-lock.svg | 0
.../shared/Icon/{ => v2}/icons/svgs/house.svg | 0
.../Icon/{ => v2}/icons/svgs/leading-icon.svg | 0
.../shared/Icon/v2/icons/svgs/linkedin.svg | 4 +
.../Icon/{ => v2}/icons/svgs/log-out.svg | 0
.../icons/svgs/long-arrow-up-left.svg | 0
.../Icon/v2/icons/svgs/nav-arrow-left.svg | 3 +
.../Icon/v2/icons/svgs/nav-arrow-right.svg | 3 +
.../Icon/{ => v2}/icons/svgs/nonpublic.svg | 0
.../icons/svgs/notification-default.svg | 0
.../icons/svgs/notification-updates.svg | 0
.../shared/Icon/v2/icons/svgs/player.svg | 3 +
.../Icon/{ => v2}/icons/svgs/preview.svg | 0
.../Icon/{ => v2}/icons/svgs/refresh.svg | 0
.../shared/Icon/v2/icons/svgs/search.svg | 3 +
components/shared/Icon/v2/icons/svgs/sent.svg | 3 +
.../Icon/{ => v2}/icons/svgs/sharing.svg | 0
.../shared/Icon/{ => v2}/icons/svgs/sort.svg | 0
.../shared/Icon/v2/icons/svgs/spiral.svg | 3 +
components/shared/Icon/v2/icons/svgs/star.svg | 3 +
.../shared/Icon/{ => v2}/icons/svgs/x.svg | 0
components/shared/Icon/v2/index.tsx | 2 +
pages/login.tsx | 8 +-
112 files changed, 416 insertions(+), 127 deletions(-)
create mode 100644 components/shared/Icon/v2/Icon.tsx
create mode 100644 components/shared/Icon/v2/icon.stories.tsx
create mode 100644 components/shared/Icon/v2/icon.test.tsx
create mode 100644 components/shared/Icon/v2/icons/index.ts
create mode 100644 components/shared/Icon/v2/icons/svgs/arcade.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/archery.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/arrow-left.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/arrow-right.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/bright-crown.svg
rename components/shared/Icon/{ => v2}/icons/svgs/calendar.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/chat-default.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/chat-updates.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/chess-rook.svg
rename components/shared/Icon/{ => v2}/icons/svgs/clock.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/collectbook.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/discord.svg
rename components/shared/Icon/{ => v2}/icons/svgs/edit-mode.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/edit.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/explore.svg
rename components/shared/Icon/{ => v2}/icons/svgs/frame.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/gamepad.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/github.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/google.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/heart.svg
rename components/shared/Icon/{ => v2}/icons/svgs/help-circle.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/home.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/hot-air-balloon.svg
rename components/shared/Icon/{ => v2}/icons/svgs/house-lock.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/house.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/leading-icon.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/linkedin.svg
rename components/shared/Icon/{ => v2}/icons/svgs/log-out.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/long-arrow-up-left.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/nav-arrow-left.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/nav-arrow-right.svg
rename components/shared/Icon/{ => v2}/icons/svgs/nonpublic.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/notification-default.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/notification-updates.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/player.svg
rename components/shared/Icon/{ => v2}/icons/svgs/preview.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/refresh.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/search.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/sent.svg
rename components/shared/Icon/{ => v2}/icons/svgs/sharing.svg (100%)
rename components/shared/Icon/{ => v2}/icons/svgs/sort.svg (100%)
create mode 100644 components/shared/Icon/v2/icons/svgs/spiral.svg
create mode 100644 components/shared/Icon/v2/icons/svgs/star.svg
rename components/shared/Icon/{ => v2}/icons/svgs/x.svg (100%)
create mode 100644 components/shared/Icon/v2/index.tsx
diff --git a/components/shared/Button/v2/Button.tsx b/components/shared/Button/v2/Button.tsx
index bf7817f8..94fd31dd 100644
--- a/components/shared/Button/v2/Button.tsx
+++ b/components/shared/Button/v2/Button.tsx
@@ -7,8 +7,8 @@ import React, {
} from "react";
import { cn } from "@/lib/utils";
import BoxFancy, { BoxFancyBorderGradientVariant } from "../../BoxFancy";
-import { IconName } from "@/components/shared/Icon/icons";
-import Icon from "@/components/shared/Icon";
+import { IconNameV2 } from "@/components/shared/Icon/v2/icons";
+import IconV2 from "@/components/shared/Icon/v2";
import { PolymorphicComponentProp, PolymorphicRef } from "@/lib/types";
export enum ButtonType {
@@ -40,7 +40,7 @@ interface BaseButtonProps {
variant?: ButtonType;
size?: ButtonSize;
icon?: ReactNode;
- iconName?: IconName;
+ iconName?: IconNameV2;
disabled?: boolean;
// inner div className for styling
boxFancyClassName?: string;
@@ -128,7 +128,8 @@ const InteralButton: InnerButtonComponent = (
borderGradientColor={borderGradientColor}
className={buttonClassName}
>
- {icon || (iconName && )}
+ {icon ||
+ (iconName && )}
{children}
diff --git a/components/shared/Icon/icons/index.ts b/components/shared/Icon/icons/index.ts
index 199d159c..ece942ba 100644
--- a/components/shared/Icon/icons/index.ts
+++ b/components/shared/Icon/icons/index.ts
@@ -60,28 +60,6 @@ import star from "./svgs/star.svg";
import tower from "./svgs/tower.svg";
import trophy from "./svgs/trophy.svg";
import tunnel from "./svgs/tunnel.svg";
-
-import calendar from "./svgs/calendar.svg";
-import chatDefault from "./svgs/chat-default.svg";
-import chatUpdates from "./svgs/chat-updates.svg";
-import clock from "./svgs/clock.svg";
-import editMode from "./svgs/edit-mode.svg";
-import frame from "./svgs/frame.svg";
-import helpCircle from "./svgs/help-circle.svg";
-import house from "./svgs/house.svg";
-import houseLock from "./svgs/house-lock.svg";
-import leadingIcon from "./svgs/leading-icon.svg";
-import logOut from "./svgs/log-out.svg";
-import longArrowUpLeft from "./svgs/long-arrow-up-left.svg";
-import nonpublic from "./svgs/nonpublic.svg";
-import notificationDefault from "./svgs/notification-default.svg";
-import notificationUpdates from "./svgs/notification-updates.svg";
-import preview from "./svgs/preview.svg";
-import refresh from "./svgs/refresh.svg";
-import sharing from "./svgs/sharing.svg";
-import sort from "./svgs/sort.svg";
-import x from "./svgs/x.svg";
-
const icons = {
logo,
check,
@@ -145,27 +123,6 @@ const icons = {
tower,
trophy,
tunnel,
-
- calendar,
- chatDefault,
- chatUpdates,
- clock,
- editMode,
- frame,
- helpCircle,
- house,
- houseLock,
- leadingIcon,
- logOut,
- longArrowUpLeft,
- nonpublic,
- notificationDefault,
- notificationUpdates,
- preview,
- refresh,
- sharing,
- sort,
- x,
};
export type IconName = keyof typeof icons;
diff --git a/components/shared/Icon/icons/svgs/arcade.svg b/components/shared/Icon/icons/svgs/arcade.svg
index c74677c0..8e6cbc2b 100644
--- a/components/shared/Icon/icons/svgs/arcade.svg
+++ b/components/shared/Icon/icons/svgs/arcade.svg
@@ -1,4 +1,4 @@
-
) : null}
-
+
遊戲微服務大平台
{!bye ? (
From a81f754d48129f1a6cedb92de23cc6b45f02f7e8 Mon Sep 17 00:00:00 2001
From: physicsSorcererKing
Date: Sun, 5 May 2024 20:56:52 +0800
Subject: [PATCH 2/6] test: use light background in IconV2 storybook
---
components/shared/Icon/v2/icon.stories.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/shared/Icon/v2/icon.stories.tsx b/components/shared/Icon/v2/icon.stories.tsx
index 81517ba1..c6b6b776 100644
--- a/components/shared/Icon/v2/icon.stories.tsx
+++ b/components/shared/Icon/v2/icon.stories.tsx
@@ -14,7 +14,7 @@ const meta: Meta = {
decorators: [
(Story) => (
-
+
From 05d8e607a540f7cc29e568a2484eb63eaa3dced3 Mon Sep 17 00:00:00 2001
From: physicsSorcererKing
Date: Sun, 5 May 2024 21:20:04 +0800
Subject: [PATCH 3/6] fix: visible, non-interactive elements with click
handlers must have at least one keyboard listener
---
components/shared/Icon/v2/icon.stories.tsx | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/components/shared/Icon/v2/icon.stories.tsx b/components/shared/Icon/v2/icon.stories.tsx
index c6b6b776..a2a94853 100644
--- a/components/shared/Icon/v2/icon.stories.tsx
+++ b/components/shared/Icon/v2/icon.stories.tsx
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
-import { useState } from "react";
+import { MouseEventHandler, useState } from "react";
import IconV2 from ".";
import icons from "./icons";
@@ -39,14 +39,18 @@ const AllIcons = () => {
const [value, setValue] = useState("");
const toast = useToast();
- const handleClick = (iconName: string) => () => {
- const cb = navigator.clipboard;
- const text = ``;
+ const handleClick =
+ (iconName: string): MouseEventHandler =>
+ (e) => {
+ e.stopPropagation();
- toast({ children: "已複製成功!!" }, { duration: 1000 });
+ const cb = navigator.clipboard;
+ const text = ``;
- cb.writeText(text).then();
- };
+ toast({ children: "已複製成功!!" }, { duration: 1000 });
+
+ cb.writeText(text).then();
+ };
return (
<>
@@ -67,7 +71,7 @@ const AllIcons = () => {
{keys(icons)
.filter((iconName) => iconName.includes(value))
.map((iconName) => (
-
+
))}
>
From 435e9e9774b54a8df89cd586f8a236e782aa7a8b Mon Sep 17 00:00:00 2001
From: physicsSorcererKing
Date: Sun, 5 May 2024 22:18:12 +0800
Subject: [PATCH 4/6] fix: change some test code to avoid SonarQube yell about
duplicated codes
---
components/shared/Icon/v2/Icon.tsx | 12 +++---------
components/shared/Icon/v2/icon.test.tsx | 10 +++++-----
2 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/components/shared/Icon/v2/Icon.tsx b/components/shared/Icon/v2/Icon.tsx
index 320a52ed..ace078d7 100644
--- a/components/shared/Icon/v2/Icon.tsx
+++ b/components/shared/Icon/v2/Icon.tsx
@@ -1,6 +1,7 @@
import type { ClassValue } from "clsx";
import { cn } from "@/lib/utils";
import icons, { IconNameV2 } from "./icons";
+import { HTMLProps } from "react";
type IconProps = {
name: IconNameV2;
@@ -15,16 +16,9 @@ type IconProps = {
const Icon = (props: IconProps) => {
const { className, name, ...rest } = props;
const transformClassName = cn("stroke-basic-black", className);
- const SvgIcon = name && icons[name];
+ const SvgIcon: React.FC> = name && icons[name];
- return (
-
- );
+ return ;
};
export default Icon;
diff --git a/components/shared/Icon/v2/icon.test.tsx b/components/shared/Icon/v2/icon.test.tsx
index 180f7e7c..62dea1bb 100644
--- a/components/shared/Icon/v2/icon.test.tsx
+++ b/components/shared/Icon/v2/icon.test.tsx
@@ -8,20 +8,20 @@ jest.mock("path/to/image.svg", () => "svg");
describe("IconV2", () => {
const TEST_ICON_NAME: IconNameV2 = "arcade";
- it("render Icon with correct name", () => {
+ it("should render Icon with correct name", () => {
const { container } = render();
const svg = container.querySelector("svg");
expect(svg).toBeInTheDocument();
});
- it("Icon has correct className", () => {
- const className = "test class";
+ it("should render Icon with correct class name", () => {
const { container } = render(
-
+
);
const svg = container.querySelector("svg");
- expect(svg).toHaveClass(className);
+ expect(svg).toHaveClass("stroke-red-500");
+ expect(svg).toHaveClass("fill-black");
});
});
From 9d1aaa867510bc473825c4150a1e345c37bc8cef Mon Sep 17 00:00:00 2001
From: physicsSorcererKing
Date: Sun, 5 May 2024 22:29:37 +0800
Subject: [PATCH 5/6] feat: add style prop to IconV2
---
components/shared/Icon/v2/Icon.tsx | 1 +
components/shared/Icon/v2/icon.test.tsx | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/components/shared/Icon/v2/Icon.tsx b/components/shared/Icon/v2/Icon.tsx
index ace078d7..01d560d7 100644
--- a/components/shared/Icon/v2/Icon.tsx
+++ b/components/shared/Icon/v2/Icon.tsx
@@ -6,6 +6,7 @@ import { HTMLProps } from "react";
type IconProps = {
name: IconNameV2;
className?: ClassValue;
+ style?: React.CSSProperties;
};
/**
diff --git a/components/shared/Icon/v2/icon.test.tsx b/components/shared/Icon/v2/icon.test.tsx
index 62dea1bb..67d0484e 100644
--- a/components/shared/Icon/v2/icon.test.tsx
+++ b/components/shared/Icon/v2/icon.test.tsx
@@ -24,4 +24,19 @@ describe("IconV2", () => {
expect(svg).toHaveClass("stroke-red-500");
expect(svg).toHaveClass("fill-black");
});
+
+ it("should render Icon with correct style", () => {
+ const { container } = render(
+
+ );
+
+ const svg = container.querySelector("svg");
+ expect(svg).toHaveStyle("width: 20px");
+ expect(svg).toHaveStyle("height: 20px");
+ expect(svg).toHaveStyle("stroke: red");
+ expect(svg).toHaveStyle("fill: aqua");
+ });
});
From f430ce7cb4dca2ad0e9225d994d1cfa4d42e98c2 Mon Sep 17 00:00:00 2001
From: Nicky Wang <36099986+physicsSorcererKing@users.noreply.github.com>
Date: Tue, 28 May 2024 22:36:41 +0800
Subject: [PATCH 6/6] chore: update icon.stories.tsx text color
---
components/shared/Icon/v2/icon.stories.tsx | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/components/shared/Icon/v2/icon.stories.tsx b/components/shared/Icon/v2/icon.stories.tsx
index a2a94853..579a7d10 100644
--- a/components/shared/Icon/v2/icon.stories.tsx
+++ b/components/shared/Icon/v2/icon.stories.tsx
@@ -54,14 +54,14 @@ const AllIcons = () => {
return (
<>
-
+
點擊 icon 即可複製
{
onClick={handleClick(iconName)}
>
-
+
{iconName}