mirror of
https://github.com/zadam/trilium.git
synced 2025-12-21 15:49:56 +01:00
chore(react): split button implementation
This commit is contained in:
@@ -17,6 +17,10 @@ button.ck.ck-button:is(.ck-button-action, .ck-button-save, .ck-button-cancel, .c
|
|||||||
padding: 4px 16px;
|
padding: 4px 16px;
|
||||||
background: var(--cmd-button-background-color);
|
background: var(--cmd-button-background-color);
|
||||||
color: var(--cmd-button-text-color);
|
color: var(--cmd-button-text-color);
|
||||||
|
|
||||||
|
&.dropdown-toggle-split {
|
||||||
|
min-width: unset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button.btn.btn-primary:hover,
|
button.btn.btn-primary:hover,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { CSSProperties } from "preact/compat";
|
|||||||
import { useMemo } from "preact/hooks";
|
import { useMemo } from "preact/hooks";
|
||||||
import { memo } from "preact/compat";
|
import { memo } from "preact/compat";
|
||||||
import { CommandNames } from "../../components/app_context";
|
import { CommandNames } from "../../components/app_context";
|
||||||
|
import Icon from "./Icon";
|
||||||
|
|
||||||
export interface ButtonProps {
|
export interface ButtonProps {
|
||||||
name?: string;
|
name?: string;
|
||||||
@@ -66,7 +67,7 @@ const Button = memo(({ name, buttonRef, className, text, onClick, keyboardShortc
|
|||||||
data-trigger-command={triggerCommand}
|
data-trigger-command={triggerCommand}
|
||||||
{...restProps}
|
{...restProps}
|
||||||
>
|
>
|
||||||
{icon && <span className={`bx ${icon}`}></span>}
|
{icon && <Icon icon={`bx ${icon}`} />}
|
||||||
{text} {shortcutElements}
|
{text} {shortcutElements}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
@@ -80,4 +81,28 @@ export function ButtonGroup({ children }: { children: ComponentChildren }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function SplitButton({ text, icon, children, onClick }: {
|
||||||
|
text: string;
|
||||||
|
icon?: string;
|
||||||
|
/** Click handler for the main button component (not the split). */
|
||||||
|
onClick?: () => void;
|
||||||
|
/** The children inside the dropdown of the split. */
|
||||||
|
children: ComponentChildren;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<ButtonGroup>
|
||||||
|
<button type="button" class="btn btn-secondary" onClick={onClick}>
|
||||||
|
{icon && <Icon icon={`bx ${icon}`} />}
|
||||||
|
{text}
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<span class="visually-hidden">Toggle Dropdown</span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
{children}
|
||||||
|
</ul>
|
||||||
|
</ButtonGroup>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default Button;
|
export default Button;
|
||||||
|
|||||||
Reference in New Issue
Block a user