2021-05-12 18:31:02 +02:00
|
|
|
import { Fragment } from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
|
|
|
import classes from './ActionButton.module.css';
|
2021-05-14 18:51:56 +02:00
|
|
|
import Icon from '../../Icons/Icon/Icon';
|
2021-05-12 18:31:02 +02:00
|
|
|
|
|
|
|
interface ComponentProps {
|
|
|
|
name: string;
|
|
|
|
icon: string;
|
|
|
|
link?: string;
|
|
|
|
handler?: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ActionButton = (props: ComponentProps): JSX.Element => {
|
|
|
|
const body = (
|
|
|
|
<Fragment>
|
|
|
|
<div className={classes.ActionButtonIcon}>
|
|
|
|
<Icon icon={props.icon} />
|
|
|
|
</div>
|
|
|
|
<div className={classes.ActionButtonName}>
|
|
|
|
{props.name}
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (props.link) {
|
2021-05-14 18:51:56 +02:00
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
to={props.link}
|
|
|
|
tabIndex={0}>
|
|
|
|
{body}
|
|
|
|
</Link>
|
|
|
|
)
|
2021-05-12 18:31:02 +02:00
|
|
|
} else if (props.handler) {
|
2021-05-14 18:51:56 +02:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classes.ActionButton}
|
|
|
|
onClick={props.handler}
|
|
|
|
onKeyPress={(e) => {
|
|
|
|
if (e.key === 'Enter' && props.handler) props.handler()
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
|
|
|
>{body}
|
|
|
|
</div>
|
|
|
|
)
|
2021-05-12 18:31:02 +02:00
|
|
|
} else {
|
2021-05-14 18:51:56 +02:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classes.ActionButton}>
|
|
|
|
{body}
|
|
|
|
</div>
|
|
|
|
)
|
2021-05-12 18:31:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ActionButton;
|