All files / components/shared/base useKoreanTheme.ts

100% Statements 32/32
96.96% Branches 32/33
100% Functions 9/9
100% Lines 32/32

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                                                                                                                                                              405x         405x 376x   332x               26x               4x               14x                         405x 376x   2x           2x                   372x                     405x 376x   376x     145x             7x               224x                     405x 376x   376x   139x         3x         5x           229x                   405x 376x 1x             405x 376x 2x                 405x                      
/**
 * useKoreanTheme - Custom hook for Korean cyberpunk theming
 * 
 * Provides centralized Korean theme styling and responsive utilities
 * Eliminates code duplication across UI components
 * 
 * @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 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;
}
 
/**
 * Custom hook for Korean cyberpunk theming
 * 
 * Provides consistent styling patterns for all Korean-themed components
 * 
 * @example
 * ```tsx
 * const { buttonVariant, sizeDimensions } = useKoreanTheme({
 *   variant: "primary",
 *   size: "md"
 * });
 * ```
 */
export function useKoreanTheme(config: UseKoreanThemeConfig = {}) {
  const {
    variant = "primary",
    size = "md",
    disabled = false,
    isMobile = 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
   */
  const buttonSize = useMemo<SizeDimensions>(() => {
    const scale = isMobile ? 0.9 : 1.0;
    
    switch (size) {
      case "sm":
      case "small":
        return {
          padding: `${Math.round(8 * scale)}px ${Math.round(16 * scale)}px`,
          fontSize: `${Math.round(14 * scale)}px`,
          borderWidth: "1px",
        };
      case "lg":
      case "large":
        return {
          padding: `${Math.round(16 * scale)}px ${Math.round(32 * scale)}px`,
          fontSize: `${Math.round(20 * scale)}px`,
          borderWidth: "3px",
        };
      case "md":
      case "medium":
      default:
        return {
          padding: `${Math.round(12 * scale)}px ${Math.round(24 * scale)}px`,
          fontSize: `${Math.round(16 * scale)}px`,
          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]);
 
  return {
    buttonVariant,
    panelVariant,
    buttonSize,
    textSize,
    calculateResponsiveSize,
    applyKoreanTheme,
    colors: KOREAN_COLORS,
    fontFamily: FONT_FAMILY,
  };
}