Skip to content

Commit

Permalink
fix: icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Nov 12, 2024
1 parent b295fe5 commit 0f379f8
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 119 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@types/node": "^22.4.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-syntax-highlighter": "^15.5.13",
"@types/react-transition-group": "^4.4.11",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.9.0",
Expand Down
2 changes: 2 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow:
10 changes: 6 additions & 4 deletions src/components/core/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useThemeColor from "@/hooks/useThemeColor";
import styles from "./Button.module.scss";
import Loading from "../../icons/Loading";
import clsx from "clsx";
import { Icon } from "../Icon";

export interface ButtonProps extends ComponentPropsWithRef<"button"> {
width?: string;
Expand All @@ -13,7 +14,7 @@ export interface ButtonProps extends ComponentPropsWithRef<"button"> {
align?: "start" | "center" | "end";
loading?: boolean;
disabled?: boolean;
icon?: React.ReactNode;
icon?: React.ReactElement;
style?: React.CSSProperties;
children?: React.ReactNode;
}
Expand Down Expand Up @@ -55,9 +56,10 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
{...rest}
>
{(loading || icon) && (
<div className={styles["icon"]}>
{loading ? <Loading /> : icon}
</div>
<Icon
className={styles["icon"]}
icon={loading ? <Loading /> : icon}
/>
)}
<div className={styles["content"]}>{children}</div>
</button>
Expand Down
4 changes: 4 additions & 0 deletions src/components/core/Icon/Icon.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.root {
width: fit-content;
height: 100%;
}
12 changes: 9 additions & 3 deletions src/components/core/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React, { ComponentProps, forwardRef } from "react";
import styles from "./Icon.module.scss";
import clsx from "clsx";

export interface IconProps extends ComponentProps<"i"> {
icon: React.ReactElement;
icon?: React.ReactElement;
}

export const Icon = forwardRef<HTMLElement, IconProps>((props, ref) => {
const { icon } = props;
const { icon, className } = props;

return <i ref={ref}>{icon}</i>;
return (
<i ref={ref} className={clsx(styles["root"], className)}>
{icon}
</i>
);
});
9 changes: 8 additions & 1 deletion src/components/core/InputBase/InputBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export const InputBase = forwardRef<HTMLDivElement, InputBaseProps>(
} as React.CSSProperties;

return (
<div className={styles["root"]} style={variables} {...rest}>
<div
className={styles["root"]}
style={{
...variables,
...style,
}}
{...rest}
>
{(label || helperText) && (
<div className={styles["info"]}>
{label && (
Expand Down
1 change: 1 addition & 0 deletions src/components/core/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function TextInput(props: TextInputProps) {
errorText={errorText}
label={label}
className={clsx(styles["root"], className)}
style={style}
{...rest}
>
{icon && <div className={styles["icon"]}>{icon}</div>}
Expand Down
12 changes: 6 additions & 6 deletions src/components/modals/ChallengeModal/ChallengeModal.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ $icon-color: var(--challenge-modal-icon-color);
align-items: center;
gap: 8px;

.icon {
width: 1.5rem;
height: 1.5rem;
}

.title {
width: 100%;
width: 80%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand All @@ -70,11 +75,6 @@ $icon-color: var(--challenge-modal-icon-color);
font-size: 1rem;
font-weight: 700;
}

.icon {
width: 1.5rem;
height: 1.5rem;
}
}

.tabs {
Expand Down
10 changes: 8 additions & 2 deletions src/components/modals/ChallengeModal/ChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SledgehammerBold from "~icons/solar/sledgehammer-bold";
import Server2Bold from "~icons/solar/server-2-bold";
import FolderWithFilesBold from "~icons/solar/folder-with-files-bold";
import FlagBold from "~icons/solar/flag-bold";
import { Icon } from "@/components/core/Icon";

export interface ChallengeModalProps {
challenge: Challenge;
Expand Down Expand Up @@ -68,7 +69,10 @@ export function ChallengeModal(props: ChallengeModalProps) {
<div className={styles["container"]}>
<div className={styles["navbar"]}>
<div className={styles["info"]}>
<div className={styles["icon"]}>{category?.icon}</div>
<Icon
icon={category?.icon}
className={styles["icon"]}
/>
<div className={styles["title"]}>
{challenge?.title}
</div>
Expand Down Expand Up @@ -147,14 +151,16 @@ export function ChallengeModal(props: ChallengeModalProps) {
}}
>
<TextInput
width={"100%"}
icon={<FlagBold />}
clearable
color={category?.color}
placeholder={placeholder}
value={flag}
variant={"solid"}
onChange={(value) => setFlag(value)}
style={{
flex: 1,
}}
/>
<Button
color={category?.color}
Expand Down
4 changes: 3 additions & 1 deletion src/components/widgets/ChallengeCard/ChallengeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export function ChallengeCard(props: ChallengeCard) {
{category?.name?.toUpperCase()}
</Badge>
</div>
<div className={styles["icon"]}>{category?.icon}</div>
<div className={styles["icon"]}>
<Icon icon={category?.icon} />
</div>
<h1 className={styles["title"]}>{challenge.title}</h1>
<div className={styles["divider"]} />
<div className={styles["status"]}>
Expand Down
5 changes: 4 additions & 1 deletion src/components/widgets/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CSSProperties, useRef, useState } from "react";
import chroma from "chroma-js";
import { Link, useLocation } from "react-router-dom";
import { Avatar, Popover } from "@/components/core";
import { Icon } from "@/components/core/Icon";

export function Navbar() {
const darkMode = useThemeStore.getState().darkMode;
Expand Down Expand Up @@ -74,7 +75,9 @@ export function Navbar() {
className={styles["link"]}
data-active={pathname === item?.href}
>
<div className={styles["icon"]}>{item?.icon}</div>
<div className={styles["icon"]}>
<Icon icon={item?.icon} />
</div>
<div className={styles["label"]}>{item?.label}</div>
</div>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/models/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export interface Category {
id?: number;
name?: string;
color?: string;
icon?: React.ReactNode;
icon?: React.ReactElement;
}
35 changes: 2 additions & 33 deletions src/pages/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export function Page() {

const [loading, setLoading] = useState(false);

const dropdownMenuButtonRef = useRef<HTMLButtonElement>(null);
const [dropdownMenuOpen, setDropdownMenuOpen] = useState<boolean>(false);

const [datetime, setDatetime] = useState<DateTime>(DateTime.now());

const [isSolveds, setIsSolveds] = useState<boolean[]>(
Expand Down Expand Up @@ -115,29 +112,6 @@ ReactDOM.render(
123
</Button>
</div>
<p>
在现代社会中,technology
已经成为生活中不可或缺的一部分。无论是使用 smartphones 还是
laptops,我们都能感受到 innovation 带来的便利。同时,
<span
style={{
fontStyle: "italic",
}}
>
communication
</span>
方式也因为 Internet 而发生了巨大的变化,人们可以通过
<span
style={{
fontWeight: 800,
}}
>
email
</span>
、social media
与世界各地的朋友保持联系。这种中英文的混合使用,不仅方便了表达,也让我们的生活充满了
globalization 的色彩。
</p>
<TextInput
clearable
// passwd
Expand Down Expand Up @@ -425,15 +399,10 @@ ReactDOM.render(

{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17].map(
(i) => (
<div
key={i}
style={{
paddingLeft: "64px",
}}
>
<div key={i}>
<ChallengeModal
challenge={{
title: "Hello CdsCTF",
title: "Hello CdsCTFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
category: i,
description: "This is a description",
}}
Expand Down
56 changes: 0 additions & 56 deletions src/utils/katex.ts

This file was deleted.

11 changes: 1 addition & 10 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineConfig(({ mode }) => {
compiler: "jsx",
jsx: "react",
scale: 1.2,
defaultStyle: "width: fit-content; height: 100%;",
defaultStyle: "width: 100%; height: 100%;",
}),
],
resolve: {
Expand Down Expand Up @@ -58,15 +58,6 @@ export default defineConfig(({ mode }) => {
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("node_modules")) {
return id.split("node_modules/")[1].split("/")[0]; // 按库拆分
}
},
},
},
cssCodeSplit: true,
},
};
Expand Down

0 comments on commit 0f379f8

Please sign in to comment.