Skip to content

Commit

Permalink
refactor: [DHIS2-17652] Replace Material-UI Avatar (#3719)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv authored Aug 11, 2024
1 parent 00b9aa4 commit e6f2a15
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import i18n from '@dhis2/d2-i18n';
import React from 'react';
import moment from 'moment';
import type { ComponentType } from 'react';
import { Avatar, Grid, withStyles } from '@material-ui/core';
import { Grid, withStyles } from '@material-ui/core';
import { colors, Tag, IconCheckmark16, Tooltip } from '@dhis2/ui';
import { useTimeZoneConversion } from '@dhis2/app-runtime';
import { CardImage } from '../../../capture-ui/CardImage/CardImage.component';
import type {
CardDataElementsInformation,
CardProfileImageElementInformation,
Expand Down Expand Up @@ -63,8 +64,8 @@ const getStyles = (theme: Theme) => ({
flexGrow: 1,
},
image: {
width: theme.typography.pxToRem(44),
height: theme.typography.pxToRem(44),
width: theme.typography.pxToRem(54),
height: theme.typography.pxToRem(54),
marginRight: theme.typography.pxToRem(8),
},
buttonMargin: {
Expand Down Expand Up @@ -151,7 +152,8 @@ const CardListItemIndex = ({
const imageValue = item.values[imageElement.id];
return (
<div>
{imageValue && <Avatar src={imageValue.url} alt={imageValue.name} className={classes.image} />}
{imageValue && <CardImage imageUrl={imageValue.url} className={classes.image} size="medium" />}

</div>
);
};
Expand Down
56 changes: 56 additions & 0 deletions src/core_modules/capture-ui/CardImage/CardImage.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @flow
import React from 'react';
import { withStyles } from '@material-ui/core/styles';

const sizes = {
extrasmall: {
height: 24,
width: 24,
},
small: {
height: 36,
width: 36,
},
medium: {
height: 48,
width: 48,
},
large: {
height: 72,
width: 72,
},
extralarge: {
height: 144,
width: 144,
},
};

const styles = {
img: {
borderRadius: '50%',
objectFit: 'cover',
},
...sizes,
};

type Props = {
imageUrl: string,
dataTest: string,
classes: Object,
className: Object,
size: 'extrasmall' | 'small' | 'medium' | 'large' | 'extralarge',
};

const CardImagePlain = ({ imageUrl, dataTest, classes, className, size }: Props) => (
<div className={className}>
<img
src={imageUrl}
alt="user avatar"
data-test={dataTest}
className={`${classes.img} ${classes[size]} className`}
/>
</div>
);


export const CardImage = withStyles(styles)(CardImagePlain);

0 comments on commit e6f2a15

Please sign in to comment.