Files
Trilium/apps/client/src/widgets/BreadcrumbBadges.tsx

37 lines
1.0 KiB
TypeScript
Raw Normal View History

import "./BreadcrumbBadges.css";
import { ComponentChildren } from "preact";
import { useIsNoteReadOnly, useNoteContext } from "./react/hooks";
2025-12-09 21:11:30 +02:00
import Icon from "./react/Icon";
export default function NoteBadges() {
return (
<div className="breadcrumb-badges">
<ReadOnlyBadge />
</div>
);
}
function ReadOnlyBadge() {
const { note, noteContext } = useNoteContext();
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
return (isReadOnly &&
2025-12-09 21:11:30 +02:00
<Badge
icon="bx bx-lock"
onClick={() => enableEditing()}>
{isExplicitReadOnly ? "Read-only" : "Auto read-only"}
</Badge>
);
}
2025-12-09 21:11:30 +02:00
function Badge({ icon, children, onClick }: { icon: string, children: ComponentChildren, onClick?: () => void }) {
return (
<div className="breadcrumb-badge" onClick={onClick}>
2025-12-09 21:11:30 +02:00
<Icon icon={icon} />&nbsp;
{children}
</div>
);
}