12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import React, { Component } from 'react';
- import './index.less';
- import { Icon } from '../Icon';
- export default class Open extends Component {
- constructor(props) {
- super(props);
- this.Text = null;
- this.state = { show: false, more: false };
- this.checkHeight();
- }
- checkHeight() {
- const { height } = this.props;
- if (this.Text != null) {
- if (this.Text.offsetHeight > height) {
- this.setState({ more: true });
- }
- } else {
- setTimeout(() => {
- this.checkHeight();
- }, 1);
- }
- }
- render() {
- const { show, more } = this.state;
- const { up, down, height, className = '', children } = this.props;
- return (
- <div className={`super-open ${className} ${more ? 'more' : ''} ${!show ? 'hide' : ''}`}>
- <div
- className="hide-content"
- ref={ref => {
- this.Text = ref;
- }}
- style={{ height: more && !show ? height : null }}
- >
- {children}
- </div>
- {more && show && <span onClick={() => this.setState({ show: false })}>{up}</span>}
- {more && !show && <span onClick={() => this.setState({ show: true })}>{down}</span>}
- </div>
- );
- }
- }
- export class OpenText extends Component {
- render() {
- const { children } = this.props;
- return (
- <Open className="super-open-text" height={60} up={<Icon name="small-up" />} down={<Icon name="small-down" />}>
- {children}
- </Open>
- );
- }
- }
|