Element-React Time Picker 時間選擇器

2020-10-16 12:02 更新

用于選擇或輸入日期

固定時間點

提供幾個固定的時間點供用戶選擇

使用 TimeSelect 標簽,分別通過star、endstep指定可選的起始時間、結束時間和步長

constructor(props) {
  super(props)


  this.state = {
    value: new Date(2016, 9, 10, 8, 30),
  }
}


handleUpdate(value) {
  console.debug('time-select update: ', value)
}


render() {
  return (
    <TimeSelect
      start="08:30"
      step="00:15"
      end="18:30"
      maxTime="12:30"
      onChange={this.handleUpdate.bind(this)}
      value={this.state.value}
      placeholder="選擇時間"
      />
  )
}

任意時間點

可以選擇任意時間

使用 TimePicker 標簽,分別通過star、endstep指定可選的起始時間、結束時間和步長

constructor(props) {
  super(props)
  this.state = {
    value: new Date(2016, 9, 10, 18, 40)
  }
}


handleUpdate(value) {
  console.debug('time-picker update: ', value)
}


render() {
  return (
    <TimePicker
      onChange={this.handleUpdate.bind(this)}
      selectableRange="18:30:00 - 20:30:00"
      placeholder="選擇時間"
      value={this.state.value}
      />
  )
}

固定時間范圍

若先選擇開始時間,則結束時間內備選項的狀態(tài)會隨之改變

constructor(props) {
  super(props)
  this.state = {
    startDate: new Date(2016, 9, 10, 14, 30),
    endDate: new Date(2016, 9, 10, 15, 30)
  }
}


handleStartUpdate(startDate) {
  console.debug('time-select startDate update: ', startDate)
  this.setState({startDate})
}


handleEndUpdate(endDate){
  console.debug('time-select endDate update: ', endDate)
  this.setState({endDate})
}


render() {
  return (
    <div>
      <TimeSelect
        start="08:30"
        step="00:15"
        end="18:30"
        onChange={this.handleStartUpdate.bind(this)}
        value={this.state.startDate}
        placeholder="選擇時間"
        />


      <TimeSelect
        start="08:30"
        step="00:15"
        end="18:30"
        onChange={this.handleEndUpdate.bind(this)}
        value={this.state.endDate}
        minTime={this.state.startDate}
        placeholder="選擇時間"
        />
    </div>


  )
}

任意時間范圍

可選擇任意的時間范圍

blah

constructor(props) {
  super(props)
  this.state = {
    value: [new Date(2016, 9, 10, 8, 40), new Date(2016, 9, 10, 9, 40)]
  }
}


handleUpdate(value) {
  console.debug('time-picker update: ', value)
}


render() {
  return (
    <TimeRangePicker
      pickerWidth={300}
      onChange={this.handleUpdate.bind(this)}
      placeholder="選擇時間"
      value={this.state.value}
      />
  )
}

公共參數(shù)

參數(shù) 說明 類型 可選值 默認值
align 對齊方式 string left, center, right left
placeholder 占位內容 string
isShowTrigger 是否顯示圖標 bool - -
isReadOnly 只讀 boolean false
isDisabled 是否禁用 boolean false
onFocus onFocus func:(TimeSelectReactComponent)=>() -
onBlur onBlur func:(TimeSelectReactComponent)=>() -
onChange onChange func:(value)=>() -

TimeSelect

參數(shù) 說明 類型 可選值 默認值
value date/null -
start 開始時間 string 09:00
end 結束時間 string 18:00
step 間隔時間 string 00:30
minTime 最小時間 date -
maxTime 最大時間 date -

TimePicker

參數(shù) 說明 類型 可選值 默認值
value date/null -
selectableRange 可選時間段,例如 '18:30:00 - 20:30:00' 或者傳入數(shù)組 ['09:30:00 - 12:00:00', '14:30:00 - 18:30:00'] string/string[]

TimeRangePicker

參數(shù) 說明 類型 可選值 默認值
value date[]/null -
selectableRange 可選時間段,例如 '18:30:00 - 20:30:00' 或者傳入數(shù)組 ['09:30:00 - 12:00:00', '14:30:00 - 18:30:00'] string/string[]
rangeSeparator 選擇范圍時的分隔符 string - ' - '
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號