# tableberg/1.1.5/components/editor/SpacingControl.tsx

Tableberg – Simple Gutenberg Table Block, version 1.1.5. 95 lines.

- Page: https://pluginprobe.com/plugins/tableberg/1.1.5/code/components/editor/SpacingControl.tsx
- Raw: https://pluginprobe.com/plugins/tableberg/1.1.5/raw/components/editor/SpacingControl.tsx
- Modified: 2026-09-16T03:30:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tableberg/1.1.5/code/components/editor/SpacingControl.tsx#L10-L20`.

```tsx
import {
    useBlockEditContext,
    __experimentalSpacingSizesControl as SpacingSizesControl,
} from "@wordpress/block-editor";
import { __experimentalToolsPanelItem as ToolsPanelItem } from "@wordpress/components";

function mutateOutgoingPaddingValue(padding: Padding) {
    for (const side in padding) {
        const key = side as keyof Padding;
        const value = padding[key];

        const slug = value?.match(/var:preset\|spacing\|(.+)/);
        if (!slug) {
            continue;
        }
        padding[key] = `var(--wp--preset--spacing--${slug[1]})`;
    }

    return padding;
}

function mutateIncomingPaddingValue(padding: Padding) {
    const newPadding = { ...padding };

    for (const side in newPadding) {
        const key = side as keyof Padding;
        const value = newPadding[key];

        const slug = value?.match(/var\(--wp--preset--spacing--(.+)\)/);
        if (!slug) {
            continue;
        }
        newPadding[key] = `var:preset|spacing|${slug[1]}`;
    }

    return newPadding;
}

type Padding = {
    top: string;
    right: string;
    bottom: string;
    left: string;
};

interface Props {
    label: string;
    value: Padding;
    hasValue: () => boolean;
    onChange: (newPadding: Padding) => any;
    resetAllFilter?: () => any;
    onDeselect: () => any;
    isShownByDefault?: boolean;
}

const SpacingControl = ({
    label,
    value,
    hasValue,
    onChange = () => {},
    resetAllFilter,
    onDeselect = () => {},
}: Props) => {
    const { clientId } = useBlockEditContext();
    const sides = ["top", "right", "bottom", "left"];

    if (!resetAllFilter) {
        resetAllFilter = onDeselect;
    }

    return (
        <ToolsPanelItem
            panelId={clientId}
            isShownByDefault={true}
            resetAllFilter={resetAllFilter}
            className={"tools-panel-item-spacing"}
            label={label}
            onDeselect={onDeselect}
            hasValue={hasValue}
        >
            <SpacingSizesControl
                allowReset={true}
                label={label}
                values={mutateIncomingPaddingValue(value)}
                sides={sides}
                onChange={newValue => {
                    onChange(mutateOutgoingPaddingValue(newValue));
                }}
            />
        </ToolsPanelItem>
    );
};

export default SpacingControl;

```
