mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
36 lines
893 B
TypeScript
36 lines
893 B
TypeScript
import classNames from 'classnames';
|
|
import type { HotkeyAction } from '../../hooks/useHotKey';
|
|
import { useFormattedHotkey } from '../../hooks/useHotKey';
|
|
import { useOsInfo } from '../../hooks/useOsInfo';
|
|
import { HStack } from './Stacks';
|
|
|
|
interface Props {
|
|
action: HotkeyAction | null;
|
|
className?: string;
|
|
variant?: 'text' | 'with-bg';
|
|
}
|
|
|
|
export function HotKey({ action, className, variant }: Props) {
|
|
const osInfo = useOsInfo();
|
|
const labelParts = useFormattedHotkey(action);
|
|
if (labelParts === null || osInfo == null) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<HStack
|
|
className={classNames(
|
|
className,
|
|
variant === 'with-bg' && 'rounded border',
|
|
'text-fg-subtler',
|
|
)}
|
|
>
|
|
{labelParts.map((char, index) => (
|
|
<div key={index} className="min-w-[1.1em] text-center">
|
|
{char}
|
|
</div>
|
|
))}
|
|
</HStack>
|
|
);
|
|
}
|