Skip to content
Time Slots preview
Rendered from the SwiftUI source on this page.

Time Slots

From syxUI — written for both platforms, not translated between them.

A booking time-slot grid with the chosen slot filled.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

TimeSlotCard.swift
// Time Slots · syxUI · https://syxui.dev/components/sel-timeslot
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Booking time-slot grid
struct TimeSlotCard: View {
    @State private var sel = 2
    let blue = Color(red: 0.0, green: 0.47, blue: 1.0)
    let slots = ["9:00", "10:30", "12:00", "1:30", "3:00", "4:30"]
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("Select a time").font(.system(size: 15, weight: .semibold))
            LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: 3), spacing: 10) {
                ForEach(Array(slots.enumerated()), id: \.offset) { i, t in
                    let on = sel == i
                    Text(t).font(.system(size: 14, weight: .medium)).foregroundStyle(on ? .white : .primary)
                        .frame(maxWidth: .infinity).padding(.vertical, 11)
                        .background(on ? blue : Color.primary.opacity(0.05), in: RoundedRectangle(cornerRadius: 10, style: .continuous))
                        .overlay(RoundedRectangle(cornerRadius: 10, style: .continuous).stroke(Color.primary.opacity(on ? 0 : 0.1), lineWidth: 1))
                        .onTapGesture { sel = i }
                }
            }
        }.formaCard().frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17