1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-06 21:46:17 +01:00
fab-manager/app/frontend/src/javascript/components/fab-button.tsx

40 lines
944 B
TypeScript
Raw Normal View History

/**
* This component is a template for a clickable button that wraps the application style
*/
import React, { ReactNode, SyntheticEvent } from 'react';
interface FabButtonProps {
onClick?: (event: SyntheticEvent) => void,
icon?: ReactNode,
className?: string,
2021-02-08 15:28:47 +01:00
disabled?: boolean,
}
2021-02-08 15:28:47 +01:00
export const FabButton: React.FC<FabButtonProps> = ({ onClick, icon, className, disabled, children }) => {
/**
* Check if the current component was provided an icon to display
*/
const hasIcon = (): boolean => {
return !!icon;
}
/**
* Handle the action of the button
*/
const handleClick = (e: SyntheticEvent): void => {
if (typeof onClick === 'function') {
onClick(e);
}
}
return (
2021-02-08 15:28:47 +01:00
<button onClick={handleClick} disabled={disabled} className={`fab-button ${className ? className : ''}`}>
{hasIcon() && <span className="fab-button--icon">{icon}</span>}
{children}
</button>
);
}