import { __ } from "@wordpress/i18n";
import {
InputControl,
Layouts,
MultiSelectDndKit,
SelectField,
SPRangeControl,
SPToggleGroupControl,
} from "../../components";
import { LayoutOne, LayoutTwo } from "./icons";
import { AlignCenter, AlignLeft, AlignRight, AlignFull } from "../../icons/icons";
import { useEffect, useRef } from "@wordpress/element";
import ProInfo from "../../components/proInfo/proInfo";
export const GeneralTab = ({ attributes, setAttributes }) => {
const {
layout,
fieldAlignment,
gap,
multipleFilterRelation,
taxonomyType,
selectedTerms,
uniqueId,
taxonomyStyle,
allTextLabel,
taxonomyLimit,
filterType,
allTaxonomies,
menuAlignment,
selectTermsType,
excludeTerms,
} = attributes;
let allTerms = [];
const taxonomyTypeList = allTaxonomies?.map((term) => ({
label: term.label,
value: term.name,
}));
allTaxonomies?.forEach((taxonomy) => {
if (taxonomyType === taxonomy.name) {
allTerms = [...allTerms, ...taxonomy.terms_items];
}
});
const layoutChange = (newValue) => {
if (newValue === layout) {
return;
}
const newData = {
layout: newValue,
};
setAttributes(newData);
};
const taxonomyRef = useRef(taxonomyType);
useEffect(() => {
// Only run when taxonomyType actually changes value
if (taxonomyRef.current !== taxonomyType) {
taxonomyRef.current = taxonomyType;
if (selectedTerms.length > 0) {
setAttributes({ selectedTerms: [] });
}
}
}, [taxonomyType]);
return (
,
value: "layoutOne",
type: "free"
},
{
icon:
,
value: "layoutTwo",
type: "pro",
demoLink: "https://wpsmartpost.com/pricing/?ref=1"
},
]}
onChange={layoutChange}
/>
{layout === "layoutTwo" ? (
<>
{
setAttributes({
filterType: newItem,
taxonomyStyle: "more",
});
}}
/>
{ selectTermsType === "specific" && (
setAttributes({ selectedTerms: e })}
items={allTerms}
/>
)}
{ selectTermsType === "exclude" && (
setAttributes({ excludeTerms: e })}
items={allTerms}
/>
)}
{filterType === "button" && (
<>
>
)}
{filterType === "button" && (
<>
>
)}
,
value: "left",
},
{
label: ,
value: "center",
},
{
label: ,
value: "right",
},
]}
/>
>
) : (
<>
,
value: "left",
},
{
label: ,
value: "center",
},
{
label: ,
value: "right",
},
{
label: ,
value: "full",
},
]}
/>
>
)}
Premium Only
Unlock advanced Filter Options, Including:
-
— Modern filter layout
-
— Button and Dropdown filter type
-
— Choose specific categories or exclude
-
— Taxonomy display limit
-
— 3 unique taxonomy display style
-
— Show Posts counter
Upgrade to Pro
);
};
export const HeadingTab = ({ attributes, setAttributes }) => {
const { headingStyle, headingLabel, headingTag, headingPadding, taxonomyStyle } = attributes;
const handleHeadingStyle = (newItem) => {
if (headingStyle === newItem) {
return null;
}
let newHeadingPadding = headingPadding;
let newTaxonomyStyle = taxonomyStyle;
switch (newItem) {
case "styleOne":
newHeadingPadding = {
...headingPadding,
device: {
...headingPadding.device,
Desktop: { top: 8, right: 20, bottom: 8, left: 20 },
Tablet: { top: 8, right: 20, bottom: 8, left: 20 },
Mobile: { top: 8, right: 20, bottom: 8, left: 20 },
},
};
break;
case "styleTwo":
newHeadingPadding = {
...headingPadding,
device: {
...headingPadding.device,
Desktop: { top: 8, right: 2, bottom: 8, left: 2 },
Tablet: { top: 8, right: 2, bottom: 8, left: 2 },
Mobile: { top: 8, right: 2, bottom: 8, left: 2 },
},
};
break;
case "styleThree":
newTaxonomyStyle = "more";
newHeadingPadding = {
...headingPadding,
device: {
...headingPadding.device,
Desktop: { top: 8, right: 2, bottom: 8, left: 2 },
Tablet: { top: 8, right: 2, bottom: 8, left: 2 },
Mobile: { top: 8, right: 2, bottom: 8, left: 2 },
},
};
break;
case "styleFour":
newTaxonomyStyle = "more";
newHeadingPadding = {
...headingPadding,
device: {
...headingPadding.device,
Desktop: { top: 8, right: 10, bottom: 8, left: 10 },
Tablet: { top: 8, right: 10, bottom: 8, left: 10 },
Mobile: { top: 8, right: 10, bottom: 8, left: 10 },
},
};
break;
case "styleFive":
newTaxonomyStyle = "more";
newHeadingPadding = {
...headingPadding,
device: {
...headingPadding.device,
Desktop: { top: 8, right: 2, bottom: 8, left: 2 },
Tablet: { top: 8, right: 2, bottom: 8, left: 2 },
Mobile: { top: 8, right: 2, bottom: 8, left: 2 },
},
};
break;
default:
break;
}
setAttributes({
headingStyle: newItem,
taxonomyStyle: newTaxonomyStyle,
headingPadding: newHeadingPadding,
});
};
return (
);
};