Carousel.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Carousel } from 'antd'
  2. import { LeftCircleFilled, RightCircleFilled } from '@ant-design/icons'
  3. import defaultPhoto from '../../materials/default-photo.png'
  4. import backendURL from '../../helpers/backendUrl'
  5. import { videoRegex } from '../../helpers'
  6. const SampleNextArrow = (props) => {
  7. const { onClick } = props
  8. return (
  9. <div className="NextArrow" onClick={onClick}>
  10. <RightCircleFilled />
  11. </div>
  12. )
  13. }
  14. const SamplePrevArrow = (props) => {
  15. const { onClick } = props
  16. return (
  17. <div className="PreviousArrow" onClick={onClick}>
  18. <LeftCircleFilled />
  19. </div>
  20. )
  21. }
  22. export const MyCarousel = ({ images = [], carouselWidth, carouselHeight }) => {
  23. return (
  24. <>
  25. <div className="MyCarousel">
  26. <Carousel
  27. effect="fade"
  28. arrows
  29. nextArrow={<SampleNextArrow />}
  30. prevArrow={<SamplePrevArrow />}
  31. >
  32. {
  33. images ? (
  34. images?.map(
  35. (i, index) =>
  36. i?.url && (
  37. i?.originalFileName?.match(videoRegex) ?
  38. <div key={index}>
  39. <video
  40. className="PostImage"
  41. muted="muted" controls loop preload="true" >
  42. <source src={backendURL + '/' + i?.url}/>
  43. </video>
  44. </div>
  45. :
  46. <div key={index}>
  47. <img
  48. key={index}
  49. className="PostImage"
  50. src={backendURL + '/' + i?.url}
  51. />
  52. </div>
  53. ),
  54. )
  55. // :
  56. ) : (
  57. <div>
  58. <img className="PostImage" src={defaultPhoto} />
  59. </div>
  60. )}
  61. </Carousel>
  62. </div>
  63. </>
  64. )
  65. }