import { FunctionComponent } from 'react';
import Image from 'next/image';
import Link from 'next/link';
import styled from 'styled-components';
import DEFAULT_THEME from '../../lib/consts/DEFAULT_THEME';
import { ButtonImageProps } from '../../types/ButtonImageProps';
import { ButtonProps } from '../../types/ButtonProps';
import Label from './Label';
const DEFAULT_BUTTON_IMAGE_SIZE = 30;
const StyledButton = styled.button`
display: flex;
flex-direction: row;
flex-wrap: nowrap;
`;
const StyledSeparator = styled.div`
margin-right: 0.5em;
`;
StyledButton.defaultProps = {
theme: DEFAULT_THEME,
};
const getButtonImageElement: (
imageProps?: ButtonImageProps,
) => JSX.Element | undefined = (imageProps) => {
let imageElement: JSX.Element | undefined;
if (imageProps) {
const {
src,
width = DEFAULT_BUTTON_IMAGE_SIZE,
height = DEFAULT_BUTTON_IMAGE_SIZE,
} = imageProps;
imageElement = ;
}
return imageElement;
};
const getButtonLabelElement: (
labelProps?: LabelProps,
) => JSX.Element | undefined = (labelProps) => {
let labelElement: JSX.Element | undefined;
if (labelProps) {
const { text } = labelProps;
labelElement = ;
}
return labelElement;
};
const Button: FunctionComponent = ({
imageProps,
isSubmit,
labelProps,
linkProps,
onClick,
}) => {
const imageElement: JSX.Element | undefined = getButtonImageElement(
imageProps,
);
const labelElement: JSX.Element | undefined = getButtonLabelElement(
labelProps,
);
const separatorElement: JSX.Element | undefined =
imageElement && labelElement ? : undefined;
let resultElement: JSX.Element;
if (linkProps) {
const { href, passHref = true } = linkProps;
resultElement = (
{imageElement}
{separatorElement}
{labelElement}
);
} else {
resultElement = (
{imageElement}
{separatorElement}
{labelElement}
);
}
return resultElement;
};
export default Button;