我正在try 制作一个可重用的InfoBlock组件.该组件呈现一个项目列表.每件物品都有标签、图标和价值.问题是我不知道如何将可用的INFO_BLOCK_ITEMS
映射到数据对象,并只呈现数据对象中存在的项.
所有可用标签和图标的完整列表如下所示:
const INFO_BLOCK_ITEMS = {
author: {
label: "Author",
icon: AccountTreeIcon
},
date: {
label: "Created",
icon: FaceRetouchingNaturalIcon
},
rawMedias: {
label: "RAW Medias",
icon: InsertDriveFileOutlinedIcon
},
face: {
label: "Faces",
icon: ScheduleOutlinedIcon,
faceAction: true,
},
s3Source: {
label: "S3 Source",
icon: AcUnitIcon
}
};
我传递给InfoBlock
组件的数据对象和数据类型(对于另一个页面,数据 struct 将不同,但它将包含INFO_BLOCK_ITEMS
中的键:
const DATASET = {
author: "extrauser@site.com",
date: 1669208819,
rawMedias: "Video name 1, Video name 2, Video name 3",
face: ""
};
<InfoBlock data={DATASET} type={"dataset"} />
对于数据对象中的每个键,结果应该是这样的列表:
<Stack>
<AccountTreeIcon />
<Stack>
<Typography>Author</Typography>
<Typography>extrauser@site.com</Typography>
</Stack>
</Stack>
这里有一个硬编码的Codesandbox:https://codesandbox.io/s/info-block-forked-0bwrze?file=/src/InfoBlock.tsx