Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuka-carousel custom arrow button

Tags:

reactjs

I'm new to nuka-carousel react.I'm trying to add prev-next arrow button instead of just 'prev' and 'next' written button. I've found various solutions where a decorator function is written.I have tried it but havn't found my desired output. Here is my code:

import Carousel from 'nuka-carousel';
import createReactClass from 'create-react-class';
var Decorators = [
    {
        component: createReactClass({
            render() {
                return (
                    <div>
                        <i className="fa fa-arrow-left" onClick={this.props.previousSlide} aria-hidden="true"></i>
                    </div>
                )
            }
        }),
        position: 'CenterLeft',
        style: {
            padding: 20
        }
    },
    {
        component: createReactClass({
            render() {
                return (
                    <div>
                        <i className="fa fa-arrow-right" onClick={this.props.nextSlide} aria-hidden="true"></i>
                    </div>
                )
            }
        }),
        position: 'CenterRight',
        style: {
            padding: 20
        }
    }
];

return(
    <Carousel decortators={Decorators} slidesToShow={3} cellSpacing={50} >
        {cards}
    </Carousel>

);
like image 827
pranta Avatar asked Mar 05 '23 14:03

pranta


1 Answers

I believe you need to set render*Controls prop of your Carousel component (where * is specific place of control, such as CenterLeft or CenterRight):

<Carousel
  renderCenterLeftControls={({ previousSlide }) => (
    <button onClick={previousSlide}>
      <i className="fa fa-arrow-left" />
    </button>
  )}
  renderCenterRightControls={({ nextSlide }) => (
    <button onClick={nextSlide}>
      <i className="fa fa-arrow-right"/>
    </button>
  )}
>
  {cards}
</Carousel>
like image 175
naffiq Avatar answered Mar 15 '23 21:03

naffiq