Placing the slides...

Oh,HELLO!

Just sliding here...

I think it's worth checking out the other slides to learn more!

Install ME!

Please copy and paste the code below!

npm i @loginamnet/simple-slider

Customize!

Change the properties of the slider to suit your needs

To PROPS!

He-he-he

Don't pay attention, just a slider in the slider

I'm just
sliding
in here
a little
woohoo!

Get the code!

Look at the resulting code and take it for yourself

To CODE!

Any questions?

Check out the documentation and learn more about the different slider features

To DOCS!

Contacts!

Questions, suggestions, criticism? The author is ready to answer everything

Width: ...

|

Height: ...

controls:
controlsOptions:
notInfinite:
showOnHover:
position:
alinging:
reverse:
gap (MIN: 0):
buttonShape:
buttonSize (MIN: 1):
buttonMargin (MIN: 0):
arrowColor:
dots:
dotsOptions:
showOnHover:
direction:
position:
alinging:
reverse:
gap (MIN: 0):
margin (MIN: 0):
dotShape:
dotSize (MIN: 1):
dotColor:
activeDotColor:
startWithSlide (MIN: 1):
slidingType:
slidingDirection:
slidingTimingFunction:
slidingDuration (MIN: 1):
slidingDelay (MIN: 50):
stopOnHover:
customPrevButtonFN:
customNextButtonFN:
customDotFN:
import SimpleSlider from "@loginamnet/simple-slider";

// ---------- import your slide components here ----------
export default function Slider() {
return (
<div style ={{ width: "100%", height: "500px", overflow: "hidden" }}>
<SimpleSlider
controls={"manual"}
controlsOptions={{
buttonShape: "transparent",
}}
dots
slidingType={"sequence"}
slidingDuration={1000}
slidingDelay={2000}
>
{/* place the imported slides or create new ones here */}
<Slide1 />
<Slide2 />
<Slide3 />
<Slide4 />
<Slide5 />
<Slide6 />
<Slide7 />
</SimpleSlider>
</div>
);
}

Simple Slider

licenceversionprettiersize

A Simple Slider on React with multiple scrolling modes and the ability to add custom dots & buttons

Navigation


Features


  • Several directions of movement and types of slide changes 🌗
  • Responsive design 💻
  • Easy to add custom rendered slides 📌
  • The ability to add your own control buttons ▶️
  • Dependency free 🌱
  • Lightweight 🎈

Usage


Instalation

npm i @loginamnet/simple-slider

Import

import SimpleSlider from "@loginamnet/simple-slider";

Basic Example

import SimpleSlider from "@loginamnet/simple-slider";

import MySlide2 from "./components";
import MySlide3 from "./components";

export default function MySliderComponent() {
  return (
    <div
      style={{
        width: "600px",
        height: "400px",
      }}
    >
      <SimpleSlider>
        {/* first slide created directly inside the slider */}
        <div
          style={{
            display: "flex",
            justifyContent: "center",
            alignItems: "center",
            height: "100%",
            width: "100%",
            padding: "20px",
          }}
        >
          <h1>First Slide</h1>
        </div>

        {/* second slide imported from components folder */}
        <MySlide2 text="Second Slide" />

        {/* third slide imported from components folder */}
        <MySlide3>Third Slide</MySlide3>
      </SimpleSlider>
    </div>
  );
}

What can I place inside

Simple Slider accepts ReactNode as "children" — this is a type that includes everything that can be returned by the render() method of React components.

Width, Height and Background

A Simple Slider occupies 100% of the width and height of the parent element, and each "child" component is wrapped in a Slide that occupies 100% of the size of the slider itself. Resize the parent container to resize the slider. At the same time, your "child" component may have a different size from the Slide, which can sometimes be useful.

In the example above, each slide will have a size of 600x400px.

Tip

Both the Simple Slider and the Slide have a transparent background. Add styles to the parent element and to each created "child" component, respectively (for example, to create a preloader).

Props


PropTypeValuesDefaultDescription
controls?undefined, boolean, stringtrue, false , "manual"undefinedаctivates the slider control buttons and disables automatic sliding if the value is set to "manual"
controlsOptions?undefined, objectexplanations and an exampleundefinedvarious options for setting slider controls when the "controls" option is enabled
dots?undefined, booleantrue, falseundefinedаctivates the slider dots component
dotsOptions?undefined, objectexplanations and an exampleundefinedvarious options for setting slider controls when the "dots" option is enabled
startWithSlide?numbernumber (MIN: 1)1the number of the slide to start scrolling from
slidingType?string"sequence", "underlay", "overlay""overlay"the type of slide offset relative to each other
slidingDirection?string"left", "top", "right", "bottom""left"the direction of movement of the slides
slidingDuration?numbernumber (MIN: 1)2000the time of one slide movement cycle (ms)
slidingDelay?numbernumber (MIN: 50)1000delay before the start of the next slide movement for auto sliding or the "controls" option with the value "on-hover" (ms)
slidingTimingFunction?stringstring"ease"transition-timing-function
stopOnHover?undefined, booleantrue, falseundefinedstopping auto sliding with hover on slider (not relevant when the "controls" option is set to "on-hover")
customPrevButtonFN?undefined, functionexplanations and an exampleundefineda function for rendering a custom button to move to the previous slide
customNextButtonFN?undefined, functionexplanations and an exampleundefineda function for rendering a custom button to move to the next slide
customDotFN?undefined, functionexplanations and an exampleundefineda function for rendering a custom dot for slider dots component

Controls Options

Will be applied only if the controls option is enabled. If they are not specified, the buttons will have a standard design and position inside the slider.

PropTypeValuesDefaultDescription
notInfinite?undefined, booleanundefined, trueundefineddisables endless sliding and stops on the first and last slides
showOnHover?undefined, booleanundefined, trueundefineddisplays buttons only when hovering over the slider
position?string"edge", "start", "center", "end";"edge"defines the position of the buttons parallel to the axis of motion (at the edges, at the beginning, at the end, in the center)
alinging?string"start", "center", "end";"center"defines the position of the buttons perpendicular to the axis of motion (at the beginning, at the end, in the center)
reverse?undefined, booleanundefined, trueundefinedswaps the control buttons
gap?numbernumber (MIN: 0)20the distance between the buttons (px)
buttonShape?string"square", "circle", "transparent", "invisible""square"the shape of the standard slider buttons
buttonSize?string, number"small", "medium", "big", number (MIN: 1)"medium"the size of the standard slider buttons (px)
buttonMargin?string, numberstring, number (MIN: 0)30the margin of the standard slider buttons (px). using a string, you can achieve different values vertically and horizontally
arrowColor?stringstring"#000000"color of the standard slider buttons arrows
Tip

If you want to enable the controls property and hide the buttons, you can set the value of the buttonShape to "invisible". This will allow users to control the slider using swipes, but not with buttons.

Controls Options Example

import SimpleSlider from "@loginamnet/simple-slider";

import MySlide1 from "./components";
import MySlide2 from "./components";

export default function MySliderComponent() {
  return (
    <div
      style={{
        width: "600px",
        height: "400px",
      }}
    >
      <SimpleSlider
        controls="on-hover"
        controlsOptions={{
          notInfinite: true,
          position: "center",
          alinging: "end",
          gap: 100,
          buttonShape: "transparent",
          buttonSize: "big",
          buttonMargin: "0 30px",
          arrowColor: "blue",
        }}
      >
        <MySlide1 text="First Slide" />
        <MySlide2>Second Slide</MySlide2>
      </SimpleSlider>
    </div>
  );
}

Dots Options

Will be applied only if the dots option is enabled. If they are not specified, the dots will have a standard design and position inside the slider.

PropTypeValuesDefaultDescription
showOnHover?undefined, booleanundefined, trueundefineddisplays dots component only when hovering over the slider
direction?string"horizontal", "vertical""horizontal"defines the vertical or horizontal position of the dots inside dots component
position?string"start", "center", "end";"center"defines the position of the dots component parallel to the axis of motion (at the beginning, at the end, in the center)
alinging?string"start", "center", "end";"end"defines the position of the dots component perpendicular to the axis of motion (at the beginning, at the end, in the center)
reverse?undefined, booleanundefined, trueundefinedchanges the direction of dots inside dots component
gap?numbernumber (MIN: 0)10the distance between the dots inside dots component (px)
margin?string, numberstring, number (MIN: 0)30the margin of the standard slider dots component (px). using a string, you can achieve different values vertically and horizontally
dotShape?string"square", "circle""square"the shape of the standard slider dots
dotSize?string, number"small", "medium", "big", number (MIN: 1)"medium"the size of the standard slider dot (px)
dotColor?stringstring"#787878"color of the standard slider dot for non-active slide
activeDotColor?stringstring"#000000"color of the standard slider dot for active slide

Dots Options Example

import SimpleSlider from "@loginamnet/simple-slider";

import MySlide1 from "./components";
import MySlide2 from "./components";

export default function MySliderComponent() {
  return (
    <div
      style={{
        width: "600px",
        height: "400px",
      }}
    >
      <SimpleSlider
        dots
        dotsOptions={{
          showOnHover: true,
          direction: "vertical",
          position: "end",
          alinging: "end",
          reverse: true,
          gap: 5,
          margin: "100px 10px",
          dotShape: "circle",
          dotSize: 22,
          dotColor: "green",
          activeDotColor: "blue",
        }}
      >
        <MySlide1 text="First Slide" />
        <MySlide2>Second Slide</MySlide2>
      </SimpleSlider>
    </div>
  );
}

Archived Props

Changing, deleting, and adding slider properties based on the version.

Version 1.1.1

Changed

Slider properties have been changed, in the form of a "from/to" comparison.

Controls Options

from (1.1.1):

PropTypeValuesDefaultDescription
buttonShape?string"square", "circle", "transparent""square"the shape of the standard slider buttons

to (actual):

PropTypeValuesDefaultDescription
buttonShape?string"square", "circle", "transparent", "invisible""square"the shape of the standard slider buttons
Version 1.0.11 & Erlier

Changed

Slider properties have been changed, in the form of a "from/to" comparison.

Props

from (1.0.11 & Erlier):

PropTypeValuesDefaultDescription
controls?undefined, boolean, stringtrue, false , "on-hover"undefineddirect control of the slider using the buttons without automatic scrolling or with a stop at hover

to (actual):

PropTypeValuesDefaultDescription
controls?undefined, boolean, stringtrue, false , "manual"undefinedаctivates the slider control buttons and disables automatic sliding if the value is set to "manual"

Not Exist

This versions of the slider does not support the following properties:

Props

PropTypeValuesDefaultDescription
dots?undefined, booleantrue, falseundefinedаctivates the slider dots component
dotsOptions?undefined, objectexplanations and an exampleundefinedvarious options for setting slider controls when the "dots" option is enabled
customDotFN?undefined, functionexplanations and an exampleundefineda function for rendering a custom dot for slider dots component

Controls Options

PropTypeValuesDefaultDescription
reverse?undefined, booleanundefined, trueundefinedswaps the control buttons

Custom Buttons

You can replace the standard slider buttons (or just one of them) with custom ones!

To do this, you need to create a custom component of the button in a special way and transfer it to the slider as a function. For the "previous" and "next" buttons, these components will be slightly different.

Custom Previous Button Component

export default function CustomPrevButton(
  prevSlide: () => void,
  sliding?: boolean,
  atFirstSlide?: boolean
) {
  return (
    <button
      onClick={(event) => {
        event.stopPropagation();

        prevSlide();
      }}
      disabled={sliding || atFirstSlide}
    >
      Custom Previous Button!
    </button>
  );
}

Custom Next Button Component

export default function CustomNextButton(
  nextSlide: () => void,
  sliding?: boolean,
  atFirstSlide?: boolean
) {
  return (
    <button
      onClick={(event) => {
        event.stopPropagation();

        nextSlide();
      }}
      disabled={sliding || atFirstSlide}
    >
      Custom Next Button!
    </button>
  );
}
Important

For the correct behavior of the slider, it is important to use the button tag! But its contents and styles depend entirely on your imagination.

The sliding property determines the behavior of the button during the slide movement cycle.

The atFirstSlide and atLastSlide properties determine the behavior of the button when the first and last slide are reached, respectively. These properties will only work if the notInfinite property in the controlsOptions object is set to true.

In the above examples of custom buttons, all these properties are used to disable the buttons, but you can apply them as you want.

Slider With Custom Buttons Example

import SimpleSlider from "@loginamnet/simple-slider";

import MySlide1 from "./components";
import MySlide2 from "./components";
import CustomPrevButton from "./components";
import CustomNextButton from "./components";

export default function MySliderComponent() {
  return (
    <div
      style={{
        width: "600px",
        height: "400px",
      }}
    >
      <SimpleSlider
        controls="on-hover"
        customPrevButtonFN={CustomPrevButton}
        customNextButtonFN={CustomNextButton}
      >
        <MySlide1 text="First Slide" />
        <MySlide2>Second Slide</MySlide2>
      </SimpleSlider>
    </div>
  );
}

Custom dots

You can replace the standard slider dots with custom ones!

To do this, you need to create a custom component of the dot in a special way and transfer it to the slider as a function.

Note

If you use custom dot, dotShape, dotSize, dotColor and activeDotColor properties will not be applied. The styling will depend on the styles within your component and your creativity. You can replace the standard slider buttons (or just one of them) with custom ones!

Custom Dot Component

export default function CustomDot(
  index: number,
  switchToSlideFN: (selectedSlideIndex: number) => void,
  nextSlideIndex?: number,
  sliding?: boolean,
  slidingDuration?: number
) {
  return (
    <button
      key={index}
      style={{
        backgroundColor: `${index === nextSlideIndex ? "red" : "white"}`,
        transition: `background-color ${slidingDuration}ms`,
      }}
      disabled={sliding}
      onClick={(event) => {
        event.stopPropagation();

        switchToSlideFN(index);
      }}
    >
      {index + 1}
    </button>
  );
}
Important

For the correct behavior of the slider, it is important to use the button tag! But its contents and styles depend entirely on your imagination.

The nextSlideIndex property defines the index of the next slide and in combination with index property can be useful for stabilizing the state of active and inactive dot (you can see the example above).

The sliding property determines the behavior of the dot during the slide movement cycle.

The slidingDuration property defines the time of one cycle of movement, which can be useful for timing the change of styles.

In the above examples of custom dots componet, these properties are used to disable the dot-button and styling the colors of active/inactive dots, but you can apply them as you want.

Preloader


The slider and its elements use a client-side rendering, which, when there are a large number of slides, may cause them to appear briefly on the screen before they are fully loaded. If you are not using a global preloader, you should consider adding this element directly to the container where the slider is located.

Important

For the slider and preloader container, the overflow property should be set to "hidden". The preloader itself should occupy 100% of the width and height of the container.

Once all the elements have loaded inside the container, remove the preloader. For React, the simplest way is to use a combination of useState and useEffect.

import { useEffect, useState } from "react";

import SimpleSlider from "@loginamnet/simple-slider";

import Preloader from "./components";
import MySlide1 from "./components";
import MySlide2 from "./components";

export default function MySliderComponent() {
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    setLoading(false);
  }, []);

  return (
    <div
      style={{
        width: "600px",
        height: "400px",
        overflow: "hidden",
      }}
    >
      {loading && <Preloader />}
      <SimpleSlider>
        <MySlide1 text="First Slide" />
        <MySlide2>Second Slide</MySlide2>
      </SimpleSlider>
    </div>
  );
}

There are many different ideas for the styling of the preloader available online, so it has been decided not to include this element directly within the slider in order to allow for greater creative freedom.

Special Case


During normal operation of the slider outside the slide change cycle, only the current slide remains visible - even if the size of the component itself is smaller than the size of the slider.

However, with certain settings, it is possible to overlay one slide on top of another to create a complete picture.

To achieve this effect, you need to set controls to manual , the notInfinite property in the controlsOptions object is set to true , the dots property to false (this value is set by default) and slidingType is set overlay (this value is set by default).

controls
controlsOptions={{
    notInfinite: true,
}}

If it is necessary that the slides be removed from the already laid out stack - set the option startWithSlide equal to the number of slides (you may have to change slidingDirection option to the opposite too).

controls
controlsOptions={{
    notInfinite: true,
}}
{/* in this example, it is assumed that we have added five slides */}
startWithSlide={5}

Plans


  • Make it possible to import slider control functions and some internal states to create external control components

Licence


MIT

It can be used for free in any personal or commercial project 🎁