Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [DHIS2-17652] Replace Material-UI Avatar #3719

Merged
merged 8 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading