Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 66 67 68 69 70 71 72 73 74 75 | 7x 7x 7x 7x 7x 13x 7x 11x 13x 13x 13x | import { styled, useMediaQuery, useTheme } from "@mui/material"; import { Breakpoint } from "@mui/material/styles"; import React, { ReactNode } from "react"; import useOnVisibleEffect from "../utils/useOnVisibleEffect"; import CircularProgress from "./CircularProgress"; interface CustomWrapperProps { isBelowBreakpoint: boolean; } const StyledWrapper = styled("div")<CustomWrapperProps>( ({ theme, isBelowBreakpoint }) => ({ ...(isBelowBreakpoint && { alignItems: "stretch", display: "inline-flex", flexDirection: "row", height: "100%", width: "100vw", padding: theme.spacing(2), WebkitOverflowScrolling: "touch", overflowX: "scroll", scrollSnapType: "x mandatory", scrollPadding: theme.spacing(1.5), "& > *": { flexShrink: 0, }, }), }) ); const StyledLoaderContainer = styled("div")(({ theme }) => ({ display: "flex", alignItems: "center", })); interface HorizontalScrollerProps { //horizontal scroller will only apply at this breakpoint and below breakpoint?: Breakpoint; fetchNext?: () => void; isFetching?: boolean; hasMore?: boolean; className?: string; children?: ReactNode; } export default function HorizontalScroller({ breakpoint = "xs", fetchNext, isFetching, hasMore, className, children, }: HorizontalScrollerProps) { const { ref: loaderRef } = useOnVisibleEffect(fetchNext); const theme = useTheme(); const isBelowBreakpoint = useMediaQuery(theme.breakpoints.down(breakpoint)); return ( <StyledWrapper className={className} isBelowBreakpoint={isBelowBreakpoint}> {children} {fetchNext && hasMore && ( <StyledLoaderContainer> {isFetching ? ( <CircularProgress /> ) : ( <CircularProgress variant="determinate" value={0} ref={loaderRef} /> )} </StyledLoaderContainer> )} </StyledWrapper> ); } |