Skip to content

Commit

Permalink
Move components outside of ContactRow
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed May 14, 2024
1 parent e7bb12e commit 44f7283
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/components/Contacts/ContactRow/ContactRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Typography,
} from '@mui/material';
import { styled } from '@mui/material/styles';
import clsx from 'clsx';
import {
ContactsContext,
ContactsType,
Expand All @@ -22,6 +23,29 @@ import { preloadContactsRightPanel } from '../ContactsRightPanel/DynamicContacts
import { StarContactIconButton } from '../StarContactIconButton/StarContactIconButton';
import { ContactRowFragment } from './ContactRow.generated';

const ListItemButton = styled(ButtonBase)(({ theme }) => ({
flex: '1 1 auto',
textAlign: 'left',
padding: theme.spacing(0, 0.5, 0, 2),
[theme.breakpoints.up('sm')]: {
padding: theme.spacing(0, 0.5),
},
'&.top-margin': {
marginTop: 16,
},
'&.checked': {
backgroundColor: theme.palette.cruGrayLight.main,
},
}));

const StyledCheckbox = styled(Checkbox, {
shouldForwardProp: (prop) => prop !== 'value',
})(() => ({
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, 0.04)',
},
}));

interface Props {
contact: ContactRowFragment;
useTopMargin?: boolean;
Expand All @@ -36,27 +60,6 @@ export const ContactRow: React.FC<Props> = ({ contact, useTopMargin }) => {
toggleSelectionById: onContactCheckToggle,
} = React.useContext(ContactsContext) as ContactsType;

const ListItemButton = styled(ButtonBase)(({ theme }) => ({
flex: '1 1 auto',
textAlign: 'left',
marginTop: useTopMargin ? '16px' : '0',
padding: theme.spacing(0, 0.5, 0, 2),
[theme.breakpoints.up('sm')]: {
padding: theme.spacing(0, 0.5),
},
...(isChecked(contactId)
? { backgroundColor: theme.palette.cruGrayLight.main }
: {}),
}));

const StyledCheckbox = styled(Checkbox, {
shouldForwardProp: (prop) => prop !== 'value',
})(() => ({
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, 0.04)',
},
}));

const onClick = () => {
onContactSelected(contact.id);
};
Expand All @@ -80,6 +83,10 @@ export const ContactRow: React.FC<Props> = ({ contact, useTopMargin }) => {
focusRipple
onClick={onClick}
onMouseEnter={preloadContactsRightPanel}
className={clsx({
'top-margin': useTopMargin,
checked: isChecked(contactId),
})}
data-testid="rowButton"
>
<Hidden xsDown>
Expand Down

0 comments on commit 44f7283

Please sign in to comment.