accounts-frontend/packages/app/components/ui/form/Button.tsx

56 lines
1.7 KiB
TypeScript
Raw Normal View History

import React from 'react';
2019-12-08 01:13:08 +05:30
import clsx from 'clsx';
import { COLOR_GREEN } from 'app/components/ui';
2019-12-07 16:58:52 +05:30
import { MessageDescriptor } from 'react-intl';
import { Color } from 'app/components/ui';
2016-05-02 12:45:42 +05:30
2019-12-09 13:17:51 +05:30
import buttons from '../buttons.scss';
import FormComponent from './FormComponent';
2019-12-07 16:58:52 +05:30
export default class Button extends FormComponent<
2020-05-24 04:38:24 +05:30
{
// TODO: drop MessageDescriptor support. It should be React.ReactNode only
label: string | MessageDescriptor | React.ReactElement;
block?: boolean;
small?: boolean;
loading?: boolean;
className?: string;
color?: Color;
disabled?: boolean;
component?: string | React.ComponentType<any>;
} & React.ButtonHTMLAttributes<HTMLButtonElement>
2019-12-07 16:58:52 +05:30
> {
2020-05-24 04:38:24 +05:30
render() {
const {
color = COLOR_GREEN,
block,
small,
disabled,
className,
loading,
label,
component: ComponentProp = 'button',
...restProps
} = this.props;
2016-05-02 12:45:42 +05:30
2020-05-24 04:38:24 +05:30
return (
<ComponentProp
className={clsx(
buttons[color],
{
[buttons.loading]: loading,
[buttons.block]: block,
[buttons.smallButton]: small,
[buttons.disabled]: disabled,
},
className,
)}
disabled={disabled}
{...restProps}
>
{typeof label === 'object' && React.isValidElement(label) ? label : this.formatMessage(label)}
</ComponentProp>
);
}
2016-05-02 12:45:42 +05:30
}