import { __ } from "@wordpress/i18n"; import { Background, Border, BoxShadow, InputControl, MultiSelectDndKit, SelectField, Spacing, SpColorPicker, SPRangeControl, SPToggleGroupControl, Toggle, TypographyNew, } from "../../components"; import { BackToTopArrowFive, BackToTopArrowFour, BackToTopArrowOne, BackToTopArrowThree, BackToTopArrowTwo, } from "../template-parts/icons"; import { BgIcon, GradientIcon } from "../../components/background/svgIcon"; import { useSelect } from "@wordpress/data"; import { useEffect, useMemo, useState } from "@wordpress/element"; import classNames from "classnames"; import moduleDynamicCss from "../template-parts/moduleDynamicCss"; import { googleFonts } from "../../controls/controls"; export const BackToTopGeneral = ({ attributes, props }) => { const { setSettingsValue } = props; const { display_position, horizontal_position, vertical_position, back_to_top_icon, top_icon_source, icon_size, back_top_label, display_on, exclude_page, include_only, smooth_scroll, transition_delay, entrance_animation, go_to_bottom, back_bottom_label, } = attributes?.options; const [pageListItems, setPageListItems] = useState([]); const allPagesList = useSelect((select) => { return select("core").getEntityRecords("postType", "page", { per_page: -1, status: "publish", _fields: "id,title,slug", }); }, []); useEffect(() => { const topTen = allPagesList?.map((item) => ({ id: item.id, label: item.title?.rendered, value: item.slug })) || []; setPageListItems(topTen); }, [allPagesList]); const updateStateHandler = (valueKey, value) => { setSettingsValue({ ...attributes, options: { ...attributes.options, [valueKey]: value } }); }; return ( <> updateStateHandler("display_position", newValue)} items={[ { label: "Button Left", value: "button-left" }, { label: "Button Right", value: "button-right" }, ]} /> updateStateHandler("horizontal_position", { ...horizontal_position, value: newValue?.value }) } onUnitChange={(newUnit) => updateStateHandler("horizontal_position", { ...horizontal_position, unit: newUnit?.unit }) } setCustomReset={true} /> updateStateHandler("vertical_position", { ...vertical_position, value: newValue?.value }) } onUnitChange={(newUnit) => updateStateHandler("vertical_position", { ...vertical_position, unit: newUnit?.unit }) } setCustomReset={true} /> updateStateHandler("back_to_top_icon", !newToggle)} /> {back_to_top_icon && ( <> updateStateHandler("top_icon_source", newValue)} items={[ { label: , value: "top-arrow-one" }, { label: , value: "top-arrow-two" }, { label: , value: "top-arrow-three" }, { label: , value: "top-arrow-four" }, { label: , value: "top-arrow-five" }, ]} /> updateStateHandler("icon_size", { ...icon_size, value: newValue?.value }) } onUnitChange={(newUnit) => updateStateHandler("icon_size", { ...icon_size, unit: newUnit?.unit }) } setCustomReset={true} /> )} updateStateHandler("back_top_label", newValue)} /> updateStateHandler("display_on", newValue)} items={[ { label: "All Pages", value: "all-pages" }, { label: "Only Archive Pages", value: "only-archive-pages" }, { label: "Single Post Pages", value: "single-pages" }, { label: "Specific Pages", value: "specific-pages" }, ]} /> {display_on === "specific-pages" && ( updateStateHandler("include_only", e)} items={pageListItems} /> )} {display_on === "all-pages" && ( updateStateHandler("exclude_page", e)} items={pageListItems} /> )} updateStateHandler("smooth_scroll", !newToggle)} /> {smooth_scroll && ( updateStateHandler("transition_delay", { ...transition_delay, value: newValue?.value }) } onUnitChange={(newUnit) => updateStateHandler("transition_delay", { ...transition_delay, unit: newUnit?.unit }) } setCustomReset={true} /> )} updateStateHandler("entrance_animation", newValue)} items={[ { label: "Fade In", value: "fade-in" }, { label: "Slide In Left", value: "slide-in-left" }, { label: "Slide In Right", value: "slide-in-right" }, { label: "Slide In Up", value: "slide-in-up" }, ]} /> updateStateHandler("go_to_bottom", !newVal)} /> {go_to_bottom && ( updateStateHandler("back_bottom_label", newValue)} /> )} ); }; export const BackToTopStyle = ({ attributes, props }) => { const { setSettingsValue } = props; const { typography, font_size, line_height, letter_spacing, word_spacing, color, background_color, border, border_width, border_radius, box_shadow_enable, box_shadow, box_shadow_enable_hover, box_shadow_hover, padding, } = attributes?.options; const [colorState, setColorState] = useState("color"); const updateStateHandler = (valueKey, value) => { setSettingsValue({ ...attributes, options: { ...attributes.options, [valueKey]: value } }); }; const updateSpacingUtilityHandler = (attrKey, attr, type, newUtility) => { const updateAttr = { ...attr, [type]: newUtility }; updateStateHandler(attrKey, updateAttr); }; const updateValueByColorState = (valueKey, value, attr, state) => { const updateValue = { ...attr, [state]: value }; updateStateHandler(valueKey, updateValue); }; return ( <> updateStateHandler(valueKey, value)} /> setColorState(newValue)} items={[ { label: "Normal", value: "color" }, { label: "Hover", value: "hover" }, ]} /> {colorState === "color" ? ( <> updateValueByColorState("color", newValue, color, "color")} /> updateStateHandler("background_color", value, background_color, "color") } colorType={"color"} items={[ { label: , value: "bgColor", tooltip: "Solid", }, { label: , value: "gradient", tooltip: "Gradient", }, ]} /> updateStateHandler("box_shadow_enable", !newVal)} /> {box_shadow_enable && ( {}} onChange={(key, newVal) => updateStateHandler(key, newVal)} /> )} ) : ( <> updateValueByColorState("color", newValue, color, "hoverColor")} /> updateStateHandler("background_color", value)} colorType={"hover"} items={[ { label: , value: "bgColor", tooltip: "Solid", }, { label: , value: "gradient", tooltip: "Gradient", }, ]} /> updateStateHandler("box_shadow_enable_hover", !newVal)} /> {box_shadow_enable_hover && ( {}} onChange={(key, newVal) => updateStateHandler(key, newVal)} /> )} )} updateStateHandler(key, newValue)} /> updateStateHandler("border_radius", newValue)} onUnitChange={(unit) => updateSpacingUtilityHandler("border_radius", border_radius, "unit", unit)} updateAllChange={(newAllChange) => updateSpacingUtilityHandler("border_radius", border_radius, "allChange", newAllChange) } /> updateStateHandler("padding", newValue)} onUnitChange={(unit) => updateSpacingUtilityHandler("padding", padding, "unit", unit)} updateAllChange={(newAllChange) => updateSpacingUtilityHandler("padding", padding, "allChange", newAllChange) } /> ); }; export const BackToTopPreview = ({ attributes, props }) => { const { setSettingsValue } = props; const { display_position, back_to_top_icon, top_icon_source, back_top_label, smooth_scroll, entrance_animation, go_to_bottom, back_bottom_label, fontListsEditPage, typography, icon_size, font_size, line_height, letter_spacing, word_spacing, color, background_color, border, border_width, border_radius, box_shadow_enable, box_shadow, padding, margin, horizontal_position, vertical_position, box_shadow_enable_hover, box_shadow_hover, display_on, exclude_page, include_only, transition_delay, } = attributes?.options; const dynamicStyle = useMemo(() => { return moduleDynamicCss(attributes?.options); }, [attributes?.options]); const iconListObj = { "top-arrow-one": , "top-arrow-two": , "top-arrow-three": , "top-arrow-four": , "top-arrow-five": , }; const wrapperClass = classNames( "sp-smart-post-back-to-top-wrapper", `sp-position-${display_position}`, `sp-animation-${entrance_animation}`, smooth_scroll && " sp-scroll-smooth" ); const updateStateHandler = (valueKey, value) => { setSettingsValue({ ...attributes, options: { ...attributes.options, [valueKey]: value } }); }; useEffect(() => { updateStateHandler("dynamic_style", moduleDynamicCss(attributes?.options)); // eslint-disable-next-line }, [ icon_size, typography, font_size, line_height, letter_spacing, word_spacing, color, background_color, border, border_width, border_radius, box_shadow_enable, box_shadow, padding, margin, display_position, back_to_top_icon, top_icon_source, back_top_label, smooth_scroll, entrance_animation, go_to_bottom, back_bottom_label, fontListsEditPage, horizontal_position, vertical_position, box_shadow_enable_hover, box_shadow_hover, display_on, exclude_page, include_only, transition_delay, ]); const googleFontLists = [typography]; useEffect(() => { updateStateHandler("fontListsEditPage", googleFonts(googleFontLists)); // eslint-disable-next-line }, [typography]); return ( <>
{back_to_top_icon && ( {iconListObj[top_icon_source]} )} {back_top_label && ( {back_top_label} )} {/* {go_to_bottom && back_bottom_label && ( {back_bottom_label} )} */}
); };