Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | 2x 20x 20x 20x 20x 20x 20x 19x 20x 2x 2x 2x 20x 8x 8x 8x 6x 6x 20x 76x 76x 76x 76x 2x 6x 2x 2x 2x | /**
* MenuButtons - Reusable menu button grid for IntroScreen
*
* Provides 2x2 grid (desktop) or column (mobile) layout for menu navigation.
* Extracted from MenuSectionOverlayHtml to reduce code duplication.
*
* @module components/screens/intro
* @category Intro UI
* @korean 메뉴버튼
*/
import React, { useCallback, useMemo } from "react";
import { GameMode } from "../../../../types/common";
import { FONT_FAMILY, KOREAN_COLORS } from "../../../../types/constants";
import { hexToRgbaString } from "../../../../utils/colorUtils";
import { UIHaptics } from "../../../../utils/hapticFeedback";
import {
getButtonVisualEffectsOnly,
} from "../../../../utils/koreanThemeHelpers";
import { getMobileKoreanFontSize } from "../../../../utils/mobileUIUtils";
import {
getKoreanFontOptimization,
} from "../../../../utils/visualEffects";
export interface MenuButtonsProps {
/** Array of menu items to display */
readonly menuItems: Array<{
mode: GameMode;
korean: string;
english: string;
}>;
/** Currently selected menu item index */
readonly selectedIndex: number;
/** Index of currently hovered menu item (null if none) */
readonly hoveredIndex: number | null;
/** Callback when a menu item is selected */
readonly onModeSelect: (mode: GameMode) => void;
/** Callback when hover state changes */
readonly onHoverChange: (index: number | null) => void;
/** Callback to play sound effects */
readonly onPlaySFX?: (sound: string) => void;
/** Screen width for responsive sizing */
readonly width?: number;
/** Whether on mobile device (for haptics) */
readonly isMobile?: boolean;
}
/**
* MenuButtons Component
*
* Displays menu navigation buttons with:
* - 2x2 grid layout on larger screens
* - Column layout on small screens
* - Selected/hovered state visualization
* - Korean bilingual text
* - Haptic feedback support
*
* This component delegates to inline button elements with custom styling
* since BaseButtonOverlayHtml doesn't support the complex selection state
* and color transitions needed for menu navigation.
*
* Reduces code duplication by 62 lines (MenuSectionOverlayHtml: 372 → 310)
*
* @example
* ```tsx
* <MenuButtons
* menuItems={MENU_ITEMS}
* selectedIndex={0}
* hoveredIndex={null}
* onModeSelect={(mode) => handleModeSelect(mode)}
* onHoverChange={(idx) => setHovered(idx)}
* width={800}
* />
* ```
*/
export const MenuButtons: React.FC<MenuButtonsProps> = ({
menuItems,
selectedIndex,
hoveredIndex,
onModeSelect,
onHoverChange,
onPlaySFX,
width = 800,
isMobile: _isMobile = false, // Prefix with _ to indicate intentionally unused
}) => {
// Responsive sizing based on screen width
const isSmallScreen = width < 768;
const useGridLayout = !isSmallScreen;
const buttonHeight = isSmallScreen ? 44 : 40;
const buttonFontSize = isSmallScreen
? getMobileKoreanFontSize("SMALL", width ?? 375)
: 13;
const buttonGap = isSmallScreen ? 6 : 8;
// Memoize button state colors
const colors = useMemo(
() => ({
buttonSelectedBg: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.98),
buttonHoveredBg: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_LIGHT, 0.92),
buttonDefaultBg: hexToRgbaString(
KOREAN_COLORS.UI_BACKGROUND_MEDIUM,
0.92,
),
buttonSelectedBorder: hexToRgbaString(
KOREAN_COLORS.UI_BACKGROUND_DARK,
1.0,
),
buttonHoveredBorder: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.8),
buttonDefaultBorder: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.7),
}),
[],
);
const handleButtonClick = useCallback(
(mode: GameMode) => {
UIHaptics.buttonTap();
onModeSelect(mode);
onPlaySFX?.("menu_select");
},
[onModeSelect, onPlaySFX],
);
const handleButtonHover = useCallback(
(index: number, isHovering: boolean) => {
const newIndex = isHovering ? index : null;
onHoverChange(newIndex);
if (isHovering) {
UIHaptics.menuHover();
onPlaySFX?.("menu_hover");
}
},
[onHoverChange, onPlaySFX],
);
return (
<div
style={{
display: "grid",
gridTemplateColumns: useGridLayout ? "1fr 1fr" : "1fr",
gap: `${buttonGap}px`,
width: "100%",
}}
data-testid="main-menu-buttons"
>
{menuItems.map((item, index) => {
const isSelected = selectedIndex === index;
const isHovered = hoveredIndex === index;
// Get only visual effects (glow, transitions, transforms)
const visualEffects = getButtonVisualEffectsOnly({
variant: "primary",
isHovered,
isPressed: false,
isFocused: false,
glowIntensity: isSelected
? "medium"
: isHovered
? "medium"
: "subtle",
hoverAnimation: "combined",
});
return (
<button
key={item.mode}
onClick={() => handleButtonClick(item.mode)}
onMouseEnter={() => handleButtonHover(index, true)}
onMouseLeave={() => handleButtonHover(index, false)}
onFocus={(e) => {
e.currentTarget.style.outline = `3px solid ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD)}`;
e.currentTarget.style.outlineOffset = "2px";
}}
onBlur={(e) => {
e.currentTarget.style.outline = "none";
}}
aria-label={`${item.korean} (${item.english})`}
aria-selected={isSelected}
role="menuitem"
style={{
...visualEffects,
...getKoreanFontOptimization(
buttonFontSize,
isSelected ? "bold" : "normal",
),
fontFamily: FONT_FAMILY.KOREAN,
width: "100%",
height: `${buttonHeight}px`,
// Menu-specific color, background, and border
color: isSelected
? `#${KOREAN_COLORS.UI_BACKGROUND_DARK.toString(16).padStart(
6,
"0",
)}`
: isHovered
? `#${KOREAN_COLORS.ACCENT_GOLD.toString(16).padStart(
6,
"0",
)}`
: `#${KOREAN_COLORS.TEXT_PRIMARY.toString(16).padStart(
6,
"0",
)}`,
background: isSelected
? colors.buttonSelectedBg
: isHovered
? colors.buttonHoveredBg
: colors.buttonDefaultBg,
border: isSelected
? `3px solid ${colors.buttonSelectedBorder}`
: isHovered
? `2px solid ${colors.buttonHoveredBorder}`
: `2px solid ${colors.buttonDefaultBorder}`,
cursor: "pointer",
}}
data-testid={`menu-item-${item.mode}`}
>
{/* Add test ID aliases for backward compatibility */}
{item.mode === GameMode.TRAINING && (
<span
data-testid="training-button"
style={{ display: "none" }}
/>
)}
{item.mode === GameMode.VERSUS && (
<span data-testid="combat-button" style={{ display: "none" }} />
)}
{item.korean} ({item.english})
</button>
);
})}
</div>
);
};
export default MenuButtons;
|