File size: 1,684 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { CellPlugin } from '@react-page/editor';
import React from 'react';

const customLayoutPlugin: CellPlugin<{
  backgroundColor: string;
  paddingX: number;
  paddingY: number;
  cellSpacingOverride?: boolean;
  cellSpacingX: number;
  cellSpacingY: number;
}> = {
  Renderer: ({ children, data }) => (
    <div
      style={{
        height: '100%',
        boxSizing: 'border-box',
        backgroundColor: data.backgroundColor,
        padding: `${data.paddingY}px ${data.paddingX}px`,
      }}
    >
      {children}
    </div>
  ),

  cellSpacing: (data) =>
    data.cellSpacingOverride
      ? { x: data.cellSpacingX, y: data.cellSpacingY }
      : null,

  createInitialData: () => ({
    backgroundColor: '#ffeeaa',
    paddingX: 12,
    paddingY: 12,
    cellSpacingOverride: false,
    cellSpacingX: 10,
    cellSpacingY: 10,
  }),

  id: 'custom-layout-plugin-with-cell-spacing',
  title: 'Background with Cell Spacing',
  description: 'Custom layout plugin with cell spacing support',
  version: 1,

  controls: {
    type: 'autoform',
    schema: {
      required: ['backgroundColor'],
      properties: {
        backgroundColor: { type: 'string', title: 'Background Color' },
        paddingX: { type: 'number', title: 'Horizontal Padding' },
        paddingY: { type: 'number', title: 'Vertical Padding' },
        cellSpacingOverride: {
          type: 'boolean',
          title: 'Override Cell Spacing',
        },
        cellSpacingX: {
          type: 'number',
          title: 'Horizontal Cell Spacing',
        },
        cellSpacingY: { type: 'number', title: 'Vertical Cell Spacing' },
      },
    },
  },
};

export default customLayoutPlugin;