2021-12-04 01:25:47 -05:00
|
|
|
import { FC, useMemo } from 'react';
|
|
|
|
import { Flex, FlexProps } from './Flex';
|
2022-02-08 22:25:01 -05:00
|
|
|
import { ButtonSizeType, ColorVariantType } from './types';
|
2021-12-04 01:25:47 -05:00
|
|
|
|
|
|
|
export interface ButtonProps extends FlexProps
|
|
|
|
{
|
|
|
|
variant?: ColorVariantType;
|
|
|
|
size?: ButtonSizeType;
|
2022-01-05 21:59:46 -05:00
|
|
|
active?: boolean;
|
2021-12-09 00:36:35 -05:00
|
|
|
disabled?: boolean;
|
2021-12-04 01:25:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Button: FC<ButtonProps> = props =>
|
|
|
|
{
|
2022-01-11 01:38:01 -05:00
|
|
|
const { variant = 'primary', size = 'sm', active = false, disabled = false, classNames = [], ...rest } = props;
|
2021-12-04 01:25:47 -05:00
|
|
|
|
|
|
|
const getClassNames = useMemo(() =>
|
|
|
|
{
|
|
|
|
const newClassNames: string[] = [ 'btn' ];
|
|
|
|
|
|
|
|
if(variant) newClassNames.push('btn-' + variant);
|
|
|
|
|
|
|
|
if(size) newClassNames.push('btn-' + size);
|
|
|
|
|
2022-01-05 21:59:46 -05:00
|
|
|
if(active) newClassNames.push('active');
|
|
|
|
|
2021-12-09 00:36:35 -05:00
|
|
|
if(disabled) newClassNames.push('disabled');
|
|
|
|
|
2021-12-04 01:25:47 -05:00
|
|
|
if(classNames.length) newClassNames.push(...classNames);
|
|
|
|
|
|
|
|
return newClassNames;
|
2022-01-05 21:59:46 -05:00
|
|
|
}, [ variant, size, active, disabled, classNames ]);
|
2021-12-04 01:25:47 -05:00
|
|
|
|
|
|
|
return <Flex center classNames={ getClassNames } { ...rest } />;
|
|
|
|
}
|