import { __ } from "@wordpress/i18n"; import { Layouts, SelectField, SPRangeControl, Toggle, SPToggleGroupControl, Background, InputControl, } from "../../components"; import { store as blockEditorStore } from "@wordpress/block-editor"; import useLayouts from "../../hooks/useLayouts"; import { useEffect, useRef, useState } from "@wordpress/element"; import { useDeviceType } from "../../controls/controls"; import { FlexAlignCenter, FlexAlignEnd, FlexAlignStart, FlexAlignStretch, FlexColumn, FlexColumnReverse, FlexJustifyCenter, FlexJustifyEnd, FlexJustifySpaceAround, FlexJustifySpaceBetween, FlexJustifySpaceEvenly, FlexJustifyStart, FlexNoWrap, FlexRow, FlexRowReverse, FlexWrap, } from "../../icons/icons"; import { BgIcon, GradientIcon } from "../../components/background/svgIcon"; import { layoutsColumnsWidth } from "./containerConstant"; import { useSelect, useDispatch, select } from "@wordpress/data"; import { createBlock } from "@wordpress/blocks"; import ProInfo from "../../components/proInfo/proInfo"; export const ContainerGeneralTab = ({ attributes, setAttributes }) => { const { columns, blockName, blockClientId, layerLayoutNo, layout, containerLayer, containerWidth, containerCustomWidth, contentWidth, contentHeightType, containerMinHeight, columnsGap, rowGap, equalHeight, htmlTag, containerOverflow, columnsTablet, columnsMobile, } = attributes; const deviceType = useDeviceType(); const deviceColumn = columns || "multi-row"; const layouts = useLayouts(`${blockName}-column-${deviceColumn}`, layout); const innerBlocks = useSelect( (select) => select(blockEditorStore).getBlocks(blockClientId), [blockClientId, columns, layout] ); const { updateBlockAttributes, replaceInnerBlocks } = useDispatch(blockEditorStore); const layoutChangeHandler = (newValue) => { if (newValue === layout) { return; } setAttributes({ layout: newValue }); }; const onColumnsChangeHandler = (newValue, key) => { setAttributes({ [key]: newValue }); if (newValue === columns) { return; } // If child block is less then columns value then create and add a new child block. if (newValue > innerBlocks?.length && "Desktop" === deviceType) { const updatedBlocks = []; for (let index = 0; index < newValue; index++) { const existingBlock = innerBlocks[index]; if (existingBlock) { const updatedAttributes = { ...existingBlock.attributes, }; const updatedBlock = createBlock( existingBlock.name, updatedAttributes, existingBlock.innerBlocks // preserve nested content. ); updatedBlocks.push(updatedBlock); } else { updatedBlocks.push( createBlock("sp-smart-post-show/column", { id: `sp-smart-column-${101 + index}`, }) ); } } replaceInnerBlocks(blockClientId, updatedBlocks, false); } }; useEffect(() => { const indexNo = layerLayoutNo !== "" ? layerLayoutNo : 0; if (containerLayer && layout === "") { setAttributes({ layout: layouts[indexNo]?.value }); } }, []); useEffect(() => { const matchLayout = layouts?.some((item) => item.value === layout); if (!matchLayout && layouts && columns) { setAttributes({ layout: layouts[0]?.value }); } }, [layouts]); const columnsKey = { Desktop: "columns", Tablet: "columnsTablet", Mobile: "columnsMobile", } const columnsValue = { Desktop: columns, Tablet: columnsTablet, Mobile: columnsMobile, } const onContainerWidthHandler = ( newValue ) => { if ( newValue === containerWidth ) { return; } const alignValue = newValue === "full-width" ? "full" : "none"; setAttributes({ containerWidth: newValue, align: alignValue, }) } return ( <> {!containerLayer.includes("layer-multi-row") && ( onColumnsChangeHandler(value, columnsKey[deviceType])} responsiveIcon={true} /> )} {layouts?.length > 0 && ( )} {"boxed" === containerWidth && ( )} {contentHeightType === "min-height" && ( )} {innerBlocks.length > 1 && ( <> )} ); }; export const ContainerFlexProperties = ({ attributes, setAttributes }) => { const { containerFlexDirection, containerJustifyContent, containerFlexWrap, containerAlignItem, blockClientId } = attributes; const deviceType = useDeviceType(); const { getBlockOrder } = useSelect((select) => select("core/block-editor")); const { updateBlockAttributes } = useDispatch("core/block-editor"); const handleFlexDir = (value) => { if (value === containerFlexDirection?.device?.[deviceType]) { return; } const childBlocks = getBlockOrder(blockClientId); if (["column", "column-reverse"].includes(value)) { childBlocks?.forEach((childBlock) => { updateBlockAttributes(childBlock, { // columnWidth: { // device: { Desktop: 100, Tablet: 100, Mobile: 100 }, // unit: { Desktop: "%", Tablet: "%", Mobile: "%" }, // }, }); }); } else { const colWidth = 100 / childBlocks?.length; childBlocks?.forEach((childBlock) => { updateBlockAttributes(childBlock, { // columnWidth: { // device: { // Desktop: colWidth, // Tablet: colWidth, // Mobile: 100, // }, // unit: { Desktop: "%", Tablet: "%", Mobile: "%" }, // }, }); }); } setAttributes({ containerFlexDirection: { ...containerFlexDirection, device: { ...containerFlexDirection.device, [deviceType]: value, }, }, }); }; const onFlexWarpHandler = (value) => { if (value === containerFlexWrap?.device?.[deviceType]) { return; } const childBlocks = getBlockOrder(blockClientId); const updateColWidth = parseFloat((100 / childBlocks?.length).toFixed(2)); if (["nowrap"].includes(value) && ["row", "row-reverse"].includes(containerFlexDirection?.device?.[deviceType])) { childBlocks?.forEach((childBlock) => { updateBlockAttributes(childBlock, { // columnWidth: { // device: { // Desktop: updateColWidth, // Tablet: updateColWidth, // Mobile: 100 // }, // unit: { Desktop: "%", Tablet: "%", Mobile: "%" }, // }, }); }); } setAttributes({ containerFlexWrap: { ...containerFlexWrap, device: { ...containerFlexWrap.device, [deviceType]: value, }, }, }); }; return ( <> handleFlexDir(value)} items={[ { label: , value: "row", tooltip: "Row" }, { label: , value: "column", tooltip: "Column", }, { label: , value: "row-reverse", tooltip: "Row Reverse", }, { label: , value: "column-reverse", tooltip: "Column Reverse", }, ]} /> , value: "flex-start", tooltip: "Flex Start", }, { label: , value: "center", tooltip: "Center", }, { label: , value: "flex-end", tooltip: "Flex End", }, { label: , value: "space-between", tooltip: "Space Between", }, { label: , value: "space-around", tooltip: "Space Around", }, { label: , value: "space-evenly", tooltip: "Space Evenly", }, ]} /> onFlexWarpHandler(value)} items={[ { label: , value: "wrap", tooltip: "Wrap" }, { label: , value: "nowrap", tooltip: "No Wrap", }, // { // label: , // value: 'wrap-reverse', // tooltip: 'Wrap Reverse', // }, ]} /> , value: "flex-start", tooltip: "Flex Start", }, { label: , value: "center", tooltip: "Center", }, { label: , value: "flex-end", tooltip: "Flex End", }, { label: , value: "stretch", tooltip: "Stretch", }, ]} /> ); }; export const ContainerShapeDivider = ({ attributes, setAttributes }) => { const { containerShapeDivider, containerTopDividerType, containerBottomDividerType, shapeDividerBgColorTop, shapeDividerWidthTop, shapeDividerHeightTop, shapeDividerFlipTop, shapeDividerBringToFrontTop, shapeDividerBgColorBottom, shapeDividerWidthBottom, shapeDividerHeightBottom, shapeDividerFlipBottom, shapeDividerBringToFrontBottom, } = attributes; const dividerType = [ { label: "None", value: "none" }, { label: "Waves", value: "waves" }, { label: "Mountains (Pro)", value: "mountains", disabled: true }, { label: "Drops (Pro)", value: "drops", disabled: true }, { label: "Clouds (Pro)", value: "clouds", disabled: true }, { label: "Zigzag (Pro)", value: "zigzag", disabled: true }, { label: "Pyramids (Pro)", value: "pyramids", disabled: true }, { label: "Triangle (Pro)", value: "triangle", disabled: true }, { label: "Triangle Asymmetrical (Pro)", value: "triangle-asymmetrical", disabled: true }, { label: "Tilt (Pro)", value: "tilt", disabled: true }, { label: "Tilt Opacity (Pro)", value: "tilt-opacity", disabled: true }, { label: "Fan Opacity (Pro)", value: "fan-opacity", disabled: true }, { label: "Curve (Pro)", value: "curve", disabled: true }, { label: "Curve Asymmetrical (Pro)", value: "curve-asymmetrical", disabled: true }, { label: "Waves Brush (Pro)", value: "waves-brush", disabled: true }, { label: "Waves Pattern (Pro)", value: "waves-pattern", disabled: true }, { label: "Arrow (Pro)", value: "arrow", disabled: true }, { label: "Arrow Split (Pro)", value: "arrow-split", disabled: true }, { label: "Book (Pro)", value: "book", disabled: true }, ] return ( <> {"top" === containerShapeDivider && ( )} {"bottom" === containerShapeDivider && ( )} {"top" === containerShapeDivider && "none" !== containerTopDividerType && ( <> , value: "bgColor", tooltip: "Solid", }, { label: , value: "gradient", tooltip: "Gradient", }, ]} /> )} {"bottom" === containerShapeDivider && "none" !== containerBottomDividerType && ( <> , value: "bgColor", tooltip: "Solid", }, { label: , value: "gradient", tooltip: "Gradient", }, ]} /> )}

Premium Only

Unlock advanced shape divider controls for more flexible section styling.

  • — 18+ Unique Divider Styles
  • — Custom width and height adjustment
  • — Flip shape orientation
  • — Bring divider to front
  • — Enhanced layout positioning
Upgrade to Pro
); }; export const ContainerAdvancedGeneralTab = ({ attributes, setAttributes }) => { const { advanceZIndex, advanceWrapperLink, advanceWrapperLinkUrl, advanceWrapperLinkNewTab } = attributes; return ( <> {advanceWrapperLink && ( <> )} ); };