1.0.14 • Published 10 months ago

@ezflawless/components v1.0.14

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

components

Slider

A slideshow component for cycling through elements—images or slides of text—like a carousel.

How it works

It accepts an array of React Elements as children. It only renders the active element and two elements next to it.

Usage

const nextSlideButtonRef = useRef<HTMLButtonElement>(null)
const prevSlideButtonRef = useRef<HTMLButtonElement>(null)

const [key, setKey] = useState<Key | null>(null)
const [items, setItems] = useState<number[]>([1,2,3,4,5])

return (
    <div style={{position: 'relative'}}>
        <button ref={nextSlideButtonRef} style={{position: 'absolute', top: 50, right: 0,}}>Next</button>
        <button ref={prevSlideButtonRef} style={{position: 'absolute', top: 50, left: 0,}}>prev</button>
        <Slider
          nextButtonRef={nextSlideButtonRef}
          prevButtonRef={prevSlideButtonRef}
          onSlide={(newKey: SetStateAction<Key | null>, newIndex: any) => setKey(newKey)}
        >
        {items.map(item => (
            <div key={item}>
                {item}
            </div>
        ))}
        </Slider>
        <div style={{display: 'flex'}}>
          {items.map((item, index) => (
              <h6 key={item} style={{color: item === key ? 'red' : 'black'}}>
                {index + 1}
              </h6>
          ))}
        </div>
    </div>
)
1.0.14

10 months ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago