2.8.0 • Published 5 years ago

react-items-carousel v2.8.0

Weekly downloads
11,459
License
MIT
Repository
github
Last release
5 years ago

react-items-carousel

Installation

$ npm install react-items-carousel --save

Demos

Example

import React, { useState } from 'react';
import ItemsCarousel from 'react-items-carousel';

export default () => {
  const [activeItemIndex, setActiveItemIndex] = useState(0);
  const chevronWidth = 40;
  return (
    <div style={{ padding: `0 ${chevronWidth}px` }}>
      <ItemsCarousel
        requestToChangeActive={setActiveItemIndex}
        activeItemIndex={activeItemIndex}
        numberOfCards={2}
        gutter={20}
        leftChevron={<button>{'<'}</button>}
        rightChevron={<button>{'>'}</button>}
        outsideChevron
        chevronWidth={chevronWidth}
      >
        <div style={{ height: 200, background: '#EEE' }}>First card</div>
        <div style={{ height: 200, background: '#EEE' }}>Second card</div>
        <div style={{ height: 200, background: '#EEE' }}>Third card</div>
        <div style={{ height: 200, background: '#EEE' }}>Fourth card</div>
      </ItemsCarousel>
    </div>
  );
};

Component Props

PropertyTypeDefaultDescription
children *node[]The cards to render in the carousel. You must specify a height for each card.
requestToChangeActive *functionThis function accepts the new activeItemIndex and should update your component state.
activeItemIndex *intThis defines which item should be active.
numberOfCardsnumber3Number of cards to show per slide.
infiniteLoopbooleanfalseEnable infinite loop. see Infinite loop limitations
gutternumber0Space between cards.
showSlitherbooleanfalseIf true a slither of next card will be shown.
firstAndLastGutterbooleanfalseIf true first and last cards will have twice the space.
enablePlaceholderbooleanfalseIf true, component will render placeholderItem until children are passed.
placeholderItemnodenullIf enablePlaceholder is true, this will be rendered until children are passed.
numberOfPlaceholderItemsnumber0This controls how many placeholderItem to render if enablePlaceholder is true.
activePositionenum ('left', 'center', 'right')leftThe position of the active item.
rightChevronnodenullRight chevron node.
leftChevronnodenullLeft chevron node.
chevronWidthnumber0This value should be the width of left and right chevron.
outsideChevronbooleanfalseIf true the chevron will be rendered outside the carousel.
alwaysShowChevronsbooleanfalseIf true the chevrons will always be visible even if there were no cards to scroll.
slidesToScrollnumber1Number of cards to scroll when right and left chevrons are clicked.
disableSwipebooleanfalseDisables left and right swiping on touch devices.
onStateChangefuncnullThis function will be called when state change with { isFirstScroll: Boolean, isLastScroll: Boolean }. It can be used to fetch more data for example.
classes{ wrapper: string, itemsWrapper: string, itemsInnerWrapper: string, itemWrapper: string, rightChevronWrapper: string, leftChevronWrapper: string }{}An object of classes to pass to the carousel inner elements

Infinite Loop Limitations

If infiniteLoop was set to true, the following props are ignored

  • activePosition: will always be left
  • alwaysShowChevrons: will always be true

Contributing

To contribute, follow these steps:

  • Fork this repo.
  • Clone your fork.
  • Run yarn
  • Run yarn start:gh
  • Goto localhost:9000
  • Add your patch then push to your fork and submit a pull request

License

MIT

2.8.0

5 years ago

2.7.0

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.0

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.7

5 years ago

2.3.6

6 years ago

2.3.5

6 years ago

2.3.4

6 years ago

2.3.3

6 years ago

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago