Skip to content

🎥 Make videos programmatically with React

abstract some stuff

Jonny Burgerae8123c10f94
diff --git a/packages/shapes/src/Ellipse.tsx b/packages/shapes/src/components/Ellipse.tsx
similarity index 82%
rename from packages/shapes/src/Ellipse.tsx
rename to packages/shapes/src/components/Ellipse.tsx
index 6b734a0d74..382a95fc13 100644
--- a/packages/shapes/src/Ellipse.tsx
+++ b/packages/shapes/src/components/Ellipse.tsx
@@ -1,6 +1,6 @@
import type React from 'react';
-import type {MakeEllipseOptions} from './make-ellipse';
-import {makeEllipse} from './make-ellipse';
+import type {MakeEllipseOptions} from '../make-ellipse';
+import {makeEllipse} from '../make-ellipse';
import {renderSvg} from './render-svg';
export type EllipseProps = MakeEllipseOptions & {
diff --git a/packages/shapes/src/circle.tsx b/packages/shapes/src/components/circle.tsx
similarity index 55%
rename from packages/shapes/src/circle.tsx
rename to packages/shapes/src/components/circle.tsx
index 02442f2dc8..299c34cdef 100644
--- a/packages/shapes/src/circle.tsx
+++ b/packages/shapes/src/components/circle.tsx
@@ -1,14 +1,10 @@
import type React from 'react';
-import type {MakeCircleProps} from './make-circle';
-import {makeCircle} from './make-circle';
+import type {MakeCircleProps} from '../make-circle';
+import {makeCircle} from '../make-circle';
+import type {AllShapesProps} from './render-svg';
import {renderSvg} from './render-svg';
-export type CircleProps = Omit<MakeCircleProps, 'cx' | 'cy'> & {
- fill?: string;
- stroke?: string;
- strokeWidth?: number;
- style?: React.CSSProperties;
-};
+export type CircleProps = MakeCircleProps & AllShapesProps;
export const Circle: React.FC<CircleProps> = ({
fill,
@@ -21,8 +17,6 @@ export const Circle: React.FC<CircleProps> = ({
return renderSvg({
path: makeCircle({
- cx: radius,
- cy: radius,
radius,
}),
height: size,
diff --git a/packages/shapes/src/rect.tsx b/packages/shapes/src/components/rect.tsx
similarity index 90%
rename from packages/shapes/src/rect.tsx
rename to packages/shapes/src/components/rect.tsx
index 1979a3ca5f..894610b941 100644
--- a/packages/shapes/src/rect.tsx
+++ b/packages/shapes/src/components/rect.tsx
@@ -1,5 +1,5 @@
import type React from 'react';
-import {makeRect} from './make-rect';
+import {makeRect} from '../make-rect';
import {renderSvg} from './render-svg';
export type SquareProps = {
diff --git a/packages/shapes/src/render-svg.tsx b/packages/shapes/src/components/render-svg.tsx
similarity index 73%
rename from packages/shapes/src/render-svg.tsx
rename to packages/shapes/src/components/render-svg.tsx
index ecff7cdc18..a4676d506a 100644
--- a/packages/shapes/src/render-svg.tsx
+++ b/packages/shapes/src/components/render-svg.tsx
@@ -1,20 +1,25 @@
import React from 'react';
+export type AllShapesProps = {
+ style?: React.CSSProperties;
+ stroke?: string;
+ strokeWidth?: number;
+ fill?: string;
+};
+
export const renderSvg = ({
width,
height,
path,
fill,
style,
+ stroke,
+ strokeWidth,
}: {
width: number;
height: number;
path: string;
- fill?: string;
- style?: React.CSSProperties;
- stroke?: string;
- strokeWidth?: number;
-}) => {
+} & AllShapesProps) => {
return (
<svg
width={width}
@@ -24,7 +29,7 @@ export const renderSvg = ({
style={style}
data-shape-type="triangle"
>
- <path d={path} fill={fill} />
+ <path d={path} fill={fill} stroke={stroke} strokeWidth={strokeWidth} />
</svg>
);
};
diff --git a/packages/shapes/src/triangle.tsx b/packages/shapes/src/components/triangle.tsx
similarity index 81%
rename from packages/shapes/src/triangle.tsx
rename to packages/shapes/src/components/triangle.tsx
index 1c2c424bef..82588163f4 100644
--- a/packages/shapes/src/triangle.tsx
+++ b/packages/shapes/src/components/triangle.tsx
@@ -1,6 +1,6 @@
import type React from 'react';
-import type {MakeTriangleProps} from './make-triangle';
-import {makeTriangle} from './make-triangle';
+import type {MakeTriangleProps} from '../make-triangle';
+import {makeTriangle} from '../make-triangle';
import {renderSvg} from './render-svg';
export type TriangleProps = MakeTriangleProps & {
diff --git a/packages/shapes/src/index.ts b/packages/shapes/src/index.ts
index f4ed5121fc..984612d326 100644
--- a/packages/shapes/src/index.ts
+++ b/packages/shapes/src/index.ts
@@ -1,8 +1,8 @@
-export {Circle} from './circle';
-export {Ellipse} from './ellipse';
+export {Circle} from './components/circle';
+export {Ellipse} from './components/Ellipse';
+export {Rect} from './components/rect';
+export {Triangle} from './components/triangle';
export {makeCircle} from './make-circle';
export {makeEllipse} from './make-ellipse';
export {makeRect} from './make-rect';
export {makeTriangle} from './make-triangle';
-export {Rect} from './rect';
-export {Triangle} from './triangle';
diff --git a/packages/shapes/src/make-circle.ts b/packages/shapes/src/make-circle.ts
index d57d61c596..10dd91a50d 100644
--- a/packages/shapes/src/make-circle.ts
+++ b/packages/shapes/src/make-circle.ts
@@ -1,10 +1,11 @@
export type MakeCircleProps = {
- cx: number;
- cy: number;
radius: number;
};
-export const makeCircle = ({cx, cy, radius}: MakeCircleProps) => {
+export const makeCircle = ({radius}: MakeCircleProps) => {
+ const cx = radius;
+ const cy = radius;
+
return `M ${cx} ${cy} m -${radius} 0 a ${radius} ${radius} 0 1 0 ${
(radius as number) * 2
} 0 ${radius} ${radius} 0 1 0 ${-radius * 2} 0`;
diff --git a/packages/shapes/src/test/circle.test.tsx b/packages/shapes/src/test/circle.test.tsx
index ddec173dec..7016161c8c 100644
--- a/packages/shapes/src/test/circle.test.tsx
+++ b/packages/shapes/src/test/circle.test.tsx
@@ -1,5 +1,5 @@
import {expect, test} from 'vitest';
-import {Circle} from '../circle';
+import {Circle} from '../components/circle';
import {render} from './test-utils';
test('Should be able to make a circle svg', () => {
diff --git a/packages/shapes/src/test/ellipse.test.tsx b/packages/shapes/src/test/ellipse.test.tsx
index 7fb214943b..4eec1e96f1 100644
--- a/packages/shapes/src/test/ellipse.test.tsx
+++ b/packages/shapes/src/test/ellipse.test.tsx
@@ -1,5 +1,5 @@
import {expect, test} from 'vitest';
-import {Ellipse} from '../ellipse';
+import {Ellipse} from '../components/Ellipse';
import {render} from './test-utils';
test('Should be able to make a circle svg', () => {
diff --git a/packages/shapes/src/test/square.test.tsx b/packages/shapes/src/test/square.test.tsx
index b6da93ee94..93bd109cd6 100644
--- a/packages/shapes/src/test/square.test.tsx
+++ b/packages/shapes/src/test/square.test.tsx
@@ -1,5 +1,5 @@
import {expect, test} from 'vitest';
-import {Rect} from '../rect';
+import {Rect} from '../components/rect';
import {render} from './test-utils';
test('Should be able to make a rect svg', () => {
diff --git a/packages/shapes/src/test/triangle.test.tsx b/packages/shapes/src/test/triangle.test.tsx
index 4dad3f094b..2903b5eeb5 100644
--- a/packages/shapes/src/test/triangle.test.tsx
+++ b/packages/shapes/src/test/triangle.test.tsx
@@ -1,5 +1,5 @@
import {expect, test} from 'vitest';
-import {Triangle} from '../triangle';
+import {Triangle} from '../components/triangle';
import {render} from './test-utils';
test('Should be able to make a triangle svg', () => {