Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
Image overlay in react

I need a help. I am making a component using react Avatar (Material MUI - v5). Initially, user profile avatar will be shown and when hovered over it then Edition will appear above user profile avatar and at the same time profile will be grayed out (sort of its opacity goes to 0.5). I have solved it using react state hook. Is there a way to solve it using css (not external css file !!!). This is my code.

import Avatar from "@mui/material/Avatar";
import IconButton from "@mui/material/IconButton";
import EditIcon from "@mui/icons-material/Edit";
import { useState } from "react";
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
const UserProfileCard = ({ imgUrl, uploadIconColor }) => {
  const [opacity, setOpacity] = useState(1);
  const onMouseEnterHandle = () => {
    setOpacity(0.3);
  };
  const onMouseLeaveHandle = () => {
    setOpacity(1);
  };
  return (
    <>
      <IconButton
        sx={{
          position: "absolute",
          "&:hover": {
            opacity: opacity,
            transition: "opacity 0.5s",
          },
          opacity: opacity,
          transition: "opacity 0.5s",
        }}
      >
        <Avatar src={imgUrl ? imgUrl : "/static/images/boy.jpg"} alt="User profile">
          {" "}
        </Avatar>
      </IconButton>
      <IconButton
        onMouseEnter={onMouseEnterHandle}
        onMouseLeave={onMouseLeaveHandle}
        sx={{
          opacity: 0,
          "&:hover": {
            opacity: 1,
            transition: "opacity 0.5s",
          },
        }}
      >
        <Avatar
          sx={{
            backgroundColor: "transparent",
          }}
        >
          <EditIcon
            sx={{
              color: uploadIconColor ? uploadIconColor : "#5B5B5B",
              position: "relative",
            }}
          />
        </Avatar>
      </IconButton>
    </>
  );
};
export default UserProfileCard;
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda