Slider.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client';
  2. import { useEffect, useRef } from 'react';
  3. import Glide from '@glidejs/glide';
  4. import Icon from '@/components/Icon';
  5. const sliderConfiguration = {
  6. gap: 0,
  7. perView: 1,
  8. type: 'carousel',
  9. autoplay: 7000,
  10. animationDuration: 1000,
  11. };
  12. export default function Slider({
  13. slides = [],
  14. style = {},
  15. }: {
  16. slides: React.ReactNode[]
  17. style?: React.CSSProperties
  18. }) {
  19. const wrapper = useRef<HTMLDivElement>(null);
  20. useEffect(() => {
  21. const glide = new Glide(wrapper.current, sliderConfiguration).mount();
  22. return () => glide.destroy();
  23. }, []);
  24. return (
  25. <div ref={wrapper} className="glide" style={style}>
  26. <div className="glide__track" data-glide-el="track">
  27. <ul className="glide__slides">
  28. {slides.map((slide, i) => (
  29. <li className="glide__slide slider" key={i}>
  30. {slide}
  31. </li>
  32. ))}
  33. </ul>
  34. </div>
  35. <div className="glide__arrows" data-glide-el="controls">
  36. <button
  37. className="glide__arrow glide__arrow--prev"
  38. data-glide-dir="<"
  39. aria-label="Previous slide"
  40. >
  41. <Icon name="chevron-left" />
  42. </button>
  43. <button
  44. className="glide__arrow glide__arrow--next"
  45. data-glide-dir=">"
  46. aria-label="Next slide"
  47. >
  48. <Icon name="chevron-right" />
  49. </button>
  50. </div>
  51. </div>
  52. );
  53. }