/simple-image-carousel

customizable image slider component for React and Next.js with built-in lazy loading.

Primary LanguageTypeScript

image-slider


Install

npm i simple-image-carousel

Languages

๐Ÿ‡ฐ๐Ÿ‡ท Korea

๐Ÿ‡บ๐Ÿ‡ธ English


Korea

์ด๋ฏธ์ง€ ์Šฌ๋ผ์ด๋”๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ lazy loading์„ ์ง€์›ํ•˜์—ฌ, ์Šคํฌ๋กค ์‹œ์ ์— ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

Props ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’ ํƒ€์ž…
images { url: string } ํ˜•์‹์˜ ๊ฐ์ฒด ๋ฐฐ์—ด๋กœ, ์Šฌ๋ผ์ด๋”์— ํ‘œ์‹œํ•  ์ด๋ฏธ์ง€ URL์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. - { url: string }[]
showArrows ์Šฌ๋ผ์ด๋” ์–‘ ์˜†์— ํ™”์‚ดํ‘œ๋ฅผ ํ‘œ์‹œํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. true boolean
showDots ์Šฌ๋ผ์ด๋” ํ•˜๋‹จ์— ์ ์„ ํ‘œ์‹œํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. true boolean
enableDrag ๋“œ๋ž˜๊ทธ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. true boolean
enableLoop ์Šฌ๋ผ์ด๋”์˜ ๋ฃจํ”„ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž๋™ ์Šฌ๋ผ์ด๋“œ๊ฐ€ ํ™œ์„ฑํ™” ๋ผ์žˆ์œผ๋ฉด ํ•ด๋‹น ๊ฐ’์€ true๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. true boolean
width ์Šฌ๋ผ์ด๋”์˜ ๋„ˆ๋น„๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. null number | null
height ์Šฌ๋ผ์ด๋”์˜ ๋†’์ด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. null number | null
objectFit ์ด๋ฏธ์ง€๋ฅผ ๋งž์ถ”๋Š” ๋ฐฉ์‹์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. fill "fill" | "contain" | "cover" | "none" | "scale-down"
dotColor ์ ์˜ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. rgb(0, 114, 255) string
dotHoverColor ์ ์„ ๋งˆ์šฐ์Šค๋กœ ๊ฐ€๋ฆฌํ‚ฌ ๋•Œ์˜ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. rgb(135, 135, 135) string
dotBorderColor ์ ์˜ ํ…Œ๋‘๋ฆฌ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. rgb(152, 152, 152) string
arrowColor ํ™”์‚ดํ‘œ์˜ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. white string
arrowSize ํ™”์‚ดํ‘œ์˜ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. 50 number
dotSize ์ ์˜ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. 13 number
borderRadius ์Šฌ๋ผ์ด๋”์˜ ๋ชจ์„œ๋ฆฌ ๋ฐ˜๊ฒฝ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. 0 number
autoSlider ์ž๋™ ์Šฌ๋ผ์ด๋“œ ์‹œ๊ฐ„(๋ฐ€๋ฆฌ์ดˆ)์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. 0 number
duration ์Šฌ๋ผ์ด๋“œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ง€์† ์‹œ๊ฐ„(๋ฐ€๋ฆฌ์ดˆ)์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. 300 number

์‚ฌ์šฉ ์˜ˆ์ œ

import React from 'react';
import ImageSlider from 'simple-image-carousel';

const images = [
  { url: 'https://example.com/image1.jpg' },
  { url: 'https://example.com/image2.jpg' },
  { url: 'https://example.com/image3.jpg' },
];

const App = () => (
{/* ๋„“์ด๋ฅผ ์ง€์ •ํ•ด ์ฃผ์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ถ€๋ชจ ํฌ๊ธฐ์˜ 100%๋ฅผ ์ฐจ์ง€ํ•ฉ๋‹ˆ๋‹ค */}
   <div>
    <ImageSlider images={images} />
  </div>

{/* ์•„๋ž˜์™€ ๊ฐ™์€ props๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. */}
  <div>
    <ImageSlider
      images={images}
      showArrows={true}
      showDots={true}
      enableDrag={true}
      enableLoop={true}
      width={600}
      height={400}
      objectFit="cover"
      dotColor="blue"
      dotHoverColor="lightblue"
      dotBorderColor="darkblue"
      dotSize={20}
      arrowColor="black"
      arrowSize={40}
      borderRadius={10}
      autoSlider={3000}
      duration={500}
    />
  </div>
);

export default App;

NextJS์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ

import dynamic from "next/dynamic";

const ImageSlider = dynamic(() => import("simple-image-carousel"), {
	ssr: false,
});

English

The image slider supports lazy loading by default, loading images as they come into view during scrolling.

Props Description Default Type
images An array of objects { url: string } containing image URLs to be displayed in the slider. - { url: string }[]
showArrows Determines whether arrows are shown on the sides of the slider. true boolean
showDots Determines whether dots are shown at the bottom of the slider. true boolean
enableDrag Enables or disables the drag functionality. true boolean
enableLoop Enables or disables the loop functionality of the slider. If auto slider is enabled, this value will be set to true. true boolean
width Sets the width of the slider. null number | null
height Sets the height of the slider. null number | null
objectFit Sets the object fit mode for the images. fill "fill" | "contain" | "cover" | "none" | "scale-down"
dotColor Sets the color of the dots. rgb(0, 114, 255) string
dotHoverColor Sets the color of the dots when hovered over. rgb(135, 135, 135) string
dotBorderColor Sets the border color of the dots. rgb(152, 152, 152) string
arrowColor Sets the color of the arrows. white string
arrowSize Sets the size of the arrows. 50 number
dotSize Sets the size of the dots. 13 number
borderRadius Sets the border radius of the slider. 0 number
autoSlider Sets the automatic slider interval time in milliseconds. 0 number
duration Sets the duration of the slide animation in milliseconds. 300 number

Example Usage

import React from 'react';
import ImageSlider from 'simple-image-carousel';

const images = [
  { url: 'https://example.com/image1.jpg' },
  { url: 'https://example.com/image2.jpg' },
  { url: 'https://example.com/image3.jpg' },
];

const App = () => (
{/* If you don't specify a width, it defaults to 100% of the parent's size */}
   <div>
    <ImageSlider images={images} />
  </div>

{/* You can use the following props */}
  <div>
    <ImageSlider
      images={images}
      showArrows={true}
      showDots={true}
      enableDrag={true}
      enableLoop={true}
      width={600}
      height={400}
      objectFit="cover"
      dotColor="blue"
      dotHoverColor="lightblue"
      dotBorderColor="darkblue"
      dotSize={20}
      arrowColor="black"
      arrowSize={40}
      borderRadius={10}
      autoSlider={3000}
      duration={500}
    />
  </div>
);

export default App;

with NextJS

import dynamic from "next/dynamic";

const ImageSlider = dynamic(() => import("simple-image-carousel"), {
	ssr: false,
});