mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-08 23:46:14 +01:00
39 lines
875 B
TypeScript
39 lines
875 B
TypeScript
|
/**
|
||
|
* 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,
|
||
|
}
|
||
|
|
||
|
|
||
|
export const FabButton: React.FC<FabButtonProps> = ({ onClick, icon, className, 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 (
|
||
|
<button onClick={handleClick} className={`fab-button ${className}`}>
|
||
|
{hasIcon() && <span className="fab-button--icon">{icon}</span>}
|
||
|
{children}
|
||
|
</button>
|
||
|
);
|
||
|
}
|
||
|
|