🎥 Make videos programmatically with React
0 offset for square and use width and height instead of size
Jonny Burger87b8df08f980
diff --git a/packages/docs/docs/shapes/square.md b/packages/docs/docs/shapes/square.mdindex fa12bd0a58..351f214604 100644--- a/packages/docs/docs/shapes/square.md+++ b/packages/docs/docs/shapes/square.md@@ -8,41 +8,55 @@ _Part of the [` @remotion/shapes`](/docs/shapes) package._Generate Square SVG component-## Arguments+## Props-### `options`-An object with the following arguments:+### `width`-- `width`: `number` - The width of the svg-- `height`: `number` - The height of the svg-- `size`: `number` - The size of the square-- `fill`: `string` - The fill color-- `style`: `React.CSSProperties` - The css styles applied to `svg` component+_number_+The width of the rect and the view box.++### `height`++_number_++The height of the rect and the view box.++### `fill`++_string_++The fill color of the rect.++### `style`++_`React.CSSProperties`, optional_++CSS styles applied to `svg` element.Example Square SVG```tsx twoslash-import { Square } from "@remotion/shapes";import { AbsoluteFill } from "remotion";export const MyComposition = () => {return (<AbsoluteFill- style={{- backgroundColor: "white",- justifyContent: "center",- alignItems: "center",- }}- >- <Square width={200} height={200} size={100} fill="red" />- </AbsoluteFill>+ style={{+ backgroundColor: "white",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <Square width={200} height={200} fill="red" />+ </AbsoluteFill>);};```## See also+- [makeTriangle()](/docs/shapes/make-triangle)- [makeSquare()](/docs/shapes/make-square)- [`@remotion/shapes`](/docs/shapes)diff --git a/packages/example/src/Shapes/SquareTest.tsx b/packages/example/src/Shapes/SquareTest.tsxindex 9b6ad76d9e..05d6d5fa5f 100644--- a/packages/example/src/Shapes/SquareTest.tsx+++ b/packages/example/src/Shapes/SquareTest.tsx@@ -12,7 +12,7 @@ const SquareTest: React.FC = () => {alignItems: 'center',}}>- <Square width={200} height={200} size={100} fill="red" />+ <Square width={200} height={400} fill="red" /></AbsoluteFill>);};diff --git a/packages/shapes/src/make-square.ts b/packages/shapes/src/make-square.tsindex 494464bb4e..690580ef15 100644--- a/packages/shapes/src/make-square.ts+++ b/packages/shapes/src/make-square.ts@@ -1,9 +1,10 @@export type MakeSquareProps = {x?: number;y?: number;- size: number;+ width: number;+ height: number;};-export const makeSquare = ({x = 50, y = 50, size}: MakeSquareProps) => {- return `M ${x}, ${y} l ${size}, 0 l 0, ${size} l ${-size}, 0 Z`;+export const makeSquare = ({x = 0, y = 0, width, height}: MakeSquareProps) => {+ return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;};diff --git a/packages/shapes/src/square.tsx b/packages/shapes/src/square.tsxindex a9c3b606e8..bf0e91a2e9 100644--- a/packages/shapes/src/square.tsx+++ b/packages/shapes/src/square.tsx@@ -4,18 +4,11 @@ import {makeSquare} from './make-square';export type SquareProps = {width: number;height: number;- size: number;fill?: string;style?: React.CSSProperties;};-export const Square: React.FC<SquareProps> = ({- width,- height,- size,- fill,- style,-}) => {+export const Square: React.FC<SquareProps> = ({width, height, fill, style}) => {return (<svgwidth={width}@@ -27,7 +20,8 @@ export const Square: React.FC<SquareProps> = ({><pathd={makeSquare({- size,+ width,+ height,})}fill={fill}/>diff --git a/packages/shapes/src/test/make-square.test.ts b/packages/shapes/src/test/make-square.test.tsindex e07e4d745c..c2b8e0a41d 100644--- a/packages/shapes/src/test/make-square.test.ts+++ b/packages/shapes/src/test/make-square.test.ts@@ -2,6 +2,6 @@ import {expect, test} from 'vitest';import {makeSquare} from '../make-square';test('Should be able to make a square path', () => {- const square = makeSquare({x: 50, y: 50, size: 100});- expect(square).toEqual('M 50, 50 l 100, 0 l 0, 100 l -100, 0 Z');+ const square = makeSquare({x: 50, y: 50, width: 100, height: 100});+ expect(square).toEqual('M 50 50 l 100 0 l 0 100 l -100 0 Z');});diff --git a/packages/shapes/src/test/square.test.tsx b/packages/shapes/src/test/square.test.tsxindex 09d2b172d4..8661ef578a 100644--- a/packages/shapes/src/test/square.test.tsx+++ b/packages/shapes/src/test/square.test.tsx@@ -3,9 +3,7 @@ import {Square} from '../square';import {render} from './test-utils';test('Should be able to make a square svg', () => {- const {container} = render(- <Square width={200} height={200} size={100} fill="red" />- );+ const {container} = render(<Square width={200} height={200} fill="red" />);// assert shape typeexpect(container.querySelector('svg')?.getAttribute('data-shape-type')@@ -13,6 +11,6 @@ test('Should be able to make a square svg', () => {// assert pathexpect(container.querySelector('path')?.getAttribute('d')).toEqual(- 'M 50, 50 l 100, 0 l 0, 100 l -100, 0 Z'+ 'M 0 0 l 200 0 l 0 200 l -200 0 Z');});