mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
refactor(ui): one Segmented control instead of four
The timeline's Segmented, the document sources' SegmentedChoice, the medication detail's SegmentedToggle and the icon-only ViewToggle were four implementations of the same control in two looks, two at 36 px on a phone. ui/segmented.tsx replaces all four, plus the hand-rolled range rows above the lab and custom metric charts, the mood dimension window and the inventory quantity mode: a muted track with the chosen segment raised, radio semantics with roving focus by default, pressed-button semantics for view switches and form sheets, icon-only segments, and 44 px per segment on a coarse pointer. A test holds the definition to that one module.
This commit is contained in:
1 parent
c849619bee
commit
ab3f21c58c
26 files changed
+428
-139
No files matched your search
@@ -20,7 +20,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Gauge } from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { nextChoiceIndex } from "@/components/documents/sources/segmented-choice";
|
||||
import { rovingRadioNextIndex } from "@/hooks/use-roving-radio-group";
|
||||
import { SettingsCard } from "@/components/settings/settings-card";
|
||||
import { SettingsCardActions } from "@/components/settings/_card-actions";
|
||||
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
||||
@@ -94,7 +94,7 @@ export function AiUsageCard() {
|
||||
level: AiUsageLevel,
|
||||
) {
|
||||
const from = allowedLevels.indexOf(level);
|
||||
const next = nextChoiceIndex(event.key, from, allowedLevels.length);
|
||||
const next = rovingRadioNextIndex(event.key, from, allowedLevels.length);
|
||||
if (next === null) return;
|
||||
event.preventDefault();
|
||||
const target = allowedLevels[next]!;
|
||||
|
||||
@@ -14,7 +14,7 @@ import { LayoutGrid, Rows3, WrapText } from "lucide-react";
|
||||
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
||||
import { SettingsCard } from "@/components/settings/settings-card";
|
||||
import { ModuleViewToggle } from "@/components/module-list/module-view-toggle";
|
||||
import { ViewToggle } from "@/components/ui/view-toggle";
|
||||
import { Segmented } from "@/components/ui/segmented";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useDocumentsLayout } from "@/lib/queries/use-documents-layout";
|
||||
|
||||
@@ -39,12 +39,14 @@ export function DocumentsSection() {
|
||||
title={t("documents.layout.arrangementHeading")}
|
||||
description={t("documents.layout.arrangementDescription")}
|
||||
status={
|
||||
<ViewToggle
|
||||
view={layout.arrangement}
|
||||
<Segmented
|
||||
mode="toggle"
|
||||
iconOnly
|
||||
value={layout.arrangement}
|
||||
onChange={setArrangement}
|
||||
groupLabel={t("documents.layout.arrangementHeading")}
|
||||
dataSlotPrefix="documents-arrangement"
|
||||
segments={[
|
||||
label={t("documents.layout.arrangementHeading")}
|
||||
optionSlot={(value) => `documents-arrangement-${value}`}
|
||||
options={[
|
||||
{
|
||||
value: "stacked",
|
||||
label: t("documents.layout.stacked"),
|
||||
|
||||
@@ -39,7 +39,7 @@ import { SettingsCardActions } from "@/components/settings/_card-actions";
|
||||
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
||||
import { SettingsCard } from "@/components/settings/settings-card";
|
||||
import { WrittenOutcomeLine } from "@/components/outcome/written-outcome-line";
|
||||
import { SegmentedChoice } from "@/components/documents/sources/segmented-choice";
|
||||
import { Segmented } from "@/components/ui/segmented";
|
||||
import {
|
||||
errorCodeOf,
|
||||
sourceErrorMessage,
|
||||
@@ -104,23 +104,22 @@ export function DocumentSourcesCard() {
|
||||
</p>
|
||||
|
||||
{options.length > 1 ? (
|
||||
<SegmentedChoice
|
||||
options={options}
|
||||
<Segmented
|
||||
options={options.map((option) => ({
|
||||
value: option,
|
||||
label: systemName(option),
|
||||
trailing: connections.some((c) => c.system === option) ? (
|
||||
<Check
|
||||
className="size-3.5"
|
||||
aria-label={t("settings.documentSources.statusConnected")}
|
||||
/>
|
||||
) : null,
|
||||
}))}
|
||||
value={system}
|
||||
onChange={setPicked}
|
||||
label={t("settings.documentSources.systemLabel")}
|
||||
slot="document-sources-system"
|
||||
renderOption={(option) => (
|
||||
<>
|
||||
{systemName(option)}
|
||||
{connections.some((c) => c.system === option) ? (
|
||||
<Check
|
||||
className="size-3.5"
|
||||
aria-label={t("settings.documentSources.statusConnected")}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
className="self-start"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
|
||||
Reference in new issue
Block a user