Coder Social home page Coder Social logo

kareemaly / react-items-carousel Goto Github PK

View Code? Open in Web Editor NEW
208.0 5.0 52.0 4.77 MB

Items Carousel Built with react-motion and styled-components

Home Page: https://kareemaly.github.io/react-items-carousel/

License: MIT License

HTML 0.32% JavaScript 99.68%
carousel react-component responsive react mobile

react-items-carousel's Introduction

react-items-carousel

Installation

$ npm install react-items-carousel --save

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

Property Type Default Description
children * node[] The cards to render in the carousel. You must specify a height for each card.
requestToChangeActive * function This function accepts the new activeItemIndex and should update your component state.
activeItemIndex * int This defines which item should be active.
numberOfCards number 3 Number of cards to show per slide.
infiniteLoop boolean false Enable infinite loop. see Infinite loop limitations
gutter number 0 Space between cards.
showSlither boolean false If true a slither of next card will be shown.
firstAndLastGutter boolean false If true first and last cards will have twice the space.
enablePlaceholder boolean false If true, component will render placeholderItem until children are passed.
placeholderItem node null If enablePlaceholder is true, this will be rendered until children are passed.
numberOfPlaceholderItems number 0 This controls how many placeholderItem to render if enablePlaceholder is true.
activePosition enum ('left', 'center', 'right') left The position of the active item.
rightChevron node null Right chevron node.
leftChevron node null Left chevron node.
chevronWidth number 0 This value should be the width of left and right chevron.
outsideChevron boolean false If true the chevron will be rendered outside the carousel.
alwaysShowChevrons boolean false If true the chevrons will always be visible even if there were no cards to scroll.
slidesToScroll number 1 Number of cards to scroll when right and left chevrons are clicked.
disableSwipe boolean false Disables left and right swiping on touch devices.
onStateChange func null This 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

react-items-carousel's People

Contributors

dependabot[bot] avatar kareemaly avatar mihaisampaleanu avatar timreynolds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-items-carousel's Issues

Ability to add Dots

I think if we will have props "withDots" and "Dots" / "Dot" - it will be cool!

Make classNames static

This is related to #1 - Make carousel responsive. When showing the carousel on mobile, there needs to be some tweaks to the chevron container styles to place the chevron(s) within the image.

The use case is that for a desktop / tablet we display 3 images. On a phone, we display one image. The numberOfCards prop can be changed by hooking up an event handler to the window.resize event. This works well. However, the chevrons need some additional padding on mobile.

Having static classes (or at least one) on the chevron container would make adding this style via a CSS media query much easier. There may be other places where it would be beneficial to have a static class name as well.

Scroll using li items in navbar

Hi,

Can we use this library to navigate navbar items instead of images.
The clicked link/li should always come in center by auto scroll.

Thanks in advance!

Scroll direction

Is there any way or prop to set the scroll direction, p/e: set the direction vertical or horizontal?

Warning: componentWillReceiveProps has been renamed

Hi, I'm getting this warning

`Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: Motion`

(I'm using "react-items-carousel": "2.8.0")

Cannot create styled-component for component:

There is an issue with Internet Explorer 8 till 11

Error: Cannot create styled-component for component: .sc-bZQynM.

I am using :
"react-items-carousel": "^2.3.0",

    "react": "^16.0.0",
    "react-dom": "^16.0.0"

Types TypeScript support

Error using TypeScript.

TypeScript error in ./client/src/components/Clients/index.tsx(2,27):
Could not find a declaration file for module 'react-items-carousel'. ./client/node_modules/react-items-carousel/dist/react-items-carousel.js' implicitly has an 'any' type.
  Try `npm install @types/react-items-carousel` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-items-carousel';`  TS7016
    1 | import React, { useState } from 'react'
  > 2 | import ItemsCarousel from 'react-items-carousel';
      |                           ^
    3 | // import '@brainhubeu/react-carousel/lib/style.css'
    4 | // import './Clietns.scss'
    5 | 

I recommend to you use dts gen created by Microsoft.

Invalid prop `children` of type `object`

Warning: Failed prop type: Invalid prop children of type object supplied to index.js:1 t, expected an array.
in t

  console. @ index.js:1
  printWarning @ checkPropTypes.js:20
  checkPropTypes @ checkPropTypes.js:82
  validatePropTypes @ react.development.js:1666
  createElementWithValidation @ react.development.js:1755
  value @ react-items-carousel.js:1
  finishClassComponent @ react-dom.development.js:17160
  updateClassComponent @ react-dom.development.js:17110
  beginWork @ react-dom.development.js:18620
  beginWork$1 @ react-dom.development.js:23179
  performUnitOfWork @ react-dom.development.js:22154
  workLoopSync @ react-dom.development.js:22130
  performSyncWorkOnRoot @ react-dom.development.js:21756
  scheduleUpdateOnFiber @ react-dom.development.js:21188
  updateContainer @ react-dom.development.js:24373
  (anonymous) @ react-dom.development.js:24758
  unbatchedUpdates @ react-dom.development.js:21903
  legacyRenderSubtreeIntoContainer @ react-dom.development.js:24757
  render @ react-dom.development.js:24840
  ./src/index.js @ index.js:6
  webpack_require @ bootstrap:784
  fn @ bootstrap:150
  1 @ theme.js:1
  webpack_require @ bootstrap:784
  checkDeferredModules @ bootstrap:45
  webpackJsonpCallback @ bootstrap:32
  (anonymous) @ main.chunk.js:1

'width' attribute NaN

Hello,

Using your basic example I got the following error :

  • Warning: Received NaN for the width attribute. If this is expected, cast the value to a string.

Here is what I did :

  • change the children (I did not used createChildren(20) where createChildren is using n => range(n).map(....)
  • I removed all the placeholder configurations cause I don't need them

Thank you for your help.

An option to show both carousel

Right now, the right or left carousel will only show if there's content to scroll. It would be nice to add an option to make the carousels stay.

touch items

hi,I need to add touch event for items.please help me

responsive?

Hi,
Is this package responsive? When decreasing the width of the page, the number of items shown in the carousel should also decrease. Any way for this? Thanks

Carousel Responsiveness

Is there a way to implement responsiveness in react-item-carousel responsiveness, I need the number of cards prop to reduce at different breakpoints

Make carousel responsive

Hello, it would be nice to basically push items vertically (on a next row) on small media.

The autogenerated css class don't permit to add extra responsiveness to the component..

Thanks!

Looping items

Hello, is it possible to loop carousel items? If it's not possible at the moment is it hard to add this feature?

Update react-motion version

I'm getting the following warning due to the Motion dependency.

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: Motion

Option for rounded item pixel widths

The auto-generated div container around each item in the carousel is assigned a CSS pixel width. Depending on the screen-size and number of items in the carousel, this width is sometimes a decimal number e.g. 268.357px

When applying CSS transformation animations to the item contents e.g. scale image on hover, the edges can jump in Chrome and Firefox because of the decimal width. It would be great to have an option to round the assigned width to the nearest whole number e.g. 268px, which will resolve this display problem.

Several instances of 'styled-components'

Warning in development mode using next.js:
It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles not rendering properly, errors happening during rehydration process and makes your application bigger without a good reason.

I'm using styled-components v5 in my main app, I tried to solve it with this:
Official fix

But when I applied this config, your component doesn't load styled-components and it's all hidden.

Scrolling draggable?

Hi, I was looking in the documentation about this, but I couldn't find it, is there any way for make the items draggable?

thanks

Motion library dependency needs updating

Using this carousel at present causes a warning due to the react-motion library that is pulled in:

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: Motion

This library has not yet been updated -- it has an open issue regarding it and sounds like it is slated for a fix, but I wanted to file this issue here so that you could track that dependency.

Issue #38 was previously filed, but auto-closed due to staleness.

sort / order by attribute / id

Hi, this is wonderful carousel till now i have used very easy to integrate and use, is there any way to sort by / order by .

TypeScript typings

Hello.

It would be nice to have TypeScript typings for this module.

gr,

Tom

autoplay option

Is there an option that allows automatically changing the carousel after a certain interval?

CDN Support

Hello! Would it be possible to make your components accessible through a CDN? And have it expose a global variable? For example:

If this script tag
<script type="text/javascript" crossorigin src="www.cdn.com/react-items-carousel"></script>
Could expose the ReactItemsCarousel global variable so I can access your components like:

<ReactItemsCarousel.ItemsCarousel />
or like
const { ItemsCarousel } = ReactItemsCarousel

This would be absolutely amazing!!!

React and MaterialUI do something similar to this. For example:
If I'm using the React prod or dev cdn links I can access the useState function with this syntax:
const [myvar, setMyVar] = React.useState(5);
or

const { useState } = React;
const [myVar, setMyVar] = useState(5);

dynamic item carousel is not working

Trying to do update/delete/add operation on the component inside the item carousel, but the chevron actions and card navigation works only when right chevron alone present in the screen. Like it works only when index as 0. But if I am in the middle of scroll and do an update/delete/add then chevron actions are not working. and no error logs also. please suggest how to fix this.

Customizing chevron

I wanna know if it's possible to customise the chevrons? Other carousels that i saw have this carousel block with large chevron icons shown when hovering on the carousel items. Wondering if such customization can be done with your item carousel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.