index.tsx 1.4 KB

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