summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/components/select-location
diff options
context:
space:
mode:
authorOskar <oskar@mullvad.net>2024-08-29 21:55:04 +0200
committerOskar <oskar@mullvad.net>2024-08-30 20:04:00 +0200
commit7a135fc03fe0179b2e7b905789855dce5085d789 (patch)
tree73a61c9c092bbb3f76b452fa8e4e71850eb8ea2e /gui/src/renderer/components/select-location
parent370857d96e5226c9fe86dcd1a5476c17df16a71d (diff)
downloadmullvadvpn-7a135fc03fe0179b2e7b905789855dce5085d789.tar.xz
mullvadvpn-7a135fc03fe0179b2e7b905789855dce5085d789.zip
Add reusable cell side button component
Diffstat (limited to 'gui/src/renderer/components/select-location')
-rw-r--r--gui/src/renderer/components/select-location/CustomLists.tsx3
-rw-r--r--gui/src/renderer/components/select-location/LocationRow.tsx3
-rw-r--r--gui/src/renderer/components/select-location/LocationRowStyles.tsx43
-rw-r--r--gui/src/renderer/components/select-location/SpecialLocationList.tsx8
4 files changed, 11 insertions, 46 deletions
diff --git a/gui/src/renderer/components/select-location/CustomLists.tsx b/gui/src/renderer/components/select-location/CustomLists.tsx
index f335f7ae87..1cbb692b1b 100644
--- a/gui/src/renderer/components/select-location/CustomLists.tsx
+++ b/gui/src/renderer/components/select-location/CustomLists.tsx
@@ -12,7 +12,6 @@ import * as Cell from '../cell';
import { measurements } from '../common-styles';
import { BackAction } from '../KeyboardNavigation';
import SimpleInput from '../SimpleInput';
-import { StyledLocationRowIcon } from './LocationRowStyles';
import { useRelayListContext } from './RelayListContext';
import RelayLocationList from './RelayLocationList';
import { useScrollPositionContext } from './ScrollPositionContext';
@@ -42,7 +41,7 @@ const StyledHeaderLabel = styled(Cell.Label)({
lineHeight: measurements.rowMinHeight,
});
-const StyledCellButton = styled(StyledLocationRowIcon)({
+const StyledCellButton = styled(Cell.SideButton)({
border: 'none',
});
diff --git a/gui/src/renderer/components/select-location/LocationRow.tsx b/gui/src/renderer/components/select-location/LocationRow.tsx
index f76b5d3f61..41f3aa7152 100644
--- a/gui/src/renderer/components/select-location/LocationRow.tsx
+++ b/gui/src/renderer/components/select-location/LocationRow.tsx
@@ -22,7 +22,6 @@ import {
StyledHoverIconButton,
StyledLocationRowButton,
StyledLocationRowContainer,
- StyledLocationRowIcon,
StyledLocationRowLabel,
} from './LocationRowStyles';
import {
@@ -183,7 +182,7 @@ function LocationRow<C extends LocationSpecification>(props: IProps<C>) {
{hasChildren ||
('customList' in props.source.location && !('country' in props.source.location)) ? (
- <StyledLocationRowIcon
+ <Cell.SideButton
as={ChevronButton}
onClick={toggleCollapse}
disabled={!hasChildren}
diff --git a/gui/src/renderer/components/select-location/LocationRowStyles.tsx b/gui/src/renderer/components/select-location/LocationRowStyles.tsx
index 6a159f4054..58e9ba9606 100644
--- a/gui/src/renderer/components/select-location/LocationRowStyles.tsx
+++ b/gui/src/renderer/components/select-location/LocationRowStyles.tsx
@@ -3,24 +3,11 @@ import { Styles } from 'styled-components/dist/types';
import { colors } from '../../../config.json';
import * as Cell from '../cell';
+import { buttonColor, ButtonColors } from '../cell/styles';
import { measurements, normalText } from '../common-styles';
import ImageView from '../ImageView';
import InfoButton from '../InfoButton';
-interface ButtonColorProps {
- $backgroundColor: string;
- $backgroundColorHover: string;
-}
-
-export const buttonColor = (props: ButtonColorProps) => {
- return {
- backgroundColor: props.$backgroundColor,
- '&&:not(:disabled):hover': {
- backgroundColor: props.$backgroundColorHover,
- },
- };
-};
-
export const StyledLocationRowContainer = styled(Cell.Container)({
display: 'flex',
padding: 0,
@@ -41,7 +28,7 @@ export const StyledLocationRowLabel = styled(Cell.Label)(normalText, {
whiteSpace: 'nowrap',
});
-export const StyledLocationRowButton = styled(Cell.Row)<ButtonColorProps & { $level: number }>(
+export const StyledLocationRowButton = styled(Cell.Row)<ButtonColors & { $level: number }>(
buttonColor,
(props) => {
const paddingLeft = (props.$level + 1) * 16 + 2;
@@ -57,32 +44,12 @@ export const StyledLocationRowButton = styled(Cell.Row)<ButtonColorProps & { $le
},
);
-export const StyledLocationRowIcon = styled.button<ButtonColorProps>(buttonColor, {
- position: 'relative',
- alignSelf: 'stretch',
- paddingLeft: measurements.viewMargin,
- paddingRight: measurements.viewMargin,
- border: 0,
-
- '&&::before': {
- content: '""',
- position: 'absolute',
- margin: 'auto',
- top: 0,
- left: 0,
- bottom: 0,
- height: '50%',
- width: '1px',
- backgroundColor: colors.darkBlue,
- },
-});
-
interface HoverButtonProps {
$isLast?: boolean;
}
const hoverButton = (
- props: ButtonColorProps & HoverButtonProps,
+ props: ButtonColors & HoverButtonProps,
): Styles<
React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
> => ({
@@ -110,7 +77,7 @@ const hoverButton = (
},
});
-export const StyledHoverIconButton = styled.button<ButtonColorProps & HoverButtonProps>(
+export const StyledHoverIconButton = styled.button<ButtonColors & HoverButtonProps>(
buttonColor,
hoverButton,
);
@@ -126,7 +93,7 @@ export const StyledHoverIcon = styled(ImageView).attrs({
},
});
-export const StyledHoverInfoButton = styled(InfoButton)<ButtonColorProps & HoverButtonProps>(
+export const StyledHoverInfoButton = styled(InfoButton)<ButtonColors & HoverButtonProps>(
buttonColor,
hoverButton,
);
diff --git a/gui/src/renderer/components/select-location/SpecialLocationList.tsx b/gui/src/renderer/components/select-location/SpecialLocationList.tsx
index a347638b0e..f4ccf13ec2 100644
--- a/gui/src/renderer/components/select-location/SpecialLocationList.tsx
+++ b/gui/src/renderer/components/select-location/SpecialLocationList.tsx
@@ -6,6 +6,7 @@ import { messages } from '../../../shared/gettext';
import { useHistory } from '../../lib/history';
import { RoutePath } from '../../lib/routes';
import { useSelector } from '../../redux/store';
+import * as Cell from '../cell';
import ImageView from '../ImageView';
import InfoButton from '../InfoButton';
import { SpecialLocationIndicator } from '../RelayStatusIndicator';
@@ -14,7 +15,6 @@ import {
StyledHoverInfoButton,
StyledLocationRowButton,
StyledLocationRowContainerWithMargin,
- StyledLocationRowIcon,
StyledLocationRowLabel,
} from './LocationRowStyles';
import { SpecialBridgeLocationType, SpecialLocation } from './select-location-types';
@@ -74,7 +74,7 @@ export function AutomaticLocationRow(
<SpecialLocationIndicator />
<StyledLocationRowLabel>{props.source.label}</StyledLocationRowLabel>
</StyledLocationRowButton>
- <StyledLocationRowIcon
+ <Cell.SideButton
as={StyledSpecialLocationInfoButton}
title={messages.gettext('Automatic')}
message={messages.pgettext(
@@ -136,7 +136,7 @@ export function CustomBridgeLocationRow(
'A custom bridge server can be used to circumvent censorship when regular Mullvad bridge servers don’t work.',
)}
/>
- <StyledLocationRowIcon
+ <Cell.SideButton
{...background}
aria-label={
bridgeConfigured
@@ -150,7 +150,7 @@ export function CustomBridgeLocationRow(
tintColor={colors.white}
tintHoverColor={colors.white80}
/>
- </StyledLocationRowIcon>
+ </Cell.SideButton>
</StyledLocationRowContainerWithMargin>
);
}