🎥 Make videos programmatically with React
Elements: Move drag callout to fallback modal
JonnyBurger97164f3dac2a
diff --git a/packages/docs/src/components/Elements/ElementInstallFallbackModal.module.css b/packages/docs/src/components/Elements/ElementInstallFallbackModal.module.cssindex 78c4eb8fd5..3f364cb86c 100644--- a/packages/docs/src/components/Elements/ElementInstallFallbackModal.module.css+++ b/packages/docs/src/components/Elements/ElementInstallFallbackModal.module.css@@ -64,10 +64,65 @@}.installAction {- width: min(100%, 260px);+ display: flex;+ width: 100%;+ align-items: center;+ gap: 14px;margin-top: 20px;}+.installAction > :first-child {+ width: min(260px, calc(100% - 128px));+ flex: none;+}++.dragCallout {+ display: flex;+ min-width: 0;+ align-items: center;+ color: var(--text-color);+ pointer-events: none;+}++.dragCalloutLine {+ display: block;+ width: 46px;+ height: 22px;+ flex: none;+}++.dragCalloutLabel {+ width: 68px;+ font-family: 'GTPlanar';+ font-size: 15px;+ line-height: 1.15;+}++.dragCalloutWiggle {+ animation: drag-callout-wiggle 400ms ease-in-out;+}++@keyframes drag-callout-wiggle {+ 0%,+ 100% {+ transform: translateX(0) rotate(0deg);+ }++ 25% {+ transform: translateX(-3px) rotate(-2deg);+ }++ 75% {+ transform: translateX(3px) rotate(2deg);+ }+}++@media (prefers-reduced-motion: reduce) {+ .dragCalloutWiggle {+ animation: none;+ }+}+.hint,.copyHint {margin: 16px 0 0;diff --git a/packages/docs/src/components/Elements/ElementInstallFallbackModal.tsx b/packages/docs/src/components/Elements/ElementInstallFallbackModal.tsxindex 3f62bcad0f..d8ba18cb14 100644--- a/packages/docs/src/components/Elements/ElementInstallFallbackModal.tsx+++ b/packages/docs/src/components/Elements/ElementInstallFallbackModal.tsx@@ -5,6 +5,7 @@ import {ElementStudioAction} from './ElementStudioAction';import styles from './ElementInstallFallbackModal.module.css';export const ElementInstallFallbackModal: React.FC<{+ readonly installFailureCount: number;readonly isInstalling: boolean;readonly isOpen: boolean;readonly onClose: () => void;@@ -13,6 +14,7 @@ export const ElementInstallFallbackModal: React.FC<{readonly posterRef: RefObject<HTMLImageElement | null>;readonly sourceCode: string;}> = ({+ installFailureCount,isInstalling,isOpen,onClose,@@ -66,6 +68,10 @@ export const ElementInstallFallbackModal: React.FC<{onClose();}}onClick={(event) => {+ if (event.target !== event.currentTarget) {+ return;+ }+const bounds = event.currentTarget.getBoundingClientRect();const clickedOutside =event.clientX < bounds.left ||@@ -100,10 +106,37 @@ export const ElementInstallFallbackModal: React.FC<{onClick={onInstall}payload={payload}posterRef={posterRef}- showDragCallout={false}showDragHandletitle="Install in the most recently focused Remotion Studio"/>+ {installFailureCount > 0 ? (+ <div+ key={installFailureCount}+ aria-hidden="true"+ className={`${styles.dragCallout} ${+ installFailureCount > 1 ? styles.dragCalloutWiggle : ''+ }`}+ >+ <svg+ className={styles.dragCalloutLine}+ fill="none"+ viewBox="0 0 160 77"+ >+ <path+ d="M5 154.5C51 121 79 81 69 5"+ stroke="currentColor"+ strokeLinecap="round"+ strokeWidth="11"+ transform="matrix(0 -1 1 0 0 77)"+ />+ </svg>+ <span className={styles.dragCalloutLabel}>+ Drag into+ <br />+ Studio+ </span>+ </div>+ ) : null}</div><p className={styles.hint}>Not working? Drag the button into your Studio instead.diff --git a/packages/docs/src/components/Elements/ElementLibrary.tsx b/packages/docs/src/components/Elements/ElementLibrary.tsxindex ac94ef6a0f..42362cf70e 100644--- a/packages/docs/src/components/Elements/ElementLibrary.tsx+++ b/packages/docs/src/components/Elements/ElementLibrary.tsx@@ -47,6 +47,7 @@ const ElementCard: React.FC<{const [playbackFailed, setPlaybackFailed] = useState(false);const [isInstalling, setIsInstalling] = useState(false);const [isInstallFallbackOpen, setIsInstallFallbackOpen] = useState(false);+ const [installFailureCount, setInstallFailureCount] = useState(0);const posterRef = useRef<HTMLImageElement>(null);const videoRef = useRef<HTMLVideoElement>(null);const shouldPlay =@@ -110,17 +111,20 @@ const ElementCard: React.FC<{fallbackPayload: assetPayload === null ? undefined : elementPayload,});if (!result.success) {+ setInstallFailureCount((count) => count + 1);setIsInstallFallbackOpen(true);return;}setIsInstallFallbackOpen(false);+ setInstallFailureCount(0);if (window.location.origin === 'https://www.remotion.dev') {navigator.sendBeacon(`https://www.remotion.pro/api/track/element-install-request?slug=${encodeURIComponent(definition.slug)}`,);}} catch {+ setInstallFailureCount((count) => count + 1);setIsInstallFallbackOpen(true);} finally {setIsInstalling(false);@@ -196,9 +200,13 @@ const ElementCard: React.FC<{</BlueButton></div><ElementInstallFallbackModal+ installFailureCount={installFailureCount}isInstalling={isInstalling}isOpen={isInstallFallbackOpen}- onClose={() => setIsInstallFallbackOpen(false)}+ onClose={() => {+ setIsInstallFallbackOpen(false);+ setInstallFailureCount(0);+ }}onInstall={installElement}payload={elementPayload}posterRef={posterRef}diff --git a/packages/docs/src/components/Elements/ElementPage.tsx b/packages/docs/src/components/Elements/ElementPage.tsxindex c426622ffc..9b55d3b00c 100644--- a/packages/docs/src/components/Elements/ElementPage.tsx+++ b/packages/docs/src/components/Elements/ElementPage.tsx@@ -46,6 +46,7 @@ export const ElementPage: React.FC<ElementPageProps> = ({type: 'idle',});const [isInstallFallbackOpen, setIsInstallFallbackOpen] = useState(false);+ const [installFailureCount, setInstallFailureCount] = useState(0);const [isInstallHintVisible, setIsInstallHintVisible] = useState(false);const [isSourceVisible, setIsSourceVisible] = useState(false);const [isBrowserStudioActionVisible, setIsBrowserStudioActionVisible] =@@ -144,11 +145,13 @@ export const ElementPage: React.FC<ElementPageProps> = ({});if (!result.success) {setInstallStatus({type: 'idle'});+ setInstallFailureCount((count) => count + 1);setIsInstallFallbackOpen(true);return;}setIsInstallFallbackOpen(false);+ setInstallFailureCount(0);if (isEmbeddedInStudio) {setInstallStatus({type: 'idle'});} else {@@ -162,6 +165,7 @@ export const ElementPage: React.FC<ElementPageProps> = ({}} catch {setInstallStatus({type: 'idle'});+ setInstallFailureCount((count) => count + 1);setIsInstallFallbackOpen(true);}}, [assetPayload, definition.slug, elementPayload, isEmbeddedInStudio]);@@ -261,7 +265,6 @@ export const ElementPage: React.FC<ElementPageProps> = ({onClick={installElement}payload={elementPayload}posterRef={posterRef}- showDragCalloutshowDragHandle={isEmbeddedInStudio === false}title={isEmbeddedInStudio@@ -372,9 +375,13 @@ export const ElementPage: React.FC<ElementPageProps> = ({</aside>{elementPayload === null || sourceCode === undefined ? null : (<ElementInstallFallbackModal+ installFailureCount={installFailureCount}isInstalling={installStatus.type === 'installing'}isOpen={isInstallFallbackOpen}- onClose={() => setIsInstallFallbackOpen(false)}+ onClose={() => {+ setIsInstallFallbackOpen(false);+ setInstallFailureCount(0);+ }}onInstall={installElement}payload={elementPayload}posterRef={posterRef}diff --git a/packages/docs/src/components/Elements/ElementStudioAction.module.css b/packages/docs/src/components/Elements/ElementStudioAction.module.cssindex 0353349c04..2be6608c71 100644--- a/packages/docs/src/components/Elements/ElementStudioAction.module.css+++ b/packages/docs/src/components/Elements/ElementStudioAction.module.css@@ -1,5 +1,4 @@.studioAction {- position: relative;display: flex;align-items: stretch;width: 100%;@@ -7,10 +6,6 @@background: var(--blue-underlay);}-.studioActionWithCallout {- margin-bottom: 68px;-}-.studioAction .buttonWithDragHandle {border-top-right-radius: 0;border-right-width: 0;@@ -73,31 +68,3 @@font-size: 1.5rem;line-height: 1;}--.dragCallout {- position: absolute;- top: calc(100% + 1px);- right: 20px;- width: 31px;- height: 64px;- color: var(--text-color);- pointer-events: none;-}--.dragCalloutLine {- display: block;- width: 31px;- height: 64px;- overflow: visible;-}--.dragCalloutLabel {- position: absolute;- top: 32px;- right: 38px;- width: max-content;- font-family: 'GTPlanar';- font-size: 15px;- line-height: 1.2;- white-space: nowrap;-}diff --git a/packages/docs/src/components/Elements/ElementStudioAction.tsx b/packages/docs/src/components/Elements/ElementStudioAction.tsxindex d93251e4d6..f290b6ae6f 100644--- a/packages/docs/src/components/Elements/ElementStudioAction.tsx+++ b/packages/docs/src/components/Elements/ElementStudioAction.tsx@@ -13,7 +13,6 @@ export const ElementStudioAction: React.FC<{readonly onClick: () => void;readonly payload: StudioElementPayload;readonly posterRef: RefObject<HTMLImageElement | null>;- readonly showDragCallout: boolean;readonly showDragHandle: boolean;readonly title: string;}> = ({@@ -22,11 +21,9 @@ export const ElementStudioAction: React.FC<{onClick,payload,posterRef,- showDragCallout,showDragHandle,title,}) => {- const hasDragCallout = showDragHandle && showDragCallout;const onDragStart = (event: React.DragEvent<HTMLElement>) => {setStudioDragData({dataTransfer: event.dataTransfer,@@ -36,9 +33,7 @@ export const ElementStudioAction: React.FC<{};return (- <div- className={`${styles.studioAction} ${hasDragCallout ? styles.studioActionWithCallout : ''}`}- >+ <div className={styles.studioAction}><BlueButtonclassName={showDragHandle ? styles.buttonWithDragHandle : undefined}draggable={showDragHandle}@@ -65,23 +60,6 @@ export const ElementStudioAction: React.FC<{</span></div>) : null}- {hasDragCallout ? (- <div aria-hidden="true" className={styles.dragCallout}>- <svg- className={styles.dragCalloutLine}- fill="none"- viewBox="0 0 77 160"- >- <path- d="M5 154.5C51 121 79 81 69 5"- stroke="currentColor"- strokeLinecap="round"- strokeWidth="8"- />- </svg>- <span className={styles.dragCalloutLabel}>Drag into Studio</span>- </div>- ) : null}</div>);};