Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.2 KB
Raw Blame
import type { FocusEventHandler, ForwardedRef, PointerEventHandler, ReactNode } from "react";
import { forwardRef } from "react";
import type { ActionIconProps } from "@mantine/core";
import { ActionIcon } from "@mantine/core";

import { Link } from "@homarr/ui";

type HeaderButtonProps = (
  | {
      onClick?: () => void;
      onFocus?: FocusEventHandler<HTMLButtonElement>;
      onPointerEnter?: PointerEventHandler<HTMLButtonElement>;
    }
  | {
      href: string;
    }
) & {
  children: ReactNode;
  onFocus?: () => void;
  onPointerDown?: () => void;
  onPointerEnter?: () => void;
} & Partial<ActionIconProps>;

const headerButtonActionIconProps: ActionIconProps = {
  variant: "subtle",
  style: { border: "none" },
  color: "gray",
  size: "lg",
};

export const HeaderButton = forwardRef<HTMLButtonElement, HeaderButtonProps>((props, ref) => {
  if ("href" in props) {
    return (
      <ActionIcon
        ref={ref as ForwardedRef<HTMLAnchorElement>}
        component={Link}
        prefetch={false}
        {...props}
        {...headerButtonActionIconProps}
      >
        {props.children}
      </ActionIcon>
    );
  }
  return (
    <ActionIcon ref={ref} {...props} {...headerButtonActionIconProps}>
      {props.children}
    </ActionIcon>
  );
});