question: is there a way to freescroll and read data out of active item after scroll
I'm seeing slidesToScroll option but I'd like the user to be able to drag/scroll over any amount of items (dates) and as they let up, whichever item (date) the carousel landed on would be highlighted and that would determine what was rendered below the carousel (hour time slots for that day).
Yes, you can do some of that. The swiping would be the most difficult part, which I'm not sure can be easily implemented. Simply replace your decorators prop with an array of custom decorators with event handlers to implement this behavior, (eg. <Carousel decorators={Decorators} />) You can copy the existing decorators and add onMouseDown, onMouseUp event handlers like so:
var Decorators = [{
component: React.createClass({
render() {
var self = this;
return (
<button
onMouseDown={self.handleScroll}
onMouseUp={self.finishScroll}
onClick={this.props.previousSlide}>
Previous Slide
</button>
)
},
finishScroll () {
window.clearInterval(this.backScroll);
},
handleScroll () {
window.clearInterval(this.backScroll);
this.backScroll = window.setInterval(() => {
this.props.previousSlide();
}, 200);
}
}),
position: 'CenterLeft',
style: {
padding: 20
}
}, {
component: React.createClass({
render() {
var self = this;
return (
<button
onMouseDown={self.handleScroll}
onMouseUp={self.finishScroll}
onClick={this.props.previousSlide}>
Previous Slide
</button>
)
},
finishScroll () {
window.clearInterval(this.forwardScroll);
},
handleScroll () {
window.clearInterval(this.forwardScroll);
this.forwardScroll = window.setInterval(() => {
console.log('forward');
this.props.nextSlide();
}, 200);
}
}),
position: 'CenterRight',
style: {
padding: 20
}
},
pay particular attention to the handleScroll functions and the finishScroll functions. Also make sure you add a third decorator component, which I left out to save space. Just go ahead and copy the array of decorators in the decorators.js file and paste it somewhere in your app and add those events and handlers to your first two decorator components. You can get the text feedback you want upon selection by managing component state in a wrapper component, and using the afterSlide callback that gets called with the new slide index, (similar to the first example in the demo code with the external controls). Sorry for the delay, and I hope I answered your question. Let me know if you need anything else. :-)
Thank you for the rundown. Unfortunately the advice is coming a bit late as I ended up writing my own custom solution. Learned a lot about events and screen coordinate calculation along the way :-)
I'll keep using nuka-carousel for my other projects though so who knows I could end up coming back to this for reference.
Thanks again!
You're welcome!