|
| 1 | +import { Box, List, ListItem, Typography } from '@mui/joy'; |
| 2 | +import * as React from 'react'; |
| 3 | +import { Changelog, ChangeType } from '../../../changelog.types.ts'; |
| 4 | +import { useMemo } from 'react'; |
| 5 | +import { |
| 6 | + ChangelogWithComponents, |
| 7 | + groupChangelogsByComponents, |
| 8 | + reorderChangelogs, |
| 9 | +} from '../../changelog.util.ts'; |
| 10 | + |
| 11 | +interface Props { |
| 12 | + changelogs: Changelog[]; |
| 13 | + changeTypeMapper: Record<ChangeType, string>; |
| 14 | + typeColorResolver: (type: ChangeType) => string; |
| 15 | +} |
| 16 | + |
| 17 | +const ComponentList: React.FC<Props> = ({ |
| 18 | + changelogs, |
| 19 | + changeTypeMapper, |
| 20 | + typeColorResolver, |
| 21 | +}) => { |
| 22 | + const componentChangelogs: ChangelogWithComponents[] = useMemo(() => { |
| 23 | + const reorderedChangelogs = reorderChangelogs(changelogs); |
| 24 | + return groupChangelogsByComponents(reorderedChangelogs); |
| 25 | + }, [changelogs]); |
| 26 | + |
| 27 | + return ( |
| 28 | + <div> |
| 29 | + {componentChangelogs.map((changelog, index) => ( |
| 30 | + <div key={`changelog-${index}`}> |
| 31 | + <Box sx={() => ({ marginBottom: '8px' })}> |
| 32 | + <Typography level="h3" sx={() => ({ marginRight: '8px' })}> |
| 33 | + Version {changelog.version} |
| 34 | + </Typography> |
| 35 | + {changelog.description && ( |
| 36 | + <Typography>{changelog.description}</Typography> |
| 37 | + )} |
| 38 | + </Box> |
| 39 | + {changelog.entries.map((entry) => ( |
| 40 | + <> |
| 41 | + <Typography level="title-lg">{entry.component}</Typography> |
| 42 | + <List |
| 43 | + marker={'circle'} |
| 44 | + sx={() => ({ '--ListItem-minHeight': 20 })} |
| 45 | + > |
| 46 | + {entry.changelogs.map((entry, entryIndex) => ( |
| 47 | + <ListItem |
| 48 | + sx={() => ({ |
| 49 | + padding: '0px', |
| 50 | + })} |
| 51 | + key={`changelog-${index}-entry-${entryIndex}`} |
| 52 | + > |
| 53 | + <Box sx={() => ({ display: 'flex', flexDirection: 'row' })}> |
| 54 | + <Typography |
| 55 | + level="title-sm" |
| 56 | + sx={() => ({ |
| 57 | + marginRight: '8px', |
| 58 | + color: typeColorResolver(entry.changeType), |
| 59 | + })} |
| 60 | + > |
| 61 | + {changeTypeMapper[entry.changeType]} |
| 62 | + </Typography> |
| 63 | + <Typography level="body-sm"> |
| 64 | + {entry.description} |
| 65 | + </Typography> |
| 66 | + </Box> |
| 67 | + </ListItem> |
| 68 | + ))} |
| 69 | + </List> |
| 70 | + </> |
| 71 | + ))} |
| 72 | + </div> |
| 73 | + ))} |
| 74 | + </div> |
| 75 | + ); |
| 76 | +}; |
| 77 | + |
| 78 | +export default ComponentList; |
0 commit comments