index.js 1.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import styles from './index.less';

export default class FooterToolbar extends Component {
  static contextTypes = {
    layoutCollapsed: PropTypes.bool,
  };
  state = {
    width: '',
  };
  componentDidMount() {
    this.syncWidth();
  }
  componentWillReceiveProps() {
    this.syncWidth();
  }
  syncWidth() {
    const sider = document.querySelectorAll('.ant-layout-sider')[0];
    if (sider) {
      this.setState({
        width: `calc(100% - ${sider.style.width})`,
      });
    }
  }
  render() {
    const { children, style, className, extra, ...restProps } = this.props;
    return (
      <div
        className={classNames(className, styles.toolbar)}
        ref={this.getRefNode}
        style={{
          width: this.state.width,
          ...style,
        }}
        {...restProps}
      >
        <div className={styles.left}>{extra}</div>
        <div className={styles.right}>{children}</div>
      </div>
    );
  }
}