@@ -104,113 +104,111 @@ export interface Collect {
104104
105105export const CollectorContext = React . createContext < Collect | undefined > ( undefined ) ;
106106
107- export default class Collector extends React . Component < CollectorProps > {
108- render ( ) {
109- const {
110- children,
111- style,
112- className,
113- data,
114- receiveRenderChildren,
115- receiveRef,
116- receiveData,
117- topMostCollector,
118- } = this . props ;
119-
120- if ( typeof children !== 'function' ) {
121- return (
122- < CollectorContext . Consumer >
123- { collect => (
124- < CollectorContext . Provider
125- value = { {
126- ref : ref => {
127- if ( receiveRef ) {
128- receiveRef ( ref ) ;
129- }
130-
131- if ( ! topMostCollector && collect ) {
132- collect . ref ( ref ) ;
133- }
134- } ,
135- focalTargetRef : ref => {
136- const { receiveFocalTargetRef } = this . props ;
137- if ( receiveFocalTargetRef ) {
138- receiveFocalTargetRef ( ref ) ;
139- }
140-
141- if ( ! topMostCollector && collect ) {
142- collect . focalTargetRef ( ref ) ;
143- }
144- } ,
145- data : childData => {
146- const collectedData = data ? [ data ] . concat ( childData ) : childData ;
147- if ( ! topMostCollector && collect ) {
148- collect . data ( collectedData ) ;
149- }
150-
151- if ( receiveData ) {
152- receiveData ( childData ) ;
153- }
154- } ,
155- renderChildren : node => {
156- if ( ! topMostCollector && collect ) {
157- collect . renderChildren ( node ) ;
158- }
159-
160- if ( receiveRenderChildren ) {
161- receiveRenderChildren ( node ) ;
162- }
163- } ,
164- style : {
165- ...style ,
166- ...( collect && ! topMostCollector ? collect . style : { } ) ,
167- } ,
168- className :
169- className || ( collect && ! topMostCollector ? collect . className : undefined ) ,
170- } }
171- >
172- { children }
173- </ CollectorContext . Provider >
174- ) }
175- </ CollectorContext . Consumer >
176- ) ;
177- }
178-
107+ const Collector : React . FC < CollectorProps > = ( {
108+ children,
109+ style,
110+ className,
111+ data,
112+ receiveRenderChildren,
113+ receiveRef,
114+ receiveData,
115+ topMostCollector,
116+ receiveFocalTargetRef,
117+ } : CollectorProps ) => {
118+ if ( typeof children !== 'function' ) {
179119 return (
180120 < CollectorContext . Consumer >
181- { collect => {
182- if ( typeof children === 'function' ) {
183- if ( ! topMostCollector && collect ) {
184- const collectedData = data ? [ data ] : [ ] ;
185- collect . renderChildren ( children ) ;
186- collect . data ( collectedData ) ;
187- }
188-
189- if ( receiveRenderChildren ) {
190- receiveRenderChildren ( children ) ;
191- }
192-
193- return React . Children . only (
194- children ( {
195- className :
196- className || ( collect && ! topMostCollector ? collect . className : undefined ) ,
197- ref : ( ref : HTMLElement ) => {
198- if ( ! topMostCollector && collect ) {
199- collect . ref ( ref ) ;
200- }
201-
202- if ( receiveRef ) {
203- receiveRef ( ref ) ;
204- }
205- } ,
206- style : collect && ! topMostCollector ? { ...style , ...collect . style } : style || { } ,
207- } )
208- ) ;
209- }
210-
211- throw new Error ( 'Children is guaranteed to be a function. Impossible condition.' ) ;
212- } }
121+ { collect => (
122+ < CollectorContext . Provider
123+ value = { {
124+ ref : ref => {
125+ if ( receiveRef ) {
126+ receiveRef ( ref ) ;
127+ }
128+
129+ if ( ! topMostCollector && collect ) {
130+ collect . ref ( ref ) ;
131+ }
132+ } ,
133+ focalTargetRef : ref => {
134+ if ( receiveFocalTargetRef ) {
135+ receiveFocalTargetRef ( ref ) ;
136+ }
137+
138+ if ( ! topMostCollector && collect ) {
139+ collect . focalTargetRef ( ref ) ;
140+ }
141+ } ,
142+ data : childData => {
143+ const collectedData = data ? [ data ] . concat ( childData ) : childData ;
144+ if ( ! topMostCollector && collect ) {
145+ collect . data ( collectedData ) ;
146+ }
147+
148+ if ( receiveData ) {
149+ receiveData ( childData ) ;
150+ }
151+ } ,
152+ renderChildren : node => {
153+ if ( ! topMostCollector && collect ) {
154+ collect . renderChildren ( node ) ;
155+ }
156+
157+ if ( receiveRenderChildren ) {
158+ receiveRenderChildren ( node ) ;
159+ }
160+ } ,
161+ style : {
162+ ...style ,
163+ ...( collect && ! topMostCollector ? collect . style : { } ) ,
164+ } ,
165+ className :
166+ className || ( collect && ! topMostCollector ? collect . className : undefined ) ,
167+ } }
168+ >
169+ { children }
170+ </ CollectorContext . Provider >
171+ ) }
213172 </ CollectorContext . Consumer >
214173 ) ;
215174 }
216- }
175+
176+ return (
177+ < CollectorContext . Consumer >
178+ { collect => {
179+ if ( typeof children === 'function' ) {
180+ if ( ! topMostCollector && collect ) {
181+ const collectedData = data ? [ data ] : [ ] ;
182+ collect . renderChildren ( children ) ;
183+ collect . data ( collectedData ) ;
184+ }
185+
186+ if ( receiveRenderChildren ) {
187+ receiveRenderChildren ( children ) ;
188+ }
189+
190+ return React . Children . only (
191+ children ( {
192+ className :
193+ className || ( collect && ! topMostCollector ? collect . className : undefined ) ,
194+ ref : ( ref : HTMLElement ) => {
195+ if ( ! topMostCollector && collect ) {
196+ collect . ref ( ref ) ;
197+ }
198+
199+ if ( receiveRef ) {
200+ receiveRef ( ref ) ;
201+ }
202+ } ,
203+ style : collect && ! topMostCollector ? { ...style , ...collect . style } : style || { } ,
204+ } )
205+ ) ;
206+ }
207+
208+ return null ;
209+ } }
210+ </ CollectorContext . Consumer >
211+ ) ;
212+ } ;
213+
214+ export default Collector ;
0 commit comments