@@ -27,22 +27,18 @@ export const fieldCommonProps = {
27
27
required : PropTypes . bool ,
28
28
} ;
29
29
30
- export const createCommonDepositFieldComponent = ( id , Child ) => {
31
- const Component = ( { hidden, ...props } ) => {
30
+ /**
31
+ * Creates a component that de-renders when the `hidden` prop is `true`.
32
+ * All props passed to the `ShowHideComponent` are forwarded to the child component except the `hidden` prop.
33
+ *
34
+ * @param Component - The child component
35
+ * @param {string= } id - An optional OverridableID for debugging purposes
36
+ */
37
+ export const createShowHideComponent = ( Component , id ) => {
38
+ const ShowHideComponent = ( { hidden, ...props } ) => {
32
39
if ( props . disabled && props . required ) {
33
40
throw new Error ( `Cannot make field component ${ id } both required and disabled` ) ;
34
41
}
35
-
36
- if ( hidden ) return null ;
37
- return < Child { ...props } /> ;
38
- } ;
39
-
40
- Component . propTypes = Child . propTypes ;
41
- return Overridable . component ( id , Component ) ;
42
- } ;
43
-
44
- export const createShowHideComponent = ( Component ) => {
45
- const ShowHideComponent = ( { hidden, ...props } ) => {
46
42
if ( hidden ) return null ;
47
43
return < Component { ...props } /> ;
48
44
} ;
@@ -55,7 +51,26 @@ export const createShowHideComponent = (Component) => {
55
51
return ShowHideComponent ;
56
52
} ;
57
53
58
- export const createDynamicOverridableWidget = ( Widget ) => {
54
+ /**
55
+ * Creates an overridable component with show/hide functionality based on the `hidden` prop.
56
+ * All high-level fields in the deposit form are exported through this function, and this
57
+ * is the only version of the component that should be exported.
58
+ *
59
+ * @param {string } id - The Overridable ID to use
60
+ * @param Child - The unexported child component
61
+ */
62
+ export const createCommonDepositFieldComponent = ( id , Child ) => {
63
+ const Component = createShowHideComponent ( Child ) ;
64
+ Component . propTypes = Child . propTypes ;
65
+ return Overridable . component ( id , Component ) ;
66
+ } ;
67
+
68
+ /**
69
+ * Create a component whos Overridable ID is defined via a prop at runtime rather than pre-assigned.
70
+ * This is necessary for custom fields, where Python will inject the Overridable ID from the user's
71
+ * configuration, allowing features like `parametrize` to be applied also to custom fields.
72
+ */
73
+ export const createDynamicOverridableComponent = ( Widget ) => {
59
74
const Component = ( { id, ...props } ) => {
60
75
if ( id === undefined ) return < Widget { ...props } /> ;
61
76
0 commit comments