Files
memos/web/src/components/MemoMetadata/Relation/RelationRow.tsx
T
2026-11-13 09:13:37 +08:00

45 lines
1.7 KiB
TypeScript

import { LinkIcon, type LucideIcon } from "lucide-react";
import type { ReactNode } from "react";
import { Link } from "react-router-dom";
import { createMemoNavigationState } from "@/components/MemoView/navigation";
import type { MemoRelation_MemoRef } from "@/types/proto/api/memo_service_pb";
import { useTranslate } from "@/utils/i18n";
import { METADATA_ROW_CLASSES, METADATA_ROW_LABEL_CLASSES, METADATA_ROW_TEXT_CLASSES, MetadataRowIconSlot } from "../MetadataSection";
interface RelationRowProps {
memo: MemoRelation_MemoRef;
parentPage?: string;
icon?: LucideIcon;
/**
* "row" is a complete row that is its own focus target; "label" is the focusable body
* of a row whose box is a wrapper carrying other controls (the editor's remove button).
*/
variant?: "row" | "label";
/** Detail on the trailing rail, such as the memo's date. */
trailing?: ReactNode;
/** Says what the glyph means, such as "Referenced by", for a pointer that rests on the row. */
title?: string;
}
/** One related memo as a metadata row: a glyph in the leading slot and the snippet. */
const RelationRow = ({ memo, parentPage, icon = LinkIcon, variant = "row", trailing, title }: RelationRowProps) => {
const t = useTranslate();
return (
<Link
className={variant === "row" ? METADATA_ROW_CLASSES : METADATA_ROW_LABEL_CLASSES}
to={`/${memo.name}`}
title={title}
state={parentPage ? createMemoNavigationState(parentPage) : undefined}
viewTransition
>
<MetadataRowIconSlot icon={icon} />
<span className={METADATA_ROW_TEXT_CLASSES}>
{memo.snippet || <span className="italic text-mu-text-secondary/60">{t("common.no-content")}</span>}
</span>
{trailing}
</Link>
);
};
export default RelationRow;