mirror of
https://github.com/zadam/trilium.git
synced 2025-12-07 07:54:26 +01:00
fix(launch_bar): title position of action buttons
This commit is contained in:
parent
facd03b6ad
commit
237ffeff52
@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from "preact/hooks";
|
import { useContext, useMemo } from "preact/hooks";
|
||||||
import { LaunchBarDropdownButton, useLauncherIconAndTitle, type LaunchBarWidgetProps } from "./launch_bar_widgets";
|
import { LaunchBarContext, LaunchBarDropdownButton, useLauncherIconAndTitle } from "./launch_bar_widgets";
|
||||||
import { CSSProperties } from "preact";
|
import { CSSProperties } from "preact";
|
||||||
import type FNote from "../../entities/fnote";
|
import type FNote from "../../entities/fnote";
|
||||||
import { useChildNotes, useNoteLabelBoolean } from "../react/hooks";
|
import { useChildNotes, useNoteLabelBoolean } from "../react/hooks";
|
||||||
@ -9,7 +9,8 @@ import { CustomNoteLauncher } from "./GenericButtons";
|
|||||||
|
|
||||||
const PARENT_NOTE_ID = "_lbBookmarks";
|
const PARENT_NOTE_ID = "_lbBookmarks";
|
||||||
|
|
||||||
export default function BookmarkButtons({ isHorizontalLayout }: LaunchBarWidgetProps) {
|
export default function BookmarkButtons() {
|
||||||
|
const { isHorizontalLayout } = useContext(LaunchBarContext);
|
||||||
const style = useMemo<CSSProperties>(() => ({
|
const style = useMemo<CSSProperties>(() => ({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: isHorizontalLayout ? "row" : "column",
|
flexDirection: isHorizontalLayout ? "row" : "column",
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import HistoryNavigationButton from "./HistoryNavigation";
|
|||||||
import AiChatButton, { CommandButton, CustomWidget, NoteLauncher, QuickSearchLauncherWidget, ScriptLauncher, TodayLauncher } from "./LauncherDefinitions";
|
import AiChatButton, { CommandButton, CustomWidget, NoteLauncher, QuickSearchLauncherWidget, ScriptLauncher, TodayLauncher } from "./LauncherDefinitions";
|
||||||
import { useTriliumEvent } from "../react/hooks";
|
import { useTriliumEvent } from "../react/hooks";
|
||||||
import { onWheelHorizontalScroll } from "../widget_utils";
|
import { onWheelHorizontalScroll } from "../widget_utils";
|
||||||
|
import { LaunchBarContext } from "./launch_bar_widgets";
|
||||||
|
|
||||||
export default function LauncherContainer({ isHorizontalLayout }: { isHorizontalLayout: boolean }) {
|
export default function LauncherContainer({ isHorizontalLayout }: { isHorizontalLayout: boolean }) {
|
||||||
const childNotes = useLauncherChildNotes();
|
const childNotes = useLauncherChildNotes();
|
||||||
@ -25,17 +26,21 @@ export default function LauncherContainer({ isHorizontalLayout }: { isHorizontal
|
|||||||
}}
|
}}
|
||||||
onWheel={isHorizontalLayout ? onWheelHorizontalScroll : undefined}
|
onWheel={isHorizontalLayout ? onWheelHorizontalScroll : undefined}
|
||||||
>
|
>
|
||||||
{childNotes?.map(childNote => {
|
<LaunchBarContext.Provider value={{
|
||||||
if (childNote.type !== "launcher") {
|
isHorizontalLayout
|
||||||
throw new Error(`Note '${childNote.noteId}' '${childNote.title}' is not a launcher even though it's in the launcher subtree`);
|
}}>
|
||||||
}
|
{childNotes?.map(childNote => {
|
||||||
|
if (childNote.type !== "launcher") {
|
||||||
|
throw new Error(`Note '${childNote.noteId}' '${childNote.title}' is not a launcher even though it's in the launcher subtree`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isDesktop() && childNote.isLabelTruthy("desktopOnly")) {
|
if (!isDesktop() && childNote.isLabelTruthy("desktopOnly")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Launcher key={childNote.noteId} note={childNote} isHorizontalLayout={isHorizontalLayout} />
|
return <Launcher key={childNote.noteId} note={childNote} isHorizontalLayout={isHorizontalLayout} />
|
||||||
})}
|
})}
|
||||||
|
</LaunchBarContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -72,7 +77,7 @@ function initBuiltinWidget(note: FNote, isHorizontalLayout: boolean) {
|
|||||||
|
|
||||||
return <SpacerWidget baseSize={baseSize} growthFactor={growthFactor} />;
|
return <SpacerWidget baseSize={baseSize} growthFactor={growthFactor} />;
|
||||||
case "bookmarks":
|
case "bookmarks":
|
||||||
return <BookmarkButtons isHorizontalLayout={isHorizontalLayout} />;
|
return <BookmarkButtons />;
|
||||||
case "protectedSession":
|
case "protectedSession":
|
||||||
return <ProtectedSessionStatusWidget />;
|
return <ProtectedSessionStatusWidget />;
|
||||||
case "syncStatus":
|
case "syncStatus":
|
||||||
@ -84,7 +89,7 @@ function initBuiltinWidget(note: FNote, isHorizontalLayout: boolean) {
|
|||||||
case "todayInJournal":
|
case "todayInJournal":
|
||||||
return <TodayLauncher launcherNote={note} />
|
return <TodayLauncher launcherNote={note} />
|
||||||
case "quickSearch":
|
case "quickSearch":
|
||||||
return <QuickSearchLauncherWidget isHorizontalLayout={isHorizontalLayout} />
|
return <QuickSearchLauncherWidget />
|
||||||
case "aiChatLauncher":
|
case "aiChatLauncher":
|
||||||
return <AiChatButton launcherNote={note} />
|
return <AiChatButton launcherNote={note} />
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import QuickSearchWidget from "../quick_search";
|
|||||||
import { isMobile } from "../../services/utils";
|
import { isMobile } from "../../services/utils";
|
||||||
import date_notes from "../../services/date_notes";
|
import date_notes from "../../services/date_notes";
|
||||||
import { CustomNoteLauncher } from "./GenericButtons";
|
import { CustomNoteLauncher } from "./GenericButtons";
|
||||||
import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets";
|
import { LaunchBarActionButton, LaunchBarContext, useLauncherIconAndTitle } from "./launch_bar_widgets";
|
||||||
import dialog from "../../services/dialog";
|
import dialog from "../../services/dialog";
|
||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
import { CommandNames } from "../../components/app_context";
|
import { CommandNames } from "../../components/app_context";
|
||||||
@ -95,7 +95,8 @@ export function TodayLauncher({ launcherNote }: { launcherNote: FNote }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function QuickSearchLauncherWidget({ isHorizontalLayout }: { isHorizontalLayout: boolean }) {
|
export function QuickSearchLauncherWidget() {
|
||||||
|
const { isHorizontalLayout } = useContext(LaunchBarContext);
|
||||||
const widget = useMemo(() => new QuickSearchWidget(), []);
|
const widget = useMemo(() => new QuickSearchWidget(), []);
|
||||||
const parentComponent = useContext(ParentComponent) as BasicWidget | null;
|
const parentComponent = useContext(ParentComponent) as BasicWidget | null;
|
||||||
const isEnabled = isHorizontalLayout && !isMobile();
|
const isEnabled = isHorizontalLayout && !isMobile();
|
||||||
|
|||||||
@ -1,20 +1,26 @@
|
|||||||
|
import { createContext } from "preact";
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import { escapeHtml } from "../../services/utils";
|
import { escapeHtml } from "../../services/utils";
|
||||||
import ActionButton, { ActionButtonProps } from "../react/ActionButton";
|
import ActionButton, { ActionButtonProps } from "../react/ActionButton";
|
||||||
import Dropdown, { DropdownProps } from "../react/Dropdown";
|
import Dropdown, { DropdownProps } from "../react/Dropdown";
|
||||||
import { useNoteLabel, useNoteProperty } from "../react/hooks";
|
import { useNoteLabel, useNoteProperty } from "../react/hooks";
|
||||||
import Icon from "../react/Icon";
|
import Icon from "../react/Icon";
|
||||||
|
import { useContext } from "preact/hooks";
|
||||||
|
|
||||||
export interface LaunchBarWidgetProps {
|
export const LaunchBarContext = createContext<{
|
||||||
isHorizontalLayout: boolean;
|
isHorizontalLayout: boolean;
|
||||||
}
|
}>({
|
||||||
|
isHorizontalLayout: false
|
||||||
|
})
|
||||||
|
|
||||||
export function LaunchBarActionButton(props: Omit<ActionButtonProps, "className" | "noIconActionClass" | "titlePosition">) {
|
export function LaunchBarActionButton(props: Omit<ActionButtonProps, "className" | "noIconActionClass" | "titlePosition">) {
|
||||||
|
const { isHorizontalLayout } = useContext(LaunchBarContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
className="button-widget launcher-button"
|
className="button-widget launcher-button"
|
||||||
noIconActionClass
|
noIconActionClass
|
||||||
titlePosition="right"
|
titlePosition={isHorizontalLayout ? "bottom" : "right"}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user