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

58 lines
1.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
2016-05-02 12:45:42 +05:30
import classNames from 'classnames';
import buttons from 'app/components/ui/buttons.scss';
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
import FormComponent from './FormComponent';
2019-12-07 16:58:52 +05:30
export default class Button extends FormComponent<
{
// 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>
> {
render() {
const {
2019-12-07 16:58:52 +05:30
color = COLOR_GREEN,
block,
small,
disabled,
className,
loading,
label,
2019-12-07 16:58:52 +05:30
component: ComponentProp = 'button',
...restProps
} = this.props;
2016-05-02 12:45:42 +05:30
return (
<ComponentProp
className={classNames(
buttons[color],
{
[buttons.loading]: loading,
[buttons.block]: block,
[buttons.smallButton]: small,
[buttons.disabled]: disabled,
},
className,
)}
disabled={disabled}
{...restProps}
>
2019-12-07 16:58:52 +05:30
{typeof label === 'object' && React.isValidElement(label)
? label
: this.formatMessage(label)}
</ComponentProp>
);
}
2016-05-02 12:45:42 +05:30
}