adminslide.tsx 2.02 KB
Newer Older
백승민's avatar
백승민 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { useRef, useState } from "react";

type num = {
    slides: any[],
}

export function MySlide({ slides}: num) {

    const firstLeftClick = useRef(true);
    const firstRightClick = useRef(true);
    const [page, setPage] = useState(1);
    const [slide,setSlide] = useState(1);
    // const slide = useRef(1);
    const [style, setStyle] = useState("");

    const leftClick = () => {
        if (firstLeftClick.current) {
            firstLeftClick.current = false;
            firstRightClick.current = true;
        } else {
            setPage(page - 1)
        }
        // slide.current -= 1;
        setSlide(slide-1)
        setStyle("-translate-x-full animate-slidetoright");
    };

    const rightClick = () => {
        if (firstRightClick.current) {
            firstLeftClick.current = true;
            firstRightClick.current = false;
        } else {
            setPage(page + 1)
        }
        // slide.current += 1;
        setSlide(slide+1)
        setStyle("animate-slidetoleft");
    };

    return (
        <div className="flex flex-row justify-center items-center ">
            <button className="mx-3 w-6 h-6 rounded-full hover:bg-sky-100 hover:text-gray-400"onClick={leftClick} disabled={slide === 1}>
                &lt;
                {/* {slide.current} */}
            </button>
            <div
                className={`m-3 md:m-5 md:basis-4/5 flex flex-row relative w-full overflow-hidden`}
            >
                {slides.slice(page - 1, page + 2).map((slide) => (
                    <div key={Math.random()} className="min-w-full"
                    >
                        <div key={slide} className={`inline-grid grid-cols-5 ${style}`}>
                            {slide}
                        </div>
                    </div>
                ))}
            </div>
            <button className="mx-3 w-6 h-6 rounded-full hover:bg-sky-100 hover:text-gray-400"onClick={rightClick} disabled={slide === slides.length}>
                &gt;
            </button>
        </div>


    );
};