Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda