import React from 'react'; import { Link } from 'gatsby'; import * as classes from './style.module.css'; export enum ButtonType { BUTTON = 'button', SUBMIT = 'submit', LINK = 'link', } interface ButtonProps { type: ButtonType; label: string; id?: string; url?: string; externalLink?: boolean; onClickHandler?: () => void; } export function Button(props: ButtonProps): React.ReactElement { if (props.type === ButtonType.LINK) { if (!props.url) { throw new Error(`Button should be a ${props.type} but no URL is given!`); } else { if (props.externalLink) { return ( {props.label} ); } else { return ( {props.label} ); } } } else if (props.type === ButtonType.BUTTON || props.type === ButtonType.SUBMIT) { if (!props.onClickHandler) { throw new Error(`Button should be a ${props.type} but no onClickHandler is given!`); } return ( ); } else { throw new Error(`Unknown button type specified.`); } }