|
1 | 1 | import { useEffect, useRef } from "react"; |
2 | | -import { Image, Magnet, MagnifyingGlassMinus, MagnifyingGlassPlus } from "@phosphor-icons/react"; |
| 2 | +import { |
| 3 | + ArrowsOutLineHorizontal, |
| 4 | + Image, |
| 5 | + Magnet, |
| 6 | + MagnifyingGlassMinus, |
| 7 | + MagnifyingGlassPlus, |
| 8 | +} from "@phosphor-icons/react"; |
3 | 9 | import { |
4 | 10 | useEnableKeyframes, |
5 | 11 | isPlayheadWithinTween, |
@@ -38,6 +44,8 @@ export interface TimelineToolbarProps { |
38 | 44 | onSplitElement?: (element: TimelineElement, splitTime: number) => void; |
39 | 45 | history?: TimelineHistoryButtonsProps; |
40 | 46 | showAddBeat?: boolean; |
| 47 | + /** Hides Add keyframe and auto-record, and turns off auto-record and the K shortcut with them. */ |
| 48 | + showKeyframes?: boolean; |
41 | 49 | } |
42 | 50 |
|
43 | 51 | interface KeyframeToggleState { |
@@ -134,6 +142,7 @@ export function TimelineToolbar({ |
134 | 142 | onSplitElement, |
135 | 143 | history, |
136 | 144 | showAddBeat = true, |
| 145 | + showKeyframes = true, |
137 | 146 | }: TimelineToolbarProps) { |
138 | 147 | const activeTool = usePlayerStore((s) => s.activeTool); |
139 | 148 | const setActiveTool = usePlayerStore((s) => s.setActiveTool); |
@@ -174,10 +183,14 @@ export function TimelineToolbar({ |
174 | 183 | // Wire the "Add keyframe (K)" shortcut the toolbar advertises. Active only when |
175 | 184 | // there's a keyframeable selection; otherwise K stays JKL-pause in playback. |
176 | 185 | useKeyframeKeyboard({ |
177 | | - enabled: Boolean(onToggleKeyframe), |
| 186 | + enabled: showKeyframes && Boolean(onToggleKeyframe), |
178 | 187 | onAddKeyframe: onToggleKeyframe, |
179 | 188 | }); |
180 | 189 |
|
| 190 | + useEffect(() => { |
| 191 | + if (!showKeyframes) setAutoKeyframeEnabled(false); |
| 192 | + }, [showKeyframes, setAutoKeyframeEnabled]); |
| 193 | + |
181 | 194 | // "N" toggles timeline snapping (industry convention: Resolve/FCP). |
182 | 195 | // Skip when typing in an input/contenteditable. |
183 | 196 | useEffect(() => { |
@@ -270,107 +283,110 @@ export function TimelineToolbar({ |
270 | 283 | </button> |
271 | 284 | </Tooltip> |
272 | 285 | )} |
273 | | - {/* Always rendered (CapCut-style): with no keyframeable selection the |
274 | | - button fades to a disabled state instead of unmounting, so the |
275 | | - toolbar layout never shifts. */} |
276 | | - <Tooltip |
277 | | - label={ |
278 | | - keyframePathEndpoint |
279 | | - ? "Motion path endpoints cannot be removed" |
280 | | - : !onToggleKeyframe |
281 | | - ? "Select an animated element to add keyframes" |
282 | | - : keyframeIsMotionPath |
283 | | - ? keyframeWillExtend |
284 | | - ? "Extend motion path to playhead (K)" |
285 | | - : keyframeState === "active" |
286 | | - ? "Remove waypoint from motion path (K)" |
287 | | - : "Add waypoint to motion path (K)" |
288 | | - : keyframeState === "active" |
289 | | - ? "Remove keyframe at playhead (K)" |
290 | | - : keyframeState === "inactive" |
| 286 | + {showKeyframes && ( |
| 287 | + <> |
| 288 | + {/* With no keyframeable selection the button fades to disabled instead of |
| 289 | + unmounting, so the toolbar layout never shifts (CapCut-style). */} |
| 290 | + <Tooltip |
| 291 | + label={ |
| 292 | + keyframePathEndpoint |
| 293 | + ? "Motion path endpoints cannot be removed" |
| 294 | + : !onToggleKeyframe |
| 295 | + ? "Select an animated element to add keyframes" |
| 296 | + : keyframeIsMotionPath |
291 | 297 | ? keyframeWillExtend |
292 | | - ? "Add keyframe at playhead, extends animation (K)" |
293 | | - : "Add keyframe at playhead (K)" |
294 | | - : "Add keyframe (K)" |
295 | | - } |
296 | | - > |
297 | | - <button |
298 | | - type="button" |
299 | | - disabled={!onToggleKeyframe} |
300 | | - onClick={onToggleKeyframe} |
301 | | - aria-label={ |
302 | | - keyframePathEndpoint |
303 | | - ? "Motion path endpoint" |
304 | | - : keyframeIsMotionPath |
305 | | - ? keyframeState === "active" |
306 | | - ? "Remove motion path waypoint" |
307 | | - : keyframeWillExtend |
308 | | - ? "Extend motion path to playhead" |
309 | | - : "Add motion path waypoint" |
310 | | - : keyframeState === "active" |
311 | | - ? "Remove keyframe at playhead" |
312 | | - : "Add keyframe at playhead" |
313 | | - } |
314 | | - className={ |
315 | | - !onToggleKeyframe |
316 | | - ? flatDisabled |
317 | | - : `${flatBtn} active:scale-[0.98] hover:bg-white/6 ${ |
318 | | - keyframeState === "active" |
319 | | - ? "text-studio-accent" |
320 | | - : keyframeState === "inactive" |
321 | | - ? "text-neutral-400 hover:text-studio-accent" |
322 | | - : "text-neutral-600 hover:text-neutral-400" |
323 | | - }` |
324 | | - } |
325 | | - > |
326 | | - <svg width="16" height="16" viewBox="0 0 10 10" fill="currentColor"> |
327 | | - {keyframeState === "active" ? ( |
328 | | - <path d="M5 0.5L9.5 5L5 9.5L0.5 5Z" /> |
329 | | - ) : ( |
330 | | - <path |
331 | | - d="M5 1.2L8.8 5L5 8.8L1.2 5Z" |
332 | | - fill="none" |
333 | | - stroke="currentColor" |
334 | | - strokeWidth="1.2" |
335 | | - /> |
336 | | - )} |
337 | | - </svg> |
338 | | - </button> |
339 | | - </Tooltip> |
340 | | - <Tooltip |
341 | | - label={ |
342 | | - autoKeyframeEnabled |
343 | | - ? "Auto-record manual edits as keyframes (click to turn off)" |
344 | | - : "Manual edits will not be recorded as keyframes (click to turn on)" |
345 | | - } |
346 | | - > |
347 | | - <button |
348 | | - type="button" |
349 | | - onClick={() => setAutoKeyframeEnabled(!autoKeyframeEnabled)} |
350 | | - aria-label="Auto-record manual edits as keyframes" |
351 | | - aria-pressed={autoKeyframeEnabled} |
352 | | - className={`${flatBtn} active:scale-[0.98] hover:bg-white/6 ${ |
353 | | - autoKeyframeEnabled |
354 | | - ? "text-red-400 hover:text-red-300" |
355 | | - : "text-neutral-600 hover:text-neutral-400" |
356 | | - }`} |
357 | | - > |
358 | | - <svg width="16" height="16" viewBox="0 0 10 10" fill="none"> |
359 | | - {/* Same diamond outline as the Add-keyframe icon, with a |
| 298 | + ? "Extend motion path to playhead (K)" |
| 299 | + : keyframeState === "active" |
| 300 | + ? "Remove waypoint from motion path (K)" |
| 301 | + : "Add waypoint to motion path (K)" |
| 302 | + : keyframeState === "active" |
| 303 | + ? "Remove keyframe at playhead (K)" |
| 304 | + : keyframeState === "inactive" |
| 305 | + ? keyframeWillExtend |
| 306 | + ? "Add keyframe at playhead, extends animation (K)" |
| 307 | + : "Add keyframe at playhead (K)" |
| 308 | + : "Add keyframe (K)" |
| 309 | + } |
| 310 | + > |
| 311 | + <button |
| 312 | + type="button" |
| 313 | + disabled={!onToggleKeyframe} |
| 314 | + onClick={onToggleKeyframe} |
| 315 | + aria-label={ |
| 316 | + keyframePathEndpoint |
| 317 | + ? "Motion path endpoint" |
| 318 | + : keyframeIsMotionPath |
| 319 | + ? keyframeState === "active" |
| 320 | + ? "Remove motion path waypoint" |
| 321 | + : keyframeWillExtend |
| 322 | + ? "Extend motion path to playhead" |
| 323 | + : "Add motion path waypoint" |
| 324 | + : keyframeState === "active" |
| 325 | + ? "Remove keyframe at playhead" |
| 326 | + : "Add keyframe at playhead" |
| 327 | + } |
| 328 | + className={ |
| 329 | + !onToggleKeyframe |
| 330 | + ? flatDisabled |
| 331 | + : `${flatBtn} active:scale-[0.98] hover:bg-white/6 ${ |
| 332 | + keyframeState === "active" |
| 333 | + ? "text-studio-accent" |
| 334 | + : keyframeState === "inactive" |
| 335 | + ? "text-neutral-400 hover:text-studio-accent" |
| 336 | + : "text-neutral-600 hover:text-neutral-400" |
| 337 | + }` |
| 338 | + } |
| 339 | + > |
| 340 | + <svg width="16" height="16" viewBox="0 0 10 10" fill="currentColor"> |
| 341 | + {keyframeState === "active" ? ( |
| 342 | + <path d="M5 0.5L9.5 5L5 9.5L0.5 5Z" /> |
| 343 | + ) : ( |
| 344 | + <path |
| 345 | + d="M5 1.2L8.8 5L5 8.8L1.2 5Z" |
| 346 | + fill="none" |
| 347 | + stroke="currentColor" |
| 348 | + strokeWidth="1.2" |
| 349 | + /> |
| 350 | + )} |
| 351 | + </svg> |
| 352 | + </button> |
| 353 | + </Tooltip> |
| 354 | + <Tooltip |
| 355 | + label={ |
| 356 | + autoKeyframeEnabled |
| 357 | + ? "Auto-record manual edits as keyframes (click to turn off)" |
| 358 | + : "Manual edits will not be recorded as keyframes (click to turn on)" |
| 359 | + } |
| 360 | + > |
| 361 | + <button |
| 362 | + type="button" |
| 363 | + onClick={() => setAutoKeyframeEnabled(!autoKeyframeEnabled)} |
| 364 | + aria-label="Auto-record manual edits as keyframes" |
| 365 | + aria-pressed={autoKeyframeEnabled} |
| 366 | + className={`${flatBtn} active:scale-[0.98] hover:bg-white/6 ${ |
| 367 | + autoKeyframeEnabled |
| 368 | + ? "text-red-400 hover:text-red-300" |
| 369 | + : "text-neutral-600 hover:text-neutral-400" |
| 370 | + }`} |
| 371 | + > |
| 372 | + <svg width="16" height="16" viewBox="0 0 10 10" fill="none"> |
| 373 | + {/* Same diamond outline as the Add-keyframe icon, with a |
360 | 374 | record-style dot inside: filled = auto-recording, |
361 | 375 | hollow = manual edits won't be keyframed. */} |
362 | | - <path d="M5 0.7L9.3 5L5 9.3L0.7 5Z" stroke="currentColor" strokeWidth="1" /> |
363 | | - <circle |
364 | | - cx="5" |
365 | | - cy="5" |
366 | | - r="1.8" |
367 | | - fill={autoKeyframeEnabled ? "currentColor" : "none"} |
368 | | - stroke="currentColor" |
369 | | - strokeWidth="1" |
370 | | - /> |
371 | | - </svg> |
372 | | - </button> |
373 | | - </Tooltip> |
| 376 | + <path d="M5 0.7L9.3 5L5 9.3L0.7 5Z" stroke="currentColor" strokeWidth="1" /> |
| 377 | + <circle |
| 378 | + cx="5" |
| 379 | + cy="5" |
| 380 | + r="1.8" |
| 381 | + fill={autoKeyframeEnabled ? "currentColor" : "none"} |
| 382 | + stroke="currentColor" |
| 383 | + strokeWidth="1" |
| 384 | + /> |
| 385 | + </svg> |
| 386 | + </button> |
| 387 | + </Tooltip> |
| 388 | + </> |
| 389 | + )} |
374 | 390 | {onSplitElement && |
375 | 391 | (() => { |
376 | 392 | // Render the button unconditionally (disabled when unusable): |
@@ -495,13 +511,15 @@ export function TimelineToolbar({ |
495 | 511 | <button |
496 | 512 | type="button" |
497 | 513 | onClick={() => setZoomMode("fit")} |
| 514 | + aria-label="Fit timeline to width" |
| 515 | + aria-pressed={zoomMode === "fit"} |
498 | 516 | className={`h-7 px-2 rounded-md text-[11px] font-medium transition-colors ${ |
499 | 517 | zoomMode === "fit" |
500 | 518 | ? "bg-studio-accent/10 text-studio-accent" |
501 | 519 | : "text-neutral-400 hover:bg-white/6 hover:text-neutral-200" |
502 | 520 | }`} |
503 | 521 | > |
504 | | - Fit |
| 522 | + <ArrowsOutLineHorizontal size={16} aria-hidden="true" /> |
505 | 523 | </button> |
506 | 524 | </Tooltip> |
507 | 525 | <Tooltip label="Zoom out"> |
|
0 commit comments