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(react): add bootstrap tooltip to menu items
Elian Doran83fd42aff291
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsxindex 5e3bae3cfa..7b44ad69d1 100644--- a/apps/client/src/widgets/react/FormList.tsx+++ b/apps/client/src/widgets/react/FormList.tsx@@ -1,9 +1,10 @@-import { Dropdown as BootstrapDropdown } from "bootstrap";+import { Dropdown as BootstrapDropdown, Tooltip } from "bootstrap";import { ComponentChildren } from "preact";import Icon from "./Icon";import { useEffect, useMemo, useRef, type CSSProperties } from "preact/compat";import "./FormList.css";import { CommandNames } from "../../components/app_context";+import { useStaticTooltip } from "./hooks";interface FormListOpts {children: ComponentChildren;@@ -90,13 +91,23 @@ interface FormListItemOpts {outsideChildren?: ComponentChildren;}+const TOOLTIP_CONFIG: Partial<Tooltip.Options> = {+ placement: "right",+ fallbackPlacements: [ "right" ]+}+export function FormListItem({ className, children, icon, value, title, active, badges, disabled, checked, onClick, description, selected, rtl, triggerCommand, outsideChildren }: FormListItemOpts) {+ const itemRef = useRef<HTMLAnchorElement>(null);+if (checked) {icon = "bx bx-check";}+ useStaticTooltip(itemRef, TOOLTIP_CONFIG);+return (<a+ ref={itemRef}class={`dropdown-item ${active ? "active" : ""} ${disabled ? "disabled" : ""} ${selected ? "selected" : ""} ${className ?? ""}`}data-value={value} title={title}tabIndex={0}@@ -131,4 +142,19 @@ export function FormListHeader({ text }: FormListHeaderOpts) {export function FormDropdownDivider() {return <div className="dropdown-divider" />;+}++export function FormDropdownSubmenu({ icon, title, children }: { icon: string, title: ComponentChildren, children: ComponentChildren }) {+ return (+ <li className="dropdown-item dropdown-submenu">+ <span class="dropdown-toggle">+ <Icon icon={icon} />+ {title}+ </span>++ <ul className="dropdown-menu">+ {children}+ </ul>+ </li>+ )}\ No newline at end of filediff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex bd0c2e287f..58670155a3 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -505,7 +505,8 @@ export function useTooltip(elRef: RefObject<HTMLElement>, config: Partial<Toolti*/export function useStaticTooltip(elRef: RefObject<Element>, config?: Partial<Tooltip.Options>) {useEffect(() => {- if (!elRef?.current) return;+ const hasTooltip = config?.title || elRef.current?.getAttribute("title");+ if (!elRef?.current || !hasTooltip) return;const $el = $(elRef.current);$el.tooltip(config);