React 标签页组件

import React from 'react';
import Style from '@/commonality/queryTime/TimeTabs.less'

class TimeTabs extends React.Component {

  constructor(props) {
    super(props)
  }
  state = {
    tabs: [
      {name: '常用时间', id: 1},
      {name: '相对时间', id: 2},
      {name: '绝对时间', id: 3},
    ],
    currentIndex: 1
  }

  handleClick = (id) => {
    this.setState({
      currentIndex: id
    })
  }

  render() {
    const wrap = {
      fontFamily: 'NotoSansCJKsc-DemiLight',
      fontSize: '10px',
      color: '#C0C1C4',
      letterSpacing: '-0.24px',
      lineHeight: '16px',
      marginTop: '6px'
    }
    const frame = {
      height: '110px',
      width: '95px',
      textAlign: 'center',
      display: 'table'
    }
    const vertical = {
      display: 'table-cell',
      verticalAlign: 'middle'
    }
    let _this = this;
    let isBox1Show=this.state.currentIndex==1 ? 'block' : 'none';
    let isbox2Show=this.state.currentIndex==2 ? 'block' : 'none';
    let isbox3Show=this.state.currentIndex==3 ? 'block' : 'none';
    let tabList = this.state.tabs.map((e, i) => {
      let tabStyle = e.id === this.state.currentIndex ? `${Style.active}` : '';  //通过id进行切换
      let imgStyle = e.id === this.state.currentIndex                            //通过id进行切换图片
          ? `${require('../../assets/calendarBLue.png')}` 
          : `${require('../../assets/calendar.png')}`
      
  return (
    <li key={i} onClick={this.handleClick.bind(_this, e.id)} className={tabStyle} style={frame}>  
      {/**this.handleClick.bind(_this, e.id)  handleClic(e.id) => {}*/}
      
      <div style={vertical}>
        <img src={imgStyle}/>
        <div style={wrap}>{e.name}</div> 
      </div>
    </li>
  )
  
})

return (
  <div style={{ display: 'flex' }}>
    <div>
      <ul style={{ background: '#011024', width: '110px', padding: '0'}}>
        {tabList}
      </ul>
    </div>
    <div>
      <div style={{ display: `${isBox1Show}` }}>
        1
      </div>  
      <div style={{ display: `${isbox2Show}` }}>
        2
      </div>
      <div style={{ display: `${isbox3Show}` }}>
        3
      </div>
    </div>
  </div>
   )
 }
}
export default TimeTabs

less 文件

.active {
  border-left: 4px solid #00BFF1;
  height: 110px;
  width: 95px;
  text-align: center;
  display: table;
  div {
    color: #00BFF1 !important
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值