Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit ed027c5

Browse files
fix: DEV-3405: Move zoom buttons to video's control panel (#847)
* Move zoom buttons to video's control panel * Fixes as per the review * Update src/components/Timeline/Controls.tsx Co-authored-by: yyassi-heartex <[email protected]>
1 parent 8d7eab3 commit ed027c5

File tree

6 files changed

+63
-19
lines changed

6 files changed

+63
-19
lines changed

src/common/Button/Button.styl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
background none
115115
padding 21px 54px
116116
font-size 13px
117-
117+
118118
&_alt
119119
--button-color #000
120120
box-shadow none
@@ -181,6 +181,9 @@
181181
margin-left 10px
182182
margin-right -10px
183183

184+
&_nopadding
185+
padding 0
186+
184187
&_withIcon
185188
justify-content space-between
186189

src/common/Button/Button.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ButtonProps extends HTMLButtonProps {
2626
style?: CSSProperties;
2727
hotkey?: keyof typeof Hotkey.keymap;
2828
tooltip?: string;
29+
nopadding?: boolean;
2930
}
3031

3132
export interface ButtonGroupProps {
@@ -51,6 +52,7 @@ export const Button: ButtonType<ButtonProps> = forwardRef(({
5152
danger,
5253
hotkey,
5354
tooltip,
55+
nopadding,
5456
...rest
5557
}, ref) => {
5658
const finalTag = tag ?? (rest.href ? "a" : "button");
@@ -60,6 +62,7 @@ export const Button: ButtonType<ButtonProps> = forwardRef(({
6062
waiting,
6163
type,
6264
danger,
65+
nopadding,
6366
look: look ?? [],
6467
withIcon: !!icon,
6568
withExtra: !!extra,

src/components/Timeline/Controls.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isDefined } from "../../utils/utilities";
77
import { TimelineContext } from "./Context";
88
import "./Controls.styl";
99
import * as SideControls from "./SideControls";
10-
import { TimelineControlsFormatterOptions, TimelineControlsProps, TimelineControlsStepHandler, TimelineProps, TimelineStepFunction } from "./Types";
10+
import { TimelineControlsFormatterOptions, TimelineControlsProps, TimelineControlsStepHandler, TimelineCustomControls, TimelineProps, TimelineStepFunction } from "./Types";
1111

1212
const 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+
};

src/components/Timeline/Timeline.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const TimelineComponent: FC<TimelineProps> = ({
126126
playing={playing}
127127
volume={props.volume}
128128
controls={props.controls}
129+
customControls={props.customControls}
129130
collapsed={viewCollapsed}
130131
onPlay={() => handlers.onPlay?.()}
131132
onPause={() => handlers.onPause?.()}

src/components/Timeline/Types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface TimelineProps<D extends ViewTypes = "frames"> {
2828
data?: any;
2929
controlsOnTop?: boolean;
3030
controls?: TimelineControls;
31+
customControls?: TimelineCustomControls[];
3132
onReady?: (data: Record<string, any>) => void;
3233
onPlay?: () => void;
3334
onPause?: () => void;
@@ -153,6 +154,7 @@ export interface TimelineControlsProps {
153154
allowFullscreen?: boolean;
154155
allowViewCollapse?: boolean;
155156
controls?: TimelineProps["controls"];
157+
customControls?: TimelineCustomControls[];
156158
onRewind: (steps?: number) => void;
157159
onForward: (steps?: number) => void;
158160
onPositionChange: (position: number) => void;
@@ -166,6 +168,11 @@ export interface TimelineControlsProps {
166168
onVolumeChange: TimelineProps["onVolumeChange"];
167169
}
168170

171+
export interface TimelineCustomControls {
172+
position: "left" | "right" | "leftCenter" | "rightCenter";
173+
component: JSX.Element | (() => JSX.Element);
174+
}
175+
169176
export interface TimelineSideControlProps {
170177
position?: number;
171178
length?: number;

src/tags/object/Video/HtxVideo.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import "./Video.styl";
1818
import { VideoRegions } from "./VideoRegions";
1919
import ResizeObserver from "../../../utils/resize-observer";
2020
import { useFullscreen } from "../../../hooks/useFullscreen";
21+
import { IconZoomIn } from "../../../assets/icons";
2122

2223
// const hotkeys = Hotkey("Video", "Video Annotation");
2324

@@ -310,23 +311,6 @@ const HtxVideoView = ({ item }) => {
310311
))}
311312

312313
<Block name="video" mod={{ fullscreen: isFullScreen }} ref={videoBlockRef}>
313-
<Elem tag={Space} name="controls" align="end" size="small">
314-
<Dropdown.Trigger
315-
inline={isFullScreen}
316-
content={(
317-
<Menu size="medium" style={{ width: 150 }} closeDropdownOnItemClick={false}>
318-
<Menu.Item onClick={zoomIn}>Zoom In</Menu.Item>
319-
<Menu.Item onClick={zoomOut}>Zoom Out</Menu.Item>
320-
<Menu.Item onClick={zoomToFit}>Zoom To Fit</Menu.Item>
321-
<Menu.Item onClick={zoomReset}>Zoom 100%</Menu.Item>
322-
</Menu>
323-
)}
324-
>
325-
<Button size="small">
326-
Zoom {Math.round(zoom * 100)}%
327-
</Button>
328-
</Dropdown.Trigger>
329-
</Elem>
330314
<Elem
331315
name="main"
332316
ref={videoContainerRef}
@@ -386,6 +370,28 @@ const HtxVideoView = ({ item }) => {
386370
disableView={!supportsRegions}
387371
framerate={item.framerate}
388372
controls={{ FramesControl: true }}
373+
customControls={[
374+
{
375+
position: "left",
376+
component: () => {
377+
return (
378+
<Dropdown.Trigger
379+
inline={isFullScreen}
380+
content={(
381+
<Menu size="auto" closeDropdownOnItemClick={false}>
382+
<Menu.Item onClick={zoomIn}>Zoom In</Menu.Item>
383+
<Menu.Item onClick={zoomOut}>Zoom Out</Menu.Item>
384+
<Menu.Item onClick={zoomToFit}>Zoom To Fit</Menu.Item>
385+
<Menu.Item onClick={zoomReset}>Zoom 100%</Menu.Item>
386+
</Menu>
387+
)}
388+
>
389+
<Button size="small" nopadding><IconZoomIn/></Button>
390+
</Dropdown.Trigger>
391+
);
392+
},
393+
},
394+
]}
389395
onPositionChange={handleTimelinePositionChange}
390396
onPlay={handlePlay}
391397
onPause={handlePause}

0 commit comments

Comments
 (0)