saleor-dashboard/src/components/IconButton/IconButton.tsx
2023-01-16 10:45:12 +01:00

25 lines
672 B
TypeScript

import { isExternalURL } from "@dashboard/utils/urls";
import {
IconButton as MacawIconButton,
IconButtonProps,
} from "@saleor/macaw-ui";
import React from "react";
import { Link } from "react-router-dom";
const _IconButton: React.FC<any> = React.forwardRef(
({ href, ...props }, ref) => {
if (href && !isExternalURL(href)) {
return (
<MacawIconButton {...props} to={href} component={Link} ref={ref} />
);
}
return <MacawIconButton href={href} {...props} ref={ref} />;
},
);
export const IconButton = _IconButton as <
T extends React.ElementType = "button"
>(
props: IconButtonProps<T>,
) => ReturnType<typeof _IconButton>;