@@ -21,11 +21,11 @@ import {
21
21
JSONSchemaCyclesContext ,
22
22
} from "../../context"
23
23
24
- const JSONSchema = forwardRef ( ( { schema, name } , ref ) => {
24
+ const JSONSchema = forwardRef ( ( { schema, name, onExpand } , ref ) => {
25
25
const fn = useFn ( )
26
26
const isExpandedDeeply = useIsExpandedDeeply ( )
27
27
const [ expanded , setExpanded ] = useState ( isExpandedDeeply )
28
- const [ expandedDeeply , setExpandedDeeply ] = useState ( false )
28
+ const [ expandedDeeply , setExpandedDeeply ] = useState ( isExpandedDeeply )
29
29
const [ level , nextLevel ] = useLevel ( )
30
30
const isEmbedded = useIsEmbedded ( )
31
31
const isExpandable = fn . isExpandable ( schema )
@@ -68,18 +68,6 @@ const JSONSchema = forwardRef(({ schema, name }, ref) => {
68
68
const KeywordDescription = useComponent ( "KeywordDescription" )
69
69
const ExpandDeepButton = useComponent ( "ExpandDeepButton" )
70
70
71
- /**
72
- * Event handlers.
73
- */
74
- const handleExpansion = useCallback ( ( e , expandedNew ) => {
75
- setExpanded ( expandedNew )
76
- ! expandedNew && setExpandedDeeply ( false )
77
- } , [ ] )
78
- const handleExpansionDeep = useCallback ( ( e , expandedDeepNew ) => {
79
- setExpanded ( expandedDeepNew )
80
- setExpandedDeeply ( expandedDeepNew )
81
- } , [ ] )
82
-
83
71
/**
84
72
* Effects handlers.
85
73
*/
@@ -91,6 +79,26 @@ const JSONSchema = forwardRef(({ schema, name }, ref) => {
91
79
setExpandedDeeply ( expandedDeeply )
92
80
} , [ expandedDeeply ] )
93
81
82
+ /**
83
+ * Event handlers.
84
+ */
85
+ const handleExpansion = useCallback (
86
+ ( e , expandedNew ) => {
87
+ setExpanded ( expandedNew )
88
+ ! expandedNew && setExpandedDeeply ( false )
89
+ onExpand ( e , expandedNew , false )
90
+ } ,
91
+ [ onExpand ]
92
+ )
93
+ const handleExpansionDeep = useCallback (
94
+ ( e , expandedDeepNew ) => {
95
+ setExpanded ( expandedDeepNew )
96
+ setExpandedDeeply ( expandedDeepNew )
97
+ onExpand ( e , expandedDeepNew , true )
98
+ } ,
99
+ [ onExpand ]
100
+ )
101
+
94
102
return (
95
103
< JSONSchemaLevelContext . Provider value = { nextLevel } >
96
104
< JSONSchemaDeepExpansionContext . Provider value = { expandedDeeply } >
@@ -173,10 +181,12 @@ const JSONSchema = forwardRef(({ schema, name }, ref) => {
173
181
JSONSchema . propTypes = {
174
182
name : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . element ] ) ,
175
183
schema : propTypes . schema . isRequired ,
184
+ onExpand : PropTypes . func ,
176
185
}
177
186
178
187
JSONSchema . defaultProps = {
179
188
name : "" ,
189
+ onExpand : ( ) => { } ,
180
190
}
181
191
182
192
export default JSONSchema
0 commit comments