import { CheckBoxOutlineBlankRounded } from '@mui/icons-material' import clsx from 'clsx' import { ComponentType, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { LoadingData } from '@dao-dao/types' import { DaoCardLoader } from './dao/DaoCard' import { NoContent } from './NoContent' export interface HorizontalScrollerProps

{ Component: ComponentType

items: LoadingData itemClassName?: string containerClassName?: string shadowClassName?: string contentContainerClassName?: string } export const HorizontalScroller =

({ Component, items, itemClassName, containerClassName, shadowClassName, contentContainerClassName, }: HorizontalScrollerProps

) => { const { t } = useTranslation() const scrollableContainerRef = useRef(null) // Detect vertical scrolling from a mouse and scroll horizontally if the mouse // is hovering over them. This is to add support for scrolling on a desktop // with only a single scrollable direction. Horizontal scrolling can be used // natively by holding shift, but most people don't know that. const [horizontalScrollActive, setHorizontalScrollActive] = useState(false) useEffect(() => { if (!horizontalScrollActive || !scrollableContainerRef.current) { return } const container = scrollableContainerRef.current const onWheel = (event: WheelEvent) => { // Subtract Y delta so that this scrolls horizontally to the right when // scrolling down and to the left when scrolling up. container.scrollLeft += event.deltaX - event.deltaY event.preventDefault() } container.addEventListener('wheel', onWheel) return () => container.removeEventListener('wheel', onWheel) }, [horizontalScrollActive]) return (

setHorizontalScrollActive(false)} onMouseOver={() => setHorizontalScrollActive(true)} > {/* Left shadow */} {!items.loading && items.data.length > 0 && (
)} {items.loading || items.data.length > 0 ? (
{items.loading ? [...Array(5)].map((_, index) => (
)) : items.data.map((item, index) => (
))}
) : ( )} {/* Right shadow */} {!items.loading && items.data.length > 0 && (
)}
) }