From 14a1c9a53b75602efe515b729948fa6b8bc0038d Mon Sep 17 00:00:00 2001 From: boojack Date: Tue, 7 Jul 2026 09:24:48 +0800 Subject: [PATCH] chore(web): icon layout switcher with radio semantics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the layout Select with a lean 28px segmented control: Rows3 / Columns2 / Columns3 / Infinity icons on a quiet muted track, only the active option filled. Each option carries a tooltip with a label and an honest description of the ceiling semantics ("up to N columns when the width allows"). The control is a proper radiogroup — roving tabindex, arrow-key movement, aria-checked — restoring the single-choice semantics the Select used to provide. Options derive from ViewContext's canonical value list, and one exhaustive record maps each value to its icon and wording, so a future column option fails to compile until both exist. The Compact mode row now stays visible in multi-column layouts, shown as on and locked (multi-column always renders compact tiles); the stored preference is untouched and resurfaces at a single column. --- web/src/components/MemoDisplaySettingMenu.tsx | 97 ++++++++++++++----- web/src/locales/en.json | 8 +- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/web/src/components/MemoDisplaySettingMenu.tsx b/web/src/components/MemoDisplaySettingMenu.tsx index 7def673a..c1250ec0 100644 --- a/web/src/components/MemoDisplaySettingMenu.tsx +++ b/web/src/components/MemoDisplaySettingMenu.tsx @@ -1,6 +1,7 @@ -import { Settings2Icon } from "lucide-react"; +import { Columns2Icon, Columns3Icon, InfinityIcon, type LucideIcon, Rows3Icon, Settings2Icon } from "lucide-react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { MAX_COLUMNS_VALUES, type MemoMaxColumns, useView } from "@/contexts/ViewContext"; import { cn } from "@/lib/utils"; import { useTranslate } from "@/utils/i18n"; @@ -10,8 +11,15 @@ interface Props { className?: string; } -// Derived from the context's canonical value list so the two can never drift; 0 renders as ∞. -const MAX_COLUMNS_OPTIONS = MAX_COLUMNS_VALUES.map((value) => ({ value, label: value === 0 ? "∞" : String(value) })); +// Keyed by the context's canonical value list, so adding a column option forces an icon and +// wording here at compile time. The i18n param is deliberately named `n`, not `count` — +// i18next would route `count` through plural-form lookup. +const LAYOUT_OPTIONS: Record = { + 1: { icon: Rows3Icon, key: "layout-list" }, + 2: { icon: Columns2Icon, key: "layout-columns" }, + 3: { icon: Columns3Icon, key: "layout-columns" }, + 0: { icon: InfinityIcon, key: "layout-auto" }, +}; function MemoDisplaySettingMenu({ className }: Props) { const t = useTranslate(); @@ -28,6 +36,9 @@ function MemoDisplaySettingMenu({ className }: Props) { setMaxColumns, } = useView(); const isApplying = orderByTimeAsc !== false || timeBasis !== "create_time" || compactMode || !linkPreview || maxColumns !== 1; + // Multi-column grids always render compact tiles, so the toggle is shown as on and locked + // there; it only becomes a real choice at a single column. + const compactLocked = maxColumns !== 1; return ( @@ -37,20 +48,59 @@ function MemoDisplaySettingMenu({ className }: Props) {
- {t("memo.columns")} - {/* Radix only reports rendered item values, so no re-validation is needed here. */} - + {t("memo.layout")} + {/* A quiet muted track (28px tall, borderless); only the active option carries the accent + fill. A radiogroup with roving tabindex, since the options are mutually exclusive. */} +
{ + const delta = + event.key === "ArrowRight" || event.key === "ArrowDown" + ? 1 + : event.key === "ArrowLeft" || event.key === "ArrowUp" + ? -1 + : 0; + if (delta === 0) return; + event.preventDefault(); + const index = MAX_COLUMNS_VALUES.indexOf(maxColumns); + const next = MAX_COLUMNS_VALUES[(index + delta + MAX_COLUMNS_VALUES.length) % MAX_COLUMNS_VALUES.length]; + setMaxColumns(next); + event.currentTarget.querySelector(`[data-value="${next}"]`)?.focus(); + }} + > + {MAX_COLUMNS_VALUES.map((value) => { + const { icon: Icon, key } = LAYOUT_OPTIONS[value]; + const label = t(`memo.${key}`, { n: value }); + const active = maxColumns === value; + return ( + + + + + +

{label}

+

{t(`memo.${key}-description`, { n: value })}

+
+
+ ); + })} +
{t("memo.shown-time")} @@ -83,13 +133,12 @@ function MemoDisplaySettingMenu({ className }: Props) {
- {/* Multi-column grids always render compact tiles, so the toggle only applies to a single column. */} - {maxColumns === 1 && ( -
- {t("memo.compact-mode")} - -
- )} +
+ + {t("memo.compact-mode")} + + +
{t("memo.link-preview")} diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 31c1b1f2..4062993c 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -265,8 +265,14 @@ "has-task-list": "hasTaskList", "label": "Filters" }, - "columns": "Columns", "compact-mode": "Compact mode", + "layout": "Layout", + "layout-auto": "Auto", + "layout-auto-description": "As many columns as fit the screen", + "layout-columns": "{{n}} columns", + "layout-columns-description": "Up to {{n}} columns when the width allows", + "layout-list": "List", + "layout-list-description": "A single reading-width column", "link-preview": "Link preview", "links": "Links", "load-more": "Load more",