| 1 |
import { __ } from "@wordpress/i18n"; |
| 2 |
import { Toggle, SPRangeControl, SelectField, Layouts, InputControl } from "../../components"; |
| 3 |
import { AlignCenter, AlignLeft, AlignRight } from "../../icons/icons"; |
| 4 |
import { getPaginationBlock } from "../shared/helpFn"; |
| 5 |
import useLayouts from "../../hooks/useLayouts"; |
| 6 |
import { openLinksOptions } from "../../controls/constants"; |
| 7 |
import { inArray } from "../../controls/controls"; |
| 8 |
import SPToggleGroupControl from "../../components/toggleGroupControl/toggleGroupControl"; |
| 9 |
import ProInfo from "../../components/proInfo/proInfo"; |
| 10 |
|
| 11 |
export const GridThreeGeneralTab = ({ attributes, setAttributes }) => { |
| 12 |
const { |
| 13 |
postGridLayout, |
| 14 |
gridThreeColumns, |
| 15 |
itemsPerPage, |
| 16 |
gridThreeHorizontalGap, |
| 17 |
gridThreeVerticalGap, |
| 18 |
contentAlignment, |
| 19 |
// gridThreeMasonryEnable, |
| 20 |
preloaderEnable, |
| 21 |
blockName, |
| 22 |
generalLinkOpen, |
| 23 |
masonryGap, |
| 24 |
postLimit, |
| 25 |
largeItemHeight, |
| 26 |
smallItemHeight, |
| 27 |
metaDisplayType, |
| 28 |
paginationEnable, |
| 29 |
liveFilterEnable, |
| 30 |
clientId, |
| 31 |
} = attributes; |
| 32 |
const layouts = useLayouts(blockName, postGridLayout); |
| 33 |
|
| 34 |
const paginationBlock = getPaginationBlock(clientId); |
| 35 |
|
| 36 |
const paginationToggle = (newValue) => { |
| 37 |
setAttributes({ paginationEnable: !newValue }); |
| 38 |
|
| 39 |
if (!newValue && paginationBlock) { |
| 40 |
const { block, select } = paginationBlock; |
| 41 |
select(block?.clientId); |
| 42 |
} |
| 43 |
}; |
| 44 |
const layoutHandler = (newLayout) => { |
| 45 |
if (newLayout === postGridLayout) { |
| 46 |
return; |
| 47 |
} |
| 48 |
let taxonomyPosition; |
| 49 |
if (newLayout === "grid-three-layout-three") { |
| 50 |
taxonomyPosition = "top-right"; |
| 51 |
} else { |
| 52 |
taxonomyPosition = ""; |
| 53 |
} |
| 54 |
setAttributes({ |
| 55 |
postGridLayout: newLayout, |
| 56 |
catTabCategoryPosition: taxonomyPosition, |
| 57 |
}); |
| 58 |
}; |
| 59 |
|
| 60 |
return ( |
| 61 |
<> |
| 62 |
{layouts?.length > 0 && ( |
| 63 |
<Layouts |
| 64 |
label={__("Grid Layout", "post-carousel")} |
| 65 |
attributes={postGridLayout} |
| 66 |
attributesKey={"postGridLayout"} |
| 67 |
setAttributes={setAttributes} |
| 68 |
displayActive={true} |
| 69 |
showDemoTitle={true} |
| 70 |
grid={3} |
| 71 |
items={layouts} |
| 72 |
onChange={layoutHandler} |
| 73 |
/> |
| 74 |
)} |
| 75 |
<Toggle |
| 76 |
label={__("Smart Frontend Filter", "post-carousel")} |
| 77 |
attributes={liveFilterEnable} |
| 78 |
setAttributes={setAttributes} |
| 79 |
attributesKey={"liveFilterEnable"} |
| 80 |
/> |
| 81 |
<Toggle |
| 82 |
label={__("Smart Pagination", "post-carousel")} |
| 83 |
attributes={paginationEnable} |
| 84 |
// attributesKey={ 'paginationEnable' } |
| 85 |
// setAttributes={ setAttributes } |
| 86 |
onChange={paginationToggle} |
| 87 |
/> |
| 88 |
{!["grid-three-layout-four"].includes(postGridLayout) && ( |
| 89 |
<SPRangeControl |
| 90 |
label={__("Columns", "post-carousel")} |
| 91 |
attributes={gridThreeColumns} |
| 92 |
attributesKey={"gridThreeColumns"} |
| 93 |
setAttributes={setAttributes} |
| 94 |
max={9} |
| 95 |
min={1} |
| 96 |
defaultValue={{ unit: "", value: "" }} |
| 97 |
/> |
| 98 |
)} |
| 99 |
|
| 100 |
<InputControl |
| 101 |
label={__("Posts Per Page", "post-carousel")} |
| 102 |
className="sp-smart-limit-field" |
| 103 |
ajax={true} |
| 104 |
attributes={postLimit} |
| 105 |
min={1} |
| 106 |
max={500} |
| 107 |
attributesKey={"postLimit"} |
| 108 |
setAttributes={setAttributes} |
| 109 |
/> |
| 110 |
{!inArray(["grid-three-layout-four"], postGridLayout) && ( |
| 111 |
<SPRangeControl |
| 112 |
label={__("Large Items Height", "post-carousel")} |
| 113 |
attributes={largeItemHeight} |
| 114 |
attributesKey={"largeItemHeight"} |
| 115 |
setAttributes={setAttributes} |
| 116 |
max={2000} |
| 117 |
units={["PX", "%", "EM"]} |
| 118 |
defaultValue={{ unit: "px", value: "" }} |
| 119 |
pro={true} |
| 120 |
/> |
| 121 |
)} |
| 122 |
<SPRangeControl |
| 123 |
label={ |
| 124 |
inArray(["grid-three-layout-four"], postGridLayout) |
| 125 |
? __("Items Height", "post-carousel") |
| 126 |
: __("Small Items Height", "post-carousel") |
| 127 |
} |
| 128 |
attributes={smallItemHeight} |
| 129 |
attributesKey={"smallItemHeight"} |
| 130 |
setAttributes={setAttributes} |
| 131 |
max={2000} |
| 132 |
units={["PX", "%", "EM"]} |
| 133 |
defaultValue={{ unit: "px", value: 244 }} |
| 134 |
pro={true} |
| 135 |
/> |
| 136 |
<SPRangeControl |
| 137 |
label={__("Horizontal Gap", "post-carousel")} |
| 138 |
attributes={gridThreeHorizontalGap} |
| 139 |
attributesKey={"gridThreeHorizontalGap"} |
| 140 |
setAttributes={setAttributes} |
| 141 |
max={150} |
| 142 |
units={["PX", "%", "EM"]} |
| 143 |
defaultValue={{ unit: "px", value: 24 }} |
| 144 |
/> |
| 145 |
<SPRangeControl |
| 146 |
label={__("Vertical Gap", "post-carousel")} |
| 147 |
attributes={gridThreeVerticalGap} |
| 148 |
attributesKey={"gridThreeVerticalGap"} |
| 149 |
setAttributes={setAttributes} |
| 150 |
max={150} |
| 151 |
units={["PX", "%", "EM"]} |
| 152 |
defaultValue={{ unit: "px", value: 24 }} |
| 153 |
/> |
| 154 |
{/* { gridThreeMasonryEnable && ( |
| 155 |
<SPRangeControl |
| 156 |
label={ __( 'Masonry Gap', 'post-carousel' ) } |
| 157 |
attributes={ masonryGap } |
| 158 |
attributesKey={ 'masonryGap' } |
| 159 |
setAttributes={ setAttributes } |
| 160 |
max={ 150 } |
| 161 |
units={ [ 'PX', '%', 'EM' ] } |
| 162 |
/> |
| 163 |
) } */} |
| 164 |
<SPToggleGroupControl |
| 165 |
label={__("Content Alignment", "post-carousel")} |
| 166 |
attributes={contentAlignment} |
| 167 |
attributesKey={"contentAlignment"} |
| 168 |
setAttributes={setAttributes} |
| 169 |
items={[ |
| 170 |
{ label: <AlignLeft />, value: "left" }, |
| 171 |
{ label: <AlignCenter />, value: "center" }, |
| 172 |
{ label: <AlignRight />, value: "right" }, |
| 173 |
]} |
| 174 |
/> |
| 175 |
<SelectField |
| 176 |
label={__("Link Open In", "post-carousel")} |
| 177 |
attributes={generalLinkOpen} |
| 178 |
attributesKey={"generalLinkOpen"} |
| 179 |
setAttributes={setAttributes} |
| 180 |
items={openLinksOptions} |
| 181 |
/> |
| 182 |
{/* <Toggle |
| 183 |
label={ __( 'Masonry', 'post-carousel' ) } |
| 184 |
attributes={ gridThreeMasonryEnable ) } |
| 185 |
attributesKey={ 'gridThreeMasonryEnable' } |
| 186 |
setAttributes={ setAttributes } |
| 187 |
/> */} |
| 188 |
<Toggle |
| 189 |
label={__("Preloader", "post-carousel")} |
| 190 |
attributes={preloaderEnable} |
| 191 |
attributesKey={"preloaderEnable"} |
| 192 |
setAttributes={setAttributes} |
| 193 |
/> |
| 194 |
<ProInfo> |
| 195 |
<span>Unlock exclusive layouts and advanced display controls.</span> <a href="https://wpsmartpost.com/pricing/?ref=1" target="_blank" rel="noopener noreferrer">Upgrade to Pro!</a> |
| 196 |
</ProInfo> |
| 197 |
</> |
| 198 |
); |
| 199 |
}; |
| 200 |
|