Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(attributes): give the label type an icon for each of its kinds
Elian Doran12a484b3884a
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.css b/apps/client/src/widgets/attribute_widgets/attribute_detail.cssindex cc4f29ba35..820e9b37ed 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.css+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.css@@ -36,7 +36,8 @@}.attr-edit-rows .option-row-input > input,-.attr-edit-rows .option-row-input > select {+.attr-edit-rows .option-row-input > select,+.attr-edit-rows .option-row-input > .dropdown {width: 100%;}diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsxindex 29402f5f10..a61d9528af 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx@@ -21,7 +21,7 @@ import { Badge, BadgeWithDropdown } from "../react/Badge.jsx";import Button from "../react/Button.jsx";import FormAutocomplete, { AUTOCOMPLETE_DROPDOWN_SELECTOR } from "../react/FormAutocomplete.jsx";import { FormDropdownDivider, FormListItem } from "../react/FormList.jsx";-import FormSelect from "../react/FormSelect.jsx";+import FormDropdownList from "../react/FormDropdownList.jsx";import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox.jsx";import HelpTooltipButton from "../react/HelpTooltipButton.jsx";import NoteAutocomplete from "../react/NoteAutocomplete.jsx";@@ -444,7 +444,7 @@ function AttributeForm({ opts, attrType, currentNoteId, onCancel, onAttributesChenough once one is picked. */}{attrType === "label-definition" && (<OptionsRow name="attr-label-type" label={t("attribute_detail.label_type")}>- <FormSelect+ <FormDropdownListclassName="attr-input-label-type"values={LABEL_TYPES}keyProperty="value"@@ -454,6 +454,7 @@ function AttributeForm({ opts, attrType, currentNoteId, onCancel, onAttributesChonChange={(labelType) => commitDefinition({ labelType: labelType as LabelType })}/></OptionsRow>+ iconProperty="icon")}{attrType === "label-definition" && definition.labelType === "number" && (@@ -601,15 +602,15 @@ const TARGET_NOTE_OPTS = { allowCreatingNotes: true };/** Exported so that hosts listing definitions can name their label type as the popup does. */export const LABEL_TYPES = [- { value: "text", title: t("attribute_detail.text") },- { value: "textarea", title: t("attribute_detail.textarea") },- { value: "number", title: t("attribute_detail.number") },- { value: "boolean", title: t("attribute_detail.boolean") },- { value: "date", title: t("attribute_detail.date") },- { value: "datetime", title: t("attribute_detail.date_time") },- { value: "time", title: t("attribute_detail.time") },- { value: "url", title: t("attribute_detail.url") },- { value: "color", title: t("attribute_detail.color_type") }+ { value: "text", title: t("attribute_detail.text"), icon: "bx bx-text" },+ { value: "textarea", title: t("attribute_detail.textarea"), icon: "bx bx-align-left" },+ { value: "number", title: t("attribute_detail.number"), icon: "bx bx-hash" },+ { value: "boolean", title: t("attribute_detail.boolean"), icon: "bx bx-toggle-left" },+ { value: "date", title: t("attribute_detail.date"), icon: "bx bx-calendar" },+ { value: "datetime", title: t("attribute_detail.date_time"), icon: "bx bx-calendar-event" },+ { value: "time", title: t("attribute_detail.time"), icon: "bx bx-time" },+ { value: "url", title: t("attribute_detail.url"), icon: "bx bx-link" },+ { value: "color", title: t("attribute_detail.color_type"), icon: "bx bx-palette" }];function fetchAttributeNames(type: "label" | "relation", query: string) {diff --git a/apps/client/src/widgets/react/FormDropdownList.tsx b/apps/client/src/widgets/react/FormDropdownList.tsxindex 150fc4a724..6c381ce0b9 100644--- a/apps/client/src/widgets/react/FormDropdownList.tsx+++ b/apps/client/src/widgets/react/FormDropdownList.tsx@@ -1,5 +1,6 @@import Dropdown, { DropdownProps } from "./Dropdown";import { FormListItem } from "./FormList";+import Icon from "./Icon";interface FormDropdownList<T> extends Omit<DropdownProps, "children"> {values: T[];@@ -8,11 +9,13 @@ interface FormDropdownList<T> extends Omit<DropdownProps, "children"> {/** Property to show as a small suffix next to the title */titleSuffixProperty?: keyof T;descriptionProperty?: keyof T;+ /** Property holding the icon of an item, e.g. `bx bx-calendar`. Shown on the items and on the button. */+ iconProperty?: keyof T;currentValue: string;onChange(newValue: string): void;}-export default function FormDropdownList<T>({ values, keyProperty, titleProperty, titleSuffixProperty, descriptionProperty, currentValue, onChange, ...restProps }: FormDropdownList<T>) {+export default function FormDropdownList<T>({ values, keyProperty, titleProperty, titleSuffixProperty, descriptionProperty, iconProperty, currentValue, onChange, ...restProps }: FormDropdownList<T>) {const currentValueData = values.find(value => value[keyProperty] === currentValue);const renderTitle = (item: T) => {@@ -24,18 +27,32 @@ export default function FormDropdownList<T>({ values, keyProperty, titlePropertyreturn title;};+ const renderLabel = (item: T) => (+ iconProperty+ ? <><Icon icon={item[iconProperty] as string} /> {renderTitle(item)}</>+ : renderTitle(item)+ );+return (- <Dropdown text={currentValueData ? renderTitle(currentValueData) : ""} {...restProps}>- {values.map(item => (- <FormListItem- onClick={() => onChange(item[keyProperty] as string)}- checked={currentValue === item[keyProperty]}- description={descriptionProperty && item[descriptionProperty] as string}- selected={currentValue === item[keyProperty]}- >- {renderTitle(item)}- </FormListItem>- ))}+ <Dropdown text={currentValueData ? renderLabel(currentValueData) : ""} {...restProps}>+ {values.map(item => {+ const isCurrent = currentValue === item[keyProperty];+ return (+ <FormListItem+ key={item[keyProperty] as string}+ icon={iconProperty ? item[iconProperty] as string : undefined}+ onClick={() => onChange(item[keyProperty] as string)}+ // The check mark takes the place of the item's icon, so where the items carry one+ // the current value is marked by highlighting the item instead of by a mark.+ checked={!iconProperty && isCurrent}+ active={!!iconProperty && isCurrent}+ description={descriptionProperty && item[descriptionProperty] as string}+ selected={isCurrent}+ >+ {renderTitle(item)}+ </FormListItem>+ );+ })}</Dropdown>- )+ );}