Files
ThreadNet-Web/src/components/views/settings/KeyboardShortcut.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-03-14 14:25:51 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2022-03-14 14:25:51 +01:00
Copyright 2022 Šimon Brandner <simon.bra.ag@gmail.com>
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2022-03-14 14:25:51 +01:00
*/
import React from "react";
import { ALTERNATE_KEY_NAME, KEY_ICON } from "../../../accessibility/KeyboardShortcuts";
2025-02-05 13:25:06 +00:00
import { type KeyCombo } from "../../../KeyBindingsManager";
import { IS_MAC, Key } from "../../../Keyboard";
2022-03-14 14:25:51 +01:00
import { _t } from "../../../languageHandler";
interface IKeyboardKeyProps {
name: string;
last?: boolean;
}
export const KeyboardKey: React.FC<IKeyboardKeyProps> = ({ name, last }) => {
const icon = KEY_ICON[name];
const alternateName = ALTERNATE_KEY_NAME[name];
return (
<React.Fragment>
<kbd> {icon || (alternateName && _t(alternateName)) || name} </kbd>
{!last && "+"}
</React.Fragment>
);
};
interface IKeyboardShortcutProps {
value: KeyCombo;
2022-10-13 12:20:31 +02:00
className?: string;
2022-03-14 14:25:51 +01:00
}
2022-10-13 12:20:31 +02:00
export const KeyboardShortcut: React.FC<IKeyboardShortcutProps> = ({ value, className = "mx_KeyboardShortcut" }) => {
2022-03-14 14:25:51 +01:00
if (!value) return null;
const modifiersElement: JSX.Element[] = [];
2022-03-14 14:25:51 +01:00
if (value.ctrlOrCmdKey) {
modifiersElement.push(<KeyboardKey key="ctrlOrCmdKey" name={IS_MAC ? Key.META : Key.CONTROL} />);
2022-03-14 14:25:51 +01:00
} else if (value.ctrlKey) {
modifiersElement.push(<KeyboardKey key="ctrlKey" name={Key.CONTROL} />);
} else if (value.metaKey) {
modifiersElement.push(<KeyboardKey key="metaKey" name={Key.META} />);
}
if (value.altKey) {
modifiersElement.push(<KeyboardKey key="altKey" name={Key.ALT} />);
}
if (value.shiftKey) {
modifiersElement.push(<KeyboardKey key="shiftKey" name={Key.SHIFT} />);
}
2022-10-13 12:20:31 +02:00
return (
<div className={className}>
2022-03-14 14:25:51 +01:00
{modifiersElement}
<KeyboardKey name={value.key} last />
</div>
);
};