From 53b7d93efbc4dab83a5647af47136a53eaf8561c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 11 Dec 2025 20:09:25 +0200 Subject: [PATCH] feat(note_bars/collection): support comboboxes --- .../src/translations/en/translation.json | 2 +- .../note_bars/CollectionProperties.tsx | 44 ++++++++++++++++++- .../ribbon/collection-properties-config.tsx | 5 ++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 1159a8bf8..2e63ef777 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -2031,7 +2031,7 @@ "book_properties_config": { "hide-weekends": "Hide weekends", "display-week-numbers": "Display week numbers", - "map-style": "Map style:", + "map-style": "Map style", "max-nesting-depth": "Max nesting depth:", "raster": "Raster", "vector_light": "Vector (Light)", diff --git a/apps/client/src/widgets/note_bars/CollectionProperties.tsx b/apps/client/src/widgets/note_bars/CollectionProperties.tsx index e8b1c82bc..142ed6ca6 100644 --- a/apps/client/src/widgets/note_bars/CollectionProperties.tsx +++ b/apps/client/src/widgets/note_bars/CollectionProperties.tsx @@ -5,11 +5,12 @@ import Dropdown from "../react/Dropdown"; import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "../react/FormList"; import Icon from "../react/Icon"; import { useViewType, VIEW_TYPE_MAPPINGS } from "../ribbon/CollectionPropertiesTab"; -import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, NumberProperty, SplitButtonProperty } from "../ribbon/collection-properties-config"; -import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks"; +import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxItem, ComboBoxProperty, NumberProperty, SplitButtonProperty } from "../ribbon/collection-properties-config"; +import { useNoteLabel, useNoteLabelBoolean, useNoteLabelWithDefault } from "../react/hooks"; import { useContext } from "preact/hooks"; import { ParentComponent } from "../react/react_utils"; import FormTextBox from "../react/FormTextBox"; +import { Fragment } from "preact/jsx-runtime"; const ICON_MAPPINGS: Record = { grid: "bx bxs-grid", @@ -86,6 +87,8 @@ function ViewProperty({ note, property }: { note: FNote, property: BookProperty return ; case "number": return ; + case "combobox": + return ; } } @@ -149,6 +152,43 @@ function NumberPropertyView({ note, property }: { note: FNote, property: NumberP ); } +function ComboBoxPropertyView({ note, property }: { note: FNote, property: ComboBoxProperty }) { + const [ value, setValue ] = useNoteLabelWithDefault(note, property.bindToLabel, property.defaultValue ?? ""); + + function renderItem(option: ComboBoxItem) { + return ( + setValue(option.value)} + > + {option.label} + + ); + } + + return ( + + {(property.options).map((option, index) => { + if ("items" in option) { + return ( + + {option.title} + {option.items.map(renderItem)} + {index < property.options.length - 1 && } + + ); + } else { + return renderItem(option); + } + })} + + ) +} + function CheckBoxPropertyView({ note, property }: { note: FNote, property: CheckBoxProperty }) { const [ value, setValue ] = useNoteLabelBoolean(note, property.bindToLabel); return ( diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsx index 9dddae75a..1f79217e9 100644 --- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx +++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx @@ -45,7 +45,7 @@ export interface NumberProperty { disabled?: (note: FNote) => boolean; } -interface ComboBoxItem { +export interface ComboBoxItem { value: string; label: string; } @@ -58,6 +58,7 @@ interface ComboBoxGroup { export interface ComboBoxProperty { type: "combobox", label: string; + icon?: string; bindToLabel: FilterLabelsByType; /** * The default value is used when the label is not set. @@ -125,6 +126,7 @@ export const bookPropertiesConfig: Record = { properties: [ { label: t("book_properties_config.map-style"), + icon: "bx bx-palette", type: "combobox", bindToLabel: "map:style", defaultValue: DEFAULT_MAP_LAYER_NAME, @@ -177,6 +179,7 @@ export const bookPropertiesConfig: Record = { { label: "Theme", type: "combobox", + icon: "bx bx-palette", bindToLabel: "presentation:theme", defaultValue: DEFAULT_THEME, options: getPresentationThemes().map(theme => ({