Skip to content

Visualize Your Ideas With Code

docs(2d): add smoothCorners, cornerSharpness (#394)

Gustav Neustadtfbeb3924e584
diff --git a/packages/2d/src/components/Rect.ts b/packages/2d/src/components/Rect.ts
index f1425791..e2cd884e 100644
--- a/packages/2d/src/components/Rect.ts
+++ b/packages/2d/src/components/Rect.ts
@@ -11,7 +11,15 @@ import {SignalValue, SimpleSignal} from '@motion-canvas/core/lib/signals';
export interface RectProps extends ShapeProps {
radius?: SignalValue<PossibleSpacing>;
+
+ /**
+ * {@inheritDoc Rect.smoothCorners}
+ */
smoothCorners?: SignalValue<boolean>;
+
+ /**
+ * {@inheritDoc Rect.cornerSharpness}
+ */
cornerSharpness?: SignalValue<number>;
}
@@ -19,10 +27,47 @@ export class Rect extends Shape {
@spacingSignal('radius')
public declare readonly radius: SpacingSignal<this>;
+ /**
+ * Will set the corner drawing method to smooth corners.
+ *
+ * @remarks
+ * Smooth corners are drawn continuously by a bezìer curves, rather than by a
+ * quarter circle.
+ *
+ * When `smoothCorners` is set to `true`, the sharpness of the curve can be
+ * controlled by the {@link Rect.cornerSharpness}.
+ *
+ * @example
+ * ```tsx
+ * <Rect
+ * width={300}
+ * height={300}
+ * smoothCorners={true}
+ * />
+ * ```
+ */
@initial(false)
@signal()
public declare readonly smoothCorners: SimpleSignal<boolean, this>;
+ /**
+ * Controlls the sharpness of the corners. {@link Rect.smoothCorners} must
+ * be set to `true`.
+ *
+ * @remarks
+ * By default the `cornerSharpness` is set to `0.6` which represents smooth,
+ * circle-like rounding. At `0` the edges are squared off.
+ *
+ * @example
+ * ```tsx
+ * <Rect
+ * width={300}
+ * height={300}
+ * smoothCorners={true}
+ * cornerSharpness={0.7}
+ * />
+ * ```
+ */
@initial(0.6)
@signal()
public declare readonly cornerSharpness: SimpleSignal<number, this>;