PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.9.0
GiveWP – Donation Plugin and Fundraising Platform v3.9.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / DonationForms / resources / app / fields / GroupNode.tsx
GroupNode.tsx
38 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {Group, Node} from '@givewp/forms/types';
2 import {useTemplateWrapper} from '../templates';
3 import type {GroupProps} from '@givewp/forms/propTypes';
4 import SectionNode from './SectionNode';
5 import memoNode from '@givewp/forms/app/utilities/memoNode';
6
7 const formTemplates = window.givewp.form.templates;
8
9 /**
10 * Renders a group node and its children. At this point, group nodes are not generic, and are only used for specific
11 * subtypes of group fields, such as the Name field. The nodes are grouped by component and props, and then passed to
12 * the group template component. This way the group template controls how the nodes are rendered, and can choose to
13 * manipulate or override props.
14 *
15 * @since 3.0.0
16 */
17 function GroupNode({node}: {node: Group}) {
18 const Group = useTemplateWrapper<GroupProps>(formTemplates.groups[node.type], 'div', node.name);
19
20 const nodeComponents = node.reduceNodes((nodes, node: Node) => {
21 nodes[node.name] = (props: Node) => <SectionNode node={{...node, ...props}} />;
22
23 return nodes;
24 }, {});
25
26 const nodeProps = node.reduceNodes((nodes, node: Node) => {
27 nodes[node.name] = node;
28
29 return nodes;
30 }, {});
31
32 return <Group key={node.name} nodeComponents={nodeComponents} nodeProps={nodeProps} {...node} />;
33 }
34
35 const MemoizedGroupNode = memoNode(GroupNode);
36
37 export default MemoizedGroupNode;
38