Skip to content

Commit 930c473

Browse files
committed
feat(preferences): Add option to change input select menu alignment
1 parent 4efc817 commit 930c473

5 files changed

Lines changed: 131 additions & 49 deletions

File tree

src/app/routes/settings/settings-general.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { Fragment, useState } from "react"
22

33
import { t } from "@lingui/core/macro"
44
import { Trans } from "@lingui/react/macro"
5-
import { LayoutGrid, TableProperties } from "lucide-react"
5+
import {
6+
AlignVerticalJustifyCenter,
7+
AlignVerticalJustifyStart,
8+
LayoutGrid,
9+
TableProperties,
10+
} from "lucide-react"
611

712
import { Card } from "components/ui/card"
813
import { Input } from "components/ui/input"
@@ -138,10 +143,40 @@ const SummaryStyle = () => {
138143
)
139144
}
140145

146+
const SelectStyle = () => {
147+
const { selectMenuAlignment } = useAtom(preferencesData)
148+
return (
149+
<Card
150+
title={t`Selection menu alignment`}
151+
description={t`Change how selection menus are aligned to the opening button. Either align the currently selected item with the button or move the menu underneath the button.`}
152+
>
153+
<OrChain role="radiogroup" onKeyDown={styleRadioButtonFocusManager}>
154+
<StyleRadioButton
155+
active={selectMenuAlignment === "item-aligned"}
156+
icon={AlignVerticalJustifyCenter}
157+
label={t`Item aligned`}
158+
onClick={() =>
159+
preferencesData.actions.setSelectMenuAlignment("item-aligned")
160+
}
161+
/>
162+
<StyleRadioButton
163+
active={selectMenuAlignment === "popper"}
164+
icon={AlignVerticalJustifyStart}
165+
label={t`Bottom aligned`}
166+
onClick={() =>
167+
preferencesData.actions.setSelectMenuAlignment("popper")
168+
}
169+
/>
170+
</OrChain>
171+
</Card>
172+
)
173+
}
174+
141175
export const SettingsGeneral = () => (
142176
<div className={cn(vstack({ gap: 2 }))}>
143177
<Language />
144178
<Locale />
145179
<SummaryStyle />
180+
<SelectStyle />
146181
</div>
147182
)

src/components/ui/select/select.tsx

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { Dispatch, PropsWithChildren } from "react"
55
import * as Primitive from "@radix-ui/react-select"
66
import { Check, ChevronDown, ChevronUp } from "lucide-react"
77

8+
import { preferencesData } from "data/preferences"
9+
import { useAtom } from "lib/yaasl"
810
import { ClassNameProp, DisableProp } from "types/base-props"
911
import { cn } from "utils/cn"
1012
import { hstack, interactive, surface } from "utils/styles"
@@ -50,33 +52,37 @@ const ScrollDownButton = () => (
5052
</Primitive.ScrollDownButton>
5153
)
5254

53-
const Content = ({ children }: PropsWithChildren) => (
54-
<Primitive.Portal>
55-
<Primitive.Content
56-
position="item-aligned"
57-
side="bottom"
58-
sideOffset={4}
59-
align="start"
60-
className={cn(
61-
zIndex.popover,
62-
surface({ look: "overlay", size: "lg" }),
63-
"relative max-h-(--radix-select-content-available-height) min-w-32 overflow-x-hidden overflow-y-auto p-0",
64-
"origin-(--radix-select-content-transform-origin) data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95"
65-
)}
66-
>
67-
<ScrollUpButton />
68-
<Primitive.Viewport
55+
const Content = ({ children }: PropsWithChildren) => {
56+
const { selectMenuAlignment } = useAtom(preferencesData)
57+
58+
return (
59+
<Primitive.Portal>
60+
<Primitive.Content
61+
position={selectMenuAlignment}
62+
side="bottom"
63+
sideOffset={4}
64+
align="start"
6965
className={cn(
70-
"p-1",
71-
"h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width) scroll-my-1"
66+
zIndex.popover,
67+
surface({ look: "overlay", size: "lg" }),
68+
"relative max-h-(--radix-select-content-available-height) min-w-32 overflow-x-hidden overflow-y-auto p-0",
69+
"origin-(--radix-select-content-transform-origin) data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95"
7270
)}
7371
>
74-
{children}
75-
</Primitive.Viewport>
76-
<ScrollDownButton />
77-
</Primitive.Content>
78-
</Primitive.Portal>
79-
)
72+
<ScrollUpButton />
73+
<Primitive.Viewport
74+
className={cn(
75+
"p-1",
76+
"h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width) scroll-my-1"
77+
)}
78+
>
79+
{children}
80+
</Primitive.Viewport>
81+
<ScrollDownButton />
82+
</Primitive.Content>
83+
</Primitive.Portal>
84+
)
85+
}
8086

8187
interface OptionProps extends DisableProp, ClassNameProp {
8288
value: string

src/data/preferences/preferences.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export const preferencesSchema = z.object({
77
locale: z.string(),
88
language: z.string(),
99
summaryStyle: z.enum(["table", "grid"]),
10+
selectMenuAlignment: z.enum(["item-aligned", "popper"]),
1011
})
1112
type Preferences = Resolve<z.infer<typeof preferencesSchema>>
1213

1314
const defaultValue: Preferences = {
1415
locale: "iso",
1516
language: "en",
1617
summaryStyle: "table",
18+
selectMenuAlignment: "item-aligned",
1719
}
1820

1921
export const preferencesData = createSlice({
@@ -33,5 +35,12 @@ export const preferencesData = createSlice({
3335
...state,
3436
summaryStyle,
3537
}),
38+
setSelectMenuAlignment: (
39+
state,
40+
selectMenuAlignment: Preferences["selectMenuAlignment"]
41+
) => ({
42+
...state,
43+
selectMenuAlignment,
44+
}),
3645
},
3746
})

src/locales/de/messages.po

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ msgstr "Gruppe hinzufügen"
6464
msgid "Adjust the border radius size of all elements."
6565
msgstr "Passe die Abrundung der Ecken aller Elemente an."
6666

67-
#: src/app/routes/settings/settings-general.tsx:79
67+
#: src/app/routes/settings/settings-general.tsx:84
6868
msgid "Adjust the locale to influcene how dates are displayed. You can either select one in the dropdown or provide your own by using the text field."
6969
msgstr "Passe das Locale an, um die Darstellung von Datumsangaben zu beeinflussen. Du kannst eines aus der Liste wählen oder ein eigenes im Textfeld angeben."
7070

@@ -118,6 +118,10 @@ msgstr "Basisfarben"
118118
msgid "Border Radius"
119119
msgstr "Eckenabrundung"
120120

121+
#: src/app/routes/settings/settings-general.tsx:165
122+
msgid "Bottom aligned"
123+
msgstr "Unten ausgerichtet"
124+
121125
#: src/components/ui/dialog/dialog.tsx:75
122126
#: src/features/data-backup/check-backup-reminder.tsx:64
123127
msgid "Cancel"
@@ -158,6 +162,10 @@ msgstr "Kategoriename"
158162
msgid "Category order"
159163
msgstr "Kategorie Reihenfolge"
160164

165+
#: src/app/routes/settings/settings-general.tsx:151
166+
msgid "Change how selection menus are aligned to the opening button. Either align the currently selected item with the button or move the menu underneath the button."
167+
msgstr "Ändere, wie Auswahlmenüs zum Button ausgerichtet werden. Entweder wird das aktuell ausgewählte Element mit dem Button ausgerichtet oder das Menü darunter platziert."
168+
161169
#: src/app/routes/settings/settings-theming.tsx:114
162170
msgid "Change the accent color which highlights focused and active elements."
163171
msgstr "Ändere die Akzentfarbe, mit der aktive und fokussierte Elemente hervorgehoben werden."
@@ -166,7 +174,7 @@ msgstr "Ändere die Akzentfarbe, mit der aktive und fokussierte Elemente hervorg
166174
msgid "Choose between dark and light mode, and decide if neutral colors should have a hue."
167175
msgstr "Wechsel zwischen hellem und dunklem Modus und entscheide, ob neutrale Farben eine Tönung haben sollen."
168176

169-
#: src/app/routes/settings/settings-general.tsx:32
177+
#: src/app/routes/settings/settings-general.tsx:37
170178
msgid "Choose the language used for texts in Clocktopus."
171179
msgstr "Wähle eine Sprache aus, welche für die Texte in Clocktopus verwendet wird."
172180

@@ -214,11 +222,11 @@ msgstr "CSV Import / Export"
214222
msgid "Custom"
215223
msgstr "Benutzerdefiniert"
216224

217-
#: src/app/routes/settings/settings-general.tsx:90
225+
#: src/app/routes/settings/settings-general.tsx:95
218226
msgid "Custom locale"
219227
msgstr "Eigenes Locale"
220228

221-
#: src/app/routes/settings/settings-general.tsx:109
229+
#: src/app/routes/settings/settings-general.tsx:114
222230
msgid "Custom locale (e.g. ja-JP)"
223231
msgstr "Eigenes Locale (z.B. ja-JP)"
224232

@@ -253,7 +261,7 @@ msgstr "Tage Rhythmus"
253261
msgid "December"
254262
msgstr "Dezember"
255263

256-
#: src/app/routes/settings/settings-general.tsx:121
264+
#: src/app/routes/settings/settings-general.tsx:126
257265
msgid "Decide how the time summary of past dates is displayed — as table rows or in grid items?"
258266
msgstr "Lege fest, wie die Übersicht vergangener Tage angezeigt wird – als Tabellenzeilen oder als Kacheln?"
259267

@@ -404,7 +412,7 @@ msgstr "Zu den Einstellungen"
404412
msgid "Go to main page"
405413
msgstr "Zurück zur Hauptseite"
406414

407-
#: src/app/routes/settings/settings-general.tsx:133
415+
#: src/app/routes/settings/settings-general.tsx:138
408416
msgid "Grid"
409417
msgstr "Raster"
410418

@@ -455,6 +463,10 @@ msgstr "{0} Einträge importiert"
455463
msgid "Insufficient data"
456464
msgstr "Unzureichende Daten"
457465

466+
#: src/app/routes/settings/settings-general.tsx:157
467+
msgid "Item aligned"
468+
msgstr "Element ausgerichtet"
469+
458470
#: src/app/routes/stats/stats-route.tsx:94
459471
#: src/features/date-selection/week.tsx:13
460472
msgid "January"
@@ -470,13 +482,13 @@ msgstr "Juli"
470482
msgid "June"
471483
msgstr "Juni"
472484

473-
#: src/app/routes/settings/settings-general.tsx:30
474-
#: src/app/routes/settings/settings-general.tsx:38
485+
#: src/app/routes/settings/settings-general.tsx:35
486+
#: src/app/routes/settings/settings-general.tsx:43
475487
msgid "Language"
476488
msgstr "Sprache"
477489

478-
#: src/app/routes/settings/settings-general.tsx:77
479-
#: src/app/routes/settings/settings-general.tsx:90
490+
#: src/app/routes/settings/settings-general.tsx:82
491+
#: src/app/routes/settings/settings-general.tsx:95
480492
msgid "Locale"
481493
msgstr "Locale"
482494

@@ -660,6 +672,10 @@ msgstr "Suchergebnisse ({0})"
660672
msgid "Selected"
661673
msgstr "Ausgewählt"
662674

675+
#: src/app/routes/settings/settings-general.tsx:150
676+
msgid "Selection menu alignment"
677+
msgstr "Ausrichtung von Auswahlmenüs"
678+
663679
#: src/app/routes/stats/stats-route.tsx:102
664680
#: src/features/date-selection/week.tsx:21
665681
msgid "September"
@@ -691,7 +707,7 @@ msgstr "Statistiken"
691707
msgid "Stats by"
692708
msgstr "Statistiken nach"
693709

694-
#: src/app/routes/settings/settings-general.tsx:120
710+
#: src/app/routes/settings/settings-general.tsx:125
695711
msgid "Summary style"
696712
msgstr "Stil des Übersichtsmodus"
697713

@@ -708,7 +724,7 @@ msgstr "Zum Bearbeitungsmodus"
708724
msgid "Switch to summary mode"
709725
msgstr "Zum Übersichtsmodus"
710726

711-
#: src/app/routes/settings/settings-general.tsx:127
727+
#: src/app/routes/settings/settings-general.tsx:132
712728
msgid "Table"
713729
msgstr "Tabelle"
714730

0 commit comments

Comments
 (0)