index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import classNames from 'classnames';
  4. import styles from './index.less';
  5. export default class FooterToolbar extends Component {
  6. static contextTypes = {
  7. layoutCollapsed: PropTypes.bool,
  8. };
  9. state = {
  10. width: '',
  11. };
  12. componentDidMount() {
  13. this.syncWidth();
  14. }
  15. componentWillReceiveProps() {
  16. this.syncWidth();
  17. }
  18. syncWidth() {
  19. const sider = document.querySelectorAll('.ant-layout-sider')[0];
  20. if (sider) {
  21. this.setState({
  22. width: `calc(100% - ${sider.style.width})`,
  23. });
  24. }
  25. }
  26. render() {
  27. const { children, style, className, extra, ...restProps } = this.props;
  28. return (
  29. <div
  30. className={classNames(className, styles.toolbar)}
  31. ref={this.getRefNode}
  32. style={{
  33. width: this.state.width,
  34. ...style,
  35. }}
  36. {...restProps}
  37. >
  38. <div className={styles.left}>{extra}</div>
  39. <div className={styles.right}>{children}</div>
  40. </div>
  41. );
  42. }
  43. }