【发布时间】:2021-10-14 04:41:50
【问题描述】:
我已尝试搜索堆栈溢出,但未找到与此尝试相关的特定问题。我正在使用样式化方式来设置 Material UI Stepper 组件的样式。我看到的所有示例都使用 withStyles、makeStyles,除了样式用于更改颜色之外的所有内容。但是,我也想在下面的步骤标签中有一个真正的图标,而不是文本。
每次我将图标组件添加到图标属性时,它只会显示图标并夹住通常包含文本的圆圈。我想保留圆圈并添加图标以及在顶部添加文本。活动/完成将是金色,灰色表示禁用/非活动。
这是我的编码尝试,我尝试了各种组合,将演示中的示例粘贴在 Material UI 网站上,但仍然没有太多运气让图标显示在圆圈内。我需要放弃 StepIcon 组件并将图标包装在 Avatar 组件中吗?
const TimelineIcon = styled(StepIcon)(({ theme }) => ({
root: {
color: theme.palette.primary.light,
display: "flex",
height: 22,
alignItems: "center",
"&$active": {
color: theme.palette.success.main,
},
"&$completed": {
backgroundColor: theme.palette.primary.light,
color: theme.palette.success.main,
zIndex: 1,
fontSize: 18,
},
},
}));
const stepIconComponent = () => {
return (
<div>
<TimelineIcon icon={<Check />} />
</div>
);
};
<Stepper
orientation={"horizontal"}
alternativeLabel
style={{ width: "100%" }}
>
{stepper.steps.map((step: TimelineStepProps) => {
return (
<Step key={step.title}>
<StepLabel StepIconComponent={stepIconComponent}>
{step.title}
</StepLabel>
</Step>
);
})}
</Stepper>
【问题讨论】:
标签: javascript reactjs material-ui react-functional-component uistepper