Layout Components

SwiftUI-inspired layout components for building modern, responsive web interfaces

← Back to Showcase

HStack - Horizontal Stack

Arrange elements horizontally with customizable alignment and spacing.

Swift Code

// Basic HStack
HStack {
    Button("Previous")
    Button("Next")
}

// With spacing and alignment
HStack(alignment: .center, spacing: 20) {
    Img(src: "/icon.png", alt: "Icon")
        .style("width", "40px")
        .style("height", "40px")
    Text("User Profile")
    Spacer()
    Button("Edit")
}

// Different alignments
HStack(alignment: .top, spacing: 16) {
    Div { Text("Tall Box") }.style("height", "100px")
    Div { Text("Short Box") }.style("height", "60px")
    Div { Text("Medium Box") }.style("height", "80px")
}

Generated HTML

<div style="display: flex; flex-direction: row; align-items: center;">
    <button>Previous</button>
    <button>Next</button>
</div>

<!-- With spacing and alignment -->
<div style="display: flex; flex-direction: row; align-items: center; gap: 20px;">
    <img src="/icon.png" alt="Icon" style="width: 40px; height: 40px;">
    User Profile
    <div style="flex: 1;"></div>
    <button>Edit</button>
</div>

Preview

Basic HStack:

Profile bar with Spacer:

πŸ‘€
John DoePremium Member

Alignment variations:

alignment: .top

100px
60px
80px

alignment: .center

100px
60px
80px

alignment: .bottom

100px
60px
80px

VStack - Vertical Stack

Arrange elements vertically with customizable alignment and spacing.

Swift Code

// Basic VStack
VStack {
    H3("Settings")
    P("Configure your preferences")
}

// Form with VStack
VStack(alignment: .leading, spacing: 16) {
    Label("Username")
    Input(type: "text", name: "username")
    Label("Email")
    Input(type: "email", name: "email")
    Button("Save Changes")
}

// Card with centered content
VStack(alignment: .center, spacing: 24) {
    Img(src: "/logo.png", alt: "Logo")
    H2("Welcome Back!")
    P("Sign in to continue")
    Button("Sign In")
}

Generated HTML

<div style="display: flex; flex-direction: column;">
    <h3>Settings</h3>
    <p>Configure your preferences</p>
</div>

<!-- Form with VStack -->
<div style="display: flex; flex-direction: column; align-items: flex-start; gap: 16px;">
    <label>Username</label>
    <input type="text" name="username">
    <label>Email</label>
    <input type="email" name="email">
    <button>Save Changes</button>
</div>

Preview

Settings

Configure your preferences below

Notifications
β†’
Privacy
β†’
Security
β†’
πŸ”

Welcome Back!

Sign in to continue to your dashboard

ZStack - Layered Stack

Layer elements on top of each other with precise alignment control.

Swift Code

// Card with badge overlay
ZStack(alignment: .topTrailing) {
    Div {
        Img(src: "/product.jpg", alt: "Product")
        H4("Premium Package")
        P("$99/month")
    }
    .class("product-card")
    
    Span("NEW")
        .class("badge")
        .style("margin", "10px")
}

// Hero section with overlay
ZStack(alignment: .center) {
    Img(src: "/hero.jpg", alt: "Hero")
        .style("width", "100%")
        .style("height", "400px")
    
    VStack(spacing: 16) {
        H1("Welcome to Swiftlets")
        P("Build beautiful web apps with Swift")
        Button("Get Started")
    }
    .style("color", "white")
    .style("text-align", "center")
}

Generated HTML

<div style="position: relative;">
    <div class="product-card">
        <img src="/product.jpg" alt="Product">
        <h4>Premium Package</h4>
        <p>$99/month</p>
    </div>
    <span class="badge" style="position: absolute; top: 0; right: 0; margin: 10px;">NEW</span>
</div>

Preview

Product cards with overlay badges:

πŸ“±

Starter

$9/month

POPULAR
πŸ’Ό

Professional

$29/month

BEST VALUE
πŸš€

Enterprise

$99/month

NEW

Hero section with centered overlay:

Build Amazing Apps

Create beautiful web experiences with SwiftUI-style syntax

Grid Layout

Create powerful grid layouts with flexible column configurations.

Swift Code

// Fixed column count
Grid(columns: .count(3), spacing: 20) {
    ForEach(1...6) { i in
        Card(number: i)
    }
}

// Responsive columns
Grid(columns: .custom("repeat(auto-fit, minmax(250px, 1fr))"), spacing: 16) {
    ForEach(features) { feature in
        FeatureCard(feature)
    }
}

// Custom grid template
Grid(
    columns: .custom("2fr 1fr"),
    rowGap: 20,
    columnGap: 30
) {
    MainContent()
    Sidebar()
}

Generated HTML

<!-- Fixed columns -->
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;">
    <!-- cards -->
</div>

<!-- Responsive columns -->
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px;">
    <!-- features -->
</div>

Preview

Dashboard stats grid:

πŸ‘₯
+12%
Users

12,543

πŸ’°
+23%
Revenue

$48.2K

πŸ“¦
+8%
Orders

3,421

πŸ“ˆ
+5%
Growth

87.3%

Responsive feature grid (resize window to see reflow):

⚑

Fast

Lightning quick performance

πŸ›‘οΈ

Secure

Enterprise-grade security

πŸ“±

Responsive

Works on all devices

🎨

Beautiful

Modern, clean design

πŸ”§

Flexible

Highly customizable

πŸš€

Scalable

Grows with your needs

Container

Responsive containers with predefined breakpoints for consistent layouts.

Swift Code

// Small container (max-width: 576px)
Container(maxWidth: .small) {
    H2("Article Title")
    P("Perfect for blog posts and focused reading.")
}

// Medium container (max-width: 768px)
Container(maxWidth: .medium, padding: 20) {
    ContactForm()
}

// Large container (max-width: 1140px)
Container(maxWidth: .large) {
    NavigationBar()
    HeroSection()
    Features()
}

// Full-width section with contained content
Section {
    Container(maxWidth: .medium) {
        H2("Contained within full-width section")
    }
}
.style("background", "#f8f9fa")

Generated HTML

<!-- Small container -->
<div style="max-width: 576px; margin: 0 auto;">
    <h2>Article Title</h2>
    <p>Perfect for blog posts and focused reading.</p>
</div>

<!-- Large container with padding -->
<div style="max-width: 1140px; margin: 0 auto; padding: 20px;">
    <!-- content -->
</div>

Preview

Container.small β€’ max-width: 576px

Use for: Blog posts, articles

Container.medium β€’ max-width: 768px

Use for: Forms, focused content

Container.large β€’ max-width: 1140px

Use for: Main site content

Spacer

Flexible space that expands to push adjacent content apart.

Swift Code

// Navigation bar
HStack {
    H3("Logo")
    Spacer()
    Link(href: "/", "Home")
    Link(href: "/about", "About")
    Link(href: "/contact", "Contact")
}

// Center content
HStack {
    Spacer()
    Button("Centered")
    Spacer()
}

// Spacer with minimum length
HStack {
    Text("Left")
    Spacer(minLength: 100)
    Text("Right")
}

Generated HTML

<div style="display: flex; align-items: center;">
    <h3>Logo</h3>
    <div style="flex: 1;"></div>
    <a href="/">Home</a>
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
</div>

Preview

πŸš€ Swiftlets

Social media bar:

Spacer with minimum length ensures spacing:

Short
Apart

Even in small containers, minimum spacing is maintained

Complex Layout Composition

Combine layout components to build sophisticated, responsive interfaces.

Swift Code

Container(maxWidth: .large) {
    VStack(spacing: 24) {
        // Header
        HStack {
            H1("Dashboard")
            Spacer()
            HStack(spacing: 12) {
                Button("Settings")
                Button("Profile")
            }
        }
        
        // Stats Grid
        Grid(columns: .count(4), spacing: 16) {
            ForEach(stats) { stat in
                StatCard(stat)
            }
        }
        
        // Main Content
        HStack(alignment: .top, spacing: 24) {
            // Main area
            VStack(spacing: 16) {
                ForEach(posts) { post in
                    PostCard(post)
                }
            }
            .style("flex", "2")
            
            // Sidebar
            VStack(spacing: 16) {
                ActivityFeed()
                QuickActions()
            }
            .style("flex", "1")
        }
    }
}

Generated HTML

<div style="max-width: 1140px; margin: 0 auto;">
    <!-- Complex nested layout -->
</div>

Preview

Analytics Dashboard

πŸ“Š
+12%
Views

45.2K

πŸ‘₯
+23%
Users

8,421

πŸ’¬
+8%
Comments

1,893

⭐
+0.2
Rating

4.8/5

Recent Activity

πŸ“
New blog post published1 hours ago β€’ 234 views
πŸ“
New blog post published2 hours ago β€’ 234 views
πŸ“
New blog post published3 hours ago β€’ 234 views

Quick Actions

πŸ“New Post
πŸ“ŠView Analytics
πŸ‘₯Manage Team
βš™οΈSettings

Performance

CPU
65%
Memory
82%
Storage
45%