All files / components/shared/base useKoreanTheme.ts

100% Statements 36/36
97.61% Branches 41/42
100% Functions 11/11
100% Lines 34/34

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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312                                                                                                                                                                                                                        2690x         2690x 1940x   1685x               118x               54x               83x                         2690x 1940x   56x           3x                   1881x                       2690x   1952x   1952x     884x             102x               966x                     2690x 1952x   1952x   735x         16x         23x           1178x                   2690x 1951x 3326x             2690x 1940x 2x                                   2690x                       2690x                 2690x                          
/**
 * useKoreanTheme - Custom hook for Korean cyberpunk theming
 * 
 * Provides centralized Korean theme styling and responsive utilities
 * Eliminates code duplication across UI components
 * 
 * Enhanced with:
 * - Korean typography optimization (line height, letter spacing, word break)
 * - Accessibility features (focus indicators, touch targets, high contrast)
 * - WCAG 2.1 AA compliant color contrast ratios
 * 
 * @module components/base
 */
 
import { useMemo } from "react";
import { KOREAN_COLORS, FONT_FAMILY } from "../../../types/constants";
import { hexToRgbaString } from "../../../utils/colorUtils";
 
/**
 * Button variant configuration
 */
export interface ButtonVariantConfig {
  readonly background: number;
  readonly border: number;
  readonly text: number;
  readonly hoverBg: string;
  readonly activeBg: string;
}
 
/**
 * Panel variant configuration
 */
export interface PanelVariantConfig {
  readonly background: string;
  readonly border: string;
  readonly boxShadow: string;
}
 
/**
 * Size dimension configuration
 */
export interface SizeDimensions {
  readonly padding: string;
  readonly fontSize: string;
  readonly borderWidth: string;
}
 
/**
 * Text size configuration
 */
export interface TextSizeConfig {
  readonly korean: string;
  readonly english: string;
}
 
/**
 * Korean typography configuration
 */
export interface KoreanTypographyConfig {
  readonly fontFamily: string;
  readonly lineHeight: number;
  readonly letterSpacing: string;
  readonly wordBreak: "normal" | "break-all" | "keep-all" | "break-word";
  readonly wordWrap: "normal" | "break-word";
}
 
/**
 * Accessibility configuration
 */
export interface AccessibilityConfig {
  readonly focusOutline: string;
  readonly focusOutlineOffset: string;
  readonly minTouchTarget: string;
  readonly highContrastFocusOutline: string;
}
 
/**
 * Korean theme hook configuration
 */
export interface UseKoreanThemeConfig {
  readonly variant?: "primary" | "secondary" | "danger" | "default" | "bordered" | "elevated";
  readonly size?: "sm" | "md" | "lg" | "small" | "medium" | "large" | "xlarge";
  readonly disabled?: boolean;
  readonly isMobile?: boolean;
  readonly highContrast?: boolean;
}
 
/**
 * Custom hook for Korean cyberpunk theming
 * 
 * Provides consistent styling patterns for all Korean-themed components
 * Enhanced with Korean typography optimization and accessibility features
 * 
 * @example
 * ```tsx
 * const { buttonVariant, sizeDimensions, koreanTypography } = useKoreanTheme({
 *   variant: "primary",
 *   size: "md"
 * });
 * ```
 */
export function useKoreanTheme(config: UseKoreanThemeConfig = {}) {
  const {
    variant = "primary",
    size = "md",
    disabled = false,
    isMobile = false,
    highContrast = false,
  } = config;
 
  /**
   * Get button variant colors
   */
  const buttonVariant = useMemo<ButtonVariantConfig>(() => {
    switch (variant) {
      case "primary":
        return {
          background: KOREAN_COLORS.UI_BACKGROUND_DARK,
          border: KOREAN_COLORS.PRIMARY_CYAN,
          text: KOREAN_COLORS.ACCENT_GOLD,
          hoverBg: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.1),
          activeBg: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.2),
        };
      case "secondary":
        return {
          background: KOREAN_COLORS.UI_BACKGROUND_MEDIUM,
          border: KOREAN_COLORS.ACCENT_GOLD,
          text: KOREAN_COLORS.TEXT_PRIMARY,
          hoverBg: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.1),
          activeBg: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.2),
        };
      case "danger":
        return {
          background: KOREAN_COLORS.UI_BACKGROUND_DARK,
          border: KOREAN_COLORS.ACCENT_RED,
          text: KOREAN_COLORS.ACCENT_RED,
          hoverBg: hexToRgbaString(KOREAN_COLORS.ACCENT_RED, 0.1),
          activeBg: hexToRgbaString(KOREAN_COLORS.ACCENT_RED, 0.2),
        };
      default:
        return {
          background: KOREAN_COLORS.UI_BACKGROUND_DARK,
          border: KOREAN_COLORS.PRIMARY_CYAN,
          text: KOREAN_COLORS.ACCENT_GOLD,
          hoverBg: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.1),
          activeBg: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.2),
        };
    }
  }, [variant]);
 
  /**
   * Get panel variant styling
   */
  const panelVariant = useMemo<PanelVariantConfig>(() => {
    switch (variant) {
      case "bordered":
        return {
          background: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, 0.95),
          border: `2px solid ${hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.8)}`,
          boxShadow: `0 0 15px ${hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.3)}`,
        };
      case "elevated":
        return {
          background: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_MEDIUM, 0.9),
          border: `1px solid ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.5)}`,
          boxShadow: `
            0 4px 12px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.5)},
            0 0 20px ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.2)}
          `,
        };
      case "default":
      default:
        return {
          background: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, 0.85),
          border: `1px solid ${hexToRgbaString(KOREAN_COLORS.UI_BORDER, 0.5)}`,
          boxShadow: "none",
        };
    }
  }, [variant]);
 
  /**
   * Get size dimensions for buttons with touch-optimized mobile values
   * Mobile: 48px+ minimum touch targets with 16px+ Korean font
   */
  const buttonSize = useMemo<SizeDimensions>(() => {
    // Touch-optimized sizing for mobile (no scale down)
    const scale = isMobile ? 1.0 : 1.0; // Keep full size on mobile for 48px+ targets
    
    switch (size) {
      case "sm":
      case "small":
        return {
          padding: `${Math.round(8 * scale)}px ${Math.round(16 * scale)}px`,
          fontSize: isMobile ? "14px" : `${Math.round(14 * scale)}px`, // Maintain readable size
          borderWidth: "1px",
        };
      case "lg":
      case "large":
        return {
          padding: `${Math.round(16 * scale)}px ${Math.round(32 * scale)}px`,
          fontSize: isMobile ? "18px" : `${Math.round(20 * scale)}px`, // 18px minimum for Korean
          borderWidth: "3px",
        };
      case "md":
      case "medium":
      default:
        return {
          padding: `${Math.round(12 * scale)}px ${Math.round(24 * scale)}px`,
          fontSize: isMobile ? "16px" : `${Math.round(16 * scale)}px`, // 16px minimum for Korean
          borderWidth: "2px",
        };
    }
  }, [size, isMobile]);
 
  /**
   * Get text size configuration
   */
  const textSize = useMemo<TextSizeConfig>(() => {
    const scale = isMobile ? 0.9 : 1.0;
    
    switch (size) {
      case "small":
        return {
          korean: `${Math.round(14 * scale)}px`,
          english: `${Math.round(12 * scale)}px`,
        };
      case "large":
        return {
          korean: `${Math.round(24 * scale)}px`,
          english: `${Math.round(18 * scale)}px`,
        };
      case "xlarge":
        return {
          korean: `${Math.round(32 * scale)}px`,
          english: `${Math.round(24 * scale)}px`,
        };
      case "medium":
      default:
        return {
          korean: `${Math.round(18 * scale)}px`,
          english: `${Math.round(14 * scale)}px`,
        };
    }
  }, [size, isMobile]);
 
  /**
   * Calculate responsive size
   */
  const calculateResponsiveSize = useMemo(() => {
    return (baseSize: number) => {
      return isMobile ? Math.round(baseSize * 0.8) : baseSize;
    };
  }, [isMobile]);
 
  /**
   * Apply Korean theme to base styles
   */
  const applyKoreanTheme = useMemo(() => {
    return (baseStyle: React.CSSProperties): React.CSSProperties => {
      return {
        ...baseStyle,
        fontFamily: FONT_FAMILY.KOREAN,
        color: hexToRgbaString(KOREAN_COLORS.TEXT_PRIMARY),
        opacity: disabled ? 0.5 : 1,
      };
    };
  }, [disabled]);
 
  /**
   * Korean typography configuration
   * Optimized for Korean character readability
   * 
   * - Line height: 1.6 for Korean characters (vs 1.5 for Latin)
   * - Letter spacing: -0.01em for tighter Korean spacing
   * - Word break: keep-all to prevent breaking Korean words
   * - Word wrap: break-word for long words
   */
  const koreanTypography = useMemo<KoreanTypographyConfig>(() => ({
    fontFamily: FONT_FAMILY.KOREAN,
    lineHeight: 1.6, // Optimal for Korean character readability
    letterSpacing: "-0.01em", // Tighter spacing for Korean
    wordBreak: "keep-all", // Prevent breaking Korean words mid-syllable
    wordWrap: "break-word", // Wrap long words appropriately
  }), []);
 
  /**
   * Accessibility configuration
   * WCAG 2.1 AA compliant focus indicators and touch targets
   */
  const accessibility = useMemo<AccessibilityConfig>(() => ({
    focusOutline: highContrast
      ? `4px solid ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD)}` // High contrast mode
      : `3px solid ${hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN)}`, // Normal mode
    focusOutlineOffset: "2px",
    minTouchTarget: "44px", // WCAG 2.1 AA minimum touch target size
    highContrastFocusOutline: `4px solid ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD)}`,
  }), [highContrast]);
 
  return {
    buttonVariant,
    panelVariant,
    buttonSize,
    textSize,
    calculateResponsiveSize,
    applyKoreanTheme,
    koreanTypography,
    accessibility,
    colors: KOREAN_COLORS,
    fontFamily: FONT_FAMILY,
  };
}