<commit_before>import React, { PureComponent } from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import PropsType from './PropsType';
import Mask from '../mask';

export interface ToastProps extends PropsType {
  prefixCls?: string;
  className?: string;
}

export default class Toast extends PureComponent<ToastProps, any> {
  static defaultProps = {
    prefixCls: 'za-toast',
    visible: false,
    stayTime: 3000,
    mask: false,
  };

  static show = (children: any, stayTime?: number, onClose?: () => void) => {
    ReactDOM.render(
      <Toast visible stayTime={stayTime} onClose={onClose}>{children}</Toast>
      , window.zarmToast);
  }

  static hide = () => {
    ReactDOM.render(<Toast visible={false} />, window.zarmToast);
  }

  private timer: number;

  constructor(props) {
    super(props);
    this.state = {
      visible: props.visible || false,
    };
  }

  componentDidMount() {
    if (this.props.visible) {
      this.enter(this.props);
    }
  }

  componentWillReceiveProps(nextProps) {
    clearTimeout(this.timer);

    if (nextProps.visible) {
      this.enter(nextProps);
    } else {
      this.leave(nextProps);
    }
  }

  componentWillUnmount() {
    clearTimeout(this.timer);
  }

  enter = (props) => {
    const { stayTime, onMaskClick } = props;

    this.setState({
      visible: true,
    });

    if (stayTime === 0) {
      return;
    }

    this.timer = setTimeout(() => {
      if (typeof onMaskClick === 'function') {
        onMaskClick();
      }
      this.leave(props);
      clearTimeout(this.timer);
    }, stayTime);
  }

  leave = (props) => {
    this.setState({
      visible: false,
    });

    const { onClose } = props;
    if (typeof onClose === 'function') {
      onClose();
    }
  }

  render() {
    const { prefixCls, className, mask, onMaskClick, children } = this.props;
    const { visible } = this.state;

    const cls = classnames(`${prefixCls}`, className, {
      [`${prefixCls}-open`]: visible,
    });

    return (
      <div className={cls}>
        <div className={`${prefixCls}-container`}>
          {children}
        </div>
        {mask && <Mask visible={visible} type="transparent" onClick={onMaskClick} />}
      </div>
    );
  }
}

if (typeof window !== 'undefined') {
  if (!window.zarmToast) {
    window.zarmToast = document.createElement('div');
    document.body.appendChild(window.zarmToast);
  }

  ReactDOM.render(<Toast visible={false} />, window.zarmToast);
}
<commit_msg>fix: append toast when show<commit_after>import React, { PureComponent } from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import PropsType from './PropsType';
import Mask from '../mask';

export interface ToastProps extends PropsType {
  prefixCls?: string;
  className?: string;
}

export default class Toast extends PureComponent<ToastProps, any> {
  static defaultProps = {
    prefixCls: 'za-toast',
    visible: false,
    stayTime: 3000,
    mask: false,
  };

  static show = (children: any, stayTime?: number, onClose?: () => void) => {
    if (!Toast.mounted) {
      document.body.appendChild(Toast.zarmToast);
      Toast.mounted = true;
    }
    ReactDOM.render(
      <Toast visible stayTime={stayTime} onClose={onClose}>
        {children}
      </Toast>,
      Toast.zarmToast,
    );
  }

  static hide = () => {
    ReactDOM.render(<Toast visible={false} />, Toast.zarmToast);
  }

  private static zarmToast: HTMLDivElement = document.createElement('div');
  private static mounted: boolean = false;
  private timer: number;

  constructor(props) {
    super(props);
    this.state = {
      visible: props.visible || false,
    };
  }

  componentDidMount() {
    if (this.props.visible) {
      this.enter(this.props);
    }
  }

  componentWillReceiveProps(nextProps) {
    clearTimeout(this.timer);

    if (nextProps.visible) {
      this.enter(nextProps);
    } else {
      this.leave(nextProps);
    }
  }

  componentWillUnmount() {
    clearTimeout(this.timer);
  }

  enter = (props) => {
    const { stayTime, onMaskClick } = props;

    this.setState({
      visible: true,
    });

    if (stayTime === 0) {
      return;
    }

    this.timer = setTimeout(() => {
      if (typeof onMaskClick === 'function') {
        onMaskClick();
      }
      this.leave(props);
      clearTimeout(this.timer);
    }, stayTime);
  }

  leave = (props) => {
    this.setState({
      visible: false,
    });

    const { onClose } = props;
    if (typeof onClose === 'function') {
      onClose();
    }
  }

  render() {
    const { prefixCls, className, mask, onMaskClick, children } = this.props;
    const { visible } = this.state;

    const cls = classnames(`${prefixCls}`, className, {
      [`${prefixCls}-open`]: visible,
    });

    return (
      <div className={cls}>
        <div className={`${prefixCls}-container`}>{children}</div>
        {mask && <Mask visible={visible} type="transparent" onClick={onMaskClick} />}
      </div>
    );
  }
}

{'fraction_non_alphanumeric': 0.15324985092426952, 'fraction_numerical': 0.0019876764062810573, 'mean_word_length': 2.7636499626028423, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6480626', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1598, 'n_words': 339}