Container
Container is Layr's most versatile layout component, mirroring Flutter's Container widget. It provides a declarative API for styling, sizing, positioning, and decorating content with comprehensive control over padding, margin, borders, shadows, gradients, and transformations.

Tsx

import { Container } from '@dynshift/layr';

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
1. Basic Usage
1a. Simple Container

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
1b. With Padding and Margin

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
2. Dimensions
Container accepts both numeric (pixels) and string (CSS) values for sizing.
2a. Fixed Dimensions

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
2b. Responsive Dimensions

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
2c. CSS Units

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
3. Padding
Container supports multiple padding syntaxes for maximum flexibility.
3a. Uniform Padding

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
3b. Horizontal & Vertical Padding

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
3c. Individual Sides

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
3d. Shorthand Props

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
3e. Padding Priority
When multiple padding props are used, more specific props override general ones.

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
4. Margin
Margin works identically to padding with the same syntaxes.
4a. Uniform Margin

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
4b. Horizontal & Vertical Margin

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
4c. Individual Sides

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5. BoxDecoration
The decoration prop provides Flutter's powerful BoxDecoration API.
5a. Background Color

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5b. Border Radius

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5c. Box Shadow

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5d. Multiple Shadows

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5e. Borders

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5f. Uniform Border (Helper)

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
5g. Border Styles

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
6. Gradients
Container supports linear and radial gradients.
6a. Linear Gradient

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
6b. Gradient with Direction

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
6c. Gradient with Color Stops

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
6d. Radial Gradient

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
7. Background Images
Display background images with full control over sizing and positioning.
7a. Basic Image

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
7b. Image Options

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
Available fit values: 'cover', 'contain', 'fill', 'none', 'scale-down'
8. Shape
Container supports rectangular and circular shapes.
8a. Circle Shape

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
Note: When shape is BoxShape.circle, borderRadius is ignored and the container becomes a perfect circle with border-radius: 50% and aspect-ratio: 1/1.
9. Foreground Decoration
Apply decoration layers on top of content:

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
10. Alignment
Align children within the container using Flutter's alignment system.
10a. Center Alignment

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
ValuePosition
topLeftTop-left corner
topCenterTop-center
topRightTop-right corner
centerLeftVertically centered, left
centerPerfect center
centerRightVertically centered, right
bottomLeftBottom-left corner
bottomCenterBottom-center
bottomRightBottom-right corner
10b. Bottom Right Alignment

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
Implementation: Uses CSS Flexbox with appropriate justify-content and align-items values.
11. Constraints
Apply min/max width and height constraints:

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
11a. Responsive Max Width

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
12. Transform
12a. Rotation

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
12b. Scale

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
12c. Transform Origin

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
transformAlignment values: Same as alignment prop — determines the transform-origin.
13. Event Handlers
13a. Click Events

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
13b. Custom Cursor

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
Available cursors: pointer, default, text, none
14. Clip Behavior
Control how overflowing content is clipped:

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
Options:"none" — No clipping (default) • "hardEdge" — Clip with overflow: hidden"antiAlias" — Clip with overflow: hidden
15. Helper Functions
Layr provides Flutter-style helper functions for cleaner syntax.
15a. EdgeInsetsAll

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
15b. EdgeInsetsSymmetric

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
15c. EdgeInsetsOnly

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
15d. BorderAll

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
15e. BorderRadiusCircular

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
16. Complete Examples
16a. Card Component

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
16b. Button Component

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
16c. Hero Section

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
16d. Avatar

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
16e. Badge

Tsx

Preview

NOTE: Previews are not depiction of actual website output.
17. TypeScript
Container is fully typed with comprehensive IntelliSense support:

Tsx

import type { ContainerProps, BoxDecoration, EdgeInsets } from '@dynshift/layr';
const decoration: BoxDecoration = {
color: '#eb1660',
borderRadius: 12,
boxShadow: [{
color: 'rgba(0, 0, 0, 0.2)',
offset: { dx: 0, dy: 4 },
blurRadius: 8,
}],
};
const Card: React.FC<ContainerProps> = (props) => {
return (
<Container
padding={24}
decoration={decoration}
{...props}
/>
);
};
18. API Reference
18a. ContainerProps
PropTypeDescription
childrenReactNodeContent to render inside container
widthnumber | stringContainer width (px or CSS)
heightnumber | stringContainer height (px or CSS)
paddingnumber | EdgeInsetsPadding on all sides or per side
paddingHorizontalnumberHorizontal padding (left + right)
paddingVerticalnumberVertical padding (top + bottom)
paddingTopnumberTop padding
paddingBottomnumberBottom padding
paddingLeftnumberLeft padding
paddingRightnumberRight padding
marginnumber | EdgeInsetsMargin on all sides or per side
marginHorizontalnumberHorizontal margin
marginVerticalnumberVertical margin
marginTopnumberTop margin
marginBottomnumberBottom margin
marginLeftnumberLeft margin
marginRightnumberRight margin
decorationBoxDecorationBackground decoration
foregroundDecorationBoxDecorationForeground decoration layer
colorstringBackground color (shorthand)
alignmentAlignmentChild alignment within container
constraintsBoxConstraintsSize constraints
transformstringCSS transform
transformAlignmentAlignmentTransform origin
clipBehavior'none' 'hardEdge' 'antiAlias'How to clip overflowing content
onTap() => voidClick handler (Flutter-style)
onClick() => voidClick handler
cursor'pointer' 'default' 'text' | 'none'Mouse cursor style
classNamestringAdditional CSS classes
styleCSSPropertiesInline CSS styles (escape hatch)
idstringHTML id attribute
rolestringARIA role
ariaLabelstringARIA label
19. Next Steps
• Column — Vertical layout with alignment • Row — Horizontal layout with alignment • Stack — Layered positioning