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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | import * as React from "react";
import { useTheme } from "@mui/material/styles";
import Box from "@mui/material/Box";
import MobileStepper from "@mui/material/MobileStepper";
import Button from "@mui/material/Button";
import KeyboardArrowLeft from "@mui/icons-material/KeyboardArrowLeft";
import KeyboardArrowRight from "@mui/icons-material/KeyboardArrowRight";
import SwipeableViews from "react-swipeable-views";
import { EventTicket } from "@components/TicketSales";
import { toEnFormat } from "@utils/index";
type TicketsProps = {
variants: any[]
}
function MobileCarousels({ variants }: TicketsProps) {
const theme = useTheme();
const [activeStep, setActiveStep] = React.useState(0);
const maxSteps = variants?.length || 0;
const handleNext = () => {
setActiveStep((prevActiveStep) => prevActiveStep + 1);
};
const handleBack = () => {
setActiveStep((prevActiveStep) => prevActiveStep - 1);
};
const handleStepChange = (step: number) => {
setActiveStep(step);
};
return (
<Box sx={{ maxWidth: "90vw", marginTop: "6px" }}>
<SwipeableViews
axis={theme.direction === "rtl" ? "x-reverse" : "x"}
index={activeStep}
onChangeIndex={handleStepChange}
enableMouseEvents
>
{variants?.map((variant, index) => (
<div
key={index}
style={{ display: "flex", justifyContent: "center" }}
>
{Math.abs(activeStep - index) <= 2 ? (
<EventTicket
key={variant.id}
title={variant.name}
price={toEnFormat(variant.price / 100)}
sold={variant.numSold}
available={variant.inventory}
enabled={true}
/>
) : null}
</div>
))}
</SwipeableViews>
<MobileStepper
sx={{
background: "none",
}}
steps={maxSteps}
position="static"
activeStep={activeStep}
nextButton={
<Button
size="small"
onClick={handleNext}
disabled={activeStep === maxSteps - 1}
sx={{ visibility: "hidden" }}
>
Next
<KeyboardArrowRight />
</Button>
}
backButton={
<Button
size="small"
onClick={handleBack}
disabled={activeStep === 0}
sx={{ visibility: "hidden" }}
>
<KeyboardArrowLeft />
Back
</Button>
}
/>
</Box>
);
}
export default MobileCarousels;
|