Skip to content

Commit c6119f0

Browse files
enhance plaincard to accept react icons instead of img paths
Signed-off-by: Rajesh-Nagarajan-11 <rajeshnagarajan36@gmail.com>
1 parent 760bede commit c6119f0

1 file changed

Lines changed: 54 additions & 46 deletions

File tree

src/custom/DashboardWidgets/PlainCard.tsx

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,34 @@ const StyledResourceList = styled('ul')({
2323
paddingLeft: '1rem'
2424
});
2525

26-
const ResourceListItem = styled('li')({
26+
const ResourceListItem = styled('li')(({ theme }) => ({
2727
listStyleType: 'none',
2828
display: 'flex',
2929
flexDirection: 'row',
30-
alignItems: 'center'
31-
});
32-
33-
const StyledResourceIcon = styled('img')({
34-
width: '12px',
35-
height: '12px',
36-
marginRight: '.25rem'
37-
});
30+
alignItems: 'center',
31+
gap: '0.25rem',
32+
33+
'&:hover': {
34+
color: theme.palette.primary.main
35+
}
36+
}));
3837

3938
const StyledResourceLink = styled(Link)({
4039
fontSize: '1rem',
4140
fontWeight: '400',
4241
marginRight: '0.25rem',
43-
textDecoration: 'none'
42+
textDecoration: 'none',
43+
color: 'inherit',
44+
45+
'&:hover': {
46+
textDecoration: 'none'
47+
}
4448
});
4549

4650
interface Resource {
4751
name: string;
4852
link: string;
49-
icon?: string;
53+
icon?: React.ReactNode;
5054
external?: boolean;
5155
}
5256

@@ -58,41 +62,45 @@ interface PlainCardProps {
5862

5963
export const PlainCard = ({ title, icon, resources }: PlainCardProps): JSX.Element => {
6064
return (
61-
<>
62-
<StyledCard>
63-
<CardContent>
64-
<StyledTitleBox>
65-
{icon}
66-
<Typography variant="h6" fontWeight="700">
67-
{title}
68-
</Typography>
69-
</StyledTitleBox>
70-
<StyledContentBox>
71-
<StyledResourceList>
72-
{resources.map((item) => (
73-
<ResourceListItem key={item.link}>
74-
{item.icon && (
75-
<StyledResourceIcon src={item.icon} alt={`Icon for ${item.name}`} />
76-
)}
77-
<StyledResourceLink
78-
href={item.link}
79-
target={item.external ? '_blank' : '_self'}
80-
rel={item.external ? 'noopener noreferrer' : ''}
81-
>
82-
{item.name}
83-
</StyledResourceLink>
65+
<StyledCard>
66+
<CardContent>
67+
<StyledTitleBox>
68+
{icon}
69+
<Typography variant="h6" fontWeight="700">
70+
{title}
71+
</Typography>
72+
</StyledTitleBox>
73+
74+
<StyledContentBox>
75+
<StyledResourceList>
76+
{resources.map((item) => (
77+
<ResourceListItem key={item.link}>
78+
<Box sx={{ flexShrink: 0, display: 'flex', alignItems: 'center' }}>
79+
{item.icon}
80+
</Box>
81+
82+
<StyledResourceLink
83+
href={item.link}
84+
target={item.external ? '_blank' : '_self'}
85+
rel={item.external ? 'noopener noreferrer' : ''}
86+
>
87+
{item.name}
88+
</StyledResourceLink>
8489

85-
{item.external && (
86-
<sup>
87-
<OpenInNewIcon width="12px" height="12px" fill={'white'} />
88-
</sup>
89-
)}
90-
</ResourceListItem>
91-
))}
92-
</StyledResourceList>
93-
</StyledContentBox>
94-
</CardContent>
95-
</StyledCard>
96-
</>
90+
{item.external && (
91+
<sup>
92+
<OpenInNewIcon
93+
width="12px"
94+
height="12px"
95+
fill="currentColor"
96+
/>
97+
</sup>
98+
)}
99+
</ResourceListItem>
100+
))}
101+
</StyledResourceList>
102+
</StyledContentBox>
103+
</CardContent>
104+
</StyledCard>
97105
);
98106
};

0 commit comments

Comments
 (0)