import { colorControls, jsonParse, randomSolidColor, stringTrim } from "../shared/helpFn"; import { useQueryTerms } from "./query"; import { hoverAnimate, useOverlay } from "./helpFunc"; import { useEffect, useState } from "@wordpress/element"; import { breakpoint } from "../../controls/controls"; import { usePanelBodyContext } from "../../context"; import classNames from "classnames"; export default function Render({ attributes }) { const { icon, taxonomyIconStyle, layout, titleEnable, noResultFoundText, countEnable, displayOverlyThum, displayOverlyHoverThum, hoverAnimation, excerptShow, excerptLength, imageEnable, imageOverlay, hoverEffect, afterCount, beforeCount, counterMultiColorBg, limit = 6, contentMultiColorBg, postCardBg, showHideDivider, postType, SelectTerms, taxonomyType, emptyCategory, allTaxonomyTerm, excludeTerms, titleGlobalTypography, excerptGlobalTypography, counterGlobalTypography, } = attributes; const { overlayColor, overlayHoverColor } = useOverlay(attributes); const [randomColor, setRandomColor] = useState(randomSolidColor(imageOverlay)); const { togglePanelBody } = usePanelBodyContext(); useEffect(() => { setRandomColor(randomSolidColor(imageOverlay)); }, [imageOverlay]); const terms = useQueryTerms( (attributes = { postType, SelectTerms, taxonomyType, emptyCategory, allTaxonomyTerm, excludeTerms, limit, }) ); const { transformValue, initialValue } = hoverAnimate(hoverAnimation, layout); const isLayoutFiveSix = ["taxonomy-layout-five", "taxonomy-layout-six"].includes(layout); const placeholderUrl = `${sp_smart_post_block_localize.placeholderImg}public/assets/img/placeholder.png`; const deviceType = breakpoint(); const getThumbnail = (term) => term?.category_thumbnail || placeholderUrl; const getStyle = (term) => ({ "--bg-url": displayOverlyThum ? `url(${getThumbnail(term)})` : "none", "--hover-bg-url": displayOverlyHoverThum ? `url(${getThumbnail(term)})` : colorControls(postCardBg.hover.style, postCardBg.hover.solidColor, postCardBg.hover.gradient), "--overlay-color": displayOverlyThum && overlayColor, "--overlay-hover-color": overlayHoverColor, }); const getTaxonomyClass = () => [ "sp-smart-post-taxonomy-info", layout !== "taxonomy-layout-one" && "sp-smart-post-taxonomy-info-overlay", displayOverlyThum && "sp-taxonomy-overlay", displayOverlyHoverThum && "sp-taxonomy-hover-overlay ", layout === "taxonomy-layout-one" && showHideDivider && "sp-smart-post-taxonomy-info-layout-one", ] .filter(Boolean) .join(" "); const shouldShowExcerpt = excerptShow && [ "taxonomy-layout-one", "taxonomy-layout-two", "taxonomy-layout-three", "taxonomy-layout-five", "taxonomy-layout-six", ].includes(layout); const shouldShowCountInName = countEnable && ["taxonomy-layout-four", "taxonomy-layout-eight"].includes(layout); const shouldShowBeforeAfterCount = ["taxonomy-layout-seven", "taxonomy-layout-eight"].includes(layout); const renderExcerpt = (term) => shouldShowExcerpt && ( togglePanelBody("excerpt", e)} > {stringTrim(term?.description, excerptLength)} ); const renderCount = (term) => countEnable && !shouldShowCountInName && (
{noResultFoundText || "No result found."}
)}