Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { ReactNode } from "react";
import styles from "./Key.module.scss";
 
// Type definitions
interface KeyboardKeyProps {
  children: ReactNode;
}
 
// Individual key styling component
const IndividualKey = ({ children }: { children: ReactNode }) => {
  return <kbd className={styles.individualKey}>{children}</kbd>;
};
 
/**
 * KeyboardKey component for displaying keyboard shortcuts as individual styled keys
 * Splits compound shortcuts (like "Ctrl+A") into separate visual key components
 *
 * @param {KeyboardKeyProps} props - The component props
 * @returns {React.ReactElement} The KeyboardKey component with individual styled keys
 */
export const KeyboardKey = ({ children }: KeyboardKeyProps) => {
  // Convert children to string for parsing
  const keyString = String(children);
 
  // Split the key combination by common separators
  const keys = keyString
    .split(/[\+\s]+/) // Split by + or spaces
    .filter((key) => key.trim().length > 0) // Remove empty strings
    .map((key) => key.trim()); // Trim whitespace
 
  // Render all keys consistently
  return (
    <div className={styles.keyGroup}>
      {keys.map((key, index) => (
        <IndividualKey key={index}>{key}</IndividualKey>
      ))}
    </div>
  );
};