Giter VIP home page Giter VIP logo

react-styled-carousel's Introduction

React Styled Slider

React Styled Slider is a react and styled component slider. It is fully configurable.

Build Status Coverage Status

Live Image

Features

  • Mostly configurable
  • Styled-Components
  • No external CSS required.
  • Server Side Rendering supported

Note: Server Side Rendering works well without the styled-components collectStyles function also. But for better user experience please use collectStyles function from styled-components

Installation

$ npm install --save react-styled-carousel

Running example in local

$ git clone github.com/itsMrAkhil/react-styled-carousel
$ npm start

It'll open localhost:9000 port, where you can see live demo.

Example

import React from 'react';
import ReactDOM from 'react-dom'
import Slider from 'react-styled-carousel';

const ExampleSlider = () => (
  <Slider>
    <h1>1</h1>
    <h1>2</h1>
    <h1>3</h1>
    <h1>4</h1>
  </Slider>
);

ReactDOM.render(<ExampleSlider />, document.getElementById('root'));

Responsive

react-styled-carousel is responsive. Below is the example configuration of responsiveness.

Note: If responsive prop is provided then, it'll override the cardsToShow prop. In other words cardsToShow will not work.

import React from 'react';
import ReactDOM from 'react-dom'
import Slider from 'react-styled-carousel';

const responsive = [
  { breakPoint: 1280, cardsToShow: 4 }, // this will be applied if screen size is greater than 1280px. cardsToShow will become 4.
  { breakPoint: 760, cardsToShow: 2 },
];

const ExampleSlider = () => (
  <Slider reponsive={responsive} >
    <h1>1</h1>
    <h1>2</h1>
    <h1>3</h1>
    <h1>4</h1>
  </Slider>
);

ReactDOM.render(<ExampleSlider />, document.getElementById('root'));

Configurable Props

Props Type Default Value Description
showArrows Boolean true If true then only Arrows of navigation will be shown
showDots Boolean true Show navigation or pagination dots below the slider
infinite Boolean true Infinitely slide cards.
Dot React Node Default Customized pagination button (Active slide Dot will get active as Boolean prop.)
DotsWrapper Styled Element Default Customized wrapper for your component to change the view of dots wrapper like position, background, etc. Note: It should be a styled ul, otherwise you may not see any Dot Components.
LeftArrow React Node Default Customized left arrow button. It'll get disabled Boolean prop if first Dot is active and infinite is false.
RightArrow React Node Default Customized right arrow button. It'll get disabled Boolean prop if last Dot is active and infinite is false.
children React Node null Cards are components which you want to show in the carousel
cardsToShow Number Children length How many cards to be shown for a single slide.
afterSlide Function null This function will be executed after every sliding is completed
beforeSlide Function null This function will be executed before starting every sliding
responsive Array null Use this for responsiveness Documentation
autoSlide Number or Boolean 2000 Used to make carousel auto slide for every given time interval. Or for 2000ms if the prop value is true.
pauseOnMouseOver Boolean true Pause auto sliding on mouse over the carousel.
hideArrowsOnNoSlides Boolean true Hide arrows if there is only one slide to show.
margin String 0px Any valid css margin value for giving margin around the slider
padding String 0px 20px Any valid css padding value for giving padding around the slider

License

MIT (Free Software, Chill Yeah!)

react-styled-carousel's People

Contributors

dependabot[bot] avatar haniotis avatar itsmrakhil avatar peterlazzarino 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-styled-carousel's Issues

Production build requires react-hot-loader

Fails in production:

{ Error: Cannot find module 'react-hot-loader'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /user_code/node_modules/react-styled-carousel/build/components/SliderTrack.js:16:48
    at Object.<anonymous> (/user_code/node_modules/react-styled-carousel/build/components/SliderTrack.js:19:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12) code: 'MODULE_NOT_FOUND' }

node_modules/react-styled-carousel/build/components/SliderTrack.js

(function () {
  var enterModule = require('react-hot-loader').enterModule;

  enterModule && enterModule(module);
})();

Version: 0.4.11

How to customize style?

How to customize style of carousel for example if I need to use different image/icon for left and right arrows and dots.

Issue with server side rendering

When I try to render

        <Slider>
          <div>Hey</div>
          <div>Hey</div>
          <div>Hey</div>
          <div>Hey</div>
        </Slider>

on the server I get the following error.

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
at invariant (/usr/src/app/node_modules/fbjs/lib/invariant.js:42:15)
at ReactDOMServerRenderer.render (/usr/src/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2522:7)
at ReactDOMServerRenderer.read (/usr/src/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2354:19)
 at Object.renderToString (/usr/src/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2726:25)
at Object.default_1 [as default] (/usr/src/app/src/lib/render.ts:15:16)
at Object.<anonymous> (/usr/src/app/src/routes/client.tsx:25:18)
at step (/usr/src/app/src/routes/client.tsx:32:23)
at Object.next (/usr/src/app/src/routes/client.tsx:13:53)
at /usr/src/app/src/routes/client.tsx:7:71
at new Promise (<anonymous>) name: 'Invariant Violation', framesToPop: 1 }

This is my render code:

  const sheet = new ServerStyleSheet(); // <-- creating out stylesheet
  const body = renderToString(sheet.collectStyles(element));

Am I missing something to be able to render server side? Sweet library by the way!

issue auto not working

Screenshot 2019-03-16 at 10 32 47 AM

<Slider
          autoSlide={2000}
          padding={"50px"}
          cardsToShow={3}
          reponsive={responsive}
        >
          {repolist}
        </Slider>

const repolist = this.state.repoList.map((item: any) => (
<GithubLoginButton
style={btnGithub}
onClick={() => this.routeChange(item.html_url)}
>
{item.name}

));

//slider auto not working

Warning: It looks like there are several instances of 'styled-components' initialized in this application.

Hey there, thanks for the great component!

I'm using this component with gatsbyjs and styled components alongside react-styled-carousel.
I'm getting this error

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.

See https://s-c.sh/2BAXzed for more info.

Is there a way for me to prevent react-styled-carousel from loading styled components as well?

If I remove react-styled-carousel the error goes away.

Doesn't work with Next.js

stops working after page refresh
I've tried in a working project as well as in this https://github.com/zeit/next.js/tree/canary/examples/with-styled-components sandbox

TypeError: Cannot read property 'href' of undefined
    at getURL (/Project/test-slider/node_modules/next/dist/lib/utils.js:160:30)
    at new Router (/Project/test-slider/node_modules/next/dist/lib/router/router.js:99:115)
    at renderPage (/Project/test-slider/node_modules/next/dist/server/render.js:161:25)
    at Function.getInitialProps (/Project/test-slider/node_modules/next/dist/server/document.js:93:25)
    at _callee$ (/Project/test-slider/node_modules/next/dist/lib/utils.js:36:30)
    at tryCatch (/Project/test-slider/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Project/test-slider/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/Project/test-slider/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/Project/test-slider/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Project/test-slider/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
    at new Promise (<anonymous>)
    at new F (/Project/test-slider/node_modules/core-js/library/modules/_export.js:35:28)
    at /Project/test-slider/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12
    at loadGetInitialProps (/Project/test-slider/node_modules/next/dist/lib/utils.js:70:17)
    at _callee3$ (/Project/test-slider/node_modules/next/dist/server/render.js:187:51)
    at tryCatch (/Project/test-slider/node_modules/regenerator-runtime/runtime.js:62:40)

errors in the console occur inside the next.js: window.location is undefined for some reasons

Any ideas?

Make carousel responsive

Take an array of the shape { breakPoint: number, cardsToShow: number } as props.
And whenever screen size matches the breakPoint change the cardsToShow to the specific number.

Left arrow issue

When I make padding prop 0px, the default left arrow is not being shown.
I have make my own arrow for this. Please fix this.

Strange issue management

@TylerBarnes Feel free to reopen the issue if you think it's an issue. And add more details

Originally posted by @ItsMrAkhil in #32 (comment)

Hey @ItsMrAkhil,
I stopped using react-styled-carousel because of this error but if I didn't think it was an issue I wouldn't have opened an issue in the first place. Why does the issue need to be opened twice for it to be considered an issue?
It also seems I can't reopen issues here.

What other details do you want? The issue was fairly specific.
If you just want to close the issue to not deal with it, it's probably better to say that when you're closing it.

space

when using the libraby, spacing between components seem to be huge, how can i reduce spacing between components ?
Screenshot from 2019-12-29 09-38-38

issue

Try npm install @types/react-styled-carousel if it exists or add a new declaration (.d.ts) file containing declare module 'react-styled-carousel';

Arrows not showing

When I am trying to do something like

<Slider>
                {items.map((item)=>{
                    return (
                        <h1 key={item.id}>
                            {item.name}
                        </h1>
                    )
                })}
</Slider>

I don't get arrows on carousel sides. Moreover it shows only one item per dot as opposed to showing all items per slide. If I use the same code but without items.map function it works as expected.

Responsive example does not work.

reponsive => responsive.
I for the life of me was wondering why it wasn't working then realize there is a typo in the example given.

Add auto sliding functionality

Allow the user to send the below props for the auto sliding of the carousel.

  1. autoSlide: Number or Boolean. If number then slide the carousel for that interval
  2. pauseOnMouseOver: Boolean. If true pause the auto sliding on mouse over the carousel.

Remove lodash sortby

Hi, removing lodash.sortby and making it by hand should significantly reduce the size of the package. If you check https://bundlephobia.com/[email protected], you will see that nearly half of the library is lodash sortby. I checked the source and the function is used only in one place, so it should be quite ok to rewrite that portion with custom sort by code.

Warning: Can't call setState (or forceUpdate) on an unmounted component.

Getting this in latest react on first slide transition:
warning.js:33 Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

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.