1.1.8 • Published 6 months ago

react-video-timelines-slider v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

react-video-timelines-slider

This project is forked from react-timeline-range-slider by lizashkod and it adds more functionality and security updates. The additional functionality includes support for tooltips, tooltip format, enabling-disabling tooltip and hiding timeline error if gap is selected.

Live demo

codesandbox-demo

Installation-steps

 npm i react-video-timelines-slider

Props

PropTypeDefaultDescription
timelineIntervalarraystartOfToday(), endOfToday()Interval to display
selectedIntervalarraynew Date(), addHours(new Date(), 1)Selected interval inside the timeline
disabledIntervalsarray[]Array of disabled intervals inside the timeline
containerClassNamestringClassName of the wrapping container
stepnumber1800000Number of milliseconds between steps (the default value is 30 minutes)
ticksNumbernumber48Number of steps on the timeline (the default value is 30 minutes). Note that this is just a hint and actual tick might vary slightly
errorboolfalseIs the selected interval is not valid
modeint/function3The interaction mode. Value of 1 will allow handles to cross each other. Value of 2 will keep the sliders from crossing and separated by a step. Value of 3 will make the handles pushable and keep them a step apart. ADVANCED: You can also supply a function that will be passed the current values and the incoming update. Your function should return what the state should be set as.
formatTickfunctionms => format(new Date(ms), 'HH:mm')Function that determines the format in which the date will be displayed
formatTooltipfunctionms => format(new Date(ms), 'HH:mm:ss')Function that determines the format in which the tooltip will be displayed
showTooltipbooltrueenable-disable the tooltip
tooltipTagstring"Value:"Tag to appear before tooltip text
showTimelineErrorboolfalseTurn timeline red if range with gap is selected
onUpdateCallbackfunction
onChangeCallbackfunction
import React from 'react'  
import { endOfToday, set } from 'date-fns' 
import TimeRange from 'react-video-timelines-slider'  

const now = new Date()
const getTodayAtSpecificHour = (hour = 12) =>
	set(now, { hours: hour, minutes: 0, seconds: 0, milliseconds: 0 })

const selectedStart = getTodayAtSpecificHour()
const selectedEnd = getTodayAtSpecificHour(14)

const startTime = getTodayAtSpecificHour(7)
const endTime = endOfToday()

const disabledIntervals = [
  { start: getTodayAtSpecificHour(16), end: getTodayAtSpecificHour(17) },
  { start: getTodayAtSpecificHour(7), end: getTodayAtSpecificHour(12) },
  { start: getTodayAtSpecificHour(20), end: getTodayAtSpecificHour(24) }
]

class App extends React.Component {  
  state = {  
    error: false,  
    selectedInterval: [selectedStart, selectedEnd],  
  }
	
  errorHandler = ({ error }) => this.setState({ error })  

  onChangeCallback = selectedInterval => this.setState({ selectedInterval })  

  render() {  
    const { selectedInterval, error } = this.state  
      return (  
        <TimeRange
          error={error}  
          ticksNumber={20}  
          step={1}
          selectedInterval={selectedInterval}  
          timelineInterval={[startTime, endTime]}  
          onUpdateCallback={this.errorHandler}  
          onChangeCallback={this.onChangeCallback}
          disabledIntervals={disabledIntervals} 
          formatTick={(ms) => format(new Date(ms), 'HH:mm:ss')} 
          formatTooltip={(ms) => format(new Date(ms), 'HH:mm:ss.SSS')}
          showTooltip={true}
          showTimelineError={false}
        />
      )  
  }  
}  

export default App
1.1.8

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago