Rectangle
Rectangle is a rectangular shape. Rectangle is used to create rectangular visual elements, such as cards, backgrounds, and containers.
Rectangle is a rectangular shape. Rectangle is used to create rectangular visual elements, such as cards, backgrounds, and containers.
Examples
Basic Usage
Preview unavailable for this example in the static docs build.
Show code
<Rectangle fill="#007AFF" style={{ width: '200px', height: '100px' }}></Rectangle>With Stroke
Preview unavailable for this example in the static docs build.
Show code
<Rectangle fill="#007AFF" stroke="#0051D5" strokeWidth={2} style={{ width: '200px', height: '100px' }}></Rectangle>Colors
Preview unavailable for this example in the static docs build.
Show code
<VStack spacing={10}>
<HStack spacing={10}>
<Rectangle fill="#007AFF" style={{ width: '100px', height: '50px' }} />
<Text>Blue</Text>
</HStack>
<HStack spacing={10}>
<Rectangle fill="#34C759" style={{ width: '100px', height: '50px' }} />
<Text>Green</Text>
</HStack>
<HStack spacing={10}>
<Rectangle fill="#FF9500" style={{ width: '100px', height: '50px' }} />
<Text>Orange</Text>
</HStack>
</VStack>API
| Prop | Type | Required | Description |
|---|---|---|---|
fill | string | No | Fill color |
stroke | string | No | Stroke color |
strokeWidth | number | No | Stroke width |
Inherits additional props from IBaseComponent.
Overview
Rectangle is a rectangular shape. Rectangle is used to create rectangular visual elements, such as cards, backgrounds, and containers.
SwiftUI Correspondence: Similar to SwiftUI's Rectangle.
With Stroke
Add a stroke to the rectangle:
Colors
Display rectangles with different colors:
Notes
- Rectangle requires
fillprop for fill color - Rectangle requires explicit dimensions via
styleprop - Rectangle supports optional
strokeandstrokeWidthprops - Rectangle has sharp corners (use RoundedRectangle for rounded corners)
- Use Rectangle for backgrounds, cards, and containers
Best Practices
- Dimensions: Always provide explicit dimensions
- Fill color: Always provide a fill color
- Stroke: Use stroke for borders and outlines
- Rounded corners: Use RoundedRectangle for rounded corners
- Accessibility: Ensure rectangles have sufficient contrast