fix(web): improve mobile control spacing

pull/6028/head
boojack 1 month ago
parent 418398587c
commit 1052c04d33

@ -25,9 +25,9 @@ const AuthFooter = ({ className }: Props) => {
}; };
return ( return (
<div className={cn("mt-4 flex flex-row items-center justify-center w-full gap-2", className)}> <div className={cn("mx-auto mt-4 grid w-full max-w-xs grid-cols-2 gap-2", className)}>
<LocaleSelect value={currentLocale} onChange={handleLocaleChange} /> <LocaleSelect value={currentLocale} onChange={handleLocaleChange} className="w-full" />
<ThemeSelect value={currentTheme} onValueChange={handleThemeChange} /> <ThemeSelect value={currentTheme} onValueChange={handleThemeChange} className="w-full" compact />
</div> </div>
); );
}; };

@ -28,8 +28,13 @@ export const LocaleSearchList = (props: LocaleSearchListProps) => {
); );
return ( return (
<div className={cn("w-64 max-w-[calc(100vw-2rem)]", className)}> <div
<div className="relative p-1"> className={cn(
"flex max-h-[min(24rem,calc(100vh-2rem))] w-[var(--radix-popover-trigger-width)] min-w-48 max-w-[calc(100vw-2rem)] flex-col",
className,
)}
>
<div className="relative shrink-0 p-1">
<SearchIcon className="absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" /> <SearchIcon className="absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
<Input <Input
value={query} value={query}
@ -40,7 +45,7 @@ export const LocaleSearchList = (props: LocaleSearchListProps) => {
aria-label={t("common.language")} aria-label={t("common.language")}
/> />
</div> </div>
<div className="mt-1 max-h-72 overflow-y-auto p-1" role="listbox" aria-label={t("common.language")}> <div className="mt-1 min-h-0 flex-1 touch-pan-y overflow-y-auto p-1" role="listbox" aria-label={t("common.language")}>
{filteredLocales.map((locale) => ( {filteredLocales.map((locale) => (
<button <button
type="button" type="button"
@ -53,9 +58,11 @@ export const LocaleSearchList = (props: LocaleSearchListProps) => {
)} )}
onClick={() => onChange(locale)} onClick={() => onChange(locale)}
> >
{value === locale ? <CheckIcon className="size-4 text-primary" /> : <span className="size-4" />} <span className="flex min-w-0 flex-1 items-baseline gap-1.5">
<span className="min-w-0 flex-1 truncate">{getLocaleDisplayName(locale)}</span> <span className="truncate">{getLocaleDisplayName(locale)}</span>
<span className="shrink-0 text-xs text-muted-foreground">{locale}</span> <span className="shrink-0 text-xs text-muted-foreground">{locale}</span>
</span>
{value === locale ? <CheckIcon className="size-4 shrink-0 text-primary" /> : <span className="size-4 shrink-0" />}
</button> </button>
))} ))}
{filteredLocales.length === 0 && ( {filteredLocales.length === 0 && (
@ -94,11 +101,11 @@ const LocalePicker = (props: LocalePickerProps) => {
<Popover open={open} onOpenChange={setOpen}> <Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild> <PopoverTrigger asChild>
<Button type="button" variant="outline" className={cn("w-full justify-between", className)}> <Button type="button" variant="outline" className={cn("w-full justify-between", className)}>
<span className="flex min-w-0 items-center gap-2"> <span className="flex min-w-0 flex-1 items-center gap-2">
<GlobeIcon className="size-4 text-muted-foreground" /> <GlobeIcon className="size-4 shrink-0 text-muted-foreground" />
<span className="truncate">{getLocaleDisplayName(value)}</span> <span className="truncate">{getLocaleDisplayName(value)}</span>
</span> </span>
<ChevronDownIcon className="size-4 text-muted-foreground" /> <ChevronDownIcon className="size-4 shrink-0 text-muted-foreground" />
</Button> </Button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent align="start" className="p-0"> <PopoverContent align="start" className="p-0">

@ -5,10 +5,11 @@ import { loadLocale } from "@/utils/i18n";
interface Props { interface Props {
value: Locale; value: Locale;
onChange: (locale: Locale) => void; onChange: (locale: Locale) => void;
className?: string;
} }
const LocaleSelect: FC<Props> = (props: Props) => { const LocaleSelect: FC<Props> = (props: Props) => {
const { onChange, value } = props; const { className, onChange, value } = props;
const handleSelectChange = async (locale: Locale) => { const handleSelectChange = async (locale: Locale) => {
// Apply locale globally immediately // Apply locale globally immediately
@ -17,7 +18,7 @@ const LocaleSelect: FC<Props> = (props: Props) => {
onChange(locale); onChange(locale);
}; };
return <LocalePicker value={value} onChange={handleSelectChange} />; return <LocalePicker value={value} onChange={handleSelectChange} className={className} />;
}; };
export default LocaleSelect; export default LocaleSelect;

@ -7,6 +7,7 @@ interface ThemeSelectProps {
value?: string; value?: string;
onValueChange?: (theme: string) => void; onValueChange?: (theme: string) => void;
className?: string; className?: string;
compact?: boolean;
} }
const THEME_ICONS: Record<string, ReactElement> = { const THEME_ICONS: Record<string, ReactElement> = {
@ -16,8 +17,9 @@ const THEME_ICONS: Record<string, ReactElement> = {
paper: <Palette className="w-4 h-4" />, paper: <Palette className="w-4 h-4" />,
}; };
const ThemeSelect = ({ value, onValueChange, className }: ThemeSelectProps = {}) => { const ThemeSelect = ({ value, onValueChange, className, compact = false }: ThemeSelectProps = {}) => {
const currentTheme = value || "system"; const currentTheme = value || "system";
const triggerLabel = currentTheme === "system" ? "System" : THEME_OPTIONS.find((option) => option.value === currentTheme)?.label;
const handleThemeChange = (newTheme: string) => { const handleThemeChange = (newTheme: string) => {
// Apply theme globally immediately // Apply theme globally immediately
@ -31,8 +33,9 @@ const ThemeSelect = ({ value, onValueChange, className }: ThemeSelectProps = {})
return ( return (
<Select value={currentTheme} onValueChange={handleThemeChange}> <Select value={currentTheme} onValueChange={handleThemeChange}>
<SelectTrigger className={className}> <SelectTrigger className={className}>
<div className="flex items-center gap-2"> <div className="flex min-w-0 flex-1 items-center gap-2">
<SelectValue placeholder="Select theme" /> {compact && THEME_ICONS[currentTheme]}
{compact ? <span className="truncate">{triggerLabel}</span> : <SelectValue className="truncate" placeholder="Select theme" />}
</div> </div>
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>

@ -151,8 +151,8 @@ const UserMenu = (props: Props) => {
<GlobeIcon className="size-4 text-muted-foreground" /> <GlobeIcon className="size-4 text-muted-foreground" />
{t("common.language")} {t("common.language")}
</DropdownMenuSubTrigger> </DropdownMenuSubTrigger>
<DropdownMenuSubContent className="p-0"> <DropdownMenuSubContent className="max-h-[min(24rem,var(--radix-dropdown-menu-content-available-height))] overflow-y-auto p-0">
<LocaleSearchList value={currentLocale} onChange={handleLocaleChange} /> <LocaleSearchList value={currentLocale} onChange={handleLocaleChange} className="w-64" />
</DropdownMenuSubContent> </DropdownMenuSubContent>
</DropdownMenuSub> </DropdownMenuSub>
<DropdownMenuSub> <DropdownMenuSub>

@ -83,7 +83,7 @@ const SponsorLogo = ({ sponsor }: { sponsor: Sponsor }) => {
const About = () => { const About = () => {
return ( return (
<section className="mx-auto w-full max-w-5xl min-h-full flex flex-col justify-start items-start sm:pt-3 md:pt-6 pb-8"> <section className="mx-auto w-full max-w-5xl min-h-full flex flex-col justify-start items-start sm:pt-3 md:pt-6 pb-8">
<div className="w-full px-4 sm:px-6"> <div className="w-full">
<div className="w-full rounded-xl border border-border bg-background px-4 py-4 text-muted-foreground"> <div className="w-full rounded-xl border border-border bg-background px-4 py-4 text-muted-foreground">
<SettingSection <SettingSection
title="About Memos" title="About Memos"

@ -41,6 +41,15 @@ describe("<About>", () => {
} }
}); });
it("does not add nested horizontal page padding on mobile", () => {
const { container } = render(<About />);
const contentWrapper = container.querySelector("section > div");
expect(contentWrapper).toHaveClass("w-full");
expect(contentWrapper).not.toHaveClass("px-4");
});
it("uses dark sponsor logos when the app theme is dark", () => { it("uses dark sponsor logos when the app theme is dark", () => {
document.documentElement.setAttribute("data-theme", "default-dark"); document.documentElement.setAttribute("data-theme", "default-dark");

Loading…
Cancel
Save