UNPKG

stone-kit

Version:
67 lines (66 loc) 2.12 kB
import { jsxs as a, Fragment as _, jsx as c } from "react/jsx-runtime"; import { useState as u, useRef as d, useEffect as h } from "react"; import { createPortal as T } from "react-dom"; import x from "./Heart.js"; import y from "./HeartFilled.js"; const C = "_root_vcwe4_1", R = "_popup_vcwe4_28", g = { root: C, popup: R }, b = ({ handleClickFavorite: l, isFavorite: t, uniqueId: w }) => { const [P, i] = u(!1), [s, n] = u(!1), [f, S] = u({ top: 0, left: 0 }), o = d(null), p = d(null), e = `favorite_popup_${w}`, I = (r) => { r.stopPropagation(), r.preventDefault(), t && sessionStorage.setItem(e, "true"), i(!0), setTimeout(() => { i(!1), l && l(r); }, 200); }; return h(() => { if (sessionStorage.getItem(e) === "true" && !t && p.current) { o.current && clearTimeout(o.current); const m = p.current.getBoundingClientRect(); S({ top: m.top + window.scrollY - 60, left: m.right + window.scrollX - 200 }), n(!0), sessionStorage.removeItem(e), o.current = setTimeout(() => { n(!1); }, 2e3); } return t && sessionStorage.removeItem(e), () => { o.current && clearTimeout(o.current); }; }, [t, e]), h(() => { t && s && (n(!1), o.current && (clearTimeout(o.current), o.current = null)); }, [t, s]), /* @__PURE__ */ a(_, { children: [ /* @__PURE__ */ a( "div", { ref: p, className: g.root, onClick: I, style: { transform: P ? "scale(0.9)" : "scale(1)", transition: "transform 0.1s ease-in-out" }, children: [ !t && /* @__PURE__ */ c(x, { width: 24, height: 24, color: "#353945" }), t && /* @__PURE__ */ c(y, { width: 24, height: 24, color: "#015FF9" }) ] } ), s && T( /* @__PURE__ */ c( "div", { className: g.popup, style: { top: `${f.top}px`, left: `${f.left}px` }, children: "Удалено из избранного" } ), document.body ) ] }); }; export { b as FavoriteIcon };