diff --git a/app/components/Switch.tsx b/app/components/Switch.tsx
index a1bac9ff45..d24b9c97b5 100644
--- a/app/components/Switch.tsx
+++ b/app/components/Switch.tsx
@@ -2,6 +2,7 @@ import * as RadixSwitch from "@radix-ui/react-switch";
import { darken } from "polished";
import * as React from "react";
import styled from "styled-components";
+import breakpoint from "styled-components-breakpoint";
import { s } from "@shared/styles";
import { LabelText } from "~/components/Input";
import Text from "~/components/Text";
@@ -67,7 +68,7 @@ function Switch({
className={label ? undefined : className}
{...props}
>
-
+
);
@@ -128,15 +129,16 @@ const Label = styled.label<{
const HOVER_EXTRA = 3;
-const StyledSwitchThumb = styled(RadixSwitch.Thumb)<{
- width: number;
- height: number;
-}>`
+/** Minimum switch size on mobile, so that small switches stay usable by touch. */
+const MOBILE_MIN_WIDTH = 32;
+const MOBILE_MIN_HEIGHT = 18;
+
+const StyledSwitchThumb = styled(RadixSwitch.Thumb)`
display: block;
- width: ${(props) => props.height - 8}px;
- height: ${(props) => props.height - 8}px;
+ width: calc(var(--switch-height) - 8px);
+ height: calc(var(--switch-height) - 8px);
background-color: white;
- border-radius: ${(props) => (props.height - 8) / 2}px;
+ border-radius: calc((var(--switch-height) - 8px) / 2);
transition:
transform 0.2s,
width 0.2s;
@@ -144,11 +146,11 @@ const StyledSwitchThumb = styled(RadixSwitch.Thumb)<{
will-change: transform, width;
&[data-state="checked"] {
- transform: translateX(${(props) => props.width - props.height}px);
+ transform: translateX(calc(var(--switch-width) - var(--switch-height)));
}
[dir="rtl"] &[data-state="checked"] {
- transform: translateX(${(props) => -(props.width - props.height)}px);
+ transform: translateX(calc(var(--switch-height) - var(--switch-width)));
}
`;
@@ -156,17 +158,25 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{
width: number;
height: number;
}>`
+ --switch-width: ${(props) => Math.max(props.width, MOBILE_MIN_WIDTH)}px;
+ --switch-height: ${(props) => Math.max(props.height, MOBILE_MIN_HEIGHT)}px;
+
position: relative;
- width: ${(props) => props.width}px;
- height: ${(props) => props.height}px;
+ width: var(--switch-width);
+ height: var(--switch-height);
background-color: ${(props) => props.theme.slate};
- border-radius: ${(props) => props.height}px;
+ border-radius: var(--switch-height);
border: none;
cursor: var(--pointer);
transition: background-color 0.2s;
padding: 0 4px;
flex-shrink: 0;
+ ${(props) => breakpoint("tablet")`
+ --switch-width: ${props.width}px;
+ --switch-height: ${props.height}px;
+ `}
+
&:focus {
box-shadow: 0 0 1px ${s("accent")};
outline: none;
@@ -190,12 +200,12 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{
}
&:hover:not(:disabled) ${StyledSwitchThumb} {
- width: ${(props) => props.height - 8 + HOVER_EXTRA}px;
+ width: calc(var(--switch-height) - 8px + ${HOVER_EXTRA}px);
}
&:hover:not(:disabled)[data-state="checked"] ${StyledSwitchThumb} {
transform: translateX(
- ${(props) => props.width - props.height - HOVER_EXTRA}px
+ calc(var(--switch-width) - var(--switch-height) - ${HOVER_EXTRA}px)
);
}
@@ -203,7 +213,7 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{
&:hover:not(:disabled)[data-state="checked"]
${StyledSwitchThumb} {
transform: translateX(
- ${(props) => -(props.width - props.height - HOVER_EXTRA)}px
+ calc(var(--switch-height) - var(--switch-width) + ${HOVER_EXTRA}px)
);
}
`;
diff --git a/app/components/primitives/Drawer.tsx b/app/components/primitives/Drawer.tsx
index f1eda8be44..073e23a92c 100644
--- a/app/components/primitives/Drawer.tsx
+++ b/app/components/primitives/Drawer.tsx
@@ -108,7 +108,9 @@ const StyledContent = styled(m.div)`
const StyledInnerContent = styled(Flex)`
padding: 6px;
- padding-bottom: calc(6px + var(--sab, 0px));
+
+ /* The safe area inset is zero unless the viewport uses viewport-fit=cover. */
+ padding-bottom: max(24px, calc(6px + var(--sab, 0px)));
height: 100%;
`;