From 446eb9f9a44f812c4672a3d23e6c86410fa2fb21 Mon Sep 17 00:00:00 2001 From: Jordan Frankfurt Date: Tue, 4 Oct 2022 15:37:57 -0500 Subject: [PATCH] fix(IconButton): improves code quality and fixes a console error re: incorrect data- attribute syntax (#4788) --- .../WalletDropdown/AuthenticatedHeader.tsx | 17 ++++---- src/components/WalletDropdown/IconButton.tsx | 43 +++++++++---------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/components/WalletDropdown/AuthenticatedHeader.tsx b/src/components/WalletDropdown/AuthenticatedHeader.tsx index 1c391433b4..dc3391735c 100644 --- a/src/components/WalletDropdown/AuthenticatedHeader.tsx +++ b/src/components/WalletDropdown/AuthenticatedHeader.tsx @@ -149,14 +149,15 @@ const AuthenticatedHeader = () => { - Copied! : Copy} /> - Explore} /> - Disconnect} - /> + + {isCopied ? Copied! : Copy} + + + Explore + + + Disconnect + diff --git a/src/components/WalletDropdown/IconButton.tsx b/src/components/WalletDropdown/IconButton.tsx index eeaba08a4f..2fe335a0e5 100644 --- a/src/components/WalletDropdown/IconButton.tsx +++ b/src/components/WalletDropdown/IconButton.tsx @@ -58,31 +58,28 @@ const IconWrapper = styled.span` width: 16px; height: 16px; ` - -interface IconButtonProps { - text: React.ReactNode +interface BaseProps { Icon: Icon - onClick?: () => void - href?: string - dataTestId?: string +} +interface IconLinkProps extends React.ComponentPropsWithoutRef<'a'>, BaseProps {} +interface IconButtonProps extends React.ComponentPropsWithoutRef<'button'>, BaseProps {} + +const IconBlock = (props: React.ComponentPropsWithoutRef<'a' | 'button'>) => { + if ('href' in props) { + return + } + // ignoring 'button' 'type' conflict between React and styled-components + // @ts-ignore + return } -const IconButton = ({ Icon, onClick, text, href, dataTestId }: IconButtonProps) => { - return href ? ( - - - - {text} - - - ) : ( - - - - {text} - - - ) -} +const IconButton = ({ Icon, children, ...rest }: IconButtonProps | IconLinkProps) => ( + + + + {children} + + +) export default IconButton