mirror of
https://github.com/zadam/trilium.git
synced 2026-01-07 23:24:25 +01:00
chore(react/type_widget): add preview buttons
This commit is contained in:
parent
6dd939df14
commit
c49b90d33f
@ -5,7 +5,7 @@ import keyboard_actions from "../../services/keyboard_actions";
|
|||||||
|
|
||||||
export interface ActionButtonProps {
|
export interface ActionButtonProps {
|
||||||
text: string;
|
text: string;
|
||||||
titlePosition?: "bottom" | "left";
|
titlePosition?: "top" | "right" | "bottom" | "left";
|
||||||
icon: string;
|
icon: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
onClick?: (e: MouseEvent) => void;
|
onClick?: (e: MouseEvent) => void;
|
||||||
|
|||||||
@ -6,11 +6,14 @@ import { TypeWidgetProps } from "../type_widget";
|
|||||||
import "./SplitEditor.css";
|
import "./SplitEditor.css";
|
||||||
import Split from "split.js";
|
import Split from "split.js";
|
||||||
import { DEFAULT_GUTTER_SIZE } from "../../../services/resizer";
|
import { DEFAULT_GUTTER_SIZE } from "../../../services/resizer";
|
||||||
import { CodeEditor, EditableCode } from "../code/Code";
|
import { EditableCode } from "../code/Code";
|
||||||
|
import { ComponentChildren } from "preact";
|
||||||
|
import ActionButton, { ActionButtonProps } from "../../react/ActionButton";
|
||||||
|
|
||||||
interface SplitEditorProps extends TypeWidgetProps {
|
export interface SplitEditorProps extends TypeWidgetProps {
|
||||||
error?: string | null;
|
error?: string | null;
|
||||||
splitOptions?: Split.Options;
|
splitOptions?: Split.Options;
|
||||||
|
previewButtons?: ComponentChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +25,7 @@ interface SplitEditorProps extends TypeWidgetProps {
|
|||||||
* - Can display errors to the user via {@link setError}.
|
* - Can display errors to the user via {@link setError}.
|
||||||
* - Horizontal or vertical orientation for the editor/preview split, adjustable via the switch split orientation button floating button.
|
* - Horizontal or vertical orientation for the editor/preview split, adjustable via the switch split orientation button floating button.
|
||||||
*/
|
*/
|
||||||
export default function SplitEditor({ note, error, splitOptions, ...editorProps }: SplitEditorProps) {
|
export default function SplitEditor({ note, error, splitOptions, previewButtons, ...editorProps }: SplitEditorProps) {
|
||||||
const splitEditorOrientation = useSplitOrientation();
|
const splitEditorOrientation = useSplitOrientation();
|
||||||
const [ readOnly ] = useNoteLabelBoolean(note, "readOnly");
|
const [ readOnly ] = useNoteLabelBoolean(note, "readOnly");
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
@ -46,7 +49,9 @@ export default function SplitEditor({ note, error, splitOptions, ...editorProps
|
|||||||
const preview = (
|
const preview = (
|
||||||
<div className={`note-detail-split-preview-col ${error ? "on-error" : ""}`}>
|
<div className={`note-detail-split-preview-col ${error ? "on-error" : ""}`}>
|
||||||
<div className="note-detail-split-preview">Preview goes here</div>
|
<div className="note-detail-split-preview">Preview goes here</div>
|
||||||
<div className="btn-group btn-group-sm map-type-switcher content-floating-buttons preview-buttons bottom-right" role="group">Buttons go here</div>
|
<div className="btn-group btn-group-sm map-type-switcher content-floating-buttons preview-buttons bottom-right" role="group">
|
||||||
|
{previewButtons}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -72,6 +77,15 @@ export default function SplitEditor({ note, error, splitOptions, ...editorProps
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function PreviewButton(props: Omit<ActionButtonProps, "titlePosition">) {
|
||||||
|
return <ActionButton
|
||||||
|
{...props}
|
||||||
|
className="tn-tool-button"
|
||||||
|
noIconActionClass
|
||||||
|
titlePosition="top"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
|
||||||
function useSplitOrientation() {
|
function useSplitOrientation() {
|
||||||
const [ splitEditorOrientation ] = useTriliumOption("splitEditorOrientation");
|
const [ splitEditorOrientation ] = useTriliumOption("splitEditorOrientation");
|
||||||
if (isMobile()) return "vertical";
|
if (isMobile()) return "vertical";
|
||||||
|
|||||||
@ -1,10 +1,27 @@
|
|||||||
import { TypeWidgetProps } from "../type_widget";
|
import { t } from "../../../services/i18n";
|
||||||
import SplitEditor from "./SplitEditor";
|
import SplitEditor, { PreviewButton, SplitEditorProps } from "./SplitEditor";
|
||||||
|
|
||||||
export default function SvgSplitEditor(props: TypeWidgetProps) {
|
export default function SvgSplitEditor(props: SplitEditorProps) {
|
||||||
return (
|
return (
|
||||||
<SplitEditor
|
<SplitEditor
|
||||||
error="Hi there"
|
error="Hi there"
|
||||||
|
previewButtons={
|
||||||
|
<>
|
||||||
|
<PreviewButton
|
||||||
|
icon="bx bx-zoom-in"
|
||||||
|
text={t("relation_map_buttons.zoom_in_title")}
|
||||||
|
onClick={() => {}}
|
||||||
|
/>
|
||||||
|
<PreviewButton
|
||||||
|
icon="bx bx-zoom-out"
|
||||||
|
text={t("relation_map_buttons.zoom_out_title")}
|
||||||
|
/>
|
||||||
|
<PreviewButton
|
||||||
|
icon="bx bx-crop"
|
||||||
|
text={t("relation_map_buttons.reset_pan_zoom_title")}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -186,19 +186,11 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
buildPreviewButtons(): OnClickButtonWidget[] {
|
buildPreviewButtons(): OnClickButtonWidget[] {
|
||||||
return [
|
return [
|
||||||
new OnClickButtonWidget()
|
new OnClickButtonWidget()
|
||||||
.icon("bx-zoom-in")
|
|
||||||
.title(t("relation_map_buttons.zoom_in_title"))
|
|
||||||
.titlePlacement("top")
|
|
||||||
.onClick(() => this.zoomInstance?.zoomIn())
|
.onClick(() => this.zoomInstance?.zoomIn())
|
||||||
, new OnClickButtonWidget()
|
, new OnClickButtonWidget()
|
||||||
.icon("bx-zoom-out")
|
|
||||||
.title(t("relation_map_buttons.zoom_out_title"))
|
|
||||||
.titlePlacement("top")
|
.titlePlacement("top")
|
||||||
.onClick(() => this.zoomInstance?.zoomOut())
|
.onClick(() => this.zoomInstance?.zoomOut())
|
||||||
, new OnClickButtonWidget()
|
, new OnClickButtonWidget()
|
||||||
.icon("bx-crop")
|
|
||||||
.title(t("relation_map_buttons.reset_pan_zoom_title"))
|
|
||||||
.titlePlacement("top")
|
|
||||||
.onClick(() => this.zoomHandler())
|
.onClick(() => this.zoomHandler())
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user