index.tsx 1.2 KB

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