mirror of
https://github.com/zadam/trilium.git
synced 2025-10-31 19:49:01 +01:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useRef } from "preact/hooks";
|
|
|
|
interface ButtonProps {
|
|
text: string;
|
|
className?: string;
|
|
keyboardShortcut?: string;
|
|
/** Called when the button is clicked. If not set, the button will submit the form (if any). */
|
|
onClick?: () => void;
|
|
}
|
|
|
|
export default function Button({ className, text, onClick, keyboardShortcut }: ButtonProps) {
|
|
const classes: string[] = ["btn"];
|
|
classes.push("btn-primary");
|
|
if (className) {
|
|
classes.push(className);
|
|
}
|
|
|
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
const splitShortcut = (keyboardShortcut ?? "").split("+");
|
|
|
|
return (
|
|
<button
|
|
className={classes.join(" ")}
|
|
type={onClick ? "button" : "submit"}
|
|
onClick={onClick}
|
|
ref={buttonRef}
|
|
>
|
|
{text} {keyboardShortcut && (
|
|
splitShortcut.map((key, index) => (
|
|
<>
|
|
<kbd key={index}>{key.toUpperCase()}</kbd>{ index < splitShortcut.length - 1 ? "+" : "" }
|
|
</>
|
|
))
|
|
)}
|
|
</button>
|
|
);
|
|
} |