Rectangle
Draws a rectangle with optional rounded corners for use with backgrounds, progress bars, and borders. background fills the interior, stroke strokes, lineWidth and strokePosition control the width and position of the stroke.
Example
function main() {
return (
<Rectangle
width={160}
height={80}
cornerRadius={16}
background={LinearGradient(['#A9E56F', '#30B3A2'])}
stroke={$env.foreground}
lineWidth={2}
strokePosition="inside"
/>
);
}
Usage
- background fills the rectangle; stroke traces its contour. cornerRadius is limited to half the shorter side. inside keeps strokes within the contour, center straddles it and outside extends beyond it. Parent clipping may cut off outside strokes.
- mask uses alpha: opaque areas reveal, transparent areas hide. Black and white with equal alpha behave identically. A mask does not affect the subject’s layout; size it explicitly and distinguish it from clipped bounds.
- background and stroke accept Paint: Color or Gradient. Construct gradients with LinearGradient, RadialGradient or AngularGradient. Stop locations and centers use 0–1; radial radii use points. HDR wraps one color; visible brightness depends on device and display environment.
Properties
background?PaintBackground paint; accepts a color or gradient. Use clear for transparency.
HDR($env.dark ? "white" : "black")cornerRadius?numberCorner radius in points.
0stroke?PaintStroke paint; accepts a color or gradient. Use clear to hide the stroke.
"clear"lineWidth?numberStroke thickness in points; 0 draws no stroke.
2strokePosition?"inside" | "center" | "outside"Stroke placement relative to the shape boundary: inside, center or outside.
"inside"lineCap?"round" | "butt" | "square"Stroke end shape: butt stops at the endpoint, square extends it, round rounds it.
"round"lineJoin?"round" | "miter" | "bevel"Shape of joined stroke segments: miter, round or bevel.
"round"dash?number[]Alternating painted and empty lengths in points; an empty array makes a solid stroke.
[]dashPhase?numberOffset along the dash pattern, in points.
0trimStart?numberVisible path interval from trimStart to trimEnd, within 0–1. Circle/Ellipse/Arc use angles instead.
0trimEnd?numberVisible path interval from trimStart to trimEnd, within 0–1. Circle/Ellipse/Arc use angles instead.
1Common properties
width?number | "auto" | "fill"Width in points, auto sizing or parent fill.
"fill"height?number | "auto" | "fill"Height in points, auto sizing or parent fill.
"fill"x?numberVisual offset in points: x moves right, y moves down. Does not change layout space.
0y?numberVisual offset in points: x moves right, y moves down. Does not change layout space.
0transform?ViewTransformTransform the whole View without changing layout. Translation uses points; rotation/skew use degrees; scale 1 is unchanged; anchors use 0–1.
{rotation: 0}opacity?numberOpacity of the whole View: 0 is transparent, 1 is opaque.
1clipped?booleanClip drawing that extends beyond the View bounds.
falseclip?"rectangle" | "ellipse"Clipping shape: rectangle or ellipse. Material also accepts false to disable clipping.
"rectangle"mask?View | nullAlpha mask View. Centered without affecting layout; null disables masking.
<Circle width="fill" height="fill" background="white"/>zIndex?numberDrawing order among siblings; larger values appear in front.
0blur?numberBlur radius in points; 0 disables blur.
4innerShadow?DrawingEffectEffect color, opacity, blur radius and x/y offset. Distances are in points.
{color: HDR("black"), opacity: 0.5, radius: 4, x: 0, y: 2}glow?DrawingEffectEffect color, opacity, blur radius and x/y offset. Distances are in points.
{color: HDR("cyan"), radius: 8, opacity: 0.8}shadowColor?ColorColor of the outer shadow.
HDR("black")shadowOpacity?numberOuter shadow opacity from 0 to 1; 0 hides it.
0shadowRadius?numberOuter shadow blur radius in points.
4shadowX?numberOuter shadow offset in points: x right, y down.
0shadowY?numberOuter shadow offset in points: x right, y down.
2animations?Animation[]Animate a supported property when it changes. duration/delay use seconds; from/to set endpoints; repeat and autoreverse control repetition; wrap sets a periodic range.
[{property: "opacity", duration: 0.25, curve: "easeInOut"}]key?string | numberStable identity among siblings.
Practical example
function main() {
return (
<HStack spacing={20}>
<Rectangle
width={90}
height={60}
background="clear"
stroke={$env.accent}
lineWidth={8}
strokePosition="inside"
/>
<Rectangle
width={90}
height={60}
background="clear"
stroke={$env.accent}
lineWidth={8}
strokePosition="outside"
/>
</HStack>
);
}
Animation
widthheightxyopacitybackgroundcornerRadiusblurshadowColorshadowOpacityshadowRadiusshadowXshadowYtrimStarttrimEnddashPhasestrokelineWidthtransform.translateXtransform.translateYtransform.scaleXtransform.scaleYtransform.rotationtransform.skewXtransform.skewYtransform.anchorXtransform.anchorYWhen omitted
The table lists omission behavior verified against implementation. Property examples are copyable syntax, not defaults. Pass explicit values for a fixed result; contextual dimensions and theme colors are not fixed constants.
| Properties | When omitted |
|---|---|
cornerRadius | 0 |
lineWidth | 2 |
strokePosition | "inside" |
trimStart | 0 |
trimEnd | 1 |
background | HDR($env.dark ? 'white' : 'black') |