nitro-react/src/common/Button.tsx

34 lines
965 B
TypeScript
Raw Normal View History

2021-12-04 07:25:47 +01:00
import { FC, useMemo } from 'react';
import { Flex, FlexProps } from './Flex';
import { ButtonSizeType } from './types/ButtonSizeType';
import { ColorVariantType } from './types/ColorVariantType';
export interface ButtonProps extends FlexProps
{
variant?: ColorVariantType;
size?: ButtonSizeType;
2021-12-09 06:36:35 +01:00
disabled?: boolean;
2021-12-04 07:25:47 +01:00
}
export const Button: FC<ButtonProps> = props =>
{
2021-12-09 06:36:35 +01:00
const { variant = 'primary', size = null, disabled = false, classNames = [], ...rest } = props;
2021-12-04 07:25:47 +01:00
const getClassNames = useMemo(() =>
{
const newClassNames: string[] = [ 'btn' ];
if(variant) newClassNames.push('btn-' + variant);
if(size) newClassNames.push('btn-' + size);
2021-12-09 06:36:35 +01:00
if(disabled) newClassNames.push('disabled');
2021-12-04 07:25:47 +01:00
if(classNames.length) newClassNames.push(...classNames);
return newClassNames;
2021-12-09 06:36:35 +01:00
}, [ variant, size, disabled, classNames ]);
2021-12-04 07:25:47 +01:00
return <Flex center classNames={ getClassNames } { ...rest } />;
}