mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
refactor(react/ribbon): shared component for labelled entry
This commit is contained in:
@@ -11,6 +11,7 @@ import { ParentComponent } from "../react/react_utils";
|
|||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import FormCheckbox from "../react/FormCheckbox";
|
import FormCheckbox from "../react/FormCheckbox";
|
||||||
import FormTextBox from "../react/FormTextBox";
|
import FormTextBox from "../react/FormTextBox";
|
||||||
|
import { ComponentChildren } from "preact";
|
||||||
|
|
||||||
const VIEW_TYPE_MAPPINGS: Record<ViewTypeOptions, string> = {
|
const VIEW_TYPE_MAPPINGS: Record<ViewTypeOptions, string> = {
|
||||||
grid: t("book_properties.grid"),
|
grid: t("book_properties.grid"),
|
||||||
@@ -106,18 +107,14 @@ function NumberPropertyView({ note, property }: { note: FNote, property: NumberP
|
|||||||
const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
|
const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<LabelledEntry label={property.label}>
|
||||||
<label>
|
|
||||||
{property.label}
|
|
||||||
|
|
||||||
<FormTextBox
|
<FormTextBox
|
||||||
type="number"
|
type="number"
|
||||||
currentValue={value ?? ""} onChange={setValue}
|
currentValue={value ?? ""} onChange={setValue}
|
||||||
style={{ width: (property.width ?? 100) + "px" }}
|
style={{ width: (property.width ?? 100) + "px" }}
|
||||||
min={property.min ?? 0}
|
min={property.min ?? 0}
|
||||||
/>
|
/>
|
||||||
</label>
|
</LabelledEntry>
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,15 +122,23 @@ function ComboBoxPropertyView({ note, property }: { note: FNote, property: Combo
|
|||||||
const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
|
const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<LabelledEntry label={property.label}>
|
||||||
<label>
|
|
||||||
{property.label}
|
|
||||||
|
|
||||||
<FormSelectWithGroups
|
<FormSelectWithGroups
|
||||||
values={property.options}
|
values={property.options}
|
||||||
keyProperty="value" titleProperty="label"
|
keyProperty="value" titleProperty="label"
|
||||||
currentValue={value ?? ""} onChange={setValue}
|
currentValue={value ?? ""} onChange={setValue}
|
||||||
/>
|
/>
|
||||||
|
</LabelledEntry>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function LabelledEntry({ label, children }: { label: string, children: ComponentChildren }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<label>
|
||||||
|
{label}
|
||||||
|
|
||||||
|
{children}
|
||||||
</label>
|
</label>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user