Skip to content
Open
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
38 changes: 22 additions & 16 deletions ui/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Text, { TextProps } from "./Text";
type Props = {
className?: string;
to?: string;
innerRef?: any;
children?: any;
href?: any;
target?: any;
Expand All @@ -28,19 +27,22 @@ const SpacedIcon = ({ icon }: { icon: JSX.Element }) => (
</>
);

function Link({
children,
href,
className,
to = "",
newTab,
onClick,
textProps,
icon,
onMouseEnter,
onMouseLeave,
...props
}: Props) {
const Link = React.forwardRef<HTMLAnchorElement, Props>(function Link(
{
children,
href,
className,
to = "",
newTab,
onClick,
textProps,
icon,
onMouseEnter,
onMouseLeave,
...props
},
ref
) {
if ((href && !isAllowedLink(href)) || (!href && !to)) {
return (
<Text className={className} {...textProps}>
Expand All @@ -58,6 +60,7 @@ function Link({
if (href) {
return (
<a
ref={ref}
className={className}
href={href}
target={newTab ? "_blank" : ""}
Expand All @@ -77,6 +80,7 @@ function Link({

return (
<RouterLink
ref={ref}
onClick={onClick}
className={className}
to={to}
Expand All @@ -89,8 +93,10 @@ function Link({
{txt}
</RouterLink>
);
}
});

export default styled(Link).attrs({ className: Link.name })`
Link.displayName = "Link";

export default styled(Link).attrs({ className: Link.displayName })`
text-decoration: none;
`;
4 changes: 2 additions & 2 deletions ui/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const LinkTabIcon = ({ iconType, color, collapsed, title }) => {
else return <Spacer padding="small" />;
};

const LinkTab = React.forwardRef((p: any, ref) => {
const LinkTab = React.forwardRef<HTMLAnchorElement, any>((p, ref) => {
const [hovered, setHovered] = React.useState<boolean>(false);
const item: NavItem = p.navItem;

Expand All @@ -147,7 +147,7 @@ const LinkTab = React.forwardRef((p: any, ref) => {
return (
<Link
className={className}
innerRef={ref}
ref={ref}
to={formatURL(item.link.value)}
href={item.link.href}
newTab={item.link.newTab}
Expand Down
4 changes: 2 additions & 2 deletions ui/components/SubRouterTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type TabProps = {

type PathConfig = { name: string; path: string };

const ForwardedLink = React.forwardRef((props, ref) => (
<Link {...props} innerRef={ref} />
const ForwardedLink = React.forwardRef<HTMLAnchorElement>((props, ref) => (
<Link {...props} ref={ref} />
));

function findChildren(childrenProp: any[]) {
Expand Down