index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import BaseButton, { ButtonProps as BaseButtonProps } from './Button';
  3. import IconButton, { IconButtonProps } from '../iconButton';
  4. export { ButtonProps as BaseButtonProps, HtmlType, Size, Theme, Type } from './Button';
  5. export { HorizontalPaddingType } from '../iconButton';
  6. export { ButtonGroupProps } from './buttonGroup';
  7. export { SplitButtonGroupProps } from './splitButtonGroup';
  8. // eslint-disable-next-line
  9. export interface ButtonProps extends IconButtonProps {} // TODO check
  10. class Button extends React.PureComponent<ButtonProps> {
  11. static propTypes = {
  12. ...BaseButton.propTypes,
  13. ...IconButton.propTypes,
  14. };
  15. static elementType: string;
  16. constructor(props = {}) {
  17. super(props);
  18. }
  19. render() {
  20. const props = { ...this.props };
  21. const hasIcon = Boolean(props.icon);
  22. const isLoading = Boolean(props.loading);
  23. const isDisabled = Boolean(props.disabled);
  24. if (hasIcon || (isLoading && !isDisabled)) {
  25. return <IconButton {...props} />;
  26. } else {
  27. return <BaseButton {...props} />;
  28. }
  29. }
  30. }
  31. Button.elementType = 'Button';
  32. export default Button;