react-alice-carousel icon indicating copy to clipboard operation
react-alice-carousel copied to clipboard

Different padding values for different screen resolutions

Open thomasbritton opened this issue 8 months ago • 1 comments

Hi,

Is there a way how I could change the paddingLeft and paddingRight values for different screen resolutions?

thomasbritton avatar Mar 08 '25 01:03 thomasbritton

I have achieved it using the following but it would be good to know if there is a better approach

const [padding, setPadding] = useState({ paddingLeft: 0, paddingRight: 0 })

useEffect(() => {
    const handleResize = () => {
      if (window.matchMedia('(min-width: 768px)').matches) {
        setPadding({ paddingLeft: 0, paddingRight: 0 })
      } else {
        setPadding({ paddingLeft: 30, paddingRight: 30 })
      }
    }

    handleResize()

    const tabletDevice = window.matchMedia('(min-width: 768px)')

    tabletDevice.addEventListener('change', handleResize)

    return () => {
      tabletDevice.removeEventListener('change', handleResize)
    }
  }, [])

<AliceCarousel
  mouseTrackingEnabled
  responsive={responsive}
  infinite
  className="flex gap-[10px]"
  paddingLeft={padding.paddingLeft}
  paddingRight={padding.paddingRight}
>
    ...
</AliceCarousel>

thomasbritton avatar Mar 09 '25 22:03 thomasbritton