2021-03-30 11:26:47 +02:00
|
|
|
import React, { ReactNode, BaseSyntheticEvent } from 'react';
|
2021-02-04 15:47:11 +01:00
|
|
|
|
|
|
|
interface FabButtonProps {
|
2021-03-30 11:26:47 +02:00
|
|
|
onClick?: (event: BaseSyntheticEvent) => void,
|
2021-02-04 15:47:11 +01:00
|
|
|
icon?: ReactNode,
|
|
|
|
className?: string,
|
2021-02-08 15:28:47 +01:00
|
|
|
disabled?: boolean,
|
2021-02-09 12:09:26 +01:00
|
|
|
type?: 'submit' | 'reset' | 'button',
|
|
|
|
form?: string,
|
2021-02-04 15:47:11 +01:00
|
|
|
}
|
|
|
|
|
2021-04-07 16:21:12 +02:00
|
|
|
/**
|
|
|
|
* This component is a template for a clickable button that wraps the application style
|
|
|
|
*/
|
2021-02-09 12:09:26 +01:00
|
|
|
export const FabButton: React.FC<FabButtonProps> = ({ onClick, icon, className, disabled, type, form, children }) => {
|
2021-02-04 15:47:11 +01:00
|
|
|
/**
|
|
|
|
* Check if the current component was provided an icon to display
|
|
|
|
*/
|
|
|
|
const hasIcon = (): boolean => {
|
|
|
|
return !!icon;
|
|
|
|
}
|
|
|
|
|
2021-06-09 09:24:39 +02:00
|
|
|
/**
|
|
|
|
* Check if the current button has children properties (like some text)
|
|
|
|
*/
|
|
|
|
const hasChildren = (): boolean => {
|
|
|
|
return !!children;
|
|
|
|
}
|
|
|
|
|
2021-02-04 15:47:11 +01:00
|
|
|
/**
|
|
|
|
* Handle the action of the button
|
|
|
|
*/
|
2021-03-30 11:26:47 +02:00
|
|
|
const handleClick = (e: BaseSyntheticEvent): void => {
|
2021-02-04 15:47:11 +01:00
|
|
|
if (typeof onClick === 'function') {
|
|
|
|
onClick(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-02-09 12:09:26 +01:00
|
|
|
<button type={type} form={form} onClick={handleClick} disabled={disabled} className={`fab-button ${className ? className : ''}`}>
|
2021-06-09 09:24:39 +02:00
|
|
|
{hasIcon() && <span className={hasChildren() ? 'fab-button--icon' : 'fab-button--icon-only'}>{icon}</span>}
|
2021-02-04 15:47:11 +01:00
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-09 12:09:26 +01:00
|
|
|
FabButton.defaultProps = { type: 'button' };
|
|
|
|
|