我正在尝试创建一个MUI时间轴组件,该组件的左侧具有粘性滚动条,其尺寸与右侧的Paper
内容相同。时间轴图标应位于页面中间。我还希望粘性滚动器最初与顶部时间轴项目处于同一水平。我该如何实现?
我对样式不是很好,这是一个相当复杂的问题,非常感谢任何可以帮助我的人。
这是一个CodeSandbox:https://codesandbox.io/s/vibrant-fog-vleuf?file=/demo.tsx
这是我当前的代码:
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Timeline from "@material-ui/lab/Timeline";
import TimelineItem from "@material-ui/lab/TimelineItem";
import TimelineSeparator from "@material-ui/lab/TimelineSeparator";
import TimelineConnector from "@material-ui/lab/TimelineConnector";
import TimelineContent from "@material-ui/lab/TimelineContent";
import TimelineDot from "@material-ui/lab/TimelineDot";
import FastfoodIcon from "@material-ui/icons/Fastfood";
import LaptopMacIcon from "@material-ui/icons/LaptopMac";
import HotelIcon from "@material-ui/icons/Hotel";
import RepeatIcon from "@material-ui/icons/Repeat";
import Paper from "@material-ui/core/Paper";
import Typography from "@material-ui/core/Typography";
const useStyles = makeStyles((theme) => ({
paper: {
padding: "6px 16px"
},
sticky: {
padding: "6px 16px",
position: "sticky",
top: 0,
zIndex: 1
},
secondaryTail: {
backgroundColor: theme.palette.secondary.main
}
}));
export default function CustomizedTimeline() {
const classes = useStyles();
return (
<React.Fragment>
<Paper elevation={3} className={classes.sticky}>
<Typography variant="h6" component="h1">
Sticky scroller
</Typography>
<Typography>
Should be same size as timeline contents and initially level with
them.
</Typography>
</Paper>
<Timeline>
<TimelineItem>
<TimelineSeparator>
<TimelineDot>
<FastfoodIcon />
</TimelineDot>
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Eat
</Typography>
<Typography>Because you need strength</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot color="primary">
<LaptopMacIcon />
</TimelineDot>
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Code
</Typography>
<Typography>Because it's awesome!</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot color="primary" variant="outlined">
<HotelIcon />
</TimelineDot>
<TimelineConnector className={classes.secondaryTail} />
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Sleep
</Typography>
<Typography>Because you need rest</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot color="secondary">
<RepeatIcon />
</TimelineDot>
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Repeat
</Typography>
<Typography>Because this is the life you love!</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot>
<FastfoodIcon />
</TimelineDot>
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Eat
</Typography>
<Typography>Because you need strength</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot color="primary">
<LaptopMacIcon />
</TimelineDot>
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Code
</Typography>
<Typography>Because it's awesome!</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot color="primary" variant="outlined">
<HotelIcon />
</TimelineDot>
<TimelineConnector className={classes.secondaryTail} />
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Sleep
</Typography>
<Typography>Because you need rest</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot color="secondary">
<RepeatIcon />
</TimelineDot>
</TimelineSeparator>
<TimelineContent>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h6" component="h1">
Repeat
</Typography>
<Typography>Because this is the life you love!</Typography>
</Paper>
</TimelineContent>
</TimelineItem>
</Timeline>
</React.Fragment>
);
}
在不引起误导的情况下,这可能相关,也可能不相关:Material-UI: Remove TimelineItem missingOppositeContent:before element (这是我尝试自己解决所有问题时问的一个问题)