0.2.9 • Published 5 years ago

react-basic-slider v0.2.9

Weekly downloads
96
License
-
Repository
github
Last release
5 years ago

React Basic Slider

A basic react slider/carousel component that uses React Hooks and styled-components and that has touch support.

alt text

DEMO -> https://lucid-easley-d4aea3.netlify.com/

Instalation

npm install react-basic-slider
# or
yarn add react-basic-slider

Usage

Simply import the component and add some children to it

import Slider from 'react-basic-slider';

...

return(
  <Slider>
     <div style={{ background: "Aquamarine" }}>
       <p>
         Lorem ipsum dolor sit amet consectetur adipisicing elit. In cumque
         dicta ut aliquam dolor recusandae, dolore facilis quo. Numquam
         quibusdam aperiam nostrum, minus laborum odio provident laboriosam
         voluptatibus veritatis doloribus.
       </p>
     </div>
     <div style={{ background: "Salmon" }}>
       <p>
         Lorem ipsum dolor sit amet consectetur adipisicing elit. In cumque
         dicta ut aliquam dolor recusandae, dolore facilis quo. Numquam
         quibusdam aperiam nostrum, minus laborum odio provident laboriosam
         voluptatibus veritatis doloribus.
       </p>
     </div>
     <div
       style={{
         background: "MediumSlateBlue",
         backgroundImage:
           "url('https://images.unsplash.com/photo-1559762705-2123aa9b467f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')"
       }}
     />
  </Slider>
);

Styling

The styling can be done using styled-components, by passing a custom className and style it directly through css or by using the customStyles prop.

Example using styled-components

import Slider from "react-basic-slider";

...

const CustomSlider = styled(Slider)`
  button{
    background: red;
  }
`;

...

return(
  <CustomSlider>
    <div style={{background: 'red'}}>a</div>
    <div style={{background: 'green'}}>b</div>
    <div style={{background: 'blue'}}>c</div>
  </CustomSlider>
);

Example using customStyles prop

import Slider from "react-basic-slider";

...

const slidesContainerStyles = {};
const mainContainerStyles = {
  background: "#e9e9e9",
  borderRadius: "10px",
  padding: "30px",
  ">p": {
    padding: "10px"
  }
};
const navigationContainerStyles = {};
const navigationButtonsStyles = {
  background: "#ccc",
  borderRadius: "1px",
  margin: "0 5px"
};
const arrowsContainerStyles = {};
const leftArrowStyles = {
  background: "grey"
};
const rightArrowStyles = {
  background: "grey"
};

...

return(
  <Slider
    customStyles={{
      mainContainer: mainContainerStyles,
      slidesContainer: slidesContainerStyles,
      navigationContainer: navigationContainerStyles,
      navigationButtons: navigationButtonsStyles,
      arrowsContainer: arrowsContainerStyles,
      leftArrow: leftArrowStyles,
      rightArrow: rightArrowStyles
    }}>
    <div style={{background: 'red'}}>a</div>
    <div style={{background: 'green'}}>b</div>
    <div style={{background: 'blue'}}>c</div>
  </Slider>
);

Props

propertytypedefaultpurpose
loopbooleantrueLet's you go through the carousel again after you reach the last slider and click the next arrow
selectednumber0Slide to display
showArrowsbooleantrueDisplays the next/prev arrows
showNavbooleantrueDisplays the bottom dotted navigation
leftArrowstringnot displayingChange the default left arrow to a custom one. Needs to be an URL that goes into the src attribute of an img tag
rightArrowstringnot displayingChange the default right arrow to a custom one. Needs to be an URL that goes into the src attribute of an img tag
arrowsPositionstringcenterChange the default arrow positioning. Can be center or bottom
customStylesobjectnot appliedChange the default styling.
onChangefunctionnot appliedCaptures the current selected index.

Note

If you're using Rollupjs and you're getting the following error or similar:

[!] Error: 'isValidElementType' is not exported by node_modules/react-is/index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules/styled-components/dist/styled-components.es.js (7:9)

You can fix it following the instruction here: https://github.com/styled-components/styled-components/issues/1654#issuecomment-441151140

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago