1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-02 22:52:21 +01:00
2021-04-08 09:35:09 +02:00

42 lines
1.1 KiB
TypeScript

import React, { ReactNode, BaseSyntheticEvent } from 'react';
interface FabButtonProps {
onClick?: (event: BaseSyntheticEvent) => void,
icon?: ReactNode,
className?: string,
disabled?: boolean,
type?: 'submit' | 'reset' | 'button',
form?: string,
}
/**
* This component is a template for a clickable button that wraps the application style
*/
export const FabButton: React.FC<FabButtonProps> = ({ onClick, icon, className, disabled, type, form, 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: BaseSyntheticEvent): void => {
if (typeof onClick === 'function') {
onClick(e);
}
}
return (
<button type={type} form={form} onClick={handleClick} disabled={disabled} className={`fab-button ${className ? className : ''}`}>
{hasIcon() && <span className="fab-button--icon">{icon}</span>}
{children}
</button>
);
}
FabButton.defaultProps = { type: 'button' };