Skip to content

🎥 Make videos programmatically with React

only show icon on hover

Jonny Burgereeadb832b283
diff --git a/packages/cli/src/editor/components/CompositionSelectorItem.tsx b/packages/cli/src/editor/components/CompositionSelectorItem.tsx
index d309e2844c..68b02c50b7 100644
--- a/packages/cli/src/editor/components/CompositionSelectorItem.tsx
+++ b/packages/cli/src/editor/components/CompositionSelectorItem.tsx
@@ -12,7 +12,9 @@ import {FilmIcon} from '../icons/film';
import {CollapsedFolderIcon, ExpandedFolderIcon} from '../icons/folder';
import {StillIcon} from '../icons/still';
import {Row, Spacing} from './layout';
-import {COMPOSITION_ITEM_HEIGHT, RenderButton} from './RenderButton';
+import {RenderButton} from './RenderButton';
+
+const COMPOSITION_ITEM_HEIGHT = 32;
const itemStyle: React.CSSProperties = {
paddingRight: 8,
@@ -32,6 +34,13 @@ const itemStyle: React.CSSProperties = {
height: COMPOSITION_ITEM_HEIGHT,
};
+const labelStyle: React.CSSProperties = {
+ textAlign: 'left',
+ textDecoration: 'none',
+ fontSize: 13,
+ flex: 1,
+};
+
const iconStyle: React.CSSProperties = {
width: 18,
height: 18,
@@ -98,6 +107,13 @@ export const CompositionSelectorItem: React.FC<{
};
}, [hovered, level, selected]);
+ const label = useMemo(() => {
+ return {
+ ...labelStyle,
+ color: selected || hovered ? 'white' : LIGHT_TEXT,
+ };
+ }, [hovered, selected]);
+
const onClick: MouseEventHandler = useCallback(
(evt) => {
evt.preventDefault();
@@ -164,14 +180,14 @@ export const CompositionSelectorItem: React.FC<{
<FilmIcon style={iconStyle} />
)}
<Spacing x={1} />
- {item.composition.id}
+ <div style={label}>{item.composition.id}</div>
+ {isCompositionStill(item.composition) ? (
+ <>
+ <Spacing x={0.5} />
+ <RenderButton visible={hovered} composition={item.composition} />
+ </>
+ ) : null}
</button>
- {isCompositionStill(item.composition) ? (
- <>
- <Spacing x={0.5} />
- <RenderButton composition={item.composition} />
- </>
- ) : null}
</Row>
);
};
diff --git a/packages/cli/src/editor/components/InlineAction.tsx b/packages/cli/src/editor/components/InlineAction.tsx
new file mode 100644
index 0000000000..f9ad3e2901
--- /dev/null
+++ b/packages/cli/src/editor/components/InlineAction.tsx
@@ -0,0 +1,49 @@
+import type {PropsWithChildren} from 'react';
+import React, {useCallback, useMemo, useState} from 'react';
+import {CLEAR_HOVER} from '../helpers/colors';
+import {useZIndex} from '../state/z-index';
+
+export const InlineAction: React.FC<
+ PropsWithChildren<{
+ onClick: React.MouseEventHandler<HTMLButtonElement> | undefined;
+ }>
+> = ({children, onClick}) => {
+ const {tabIndex} = useZIndex();
+
+ const [hovered, setHovered] = useState(false);
+
+ const onPointerEnter = useCallback(() => {
+ setHovered(true);
+ }, []);
+
+ const onPointerLeave = useCallback(() => {
+ setHovered(false);
+ }, []);
+
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ border: 'none',
+ background: hovered ? CLEAR_HOVER : 'transparent',
+ height: 24,
+ width: 24,
+ display: 'inline-flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ borderRadius: 3,
+ opacity: hovered ? 1 : 0.6,
+ };
+ }, [hovered]);
+
+ return (
+ <button
+ onPointerEnter={onPointerEnter}
+ onPointerLeave={onPointerLeave}
+ type="button"
+ onClick={onClick}
+ style={style}
+ tabIndex={tabIndex}
+ >
+ {children}
+ </button>
+ );
+};
diff --git a/packages/cli/src/editor/components/RenderButton.tsx b/packages/cli/src/editor/components/RenderButton.tsx
index c64aa4a60c..2926454a7d 100644
--- a/packages/cli/src/editor/components/RenderButton.tsx
+++ b/packages/cli/src/editor/components/RenderButton.tsx
@@ -1,73 +1,42 @@
import type {SVGProps} from 'react';
-import React, {useCallback, useContext, useMemo, useState} from 'react';
+import React, {useCallback, useContext, useMemo} from 'react';
import type {TCompMetadata} from 'remotion';
-import {CLEAR_HOVER, LIGHT_TEXT} from '../helpers/colors';
import {RenderIcon} from '../icons/render';
import {ModalsContext} from '../state/modals';
-import {useZIndex} from '../state/z-index';
-
-export const COMPOSITION_ITEM_HEIGHT = 32;
-
-const itemStyle: React.CSSProperties = {
- display: 'flex',
- cursor: 'default',
- alignItems: 'center',
- justifyContent: 'center',
- marginBottom: 1,
- appearance: 'none',
- border: 'none',
- height: COMPOSITION_ITEM_HEIGHT,
-};
+import {InlineAction} from './InlineAction';
export const RenderButton: React.FC<{
composition: TCompMetadata;
-}> = ({composition}) => {
- const [hovered, setHovered] = useState(false);
+ visible: boolean;
+}> = ({composition, visible}) => {
const {setSelectedModal} = useContext(ModalsContext);
- const onPointerEnter = useCallback(() => {
- setHovered(true);
- }, []);
-
- const onPointerLeave = useCallback(() => {
- setHovered(false);
- }, []);
-
- const {tabIndex} = useZIndex();
-
- const style: React.CSSProperties = useMemo(() => {
- return {
- ...itemStyle,
- backgroundColor: hovered ? CLEAR_HOVER : 'transparent',
- color: hovered ? 'white' : LIGHT_TEXT,
- };
- }, [hovered]);
-
const iconStyle: SVGProps<SVGSVGElement> = useMemo(() => {
return {
style: {
- height: 14,
+ height: 12,
},
};
}, []);
- const onClick = useCallback(() => {
- setSelectedModal({
- type: 'render',
- composition,
- });
- }, [composition, setSelectedModal]);
+ const onClick: React.MouseEventHandler<HTMLButtonElement> = useCallback(
+ (e) => {
+ e.stopPropagation();
+ setSelectedModal({
+ type: 'render',
+ composition,
+ });
+ },
+ [composition, setSelectedModal]
+ );
+
+ if (!visible) {
+ return null;
+ }
return (
- <button
- style={style}
- tabIndex={tabIndex}
- onClick={onClick}
- onPointerEnter={onPointerEnter}
- onPointerLeave={onPointerLeave}
- type="button"
- >
- <RenderIcon svgProps={iconStyle} color={hovered ? 'white' : LIGHT_TEXT} />
- </button>
+ <InlineAction onClick={onClick}>
+ <RenderIcon svgProps={iconStyle} />
+ </InlineAction>
);
};
diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueRemoveItem.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueRemoveItem.tsx
index e17a8408dd..1187c0195f 100644
--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueRemoveItem.tsx
+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueRemoveItem.tsx
@@ -1,12 +1,9 @@
-import React, {useCallback, useMemo, useState} from 'react';
+import React, {useCallback, useMemo} from 'react';
import type {RenderJob} from '../../../preview-server/render-queue/job';
-import {CLEAR_HOVER, LIGHT_TEXT} from '../../helpers/colors';
-import {useZIndex} from '../../state/z-index';
+import {InlineAction} from '../InlineAction';
import {removeRenderJob} from './actions';
export const RenderQueueRemoveItem: React.FC<{job: RenderJob}> = ({job}) => {
- const {tabIndex} = useZIndex();
-
const onClick = useCallback(() => {
removeRenderJob(job).catch((err) => {
// TODO: Handle error
@@ -14,55 +11,24 @@ export const RenderQueueRemoveItem: React.FC<{job: RenderJob}> = ({job}) => {
});
}, [job]);
- const [hovered, setHovered] = useState(false);
-
const icon: React.CSSProperties = useMemo(() => {
return {
height: 12,
};
}, []);
- const onPointerEnter = useCallback(() => {
- setHovered(true);
- }, []);
-
- const onPointerLeave = useCallback(() => {
- setHovered(false);
- }, []);
-
- const style: React.CSSProperties = useMemo(() => {
- return {
- border: 'none',
- background: hovered ? CLEAR_HOVER : 'transparent',
- height: 24,
- width: 24,
- display: 'inline-flex',
- justifyContent: 'center',
- alignItems: 'center',
- borderRadius: 3,
- cursor: 'pointer',
- };
- }, [hovered]);
-
return (
- <button
- onPointerEnter={onPointerEnter}
- onPointerLeave={onPointerLeave}
- type="button"
- onClick={onClick}
- style={style}
- tabIndex={tabIndex}
- >
+ <InlineAction onClick={onClick}>
<svg
style={icon}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 448 512"
>
<path
- fill={hovered ? 'white' : LIGHT_TEXT}
+ fill="currentColor"
d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"
/>
</svg>
- </button>
+ </InlineAction>
);
};
diff --git a/packages/cli/src/editor/icons/render.tsx b/packages/cli/src/editor/icons/render.tsx
index f5a1472342..8230095565 100644
--- a/packages/cli/src/editor/icons/render.tsx
+++ b/packages/cli/src/editor/icons/render.tsx
@@ -3,7 +3,6 @@ import React from 'react';
export const RenderIcon: React.FC<{
svgProps: SVGProps<SVGSVGElement>;
- color: string;
}> = (props) => {
return (
<svg
@@ -12,7 +11,7 @@ export const RenderIcon: React.FC<{
viewBox="0 0 512 512"
>
<path
- fill={props.color}
+ fill={'currentColor'}
d="M408 143.1C408 166.1 390.1 183.1 368 183.1C345.9 183.1 328 166.1 328 143.1C328 121.9 345.9 103.1 368 103.1C390.1 103.1 408 121.9 408 143.1zM384 312.1V394.2C384 419.7 370.6 443.2 348.7 456.2L260.2 508.6C252.8 513 243.6 513.1 236.1 508.9C228.6 504.6 224 496.6 224 488V373.3C224 350.6 215 328.1 199 312.1C183 296.1 161.4 288 138.7 288H24C15.38 288 7.414 283.4 3.146 275.9C-1.123 268.4-1.042 259.2 3.357 251.8L55.83 163.3C68.79 141.4 92.33 127.1 117.8 127.1H199.9C281.7-3.798 408.8-8.546 483.9 5.272C495.6 7.411 504.6 16.45 506.7 28.07C520.5 103.2 515.8 230.3 384 312.1V312.1zM197.9 253.9C210.8 260.2 222.6 268.7 232.1 279C243.3 289.4 251.8 301.2 258.1 314.1C363.9 284.1 414.8 234.5 439.7 188C464.7 141.3 466.1 90.47 461.7 50.33C421.5 45.02 370.7 47.34 323.1 72.33C277.5 97.16 227.9 148.1 197.9 253.9H197.9zM41.98 345.5C76.37 311.1 132.1 311.1 166.5 345.5C200.9 379.9 200.9 435.6 166.5 470C117 519.5 .4765 511.5 .4765 511.5C.4765 511.5-7.516 394.1 41.98 345.5V345.5zM64.58 447.4C64.58 447.4 103.3 450.1 119.8 433.6C131.2 422.2 131.2 403.6 119.8 392.2C108.3 380.8 89.81 380.8 78.38 392.2C61.92 408.7 64.58 447.4 64.58 447.4z"
/>
</svg>
diff --git a/packages/cli/styles/styles.css b/packages/cli/styles/styles.css
index 8cd0597a78..e48b1edd69 100644
--- a/packages/cli/styles/styles.css
+++ b/packages/cli/styles/styles.css
@@ -29,6 +29,7 @@ button:focus,
a:focus {
outline: none;
box-shadow: inset 1px 1px #555, inset -1px -1px #555, inset 1px -1px #555, inset -1px 1px #555;
+ border-radius: 0 !important;
}
input.no-focus-ring:focus,