Skip to content

Commit

Permalink
[front] fix: ensure background color is set on hover for mobile butto…
Browse files Browse the repository at this point in the history
…ns (#2026)

* [front] fix: ensure background color is set on hover for mobile buttons

* use color from palette in CriterionButtons
  • Loading branch information
amatissart authored Nov 14, 2024
1 parent 46d0d2c commit 07973b3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
19 changes: 19 additions & 0 deletions frontend/src/components/buttons/MobileButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { Button, ButtonProps } from '@mui/material';

const MobileButton = (props: ButtonProps) => {
return (
<Button
{...props}
sx={{
...props.sx,
bgcolor: 'background.mobileButton',
'&:hover': {
bgcolor: 'background.mobileButton',
},
}}
/>
);
};

export default MobileButton;
19 changes: 19 additions & 0 deletions frontend/src/components/buttons/MobileIconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { IconButton, IconButtonProps } from '@mui/material';

const MobileIconButton = (props: IconButtonProps) => {
return (
<IconButton
{...props}
sx={{
...props.sx,
bgcolor: 'background.mobileButton',
'&:hover': {
bgcolor: 'background.mobileButton',
},
}}
/>
);
};

export default MobileIconButton;
2 changes: 2 additions & 0 deletions frontend/src/components/buttons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as MobileButton } from './MobileButton';
export { default as MobileIconButton } from './MobileIconButton';
13 changes: 6 additions & 7 deletions frontend/src/features/comparisons/inputs/CriteriaButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
import { useDrag } from '@use-gesture/react';
import { Vector2 } from '@use-gesture/core/types';

import { Box, Fade, IconButton, Slide } from '@mui/material';
import { Box, Fade, Slide } from '@mui/material';
import { ArrowDropDown, ArrowDropUp } from '@mui/icons-material';

import { useCurrentPoll } from 'src/hooks';
Expand All @@ -14,6 +14,7 @@ import { ComparisonRequest } from 'src/services/openapi';

import CriterionButtons, { BUTTON_SCORE_MAX } from './CriterionButtons';
import { useOrderedCriteria } from 'src/hooks/useOrderedCriteria';
import { MobileIconButton } from 'src/components/buttons';

const SWIPE_TIMEOUT = 180;
const SWIPE_VELOCITY: number | Vector2 = [0.25, 0.25];
Expand Down Expand Up @@ -215,15 +216,14 @@ const CriteriaButtons = ({
justifyContent="center"
visibility={navigationDisabled ? 'hidden' : 'visible'}
>
<IconButton
<MobileIconButton
color="secondary"
aria-label={t('comparisonCriteriaButtons.nextQualityCriterion')}
onClick={() => moveWithoutPatching('down')}
disabled={disableScoreButtons || navigationDisabled}
sx={{ bgcolor: 'background.mobileButton' }}
>
<ArrowDropUp />
</IconButton>
</MobileIconButton>
</Box>
<Slide
in={slideIn}
Expand Down Expand Up @@ -263,15 +263,14 @@ const CriteriaButtons = ({
justifyContent="center"
visibility={navigationDisabled ? 'hidden' : 'visible'}
>
<IconButton
<MobileIconButton
color="secondary"
aria-label={t('comparisonCriteriaButtons.previousQualityCriterion')}
onClick={() => moveWithoutPatching('up')}
disabled={disableScoreButtons || navigationDisabled}
sx={{ bgcolor: 'background.mobileButton' }}
>
<ArrowDropDown />
</IconButton>
</MobileIconButton>
</Box>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ScoreButton = ({
color: undefined,
backgroundColor: selected
? theme.palette.primary.main
: 'grey.200',
: theme.palette.background.mobileButton,
},
}}
>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/entity_selector/AutoEntityButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useCurrentPoll } from 'src/hooks/useCurrentPoll';
import { theme } from 'src/theme';
import { YOUTUBE_POLL_NAME } from 'src/utils/constants';
import { ComparisonsContext } from 'src/pages/comparisons/Comparison';
import { MobileButton } from 'src/components/buttons';

interface Props {
onClick: () => Promise<void>;
Expand Down Expand Up @@ -36,22 +37,21 @@ const AutoEntityButton = ({
return (
<>
{smallScreen && variant === 'compact' ? (
<Button
<MobileButton
className={context.hasLoopedThroughCriteria ? 'glowing' : undefined}
disabled={disabled}
color="secondary"
size="small"
onClick={onClick}
sx={{
fontSize: { xs: '0.7rem', sm: '0.8rem' },
bgcolor: 'background.mobileButton',
}}
data-testid={`auto-entity-button-${variant}`}
startIcon={compactLabelLoc === 'left' ? compactLabel : undefined}
endIcon={compactLabelLoc === 'right' ? compactLabel : undefined}
>
<SwipeUp />
</Button>
</MobileButton>
) : (
<Tooltip
title={`${t('entitySelector.newVideo')}`}
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/features/entity_selector/EntitySelectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useMediaQuery,
Theme,
Button,
IconButton,
} from '@mui/material';
import { Search } from '@mui/icons-material';

Expand All @@ -28,6 +27,7 @@ import SelectorPopper from './SelectorPopper';
import { useLoginState, usePreferredLanguages } from 'src/hooks';
import { ComparisonsContext } from 'src/pages/comparisons/Comparison';
import { EntityObject } from 'src/utils/types';
import { MobileIconButton } from 'src/components/buttons';

// in milliseconds
const TYPING_DELAY = 50;
Expand Down Expand Up @@ -193,19 +193,18 @@ const VideoInput = ({
}}
>
{smallScreen && variant === 'compact' ? (
<IconButton
<MobileIconButton
onClick={toggleSuggestions}
size="small"
color="secondary"
disabled={disabled}
sx={{
fontSize: { xs: '0.7rem', sm: '0.8rem' },
bgcolor: 'background.mobileButton',
}}
data-testid={`entity-select-button-${variant}`}
>
<Search />
</IconButton>
</MobileIconButton>
) : (
<Button
fullWidth={variant === 'full' ? true : false}
Expand Down

0 comments on commit 07973b3

Please sign in to comment.