Skip to content

🎥 Make videos programmatically with React

Elements: Add spinning text wheel (#10447)

Igor Samokhovets051ddc91678d
diff --git a/packages/docs/elements/text/spinning-text-wheel/index.mdx b/packages/docs/elements/text/spinning-text-wheel/index.mdx
new file mode 100644
index 0000000000..cb620fe051
--- /dev/null
+++ b/packages/docs/elements/text/spinning-text-wheel/index.mdx
@@ -0,0 +1,12 @@
+---
+title: Spinning Text Wheel
+description: A 3D text wheel that spins through options and decelerates onto a highlighted selection.
+image: https://remotion.media/elements/text-spinning-text-wheel-preview.png
+---
+
+import {elementDefinitions} from '@site/src/components/Elements/element-definitions';
+import {ElementPage} from '@site/src/components/Elements/ElementPage';
+
+# Spinning Text Wheel
+
+<ElementPage definition={elementDefinitions['text/spinning-text-wheel']} sourceFile="./spinning-text-wheel.tsx" />
diff --git a/packages/docs/elements/text/spinning-text-wheel/spinning-text-wheel.tsx b/packages/docs/elements/text/spinning-text-wheel/spinning-text-wheel.tsx
new file mode 100644
index 0000000000..004fa77e73
--- /dev/null
+++ b/packages/docs/elements/text/spinning-text-wheel/spinning-text-wheel.tsx
@@ -0,0 +1,169 @@
+import {loadFont} from '@remotion/google-fonts/MonaSans';
+import React, {forwardRef, useImperativeHandle, useRef} from 'react';
+import {
+ Interactive,
+ Sequence,
+ interpolate,
+ spring,
+ type InteractiveBaseProps,
+ type InteractiveTransformProps,
+ type InteractivitySchema,
+ type SequenceControls,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+loadFont('normal', {
+ weights: ['700'],
+ subsets: ['latin'],
+});
+
+type SpinningTextWheelProps = InteractiveBaseProps &
+ InteractiveTransformProps & {
+ readonly items?: string;
+ };
+
+const spinningTextWheelSchema = {
+ ...Interactive.baseSchema,
+ items: {
+ type: 'text-content',
+ default: 'Friday\nSaturday\nSunday\nMonday\nTuesday\nWednesday\nThursday',
+ description: 'Items (selected first, one per line)',
+ },
+ ...Interactive.textSchema,
+ ...Interactive.transformSchema,
+} as const satisfies InteractivitySchema;
+
+const SpinningTextWheelInner = forwardRef<
+ HTMLDivElement,
+ SpinningTextWheelProps & {
+ readonly controls: SequenceControls | undefined;
+ }
+>(
+ (
+ {
+ controls,
+ items = 'Friday\nSaturday\nSunday\nMonday\nTuesday\nWednesday\nThursday',
+ name,
+ style,
+ ...sequenceProps
+ },
+ ref,
+ ) => {
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const outlineRef = useRef<HTMLDivElement>(null);
+ const values = items
+ .split('\n')
+ .map((item) => item.trim())
+ .filter(Boolean);
+ const progress = spring({
+ fps,
+ frame,
+ config: {
+ mass: 10,
+ damping: 200,
+ stiffness: 200,
+ },
+ durationInFrames: 90,
+ durationRestThreshold: 0.0001,
+ });
+ const rotation = interpolate(progress, [0, 1], [1, 0]);
+
+ useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);
+
+ return (
+ <Sequence
+ layout="none"
+ {...sequenceProps}
+ controls={controls}
+ name={name ?? '<SpinningTextWheel>'}
+ outlineRef={outlineRef}
+ >
+ <div
+ ref={outlineRef}
+ style={{
+ height: 200,
+ maskImage:
+ 'linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 1) 30%, rgba(0, 0, 0, 1) 70%, transparent 100%)',
+ overflow: 'hidden',
+ WebkitMaskImage:
+ 'linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 1) 30%, rgba(0, 0, 0, 1) 70%, transparent 100%)',
+ perspective: 10000,
+ position: 'relative',
+ width: 400,
+ ...style,
+ }}
+ >
+ {values.map((value, index) => {
+ const wheelIndex = index / values.length + rotation;
+ const angle = wheelIndex * Math.PI * 2;
+ const rotateX = wheelIndex * 360;
+
+ return (
+ <div
+ key={`${index}-${value}`}
+ style={{
+ alignItems: 'center',
+ backfaceVisibility: 'hidden',
+ display: 'flex',
+ height: '100%',
+ justifyContent: 'center',
+ left: 0,
+ opacity:
+ index === 0
+ ? interpolate(progress, [0.88, 1], [0.28, 1], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ })
+ : 0.28,
+ position: 'absolute',
+ top: 0,
+ perspective: 1000,
+ transform: `translateZ(${Math.cos(angle) * 100}px) translateY(${Math.sin(angle) * 100}px) rotateX(${rotateX}deg)`,
+ width: '100%',
+ }}
+ >
+ <div
+ style={{
+ backfaceVisibility: 'hidden',
+ textAlign: 'center',
+ transform: `rotateX(${-rotateX}deg)`,
+ width: '100%',
+ }}
+ >
+ {value}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </Sequence>
+ );
+ },
+);
+
+const InteractiveSpinningTextWheel = Interactive.withSchema({
+ Component: SpinningTextWheelInner,
+ componentName: '<SpinningTextWheel>',
+ componentIdentity: null,
+ schema: spinningTextWheelSchema,
+ supportsEffects: false,
+}) as React.FC<SpinningTextWheelProps>;
+
+export const SpinningTextWheel: React.FC<SpinningTextWheelProps> = (props) => {
+ return (
+ <InteractiveSpinningTextWheel
+ items={'Friday\nSaturday\nSunday\nMonday\nTuesday\nWednesday\nThursday'}
+ name="Spinning text wheel"
+ style={{
+ color: '#182033',
+ fontFamily: 'Mona Sans',
+ fontSize: 65,
+ fontWeight: 700,
+ lineHeight: 1,
+ }}
+ {...props}
+ />
+ );
+};
diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.ts
index dc771b00cf..423fbe74ee 100644
--- a/packages/docs/src/components/Elements/element-definitions.ts
+++ b/packages/docs/src/components/Elements/element-definitions.ts
@@ -23,6 +23,7 @@ import {NameLowerThird} from '../../../elements/overlays/name-lower-third/name-l
import {CircleMarker} from '../../../elements/text/circle-marker/circle-marker';
import {CrossedOffText} from '../../../elements/text/crossed-off/crossed-off';
import {NewsArticleHighlight} from '../../../elements/text/news-article-highlight/news-article-highlight';
+import {SpinningTextWheel} from '../../../elements/text/spinning-text-wheel/spinning-text-wheel';
import {StrikeThroughText} from '../../../elements/text/strike-through/strike-through';
import {TextMarker} from '../../../elements/text/text-marker/text-marker';
import {YouTubeEndCard} from '../../../elements/youtube/youtube-end-card/youtube-end-card';
@@ -442,6 +443,28 @@ const elementImplementations = {
installationMode: 'wrapped',
width: 1920,
},
+ 'text/spinning-text-wheel': {
+ component: SpinningTextWheel,
+ contributors: [{username: 'JonnyBurger', contribution: null}],
+ description:
+ 'A 3D text wheel that spins through options and decelerates onto a highlighted selection.',
+ dependencies: [{name: '@remotion/google-fonts', version: null}],
+ durationInFrames: 120,
+ elementHeight: 200,
+ elementWidth: 400,
+ fps: 30,
+ height: 1080,
+ posterFrame: 105,
+ preview: {
+ posterUrl:
+ 'https://remotion.media/elements/text-spinning-text-wheel-preview.png',
+ videoUrl:
+ 'https://remotion.media/elements/text-spinning-text-wheel-preview.mp4',
+ },
+ previewPadding: 120,
+ installationMode: 'component-owned-sequence',
+ width: 1920,
+ },
'text/news-article-highlight': {
component: NewsArticleHighlight,
contributors: [],
diff --git a/packages/docs/src/components/Elements/element-registry.ts b/packages/docs/src/components/Elements/element-registry.ts
index efb65fab0d..e9e38bed97 100644
--- a/packages/docs/src/components/Elements/element-registry.ts
+++ b/packages/docs/src/components/Elements/element-registry.ts
@@ -93,6 +93,10 @@ export const elementRegistry = {
category: 'text',
displayName: 'Crossed Off',
},
+ 'text/spinning-text-wheel': {
+ category: 'text',
+ displayName: 'Spinning Text Wheel',
+ },
'text/strike-through': {
category: 'text',
displayName: 'Strike Through',
diff --git a/packages/docs/src/test/elements.test.ts b/packages/docs/src/test/elements.test.ts
index a76a9a82d1..80b6deaf34 100644
--- a/packages/docs/src/test/elements.test.ts
+++ b/packages/docs/src/test/elements.test.ts
@@ -524,6 +524,7 @@ describe('Elements sidebar', () => {
items: [
'text/circle-marker/index',
'text/crossed-off/index',
+ 'text/spinning-text-wheel/index',
'text/strike-through/index',
'text/text-marker/index',
],
@@ -609,6 +610,7 @@ describe('Element preview definitions', () => {
'captions/popping-word-captions',
'captions/word-highlight-captions',
'maps/map-flyover',
+ 'text/spinning-text-wheel',
]);
for (const definition of elementDefinitionList) {