zoukankan      html  css  js  c++  java
  • react---简易展开收起组件

    组件核心代码:

    import React from 'react';
    // import PropTypes from 'prop-types';
    
    // 展开收起组件
    class ArrowSlide extends React.Component {
      static defaultProps = {
        itemLable: false, // 是否展开
        itemsName: '' // 检查项目名称
      };
      constructor(props) {
        super(props);
        const { itemLable } = props; // 是否展开收起列表项
        this.state = {
          itemLable
        };
      }
    
      /**
       * 展开收起切换
       * @memberof EleItem
       */
      handleToggleCondition = () => {
        const { itemLable } = this.state;
        this.setState({ itemLable: !itemLable });
      }
    
      render() {
        const { itemsName } = this.props;
        const { itemLable } = this.state;
    
        return (
          <div style={{ marginTop: '10px' }}>
            <a className="arrow-alide" onClick={this.handleToggleCondition}>
              {itemsName}<i className={`iconfont ${itemLable ? 'icon-xiangxia2' : 'icon-xiangshang2'}`} />
            </a>
            <div style={{ transition: 'all .4s', maxHeight: itemLable ? '10000px' : '0px', overflow: 'hidden' }}>{this.props.children}</div>
          </div>
        );
      }
    }
    
    export default ArrowSlide;
    

      组件调用:

                <ArrowSlide
                  itemsName={elem.exam_fee_name} // 检查项组名称
                  itemLable={index === 0} // 是否展开
                  key={i}
                >
                  <TemplateBase
                    isNum={isNum}
                    form={form}
                    data={exam_pro_lists}
                    parentCode={elem.exam_pro_id}
                    onFieldValueChange={(e, field, code, id) => handleTemplateFieldsChange(e, field, code, id)}
                  >
                    {(exam_pro_lists || []).map(({ exam_code: code = 0 }) => {
                      const checkItem = TemplateBase.config[code];
                      const config = `${code}` === '326';
                      if (checkItem) {
                        return <checkItem.name
                          key={code}
                          code={code}
                          config={config}
                        />;
                      }
                      return '';
                    })}
                  </TemplateBase>
                </ArrowSlide>
    

      页面:

    且默认第一项是展开的,代码控制:

  • 相关阅读:
    原生AJAX基础讲解及兼容处理
    JS子元素oumouseover触发父元素onmouseout
    IE6常见bug
    让IE6支持position:fixed的方法,CSS expression与JavaScript eval讲解
    Alpha通道
    网络游戏开发前的pixel像素画习作
    网络游戏开发其一(游戏美工)
    周内琐记
    地图重置与各项绘图优化
    四足机器人搭建尝试
  • 原文地址:https://www.cnblogs.com/yxfboke/p/11281030.html
Copyright © 2011-2022 走看看