@@ -7,7 +7,7 @@ import { isDefined } from "../../utils/utilities";
77import { TimelineContext } from "./Context" ;
88import "./Controls.styl" ;
99import * as SideControls from "./SideControls" ;
10- import { TimelineControlsFormatterOptions , TimelineControlsProps , TimelineControlsStepHandler , TimelineProps , TimelineStepFunction } from "./Types" ;
10+ import { TimelineControlsFormatterOptions , TimelineControlsProps , TimelineControlsStepHandler , TimelineCustomControls , TimelineProps , TimelineStepFunction } from "./Types" ;
1111
1212const positionFromTime = ( { time, fps } : TimelineControlsFormatterOptions ) => {
1313 const roundedFps = Math . round ( fps ) . toString ( ) ;
@@ -53,6 +53,7 @@ export const Controls: FC<TimelineControlsProps> = memo(({
5353 return ( position - 1 ) / frameRate ;
5454 } , [ position , frameRate ] ) ;
5555
56+ const customControls = useCustomControls ( props . customControls ) ;
5657 const stepHandlerWrapper = ( handler : TimelineControlsStepHandler , stepSize ?: TimelineStepFunction ) => ( e : MouseEvent < HTMLButtonElement > ) => {
5758 handler ( e , stepSize ?? undefined ) ;
5859 } ;
@@ -101,13 +102,15 @@ export const Controls: FC<TimelineControlsProps> = memo(({
101102 />
102103 ) ;
103104 } ) }
105+ { customControls ?. left }
104106 </ Elem >
105107
106108 < Elem name = "main-controls" >
107109 < Elem name = "group" tag = { Space } collapsed >
108110 { extraControls }
109111 </ Elem >
110112 < Elem name = "group" tag = { Space } collapsed >
113+ { customControls ?. leftCenter }
111114 < AltControls
112115 showAlterantive = { altControlsMode && ! disableFrames }
113116 main = { (
@@ -193,6 +196,7 @@ export const Controls: FC<TimelineControlsProps> = memo(({
193196 </ >
194197 ) }
195198 />
199+ { customControls ?. rightCenter }
196200 </ Elem >
197201 < Elem name = "group" tag = { Space } collapsed >
198202 { ! disableFrames && allowViewCollapse && (
@@ -219,6 +223,7 @@ export const Controls: FC<TimelineControlsProps> = memo(({
219223 </ Elem >
220224
221225 < Elem name = "group" tag = { Space } size = "small" >
226+ { customControls ?. right }
222227 < TimeDisplay
223228 currentTime = { currentTime }
224229 duration = { duration }
@@ -304,3 +309,22 @@ const AltControls: FC<AltControlsProps> = (props) => {
304309 return props . showAlterantive ? props . alt : props . main ;
305310} ;
306311
312+ type ControlGroups = Record < TimelineCustomControls [ "position" ] , JSX . Element [ ] > ;
313+
314+ const useCustomControls = (
315+ customControls ?: TimelineCustomControls [ ] ,
316+ ) : ControlGroups | null => {
317+ if ( ! customControls ) return null ;
318+
319+ const groups = customControls ?. reduce < ControlGroups > ( ( groups , item ) => {
320+ const group = groups [ item . position ] ?? [ ] ;
321+ const component = item . component instanceof Function ? item . component ( ) : item . component ;
322+
323+ group . push ( component ) ;
324+ groups [ item . position ] = group ;
325+
326+ return groups ;
327+ } , { } as ControlGroups ) ;
328+
329+ return groups ;
330+ } ;
0 commit comments