🎥 Make videos programmatically with React
@remotion/studio: Replace diamond icon with SVG (#8126)
Jonny Burger8dee2922e70e
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsxindex 5199eb16af..426d82373e 100644--- a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx+++ b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx@@ -24,6 +24,7 @@ import {hasKeyframeAtSourceFrame,} from './get-keyframe-navigation';import {getTimelineKeyframes} from './get-timeline-keyframes';+import {TimelineKeyframeDiamondIcon} from './TimelineKeyframeDiamondIcon';import {SELECTION_ENABLED} from './TimelineSelection';const controlsContainerStyle: React.CSSProperties = {@@ -63,14 +64,6 @@ const diamondButtonStyle: React.CSSProperties = {translate: '0 -0.5px',};-const diamondIconStyle: React.CSSProperties = {- borderRadius: 1,- boxShadow: '0 0 0 1px rgba(0, 0, 0, 0.4)',- height: 7,- transform: 'rotate(45deg)',- width: 7,-};-const svgStyle: React.CSSProperties = {display: 'block'};const getCurrentKeyframeValue = ({@@ -361,13 +354,7 @@ export const TimelineKeyframeControls: React.FC<{[canToggleKeyframe, clientId],);- const diamondIcon = useMemo(- (): React.CSSProperties => ({- ...diamondIconStyle,- backgroundColor: hasKeyframeAtCurrentFrame ? BLUE : LIGHT_TEXT,- }),- [hasKeyframeAtCurrentFrame],- );+ const diamondColor = hasKeyframeAtCurrentFrame ? BLUE : LIGHT_TEXT;return (<div style={controlsContainerStyle}>@@ -395,7 +382,7 @@ export const TimelineKeyframeControls: React.FC<{}title={hasKeyframeAtCurrentFrame ? 'Remove keyframe' : 'Add keyframe'}>- <span style={diamondIcon} />+ <TimelineKeyframeDiamondIcon color={diamondColor} size={10} /></button><buttontype="button"diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsxindex f3b5513bb6..d6d795a5d1 100644--- a/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsx+++ b/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsx@@ -1,21 +1,27 @@import React, {useContext, useMemo} from 'react';import {useVideoConfig} from 'remotion';-import {BLUE, LIGHT_TEXT} from '../../helpers/colors';+import {LIGHT_TEXT} from '../../helpers/colors';import {getXPositionOfItemInTimelineImperatively} from '../../helpers/get-left-of-timeline-slider';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import {TIMELINE_PADDING} from '../../helpers/timeline-layout';+import {TimelineKeyframeDiamondIcon} from './TimelineKeyframeDiamondIcon';import {useTimelineKeyframeDragState} from './TimelineKeyframeDragState';import {useTimelineKeyframeSelection} from './TimelineSelection';import {TimelineWidthContext} from './TimelineWidthProvider';import {useTimelineKeyframeDrag} from './use-timeline-keyframe-drag';+const diamondSize = 12;+const diamondBase: React.CSSProperties = {+ alignItems: 'center',+ background: 'none',+ border: 'none',+ display: 'flex',+ height: diamondSize,+ justifyContent: 'center',+ padding: 0,position: 'absolute',- width: 8,- height: 8,- backgroundColor: LIGHT_TEXT,- borderRadius: 1,- boxShadow: '0 0 0 1px rgba(0, 0, 0, 0.4)',+ width: diamondSize,};const TimelineKeyframeDiamondUnmemoized: React.FC<{@@ -40,27 +46,18 @@ const TimelineKeyframeDiamondUnmemoized: React.FC<{return {...diamondBase,- backgroundColor: LIGHT_TEXT,- outline: visuallySelected ? '2px solid ' + BLUE : 'none',- border: 'none',+ cursor: 'pointer',left:getXPositionOfItemInTimelineImperatively(frame,videoConfig.durationInFrames,timelineWidth,) - TIMELINE_PADDING,- padding: 0,pointerEvents: 'auto',top: rowHeight / 2,- transform: 'translate(-50%, -50%) rotate(45deg)',+ transform: 'translate(-50%, -50%)',};- }, [- frame,- rowHeight,- timelineWidth,- videoConfig.durationInFrames,- visuallySelected,- ]);+ }, [frame, rowHeight, timelineWidth, videoConfig.durationInFrames]);const onPointerDown = useTimelineKeyframeDrag({frame,@@ -81,7 +78,13 @@ const TimelineKeyframeDiamondUnmemoized: React.FC<{title={`Keyframe at frame ${frame}`}aria-label={`Select keyframe at frame ${frame}`}onPointerDown={selectable ? onPointerDown : undefined}- />+ >+ <TimelineKeyframeDiamondIcon+ color={LIGHT_TEXT}+ selected={visuallySelected}+ size={diamondSize}+ />+ </button>);};diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeDiamondIcon.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeDiamondIcon.tsxnew file mode 100644index 0000000000..956f1c8ae2--- /dev/null+++ b/packages/studio/src/components/Timeline/TimelineKeyframeDiamondIcon.tsx@@ -0,0 +1,41 @@+import React from 'react';+import {BLUE} from '../../helpers/colors';++const svgStyle: React.CSSProperties = {+ display: 'block',+ overflow: 'visible',+};++export const TimelineKeyframeDiamondIcon: React.FC<{+ readonly color: string;+ readonly selected?: boolean;+ readonly size: number;+}> = ({color, selected = false, size}) => {+ return (+ <svg+ width={size}+ height={size}+ viewBox="0 0 12 12"+ style={svgStyle}+ aria-hidden="true"+ focusable="false"+ >+ {selected ? (+ <polygon+ points="6 0.75 11.25 6 6 11.25 0.75 6"+ fill="none"+ stroke={BLUE}+ strokeWidth="1.5"+ strokeLinejoin="round"+ />+ ) : null}+ <polygon+ points="6 1.5 10.5 6 6 10.5 1.5 6"+ fill={color}+ stroke="rgba(0, 0, 0, 0.4)"+ strokeWidth="1"+ strokeLinejoin="round"+ />+ </svg>+ );+};