Element-React Time Picker 時(shí)間選擇器

2020-10-16 12:02 更新

用于選擇或輸入日期

固定時(shí)間點(diǎn)

提供幾個(gè)固定的時(shí)間點(diǎn)供用戶(hù)選擇

使用 TimeSelect 標(biāo)簽,分別通過(guò)star、endstep指定可選的起始時(shí)間、結(jié)束時(shí)間和步長(zhǎng)

  1. constructor(props) {
  2. super(props)
  3. this.state = {
  4. value: new Date(2016, 9, 10, 8, 30),
  5. }
  6. }
  7. handleUpdate(value) {
  8. console.debug('time-select update: ', value)
  9. }
  10. render() {
  11. return (
  12. <TimeSelect
  13. start="08:30"
  14. step="00:15"
  15. end="18:30"
  16. maxTime="12:30"
  17. onChange={this.handleUpdate.bind(this)}
  18. value={this.state.value}
  19. placeholder="選擇時(shí)間"
  20. />
  21. )
  22. }

任意時(shí)間點(diǎn)

可以選擇任意時(shí)間

使用 TimePicker 標(biāo)簽,分別通過(guò)starendstep指定可選的起始時(shí)間、結(jié)束時(shí)間和步長(zhǎng)

  1. constructor(props) {
  2. super(props)
  3. this.state = {
  4. value: new Date(2016, 9, 10, 18, 40)
  5. }
  6. }
  7. handleUpdate(value) {
  8. console.debug('time-picker update: ', value)
  9. }
  10. render() {
  11. return (
  12. <TimePicker
  13. onChange={this.handleUpdate.bind(this)}
  14. selectableRange="18:30:00 - 20:30:00"
  15. placeholder="選擇時(shí)間"
  16. value={this.state.value}
  17. />
  18. )
  19. }

固定時(shí)間范圍

若先選擇開(kāi)始時(shí)間,則結(jié)束時(shí)間內(nèi)備選項(xiàng)的狀態(tài)會(huì)隨之改變

  1. constructor(props) {
  2. super(props)
  3. this.state = {
  4. startDate: new Date(2016, 9, 10, 14, 30),
  5. endDate: new Date(2016, 9, 10, 15, 30)
  6. }
  7. }
  8. handleStartUpdate(startDate) {
  9. console.debug('time-select startDate update: ', startDate)
  10. this.setState({startDate})
  11. }
  12. handleEndUpdate(endDate){
  13. console.debug('time-select endDate update: ', endDate)
  14. this.setState({endDate})
  15. }
  16. render() {
  17. return (
  18. <div>
  19. <TimeSelect
  20. start="08:30"
  21. step="00:15"
  22. end="18:30"
  23. onChange={this.handleStartUpdate.bind(this)}
  24. value={this.state.startDate}
  25. placeholder="選擇時(shí)間"
  26. />
  27. <TimeSelect
  28. start="08:30"
  29. step="00:15"
  30. end="18:30"
  31. onChange={this.handleEndUpdate.bind(this)}
  32. value={this.state.endDate}
  33. minTime={this.state.startDate}
  34. placeholder="選擇時(shí)間"
  35. />
  36. </div>
  37. )
  38. }

任意時(shí)間范圍

可選擇任意的時(shí)間范圍

blah

  1. constructor(props) {
  2. super(props)
  3. this.state = {
  4. value: [new Date(2016, 9, 10, 8, 40), new Date(2016, 9, 10, 9, 40)]
  5. }
  6. }
  7. handleUpdate(value) {
  8. console.debug('time-picker update: ', value)
  9. }
  10. render() {
  11. return (
  12. <TimeRangePicker
  13. pickerWidth={300}
  14. onChange={this.handleUpdate.bind(this)}
  15. placeholder="選擇時(shí)間"
  16. value={this.state.value}
  17. />
  18. )
  19. }

公共參數(shù)

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

TimeSelect

參數(shù) 說(shuō)明 類(lèi)型 可選值 默認(rèn)值
value date/null -
start 開(kāi)始時(shí)間 string 09:00
end 結(jié)束時(shí)間 string 18:00
step 間隔時(shí)間 string 00:30
minTime 最小時(shí)間 date -
maxTime 最大時(shí)間 date -

TimePicker

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

TimeRangePicker

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)