From f2ced4fad182d9de64a7c0d0755f605d2b9c3d9b Mon Sep 17 00:00:00 2001 From: mybearworld <130385691+mybearworld@users.noreply.github.com> Date: Thu, 25 Jul 2024 08:04:01 +0200 Subject: [PATCH] Make all icon buttons use one component --- src/App.tsx | 21 +++++++++++---------- src/components/IconButton.tsx | 20 ++++++++++++++++++++ src/components/MarkdownInput.tsx | 13 +++++++------ src/components/Post.tsx | 13 +++++++------ src/components/StoredAccounts.tsx | 5 +++-- src/components/User.tsx | 9 +++++++-- 6 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 src/components/IconButton.tsx diff --git a/src/App.tsx b/src/App.tsx index d83f044..94e3ed4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,6 +13,7 @@ import { Button } from "./components/Button"; import { Ulist } from "./components/Ulist"; import { Popup } from "./components/Popup"; import { User } from "./components/User"; +import { IconButton } from "./components/IconButton"; export const App = () => { const [showSideNav, setShowSideNav] = useState(false); @@ -65,14 +66,14 @@ export const App = () => { - + @@ -105,11 +106,11 @@ const DarkMode = () => { }, [darkMode]); return ( - + ); }; @@ -124,31 +125,31 @@ const NotificationToggle = () => { return ( notificationState === "disabled" ? - + : notificationState === "enabled" ? - + : - + } >
diff --git a/src/components/IconButton.tsx b/src/components/IconButton.tsx new file mode 100644 index 0000000..116c081 --- /dev/null +++ b/src/components/IconButton.tsx @@ -0,0 +1,20 @@ +import { forwardRef, ComponentPropsWithoutRef, ReactNode } from "react"; +import { twMerge } from "tailwind-merge"; + +export type IconButtonProps = ComponentPropsWithoutRef<"button"> & { + children: ReactNode; +}; +export const IconButton = forwardRef( + (props: IconButtonProps, ref) => { + const buttonProps = { ...props }; + return ( + + ); + }, +); diff --git a/src/components/MarkdownInput.tsx b/src/components/MarkdownInput.tsx index 533cb60..6e2fb1d 100644 --- a/src/components/MarkdownInput.tsx +++ b/src/components/MarkdownInput.tsx @@ -16,6 +16,7 @@ import { Attachment } from "../lib/api/posts"; import { Checkbox } from "./Checkbox"; import { EmojiPicker } from "./EmojiPicker"; import { Markdown } from "./Markdown"; +import { IconButton } from "./IconButton"; export type MarkdownInputProps = { chat: string; @@ -141,7 +142,7 @@ export const MarkdownInput = (props: MarkdownInputProps) => { before={ <> {showAttachments ? - + : undefined} } @@ -171,22 +172,22 @@ export const MarkdownInput = (props: MarkdownInputProps) => { - + } /> - +
} above={ diff --git a/src/components/Post.tsx b/src/components/Post.tsx index fa2d040..9c727bf 100644 --- a/src/components/Post.tsx +++ b/src/components/Post.tsx @@ -20,6 +20,7 @@ import { RelativeTime } from "./RelativeTime"; import { twMerge } from "tailwind-merge"; import { EmojiPicker } from "./EmojiPicker"; import { DiscordEmoji } from "../lib/discordEmoji"; +import { IconButton } from "./IconButton"; export type PostProps = { id: string; @@ -218,29 +219,29 @@ const PostBase = memo((props: PostBaseProps) => { onEmoji={handleReaction} discordEmoji={false} trigger={ - + } /> {isInbox ? undefined - : + } - + } > Report diff --git a/src/components/StoredAccounts.tsx b/src/components/StoredAccounts.tsx index 22a9ece..f551476 100644 --- a/src/components/StoredAccounts.tsx +++ b/src/components/StoredAccounts.tsx @@ -5,6 +5,7 @@ import { Popup } from "./Popup"; import { UserView } from "./UserView"; import { useAPI } from "../lib/api"; import * as Dialog from "@radix-ui/react-dialog"; +import { IconButton } from "./IconButton"; export type StoredAccountsProps = { children: ReactNode; @@ -60,13 +61,13 @@ const StoredAccount = (props: StoredAccountProps) => { text={props.isLoggedIn ? "Logged in" : undefined} className="px-4" /> - + ); }; diff --git a/src/components/User.tsx b/src/components/User.tsx index 1fac3b2..33fa655 100644 --- a/src/components/User.tsx +++ b/src/components/User.tsx @@ -9,6 +9,7 @@ import { Markdown } from "./Markdown"; import { ProfilePicture } from "./ProfilePicture"; import { RelativeTime } from "./RelativeTime"; import { PERMISSIONS } from "../lib/permissions"; +import { IconButton } from "./IconButton"; export type UserProps = { username: string; @@ -86,11 +87,15 @@ export const User = (props: UserProps) => { - + : undefined}