Skip to content

🎥 Make videos programmatically with React

documentation page

Jonny Burger0cc7b06febc1
diff --git a/packages/docs/components/demos/Star.tsx b/packages/docs/components/demos/Star.tsx
index 5cafc711ef..a309e83ca1 100644
--- a/packages/docs/components/demos/Star.tsx
+++ b/packages/docs/components/demos/Star.tsx
@@ -6,7 +6,17 @@ export const StarDemo: React.FC<{
darkMode: boolean;
innerRadius: number;
outerRadius: number;
-}> = ({ innerRadius, outerRadius, darkMode }) => {
+ cornerRadius: number;
+ edgeRoundness: number | null;
+ points: number;
+}> = ({
+ innerRadius,
+ points,
+ outerRadius,
+ darkMode,
+ cornerRadius,
+ edgeRoundness,
+}) => {
return (
<AbsoluteFill
style={{
@@ -18,9 +28,11 @@ export const StarDemo: React.FC<{
fill={darkMode ? "white" : "var(--ifm-link-color)"}
height={200}
width={200}
- points={5}
+ points={points}
innerRadius={innerRadius}
outerRadius={outerRadius}
+ cornerRadius={cornerRadius}
+ edgeRoundness={edgeRoundness}
/>
</AbsoluteFill>
);
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 9d36ba01e8..e7cb563354 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -222,6 +222,33 @@ export const starDemo: DemoType = {
name: "outerRadius",
optional: "no",
},
+ {
+ name: "edgeRoundness",
+ default: 1,
+ max: 2,
+ min: -2,
+ step: 0.01,
+ type: "numeric",
+ optional: "default-disabled",
+ },
+ {
+ name: "points",
+ default: 5,
+ max: 20,
+ min: 3,
+ step: 1,
+ type: "numeric",
+ optional: "no",
+ },
+ {
+ name: "cornerRadius",
+ default: 0,
+ max: 100,
+ min: 0,
+ step: 1,
+ type: "numeric",
+ optional: "no",
+ },
],
};
diff --git a/packages/shapes/src/components/star.tsx b/packages/shapes/src/components/star.tsx
index 6d4bbace4d..eb334fc0e7 100644
--- a/packages/shapes/src/components/star.tsx
+++ b/packages/shapes/src/components/star.tsx
@@ -12,11 +12,21 @@ export const Star: React.FC<StarProps> = ({
innerRadius,
outerRadius,
points,
+ cornerRadius,
+ edgeRoundness,
...props
}) => {
return (
<RenderSvg
- {...makeStar({height, width, innerRadius, outerRadius, points})}
+ {...makeStar({
+ height,
+ width,
+ innerRadius,
+ outerRadius,
+ points,
+ cornerRadius,
+ edgeRoundness,
+ })}
{...props}
/>
);
diff --git a/packages/shapes/src/utils/make-star.ts b/packages/shapes/src/utils/make-star.ts
index 9b428344f5..1dcff6b881 100644
--- a/packages/shapes/src/utils/make-star.ts
+++ b/packages/shapes/src/utils/make-star.ts
@@ -9,6 +9,8 @@ export type MakeStarProps = {
points: number;
innerRadius: number;
outerRadius: number;
+ edgeRoundness: number | null;
+ cornerRadius: number;
};
export const makeStar = ({
@@ -17,6 +19,8 @@ export const makeStar = ({
points,
innerRadius,
outerRadius,
+ cornerRadius,
+ edgeRoundness,
}: MakeStarProps): ShapeInfo => {
const centerX = width / 2;
const centerY = height / 2;
@@ -27,6 +31,8 @@ export const makeStar = ({
points,
innerRadius,
outerRadius,
+ cornerRadius,
+ edgeRoundness,
});
return {
diff --git a/packages/shapes/src/utils/star.ts b/packages/shapes/src/utils/star.ts
index df1942db6c..9a24ca4a21 100644
--- a/packages/shapes/src/utils/star.ts
+++ b/packages/shapes/src/utils/star.ts
@@ -1,3 +1,6 @@
+import {serializeInstructions} from './instructions';
+import {joinPoints} from './join-points';
+
type PolarToCartesianProps = {
centerX: number;
centerY: number;
@@ -25,6 +28,8 @@ export type StarProps = {
points: number;
innerRadius: number;
outerRadius: number;
+ edgeRoundness: number | null;
+ cornerRadius: number;
};
export const star = ({
@@ -33,18 +38,30 @@ export const star = ({
points,
innerRadius,
outerRadius,
+ cornerRadius,
+ edgeRoundness,
}: StarProps): string => {
const degreeIncrement = 360 / (points * 2);
- const d = new Array(points * 2).fill('true').map((_p, i) => {
- const radius = i % 2 === 0 ? outerRadius : innerRadius;
- const degrees = degreeIncrement * i;
- const point = polarToCartesian({
- centerX,
- centerY,
- radius,
- angleInDegrees: degrees,
+ const d = new Array(points * 2)
+ .fill('true')
+ .map((_p, i): [number, number] => {
+ const radius = i % 2 === 0 ? outerRadius : innerRadius;
+ const degrees = degreeIncrement * i;
+ const point = polarToCartesian({
+ centerX,
+ centerY,
+ radius,
+ angleInDegrees: degrees,
+ });
+
+ return [point.x, point.y];
});
- return `${point.x},${point.y}`;
- });
- return `M${d}Z`;
+
+ return serializeInstructions(
+ joinPoints([...d, d[0]], {
+ edgeRoundness,
+ cornerRadius,
+ roundCornerStrategy: 'arc',
+ })
+ );
};