All files / components/shared/base BaseButtonHTML.tsx

92.85% Statements 26/28
90.62% Branches 29/32
85.71% Functions 6/7
92.85% Lines 26/28

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                                                                                                    13x                             88x 88x     88x             88x 5x 5x       88x 5x 5x 5x       88x         88x 5x 5x       88x 5x       88x 88x   88x 5x 83x 9x     88x                                                                   88x                                                               13x  
/**
 * BaseButtonHTML - HTML button component with Korean theming (non-Three.js)
 * 
 * A version of BaseButton that doesn't require Three.js/Canvas context
 * Can be used in regular DOM components
 * 
 * @module components/base
 */
 
import React, { useCallback, useMemo, useState } from "react";
import { KOREAN_COLORS } from "../../../types/constants";
import { hexToRgbaString } from "../../../utils/colorUtils";
import { useKoreanTheme } from "./useKoreanTheme";
 
/**
 * Props for BaseButtonHTML component
 */
export interface BaseButtonHTMLProps {
  readonly korean: string;
  readonly english: string;
  readonly onClick: () => void;
  readonly onMouseEnter?: () => void;
  readonly disabled?: boolean;
  readonly variant?: "primary" | "secondary" | "danger";
  readonly size?: "sm" | "md" | "lg";
  readonly fullWidth?: boolean;
  readonly testId?: string;
  readonly isMobile?: boolean;
  readonly className?: string;
  readonly style?: React.CSSProperties;
  readonly autoFocus?: boolean;
}
 
/**
 * BaseButtonHTML Component
 * 
 * HTML button with Korean theming (no Three.js dependency).
 * Uses useKoreanTheme hook for consistent styling.
 * 
 * @example
 * ```tsx
 * <BaseButtonHTML
 *   korean="확인"
 *   english="Confirm"
 *   onClick={() => handleConfirm()}
 *   variant="primary"
 *   size="md"
 * />
 * ```
 */
export const BaseButtonHTML: React.FC<BaseButtonHTMLProps> = ({
  korean,
  english,
  onClick,
  onMouseEnter,
  disabled = false,
  variant = "primary",
  size = "md",
  fullWidth = false,
  testId,
  isMobile = false,
  className,
  style: customStyle,
  autoFocus = false,
}) => {
  const [isHovered, setIsHovered] = useState(false);
  const [isPressed, setIsPressed] = useState(false);
 
  // Use Korean theme hook for consistent styling
  const { buttonVariant, buttonSize, fontFamily } = useKoreanTheme({
    variant,
    size,
    disabled,
    isMobile,
  });
 
  const handleClick = useCallback(() => {
    Eif (!disabled) {
      onClick();
    }
  }, [onClick, disabled]);
 
  const handleMouseEnterInternal = useCallback(() => {
    Eif (!disabled) {
      setIsHovered(true);
      onMouseEnter?.();
    }
  }, [disabled, onMouseEnter]);
 
  const handleMouseLeave = useCallback(() => {
    setIsHovered(false);
    setIsPressed(false);
  }, []);
 
  const handleMouseDown = useCallback(() => {
    Eif (!disabled) {
      setIsPressed(true);
    }
  }, [disabled]);
 
  const handleMouseUp = useCallback(() => {
    setIsPressed(false);
  }, []);
 
  // Memoize button styles for performance
  const buttonStyle = useMemo<React.CSSProperties>(() => {
    let background = hexToRgbaString(buttonVariant.background, 0.9);
    
    if (isPressed) {
      background = buttonVariant.activeBg;
    } else if (isHovered) {
      background = buttonVariant.hoverBg;
    }
 
    return {
      background,
      border: `${buttonSize.borderWidth} solid ${hexToRgbaString(buttonVariant.border)}`,
      color: hexToRgbaString(buttonVariant.text),
      padding: buttonSize.padding,
      fontSize: buttonSize.fontSize,
      fontFamily: fontFamily.KOREAN,
      fontWeight: "bold",
      cursor: disabled ? "not-allowed" : "pointer",
      opacity: disabled ? 0.5 : 1,
      borderRadius: "4px",
      transition: "all 0.2s ease",
      textAlign: "center",
      userSelect: "none",
      WebkitUserSelect: "none",
      width: fullWidth ? "100%" : "auto",
      boxShadow: isHovered && !disabled
        ? `0 0 10px ${hexToRgbaString(buttonVariant.border, 0.5)}`
        : "none",
      transform: isPressed && !disabled ? "scale(0.98)" : "scale(1)",
      textShadow: `0 2px 4px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.5)}`,
      ...customStyle,
    };
  }, [
    buttonVariant,
    buttonSize,
    fontFamily,
    disabled,
    fullWidth,
    isHovered,
    isPressed,
    customStyle,
  ]);
 
  return (
    <button
      onClick={handleClick}
      onMouseEnter={handleMouseEnterInternal}
      onMouseLeave={handleMouseLeave}
      onMouseDown={handleMouseDown}
      onMouseUp={handleMouseUp}
      disabled={disabled}
      style={buttonStyle}
      className={className}
      data-testid={testId ?? "base-button-html"}
      autoFocus={autoFocus}
    >
      <div style={{ 
        display: "flex", 
        flexDirection: "column", 
        alignItems: "center",
        gap: "2px"
      }}>
        <span style={{ fontSize: "1em" }}>{korean}</span>
        <span style={{ 
          fontSize: "0.75em", 
          opacity: 0.8,
          fontStyle: "italic"
        }}>
          {english}
        </span>
      </div>
    </button>
  );
};
 
BaseButtonHTML.displayName = "BaseButtonHTML";