🎥 Make videos programmatically with React
`remotion`: Release `<Solid>` component
JonnyBurger1cf23d600efc
diff --git a/packages/core/src/effects/Solid.tsx b/packages/core/src/effects/Solid.tsxindex 2004cecdfc..23ca156e97 100644--- a/packages/core/src/effects/Solid.tsx+++ b/packages/core/src/effects/Solid.tsx@@ -24,12 +24,12 @@ import {} from './use-memoized-effects.js';type MandatoryProps = {- readonly color: string;readonly width: number;readonly height: number;};type OptionalProps = {+ readonly color: string | undefined;readonly _experimentalEffects: EffectsProp;readonly className: string | undefined;readonly style: React.CSSProperties | undefined;@@ -44,7 +44,7 @@ export type SolidProps = MandatoryProps & Partial<OptionalProps>;const solidSchema = {color: {type: 'color',- default: '#ffffff',+ default: undefined,description: 'Color',},width: {@@ -139,8 +139,11 @@ const SolidInner: React.FC<return;}- ctx.fillStyle = color;- ctx.fillRect(0, 0, 1, 1);+ ctx.clearRect(0, 0, 1, 1);+ if (color !== undefined) {+ ctx.fillStyle = color;+ ctx.fillRect(0, 0, 1, 1);+ }runEffectChain({state: chainState.get(width, height)!,diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 4ff544eeee..c526aee732 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -12,7 +12,6 @@ import type {TRenderAsset,} from './CompositionManager.js';import type {DelayRenderScope} from './delay-render.js';-import {Solid} from './effects/Solid.js';import {addSequenceStackTraces} from './enable-sequence-stack-traces.js';import type {StaticFile} from './get-static-files.js';import {useIsPlayer} from './is-player.js';@@ -138,6 +137,11 @@ export type {EffectDefinition,EffectFactory,} from './effects/index.js';+/**+ * @description Renders a solid-color rectangle on a `<canvas>`.+ * @see [Documentation](https://www.remotion.dev/docs/solid)+ */+export {Solid} from './effects/Solid.js';export type {SolidProps} from './effects/Solid.js';export {HtmlInCanvas,@@ -243,7 +247,6 @@ export const Experimental = {* @see [Documentation](https://www.remotion.dev/docs/null)*/Null,- Solid,useIsPlayer,};diff --git a/packages/core/src/test/solid.test.tsx b/packages/core/src/test/solid.test.tsxindex 30edfeeb47..f8d78b8cae 100644--- a/packages/core/src/test/solid.test.tsx+++ b/packages/core/src/test/solid.test.tsx@@ -69,6 +69,16 @@ test('<Solid> forwards className and style', () => {expect(canvas?.style.opacity).toBe('0.5');});+test('<Solid> renders without a color', () => {+ const {container} = render(+ <WrapSequenceContext>+ <Solid width={64} height={64} />+ </WrapSequenceContext>,+ );++ expect(container.querySelector('canvas')).not.toBeNull();+});+test('<Solid> accepts an empty effects array', () => {const {container} = render(<WrapSequenceContext>diff --git a/packages/docs/docs/solid.mdx b/packages/docs/docs/solid.mdxnew file mode 100644index 0000000000..36d229f341--- /dev/null+++ b/packages/docs/docs/solid.mdx@@ -0,0 +1,87 @@+---+image: /generated/articles-docs-solid.png+id: solid+title: <Solid>+crumb: 'API'+---++# <Solid><AvailableFrom v="4.0.464" />++Renders a solid-color rectangle on a `<canvas>` element.+Use it for colored backgrounds or overlays in your composition.++```tsx twoslash title="MyComp.tsx"+import {AbsoluteFill, Solid} from 'remotion';++export const MyComp: React.FC = () => {+ return (+ <AbsoluteFill>+ <Solid color="#3344ff" width={1920} height={1080} />+ </AbsoluteFill>+ );+};+```++## API++### `width`++Width of the canvas in pixels. Must be a positive integer.++### `height`++Height of the canvas in pixels. Must be a positive integer.++### `color?`++Fill color of the rectangle.+If omitted, the canvas stays transparent.++```tsx twoslash title="Transparent background"+import {AbsoluteFill, Solid} from 'remotion';++export const MyComp: React.FC = () => {+ return (+ <AbsoluteFill>+ <Solid width={1920} height={1080} />+ </AbsoluteFill>+ );+};+```++### `className?`++A class name to apply to the `<canvas>` element.++### `style?`++Inline styles to apply to the `<canvas>` element.+The component also supports the visual transform fields documented on [`<Sequence>`](/docs/sequence#style) (`style.translate`, `style.scale`, `style.rotate`).++## Sequence props++`<Solid>` is wrapped in a [`<Sequence>`](/docs/sequence) with `layout="none"`.+You can pass [`from`](/docs/sequence#from), [`durationInFrames`](/docs/sequence#durationinframes), [`name`](/docs/sequence#name) and other sequence props to time-shift the layer.++## Adding a ref++You can add a [React ref](https://react.dev/learn/manipulating-the-dom-with-refs) to a `<Solid>` component. If you use TypeScript, type it with `HTMLCanvasElement`:++```tsx twoslash title="MyComp.tsx"+import {useRef} from 'react';+import {Solid} from 'remotion';++const MyComp = () => {+ const ref = useRef<HTMLCanvasElement>(null);+ return <Solid ref={ref} color="red" width={100} height={100} />;+};+```++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering serverSideRendering player studio hideServers/>++## See also++- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/effects/Solid.tsx)+- [`<AbsoluteFill>`](/docs/absolute-fill)diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 1d9d40a2c1..942dfdc1b1 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -170,6 +170,7 @@ const sidebars: SidebarsConfig = {'sequence','series','spring',+ 'solid','staticfile','still','use-buffer-state',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex bb298dc90f..6670929e95 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -5637,6 +5637,15 @@ export const articles = [noAi: false,slug: 'slow-method-to-extract-frame',},+ {+ id: 'solid',+ title: '<Solid>',+ relativePath: 'docs/solid.mdx',+ compId: 'articles-docs-solid',+ crumb: 'API',+ noAi: false,+ slug: 'solid',+ },{id: 'spline',title: 'Import from Spline',diff --git a/packages/docs/static/generated/articles-docs-solid.png b/packages/docs/static/generated/articles-docs-solid.pngnew file mode 100644index 0000000000..dc28aca7f1Binary files /dev/null and b/packages/docs/static/generated/articles-docs-solid.png differdiff --git a/packages/example/src/EffectsTestbed/EffectsTestbed.tsx b/packages/example/src/EffectsTestbed/EffectsTestbed.tsxindex f8c2e735e6..ed69947dad 100644--- a/packages/example/src/EffectsTestbed/EffectsTestbed.tsx+++ b/packages/example/src/EffectsTestbed/EffectsTestbed.tsx@@ -8,7 +8,7 @@ import {StarburstInternals} from '@remotion/starburst';import React from 'react';import {AbsoluteFill,- Experimental,+ Solid,staticFile,useCurrentFrame,useVideoConfig,@@ -113,7 +113,7 @@ const AnimatedLightLeakSolid: React.FC = () => {const progress = durationInFrames <= 1 ? 0 : frame / (durationInFrames - 1);return (- <Experimental.Solid+ <Solidwidth={400}height={300}color="#ff5fa2"diff --git a/packages/example/src/ExperimentalControls/index.tsx b/packages/example/src/ExperimentalControls/index.tsxindex a91fdd5acf..555e87b105 100644--- a/packages/example/src/ExperimentalControls/index.tsx+++ b/packages/example/src/ExperimentalControls/index.tsx@@ -6,13 +6,13 @@ import React from 'react';import {AbsoluteFill,AnimatedImage,- Experimental,Html5Audio,Html5Video,HtmlInCanvas,Img,Sequence,Series,+ Solid,staticFile,} from 'remotion';@@ -229,7 +229,7 @@ export const ExperimentalControlsShowcase: React.FC = () => {</Series></Tile><Tile title="Solid">- <Experimental.Solid color="red" width={100} height={100} />+ <Solid color="red" width={100} height={100} /></Tile></div></AbsoluteFill>