import { __ } from "@wordpress/i18n"; import { InputControl, Layouts, MultiSelectDndKit, SelectField, SPRangeControl, SPToggleGroupControl, Toggle, } from "../../components"; import { useMemo } from "@wordpress/element"; import RangeControl from "../../components/rangeControl/rangeControl"; import useMetaData from "../../hooks/useMetaData"; import { getObjectValuesToJsArray } from "../shared/helpFn"; import { capitalizeString, filterSelectOptions, findDataFromArray } from "../../controls/controls"; import { SearchFormPresetFive, SearchFormPresetFour, SearchFormPresetOne, SearchFormPresetThree, SearchFormPresetTwo, SearchResultLayoutOne, SearchResultLayoutThree, SearchResultLayoutTwo, } from "./icons"; import { AlignCenter, AlignLeft, AlignRight } from "../../icons/icons"; export const PresetTab = ({ attributes, setAttributes }) => { const { searchFormPreset, displayType, placeholderEnable, placeholder, searchFormBorderWidth, searchFormHoverBorder, searchFormBorder, searchFormPadding, searchButtonPosition, searchFormAlignment, searchFormHoverBorderWidth, searchFormWidth, searchFormHeight, } = attributes; const layoutDefault = useMemo( () => ({ "smart-search-form-preset-one": { searchFormBorderWidth: { ...searchFormBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormBorder: { ...searchFormBorder, style: "solid", color: "#CCCCCC", }, searchFormHoverBorderWidth: { ...searchFormHoverBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormHoverBorder: { ...searchFormHoverBorder, style: "solid", color: "#CCCCCC", }, searchFormPadding: { ...searchFormPadding, device: { Desktop: { top: 12, right: 12, bottom: 12, left: 12 }, Mobile: { top: 12, right: 12, bottom: 12, left: 12 }, Tablet: { top: 12, right: 12, bottom: 12, left: 12 }, }, }, searchButtonIconColor: { color: "#2F2F2F", hoverColor: "", }, searchButtonPosition: "right", }, "smart-search-form-preset-two": { searchFormBorderWidth: { ...searchFormBorderWidth, device: { Desktop: { top: 0, right: 0, bottom: 1, left: 0 }, Mobile: { top: 0, right: 0, bottom: 1, left: 0 }, Tablet: { top: 0, right: 0, bottom: 1, left: 0 }, }, }, searchFormBorder: { ...searchFormBorder, style: "solid", color: "#2F2F2F", }, searchFormHoverBorderWidth: { ...searchFormHoverBorderWidth, device: { Desktop: { top: 0, right: 0, bottom: 1, left: 0 }, Mobile: { top: 0, right: 0, bottom: 1, left: 0 }, Tablet: { top: 0, right: 0, bottom: 1, left: 0 }, }, }, searchFormHoverBorder: { ...searchFormHoverBorder, style: "solid", color: "#2F2F2F", }, searchFormPadding: { ...searchFormPadding, device: { Desktop: { top: 12, right: 12, bottom: 12, left: 12 }, Mobile: { top: 12, right: 12, bottom: 12, left: 12 }, Tablet: { top: 12, right: 12, bottom: 12, left: 12 }, }, }, searchButtonIconColor: { color: "#2F2F2F", hoverColor: "", }, searchButtonPosition: "left" }, "smart-search-form-preset-three": { searchFormBorderWidth: { ...searchFormBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormBorder: { ...searchFormBorder, style: "solid", color: "#2F2F2F", }, searchFormHoverBorderWidth: { ...searchFormHoverBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormHoverBorder: { ...searchFormHoverBorder, style: "solid", color: "#2F2F2F", }, searchFormPadding: { ...searchFormPadding, device: { Desktop: { ...searchFormPadding.Desktop, right: 0, left: searchButtonPosition === "left" ? 0 : 12, }, Mobile: { ...searchFormPadding.Mobile, right: 0, left: searchButtonPosition === "left" ? 0 : 12, }, Tablet: { ...searchFormPadding.Tablet, right: 0, left: searchButtonPosition === "left" ? 0 : 12, }, }, }, searchButtonIconColor: { color: "#ffffff", hoverColor: "", }, searchButtonPosition: "right", }, "smart-search-form-preset-four": { searchFormBorderWidth: { ...searchFormBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormBorder: { ...searchFormBorder, style: "solid", color: "#2F2F2F", }, searchFormHoverBorderWidth: { ...searchFormHoverBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormHoverBorder: { ...searchFormHoverBorder, style: "solid", color: "#2F2F2F", }, searchFormPadding: { ...searchFormPadding, device: { Desktop: { ...searchFormPadding.Desktop, right: 0, left: 12, }, Mobile: { ...searchFormPadding.Mobile, right: 0, left: 12, }, Tablet: { ...searchFormPadding.Tablet, right: 0, left: 12, }, }, }, searchButtonIconColor: { color: "#ffffff", hoverColor: "", }, searchButtonPosition: "right", }, "smart-search-form-preset-five": { searchFormBorderWidth: { ...searchFormBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormBorder: { ...searchFormBorder, style: "solid", color: "#2F2F2F", }, searchFormHoverBorderWidth: { ...searchFormHoverBorderWidth, device: { Desktop: { top: 1, right: 1, bottom: 1, left: 1 }, Mobile: { top: 1, right: 1, bottom: 1, left: 1 }, Tablet: { top: 1, right: 1, bottom: 1, left: 1 }, }, }, searchFormHoverBorder: { ...searchFormHoverBorder, style: "solid", color: "#2F2F2F", }, searchFormPadding: { ...searchFormPadding, device: { Desktop: { top: 4, right: 4, bottom: 4, left: searchButtonPosition === "left" ? 4 : 12, }, Mobile: { top: 4, right: 4, bottom: 4, left: searchButtonPosition === "left" ? 4 : 12, }, Tablet: { top: 4, right: 4, bottom: 4, left: searchButtonPosition === "left" ? 4 : 12, }, }, }, searchButtonIconColor: { color: "#ffffff", hoverColor: "", }, searchButtonPosition: "right", }, }), [] ); const layoutChange = (newValue) => { if (newValue === searchFormPreset) { return; } const newData = { searchFormPreset: newValue, ...layoutDefault[newValue], }; setAttributes(newData); }; return ( <> , value: "smart-search-form-preset-one", }, { icon: , value: "smart-search-form-preset-two", }, { icon: , value: "smart-search-form-preset-three", }, { icon: , value: "smart-search-form-preset-four", }, { icon: , value: "smart-search-form-preset-five", }, ]} /> {placeholderEnable && ( )} , value: "flex-start" }, { label: , value: "center" }, { label: , value: "flex-end" }, ]} /> ); }; export const SearchButtonGeneralTab = ({ attributes, setAttributes }) => { const { searchButtonPosition, searchIcon, searchButtonIconSize, searchButtonNewTabEnable, searchIconDivider, searchFormPreset, searchBtnLabelText, searchBtnLabel, searchBtnReverse, } = attributes; return ( <> {searchIcon && ( <> {searchFormPreset === "smart-search-form-preset-one" && ( )} )} {[ "smart-search-form-preset-three", "smart-search-form-preset-four", "smart-search-form-preset-five", ].includes(searchFormPreset) && ( <> {searchBtnLabel && ( <> {searchIcon && ( )} )} )} ); }; export const SearchResultGeneralTab = ({ attributes, setAttributes }) => { const { ajaxSearch, searchResultDisplayType, searchResultNotFoundText, searchResultColumns, searchResultColumnGap, searchResultBoxWidth, searchResultBoxHeight, searchResultShowImage, searchResultImageSize, searchResultImageContentGap, searchResultShowExcerpt, searchResultShowTaxonomy, searchResultShowAuthor, searchResultShowDate, hightLightSearchTerm, searchResultItemSeparator, searchResultHorizontalPosition, searchResultVerticalPosition, searchResultTitleFontSize, searchResultExcerptLimit, searchResultSpaceBetweenMeta, taxonomyFilterEnable, } = attributes; const layoutDefault = useMemo( () => ({ "smart-search-result-layout-one": { searchResultColumns: { ...searchResultColumns, device: { Desktop: 1, Tablet: 1, Mobile: 1, }, }, searchResultColumnGap: { ...searchResultColumnGap, device: { Desktop: 0, Tablet: 0, Mobile: 0, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultImageContentGap: { ...searchResultImageContentGap, device: { Desktop: 20, Tablet: 20, Mobile: 20, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultTitleFontSize: { ...searchResultTitleFontSize, device: { Desktop: 18, Tablet: 18, Mobile: 18, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, popupCanvasWidth: { device: { Desktop: 500, Tablet: 500, Mobile: 500, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultVerticalPosition: { device: { Desktop: 100, Tablet: 100, Mobile: 100, }, unit: { Desktop: "%", Tablet: "%", Mobile: "%", }, }, searchResultImageSize: { device: { Desktop: 55, Tablet: 55, Mobile: 55, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, }, "smart-search-result-layout-two": { searchResultColumns: { ...searchResultColumns, device: { Desktop: 1, Tablet: 1, Mobile: 1, }, }, searchResultColumnGap: { ...searchResultColumnGap, device: { Desktop: 0, Tablet: 0, Mobile: 0, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultTitleFontSize: { ...searchResultTitleFontSize, device: { Desktop: 18, Tablet: 18, Mobile: 18, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, popupCanvasWidth: { device: { Desktop: 500, Tablet: 500, Mobile: 500, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultImageContentGap: { device: { Desktop: 20, Tablet: 20, Mobile: 20, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, searchResultVerticalPosition: { device: { Desktop: 100, Tablet: 100, Mobile: 100, }, unit: { Desktop: "%", Tablet: "%", Mobile: "%", }, }, }, }, "smart-search-result-layout-three": { searchResultColumns: { ...searchResultColumns, device: { Desktop: 6, Tablet: 4, Mobile: 1, }, }, searchResultColumnGap: { ...searchResultColumnGap, device: { Desktop: 10, Tablet: 10, Mobile: 10, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultImageContentGap: { ...searchResultImageContentGap, device: { Desktop: 12, Tablet: 12, Mobile: 12, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultTitleFontSize: { ...searchResultTitleFontSize, device: { Desktop: 16, Tablet: 16, Mobile: 16, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, popupCanvasWidth: { device: { Desktop: 65, Tablet: 65, Mobile: 65, }, unit: { Desktop: "%", Tablet: "%", Mobile: "%", }, }, searchResultVerticalPosition: { device: { Desktop: 80, Tablet: 80, Mobile: 80, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, searchResultImageSize: { device: { Desktop: 150, Tablet: 150, Mobile: 150, }, unit: { Desktop: "px", Tablet: "px", Mobile: "px", }, }, }, }), [] ); const layoutChange = (newValue) => { if (newValue === searchResultDisplayType) { return; } const newData = { searchResultDisplayType: newValue, ...layoutDefault[newValue], }; setAttributes(newData); }; return ( <> {!taxonomyFilterEnable && ( )} , value: "smart-search-result-layout-one", }, { icon: , value: "smart-search-result-layout-two", }, { icon: , value: "smart-search-result-layout-three", }, ]} /> {searchResultDisplayType !== "smart-search-result-layout-two" && ( <> {!!searchResultShowImage && ( <> )} )} {searchResultShowExcerpt && ( )} {/* TODO: Need to clarification about this feature*/} ); }; export const MoreResultGeneralTab = ({ attributes, setAttributes }) => { const { moreResultsEnable, moreResultLabelText, showResultsCount, initialPostDisplay, moreResultClickAction, taxonomyFilterEnable, } = attributes; const actionOptions = [ { value: "expanded", label: __("Expanded", "post-carousel"), }, { value: "same_tab", label: __("Same Tab", "post-carousel"), }, { value: "new_tab", label: __("New Tab", "post-carousel"), }, ]; return ( <> {moreResultsEnable && ( <> {!taxonomyFilterEnable && ( )} )} ); }; export const QueryFilterGeneralTab = ({ attributes, setAttributes }) => { const { uniqueId, postType, taxonomyFilterEnable, selectedTaxonomy, selectedTerms, filterLabelText } = attributes; const { allPostTypes, allTaxonomies } = useMetaData(attributes, "editSite"); const postTypeValues = getObjectValuesToJsArray(allPostTypes); const postTypeOptions = postTypeValues?.map((singlePostType) => ({ label: `${capitalizeString(singlePostType)}s`, value: singlePostType, })); const updatePostTypeOptions = postTypeOptions?.map((item, index) => ({ id: index + 1, label: item.value === "attachment" ? "Media" : item.label, value: item.value, })); const defaultPostType = [ { label: "Posts", value: "post" }, { label: "Pages", value: "page" }, ]; const postTypeChangeHandler = (newValue) => { if (postType === newValue) { return; } setAttributes({ postType: newValue, selectedTerms: [] }); }; const taxonomiesSelectOptions = filterSelectOptions(allTaxonomies, "label", "name"); const selectedTaxonomyData = findDataFromArray(allTaxonomies, "name", selectedTaxonomy); const terms = selectedTaxonomyData?.terms_items.map((item) => ({ ...item, id: item.value, })); const taxonomyTypeTitle = selectedTaxonomy ? selectedTaxonomyData?.label : __("Taxonomy", "post-carousel"); return ( <> 0 ? [...updatePostTypeOptions] : defaultPostType} onChange={postTypeChangeHandler} /> {postType && taxonomiesSelectOptions?.length > 0 && ( <> {taxonomyFilterEnable && ( <> 0 ? taxonomiesSelectOptions : [{ label: "Default", value: "" }] } /> {selectedTaxonomy !== "" && taxonomyTypeTitle && ( setAttributes({ selectedTerms: e })} /> )} )} )} ); }; export const PopupCanvasGeneralTab = ({ attributes, setAttributes }) => { const { popupHeadingGap, enablePopupCloseButton, popupHeadingText, enablePopupHeading, popupCanvasWidth, popupCloseBtnIconSize, popupHeadingAlignment, } = attributes; return ( <> {enablePopupHeading && ( <> )} {enablePopupCloseButton && ( )} , value: "left" }, { label: , value: "center" }, { label: , value: "right" }, ]} /> ); };