chore(react/type_widgets): introduce disabled tooltip

This commit is contained in:
Elian Doran 2025-09-21 12:01:27 +03:00
parent b7574b3ca7
commit 376ef0c679
No known key found for this signature in database
4 changed files with 21 additions and 27 deletions

View File

@ -408,7 +408,7 @@ body.desktop .tabulator-popup-container {
.dropdown-menu .disabled .disabled-tooltip { .dropdown-menu .disabled .disabled-tooltip {
pointer-events: all; pointer-events: all;
margin-left: 8px; margin-left: 8px;
font-size: 0.5em; font-size: 0.75rem;
color: var(--disabled-tooltip-icon-color); color: var(--disabled-tooltip-icon-color);
cursor: help; cursor: help;
opacity: 0.75; opacity: 0.75;

View File

@ -15,9 +15,6 @@ import type { NoteRow } from "@triliumnext/commons";
const TPL = /*html*/` const TPL = /*html*/`
<div class="dropdown"> <div class="dropdown">
<div class="dropdown-menu dropdown-menu-right"> <div class="dropdown-menu dropdown-menu-right">
<li data-trigger-command="openAttachmentCustom" class="dropdown-item"
title="${t("attachments_actions.open_custom_title")}"><span class="bx bx-customize"></span> ${t("attachments_actions.open_custom")}</li>
<li data-trigger-command="downloadAttachment" class="dropdown-item"> <li data-trigger-command="downloadAttachment" class="dropdown-item">
<span class="bx bx-download"></span> ${t("attachments_actions.download")}</li> <span class="bx bx-download"></span> ${t("attachments_actions.download")}</li>
@ -84,24 +81,6 @@ export default class AttachmentActionsWidget extends BasicWidget {
} }
} }
}); });
const isElectron = utils.isElectron();
if (!this.isFullDetail) {
const $openAttachmentButton = this.$widget.find("[data-trigger-command='openAttachment']");
$openAttachmentButton.addClass("disabled").append($('<span class="bx bx-info-circle disabled-tooltip" />').attr("title", t("attachments_actions.open_externally_detail_page")));
if (isElectron) {
const $openAttachmentCustomButton = this.$widget.find("[data-trigger-command='openAttachmentCustom']");
$openAttachmentCustomButton.addClass("disabled").append($('<span class="bx bx-info-circle disabled-tooltip" />').attr("title", t("attachments_actions.open_externally_detail_page")));
}
}
if (!isElectron) {
const $openAttachmentCustomButton = this.$widget.find("[data-trigger-command='openAttachmentCustom']");
$openAttachmentCustomButton.addClass("disabled").append($('<span class="bx bx-info-circle disabled-tooltip" />').attr("title", t("attachments_actions.open_custom_client_only")));
}
}
async openAttachmentCustomCommand() {
await openService.openAttachmentCustom(this.attachmentId, this.attachment.mime);
} }
async downloadAttachmentCommand() { async downloadAttachmentCommand() {

View File

@ -22,7 +22,7 @@ export default function FormList({ children, onSelect, style, fullHeight }: Form
if (!triggerRef.current || !wrapperRef.current) { if (!triggerRef.current || !wrapperRef.current) {
return; return;
} }
const $wrapperRef = $(wrapperRef.current); const $wrapperRef = $(wrapperRef.current);
const dropdown = BootstrapDropdown.getOrCreateInstance(triggerRef.current); const dropdown = BootstrapDropdown.getOrCreateInstance(triggerRef.current);
$wrapperRef.on("hide.bs.dropdown", (e) => e.preventDefault()); $wrapperRef.on("hide.bs.dropdown", (e) => e.preventDefault());
@ -82,6 +82,8 @@ interface FormListItemOpts {
active?: boolean; active?: boolean;
badges?: FormListBadge[]; badges?: FormListBadge[];
disabled?: boolean; disabled?: boolean;
/** Will indicate the reason why the item is disabled via an icon, when hovered over it. */
disabledTooltip?: string;
checked?: boolean | null; checked?: boolean | null;
selected?: boolean; selected?: boolean;
onClick?: (e: MouseEvent) => void; onClick?: (e: MouseEvent) => void;
@ -118,21 +120,24 @@ export function FormListItem({ className, icon, value, title, active, disabled,
<Icon icon={icon} />&nbsp; <Icon icon={icon} />&nbsp;
{description ? ( {description ? (
<div> <div>
<FormListContent description={description} {...contentProps} /> <FormListContent description={description} disabled={disabled} {...contentProps} />
</div> </div>
) : ( ) : (
<FormListContent description={description} {...contentProps} /> <FormListContent description={description} disabled={disabled} {...contentProps} />
)} )}
</li> </li>
); );
} }
function FormListContent({ children, badges, description }: Pick<FormListItemOpts, "children" | "badges" | "description">) { function FormListContent({ children, badges, description, disabled, disabledTooltip }: Pick<FormListItemOpts, "children" | "badges" | "description" | "disabled" | "disabledTooltip">) {
return <> return <>
{children} {children}
{badges && badges.map(({ className, text }) => ( {badges && badges.map(({ className, text }) => (
<span className={`badge ${className ?? ""}`}>{text}</span> <span className={`badge ${className ?? ""}`}>{text}</span>
))} ))}
{disabled && disabledTooltip && (
<span class="bx bx-info-circle disabled-tooltip" title={disabledTooltip} />
)}
{description && <div className="description">{description}</div>} {description && <div className="description">{description}</div>}
</>; </>;
} }
@ -177,4 +182,4 @@ export function FormDropdownSubmenu({ icon, title, children }: { icon: string, t
</ul> </ul>
</li> </li>
) )
} }

View File

@ -156,6 +156,8 @@ function AttachmentInfo({ attachment, isFullDetail }: { attachment: FAttachment,
} }
function AttachmentActions({ attachment }: { attachment: FAttachment }) { function AttachmentActions({ attachment }: { attachment: FAttachment }) {
const isElectron = utils.isElectron();
return ( return (
<div className="attachment-actions-container"> <div className="attachment-actions-container">
<Dropdown <Dropdown
@ -169,6 +171,14 @@ function AttachmentActions({ attachment }: { attachment: FAttachment }) {
title={t("attachments_actions.open_externally_title")} title={t("attachments_actions.open_externally_title")}
onClick={(e) => open.openAttachmentExternally(attachment.attachmentId, attachment.mime)} onClick={(e) => open.openAttachmentExternally(attachment.attachmentId, attachment.mime)}
>{t("attachments_actions.open_externally")}</FormListItem> >{t("attachments_actions.open_externally")}</FormListItem>
<FormListItem
icon="bx bx-customize"
title={t("attachments_actions.open_custom_title")}
onClick={(e) => open.openAttachmentCustom(attachment.attachmentId, attachment.mime)}
disabled={!isElectron}
disabledTooltip={!isElectron ? t("attachments_actions.open_custom_client_only") : t("attachments_actions.open_externally_detail_page")}
>{t("attachments_actions.open_custom")}</FormListItem>
</Dropdown> </Dropdown>
</div> </div>
) )