国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

Element-React Tag 標簽

2020-10-16 11:23 更新

用于標記和選擇。

基礎(chǔ)用法

type屬性來選擇tag的類型,也可以通過color屬性來自定義背景色。

render() {
  return (
    <div>
      <Tag>標簽一</Tag>
      <Tag type="gray">標簽二</Tag>
      <Tag type="primary">標簽三</Tag>
      <Tag type="success">標簽四</Tag>
      <Tag type="warning">標簽五</Tag>
      <Tag type="danger">標簽六</Tag>
    </div>
  )
}

可移除標簽

設(shè)置closable屬性來定義一個可移除的標簽,接受一個Boolean,設(shè)置為true即可。默認的標簽移除時會附帶漸變動畫,如果不想使用,可以設(shè)置closeTransition屬性,它接受一個Boolean,true 為關(guān)閉。設(shè)置close事件可以處理關(guān)閉后的回調(diào)函數(shù)。

constructor(props) {
  super(props);


  this.state = {
    tags: [
      { key: 1, name: '標簽一', type: '' },
      { key: 2, name: '標簽二', type: 'gray' },
      { key: 5, name: '標簽三', type: 'primary' },
      { key: 3, name: '標簽四', type: 'success' },
      { key: 4, name: '標簽五', type: 'warning' },
      { key: 6, name: '標簽六', type: 'danger' }
    ]
  }
}


handleClose(tag) {
  const { tags } = this.state;


  tags.splice(tags.map(el => el.key).indexOf(tag.key), 1);


  this.setState({ tag });
}


render() {
  return (
    <div>
      {
        this.state.tags.map(tag => {
          return (
            <Tag
              key={tag.key}
              closable={true}
              type={tag.type}
              closeTransition={false}
              onClose={this.handleClose.bind(this, tag)}>{tag.name}</Tag>
          )
        })
      }
    </div>
  )
}

動態(tài)編輯標簽

動態(tài)編輯標簽可以通過點擊標簽關(guān)閉按鈕后觸發(fā)的 onClose 事件來實現(xiàn)

constructor(props) {
  super(props);


  this.state = {
    dynamicTags: ['標簽一', '標簽二', '標簽三'],
    inputVisible: false,
    inputValue: ''
  }
}


onKeyUp(e) {
  if (e.keyCode === 13) {
    this.handleInputConfirm();
  }
}


onChange(value) {
  this.setState({ inputValue: value });
}


handleClose(index) {
  this.state.dynamicTags.splice(index, 1);
  this.forceUpdate();
}


showInput() {
  this.setState({ inputVisible: true }, () => {
    this.refs.saveTagInput.focus();
  });
}


handleInputConfirm() {
  let inputValue = this.state.inputValue;


  if (inputValue) {
    this.state.dynamicTags.push(inputValue);
  }


  this.state.inputVisible = false;
  this.state.inputValue = '';


  this.forceUpdate();
}


render() {
  return (
    <div>
      {
        this.state.dynamicTags.map((tag, index) => {
          return (
            <Tag
              key={Math.random()}
              closable={true}
              closeTransition={false}
              onClose={this.handleClose.bind(this, index)}>{tag}</Tag>
          )
        })
      }
      {
        this.state.inputVisible ? (
          <Input
            className="input-new-tag"
            value={this.state.inputValue}
            ref="saveTagInput"
            size="mini"
            onChange={this.onChange.bind(this)}
            onKeyUp={this.onKeyUp.bind(this)}
            onBlur={this.handleInputConfirm.bind(this)}
          />
        ) : <Button className="button-new-tag" size="small" onClick={this.showInput.bind(this)}>+ New Tag</Button>
      }
    </div>
  )
}

Attributes

參數(shù) 說明 類型 可選值 默認值
type 主題 string 'primary', 'gray', 'success', 'warning', 'danger'
closable 是否可關(guān)閉 boolean false
closeTransition 是否禁用關(guān)閉時的漸變動畫 boolean false
hit 是否有邊框描邊 boolean false
color 背景色 string

Events

事件名稱 說明 回調(diào)參數(shù)
onClose 關(guān)閉tag時觸發(fā)的事件
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號