кнопка удаления у эмоджи

This commit is contained in:
Nastya 2025-06-22 18:49:50 +03:00
parent f274070c60
commit 7292287da5
2 changed files with 55 additions and 17 deletions

@ -18,6 +18,7 @@ import { quizThemes } from "@utils/themes/Publication/themePublication";
import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill"; import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill";
import type { MouseEvent } from "react"; import type { MouseEvent } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useEffect } from "react";
import { OwnEmojiPicker } from "./OwnEmojiPicker"; import { OwnEmojiPicker } from "./OwnEmojiPicker";
polyfillCountryFlagEmojis(); polyfillCountryFlagEmojis();
@ -138,6 +139,12 @@ export const EmojiVariant = ({
updateOwnVariant(variant.id, currentOwnAnswer, emoji); updateOwnVariant(variant.id, currentOwnAnswer, emoji);
}; };
const handleEmojiRemove = () => {
// Сохраняем текущий answer, очищаем только extendedText (эмодзи)
const currentOwnAnswer = ownVariants.find((v: OwnVariant) => v.id === variant.id)?.variant.answer || "";
updateOwnVariant(variant.id, currentOwnAnswer, "");
};
const isSelected = isMulti ? Array.isArray(answer) && answer.includes(variant.id) : answer === variant.id; const isSelected = isMulti ? Array.isArray(answer) && answer.includes(variant.id) : answer === variant.id;
return ( return (
@ -174,6 +181,7 @@ export const EmojiVariant = ({
<OwnEmojiPicker <OwnEmojiPicker
emoji={customEmoji || variant.extendedText} emoji={customEmoji || variant.extendedText}
onEmojiSelect={handleEmojiSelect} onEmojiSelect={handleEmojiSelect}
onEmojiRemove={customEmoji ? handleEmojiRemove : undefined}
/> />
) : ( ) : (
<Box <Box

@ -1,14 +1,16 @@
import { Box, ButtonBase, Typography, useTheme, Modal } from "@mui/material"; import { Box, ButtonBase, Typography, useTheme, Modal, IconButton } from "@mui/material";
import { useState } from "react"; import { useState } from "react";
import { EmojiPicker } from "./EmojiPicker"; import { EmojiPicker } from "./EmojiPicker";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import CloseIcon from "@mui/icons-material/Close";
interface Props { interface Props {
emoji: string; emoji: string;
onEmojiSelect?: (emoji: string) => void; onEmojiSelect?: (emoji: string) => void;
onEmojiRemove?: () => void;
} }
export const OwnEmojiPicker = ({ emoji = "", onEmojiSelect }: Props) => { export const OwnEmojiPicker = ({ emoji = "", onEmojiSelect, onEmojiRemove }: Props) => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
const [isPickerOpen, setIsPickerOpen] = useState(false); const [isPickerOpen, setIsPickerOpen] = useState(false);
@ -28,23 +30,51 @@ export const OwnEmojiPicker = ({ emoji = "", onEmojiSelect }: Props) => {
setIsPickerOpen(false); setIsPickerOpen(false);
}; };
const handleRemoveEmoji = (e: React.MouseEvent) => {
e.stopPropagation();
onEmojiRemove?.();
};
return ( return (
<> <>
<ButtonBase <Box sx={{ width: "100%", height: "100%", position: "relative" }}>
onClick={handleClick} <ButtonBase
sx={{ onClick={handleClick}
width: "100%", sx={{
height: "100%", width: "100%",
display: "flex", height: "100%",
alignItems: "center", display: "flex",
justifyContent: "center", alignItems: "center",
"&:hover": { justifyContent: "center",
bgcolor: theme.palette.grey[100], "&:hover": {
}, bgcolor: theme.palette.grey[100],
}} },
> }}
<Typography fontSize={emoji ? "100px" : "18px"}>{emoji || t("select emoji")}</Typography> >
</ButtonBase> <Typography fontSize={emoji ? "100px" : "18px"}>{emoji || t("select emoji")}</Typography>
</ButtonBase>
{onEmojiRemove && (
<IconButton
onClick={handleRemoveEmoji}
sx={{
position: "absolute",
top: 8,
left: 8,
zIndex: 1,
backgroundColor: "rgba(0, 0, 0, 0.5)",
color: "white",
height: "25px",
width: "25px",
"&:hover": {
backgroundColor: "rgba(0, 0, 0, 0.7)",
},
}}
>
<CloseIcon />
</IconButton>
)}
</Box>
<Modal <Modal
open={isPickerOpen} open={isPickerOpen}