saleor-dashboard/src/components/Link.tsx

64 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-10-30 14:34:24 +00:00
import { makeStyles } from "@material-ui/core/styles";
2019-06-19 14:40:52 +00:00
import Typography, { TypographyProps } from "@material-ui/core/Typography";
2019-08-09 11:14:35 +00:00
import classNames from "classnames";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
primary: {
color: theme.palette.primary.main
},
root: {
cursor: "pointer",
display: "inline"
},
secondary: {
color: theme.palette.primary.main
},
underline: {
textDecoration: "underline"
}
}),
{ name: "Link" }
);
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
2019-06-19 14:40:52 +00:00
color?: "primary" | "secondary";
underline?: boolean;
typographyProps?: TypographyProps;
onClick: () => void;
}
2019-10-30 14:34:24 +00:00
const Link: React.FC<LinkProps> = props => {
const {
2019-06-19 14:40:52 +00:00
className,
children,
color = "primary",
underline = false,
onClick,
...linkProps
2019-10-30 14:34:24 +00:00
} = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<Typography
component="a"
2020-01-16 13:44:16 +00:00
className={classNames(className, {
2019-06-19 14:40:52 +00:00
[classes.root]: true,
[classes[color]]: true,
[classes.underline]: underline
})}
onClick={event => {
event.preventDefault();
onClick();
}}
{...linkProps}
>
{children}
</Typography>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
Link.displayName = "Link";
export default Link;