Skip to content

🎥 Make videos programmatically with React

show in gutter when hovered

Jonny Burger1cb5100702b0
diff --git a/packages/cli/src/editor/components/EditorGuides/Guide.tsx b/packages/cli/src/editor/components/EditorGuides/Guide.tsx
index 89d7163766..4ff5ea7234 100644
--- a/packages/cli/src/editor/components/EditorGuides/Guide.tsx
+++ b/packages/cli/src/editor/components/EditorGuides/Guide.tsx
@@ -1,5 +1,6 @@
import {memo, useCallback, useContext, useMemo} from 'react';
import {truthy} from '../../../truthy';
+import {SELECTED_GUIDE, UNSELECTED_GUIDE} from '../../helpers/colors';
import type {Guide} from '../../state/editor-guides';
import {
EditorShowGuidesContext,
@@ -9,7 +10,7 @@ import {RULER_WIDTH} from '../../state/editor-rulers';
import {ContextMenu} from '../ContextMenu';
import type {ComboboxValue} from '../NewComposition/ComboBox';
-const PADDING_FOR_EASY_DRAG = 2;
+const PADDING_FOR_EASY_DRAG = 4;
const GuideComp: React.FC<{
guide: Guide;
@@ -26,7 +27,18 @@ const GuideComp: React.FC<{
setGuidesList,
setSelectedGuideId,
selectedGuideId,
+ setHoveredGuideId,
+ hoveredGuideId,
} = useContext(EditorShowGuidesContext);
+
+ const onPointerEnter = useCallback(() => {
+ setHoveredGuideId(() => guide.id);
+ }, [guide.id, setHoveredGuideId]);
+
+ const onPointerLeave = useCallback(() => {
+ setHoveredGuideId(() => null);
+ }, [setHoveredGuideId]);
+
const isVerticalGuide = guide.orientation === 'vertical';
const guideStyle: React.CSSProperties = useMemo(() => {
@@ -55,8 +67,12 @@ const GuideComp: React.FC<{
top: `${isVerticalGuide ? `-${RULER_WIDTH}px` : '0px'}`,
left: `${isVerticalGuide ? '0px' : `-${RULER_WIDTH}px`}`,
display: guide.show ? 'block' : 'none',
+ backgroundColor:
+ selectedGuideId === guide.id || hoveredGuideId === guide.id
+ ? SELECTED_GUIDE
+ : UNSELECTED_GUIDE,
};
- }, [isVerticalGuide, guide.show]);
+ }, [isVerticalGuide, guide.show, guide.id, selectedGuideId, hoveredGuideId]);
const onMouseDown = useCallback(
(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
@@ -102,12 +118,14 @@ const GuideComp: React.FC<{
style={guideStyle}
onMouseDown={onMouseDown}
className="__remotion_editor_guide"
+ onPointerEnter={onPointerEnter}
+ onPointerLeave={onPointerLeave}
>
<div
style={guideContentStyle}
className={[
'__remotion_editor_guide_content',
- selectedGuideId === guide.id
+ selectedGuideId === guide.id || hoveredGuideId === guide.id
? '__remotion_editor_guide_selected'
: null,
]
diff --git a/packages/cli/src/editor/components/EditorRuler/Ruler.tsx b/packages/cli/src/editor/components/EditorRuler/Ruler.tsx
index d9083b0199..835c0c3a12 100644
--- a/packages/cli/src/editor/components/EditorRuler/Ruler.tsx
+++ b/packages/cli/src/editor/components/EditorRuler/Ruler.tsx
@@ -46,6 +46,7 @@ const Ruler: React.FC<RulerProps> = ({
shouldCreateGuideRef,
setGuidesList,
selectedGuideId,
+ hoveredGuideId,
setSelectedGuideId,
guidesList,
} = useContext(EditorShowGuidesContext);
@@ -59,9 +60,13 @@ const Ruler: React.FC<RulerProps> = ({
isVerticalRuler ? 'ew-resize' : 'ns-resize',
);
- const selectedGuide = useMemo(() => {
- return guidesList.find((guide) => guide.id === selectedGuideId) ?? null;
- }, [guidesList, selectedGuideId]);
+ const selectedOrHoveredGuide = useMemo(() => {
+ return (
+ guidesList.find((guide) => guide.id === selectedGuideId) ??
+ guidesList.find((guide) => guide.id === hoveredGuideId) ??
+ null
+ );
+ }, [guidesList, hoveredGuideId, selectedGuideId]);
useEffect(() => {
drawMarkingOnRulerCanvas({
@@ -72,7 +77,7 @@ const Ruler: React.FC<RulerProps> = ({
markingGaps,
orientation,
rulerCanvasRef,
- selectedGuide,
+ selectedGuide: selectedOrHoveredGuide,
});
}, [
scale,
@@ -81,7 +86,7 @@ const Ruler: React.FC<RulerProps> = ({
originOffset,
markingGaps,
orientation,
- selectedGuide,
+ selectedOrHoveredGuide,
]);
const {width: canvasContainerWidth, height: canvasContainerHeight} =
diff --git a/packages/cli/src/editor/components/ShowGuidesProvider.tsx b/packages/cli/src/editor/components/ShowGuidesProvider.tsx
index 136d4d95d0..da2e6056ff 100644
--- a/packages/cli/src/editor/components/ShowGuidesProvider.tsx
+++ b/packages/cli/src/editor/components/ShowGuidesProvider.tsx
@@ -12,6 +12,7 @@ export const ShowGuidesProvider: React.FC<{
}> = ({children}) => {
const [guidesList, setGuidesList] = useState<Guide[]>(() => loadGuidesList());
const [selectedGuideId, setSelectedGuideId] = useState<string | null>(null);
+ const [hoveredGuideId, setHoveredGuideId] = useState<string | null>(null);
const [editorShowGuides, setEditorShowGuidesState] = useState(() =>
loadEditorShowGuidesOption(),
);
@@ -39,16 +40,15 @@ export const ShowGuidesProvider: React.FC<{
setSelectedGuideId,
shouldCreateGuideRef,
shouldDeleteGuideRef,
+ hoveredGuideId,
+ setHoveredGuideId,
};
}, [
editorShowGuides,
setEditorShowGuides,
guidesList,
- setGuidesList,
selectedGuideId,
- setSelectedGuideId,
- shouldCreateGuideRef,
- shouldDeleteGuideRef,
+ hoveredGuideId,
]);
return (
diff --git a/packages/cli/src/editor/helpers/colors.ts b/packages/cli/src/editor/helpers/colors.ts
index 2c941d980b..ac800b949a 100644
--- a/packages/cli/src/editor/helpers/colors.ts
+++ b/packages/cli/src/editor/helpers/colors.ts
@@ -17,6 +17,7 @@ export const WARNING_COLOR = '#f1c40f';
export const BLUE = '#0b84f3';
export const BLUE_DISABLED = '#284f73';
export const LIGHT_TRANSPARENT = 'rgba(255, 255, 255, 0.7)';
+export const UNSELECTED_GUIDE = '#7e1219';
export const SELECTED_GUIDE = '#d22d3a';
export const getBackgroundFromHoverState = ({
diff --git a/packages/cli/src/editor/helpers/editor-ruler.ts b/packages/cli/src/editor/helpers/editor-ruler.ts
index 4273800f23..e3337b25de 100644
--- a/packages/cli/src/editor/helpers/editor-ruler.ts
+++ b/packages/cli/src/editor/helpers/editor-ruler.ts
@@ -45,12 +45,13 @@ const drawGradient = ({
canvasHeight: number;
canvasWidth: number;
}) => {
- const size = 150;
+ const size = 250;
const startX = orientation === 'horizontal' ? originDistance - size / 2 : 0;
const startY = orientation === 'horizontal' ? 0 : originDistance - size / 2;
- const endX = orientation === 'horizontal' ? originDistance + 75 : canvasWidth;
+ const endX =
+ orientation === 'horizontal' ? originDistance + size / 2 : canvasWidth;
const endY =
- orientation === 'horizontal' ? canvasHeight : originDistance + 75;
+ orientation === 'horizontal' ? canvasHeight : originDistance + size / 2;
const grd = context.createLinearGradient(startX, startY, endX, endY);
grd.addColorStop(0, BACKGROUND__TRANSPARENT);
grd.addColorStop(0.25, BACKGROUND);
diff --git a/packages/cli/src/editor/state/editor-guides.ts b/packages/cli/src/editor/state/editor-guides.ts
index 44dcebb018..23e95252b7 100644
--- a/packages/cli/src/editor/state/editor-guides.ts
+++ b/packages/cli/src/editor/state/editor-guides.ts
@@ -15,6 +15,8 @@ export type GuideState = {
setGuidesList: (cb: (prevState: Guide[]) => Guide[]) => void;
selectedGuideId: string | null;
setSelectedGuideId: (cb: (prevState: string | null) => string | null) => void;
+ setHoveredGuideId: (cb: (prevState: string | null) => string | null) => void;
+ hoveredGuideId: string | null;
shouldCreateGuideRef: React.MutableRefObject<boolean>;
shouldDeleteGuideRef: React.MutableRefObject<boolean>;
};
@@ -46,4 +48,6 @@ export const EditorShowGuidesContext = createContext<GuideState>({
setSelectedGuideId: () => undefined,
shouldCreateGuideRef: {current: false},
shouldDeleteGuideRef: {current: false},
+ hoveredGuideId: null,
+ setHoveredGuideId: () => undefined,
});
diff --git a/packages/cli/styles/styles.css b/packages/cli/styles/styles.css
index 09326bdd10..954bde6dbc 100644
--- a/packages/cli/styles/styles.css
+++ b/packages/cli/styles/styles.css
@@ -123,11 +123,3 @@ input[type='color'].__remotion_color_picker::-webkit-color-swatch {
background-color: white;
position: relative;
}
-
-.__remotion_editor_guide_content {
- background: #7e1219;
-}
-.__remotion_editor_guide:hover .__remotion_editor_guide_content,
-.__remotion_editor_guide_selected {
- background: var(--guide-selected);
-}