import { Box, Chip } from "@mui/material"; import { useGame } from "../contexts/GameContext"; /** * A component that renders text with styled words (bold, italic, etc.) * It automatically handles spacing between words and styled segments * It also removes any text enclosed in [ ] or ( ) */ export function StyledText({ text, ...props }) { const { heroName } = useGame(); if (!text || !heroName) return text; // Remove text enclosed in [ ] or ( ) const cleanedText = text.replace(/\[.*?\]|\(.*?\)/g, ""); const parts = cleanedText.split(new RegExp(`(${heroName})`, "i")); return ( {parts.map((part, index) => { if (part.toLowerCase() === heroName.toLowerCase()) { return ( ); } return part; })} ); } export default StyledText;