Components

Product detail

A product with its picture, price, options, rating and an add-to-cart button. Built in all 5 Effect UI styles, in light and dark mode.

Product detail in Prism, light mode
Product detail in Prism, dark mode
Prism ProLiquid Glass on living colour.
Product detail in Ledger, light mode
Product detail in Ledger, dark mode
Ledger FreeCalm, precise, trustworthy.
Product detail in Bounce, light mode
Product detail in Bounce, dark mode
Bounce ProChunky, tactile, joyful.
Product detail in Folio, light mode
Product detail in Folio, dark mode
Folio ProEditorial and literary.
Product detail in Bloom, light mode
Product detail in Bloom, dark mode
Bloom ProSoft, organic, calming.

Source: Ledger

ProductDetailView.swift in the free Ledger style. It needs Ledger's Theme.swift, which comes with the style: join early access on the home page and it's emailed to you.

import SwiftUI

// MARK: - Sample data

private enum Leather: String, CaseIterable, Identifiable {
    case tan, ink, stone, forest
    var id: String { rawValue }

    var name: String {
        switch self {
        case .tan: return "Tan"
        case .ink: return "Ink"
        case .stone: return "Stone"
        case .forest: return "Forest"
        }
    }

    /// Product colour. It is data, not decoration, so it stays fixed across modes.
    var color: Color {
        switch self {
        case .tan: return Color(hex: "#B4532A")
        case .ink: return Color(hex: "#2B2A24")
        case .stone: return Color(hex: "#A59E8C")
        case .forest: return Color(hex: "#0E5C46")
        }
    }

    var stock: String {
        switch self {
        case .stone: return "Only 4 left"
        default: return "In stock"
        }
    }
}

// MARK: - Screen

struct ProductDetailView: View {
    @State private var leather: Leather = .tan
    @State private var saved = false

    private let price = 64.00

    var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: Theme.Space.xl) {
                topBar
                WalletFigure(color: leather.color)
                    .animation(Theme.Motion.stateChange, value: leather)
                summary
                colourPicker
                Text("Cut from one piece of vegetable-tanned bridle leather and stitched by hand. Six cards in three pockets, notes folded in the centre. It darkens with use and keeps its shape.")
                    .ledgerType(.bodyMd)
                    .foregroundStyle(Theme.onSurfaceVariant)
                    .fixedSize(horizontal: false, vertical: true)
                details
            }
            .padding(.horizontal, Theme.Space.margin)
            .padding(.top, Theme.Space.sm)
            .padding(.bottom, Theme.Space.xl)
        }
        .scrollIndicators(.hidden)
        .paperBackground()
        .safeAreaInset(edge: .bottom) {
            BottomActionBar {
                Button("Add to cart · \(Money.format(price, decimals: 2))") {}
                    .buttonStyle(.ledgerPrimary)
                Text("Free shipping over $100.00. Returns within 30 days.")
                    .ledgerType(.bodySm)
                    .monospacedDigit()
                    .foregroundStyle(Theme.onSurfaceMuted)
                    .frame(maxWidth: .infinity, alignment: .leading)
                    .padding(.top, Theme.Space.sm)
            }
        }
        .sensoryFeedback(.selection, trigger: leather)
    }

    // MARK: Sections

    private var topBar: some View {
        HStack(spacing: Theme.Space.sm) {
            IconButton(symbol: "chevron.left")
            Spacer()
            IconButton(symbol: saved ? "bookmark.fill" : "bookmark") { saved.toggle() }
                .sensoryFeedback(.impact(weight: .light), trigger: saved)
            IconButton(symbol: "square.and.arrow.up")
        }
    }

    private var summary: some View {
        VStack(alignment: .leading, spacing: Theme.Space.sm) {
            MicroLabel("Bridle leather · Holds 6 cards")
            Text("Slim card wallet")
                .ledgerType(.headlineLg)
                .foregroundStyle(Theme.onSurface)
            HStack(alignment: .lastTextBaseline) {
                HeroAmount(value: price)
                Spacer()
                rating
            }
            .padding(.top, Theme.Space.xs)
            Hairline(strong: true).padding(.top, Theme.Space.sm)
        }
    }

    private var rating: some View {
        VStack(alignment: .trailing, spacing: Theme.Space.xs) {
            HStack(spacing: Theme.Space.xxs) {
                ForEach(0..<5, id: \.self) { i in
                    Image(systemName: i < 4 ? "star.fill" : "star.leadinghalf.filled")
                        .font(.system(size: 11, weight: .semibold))
                }
                Text("4.6")
                    .font(.system(size: 13, weight: .semibold, design: .monospaced))
                    .padding(.leading, Theme.Space.xs)
            }
            .foregroundStyle(Theme.onSurface)
            Text("1,284 reviews")
                .ledgerType(.bodySm)
                .monospacedDigit()
                .foregroundStyle(Theme.onSurfaceMuted)
        }
        .accessibilityElement(children: .ignore)
        .accessibilityLabel("Rated 4.6 out of 5 from 1,284 reviews")
    }

    private var colourPicker: some View {
        VStack(alignment: .leading, spacing: Theme.Space.md) {
            SectionHeader(title: "Colour", detail: "\(leather.name) · \(leather.stock)")
            HStack(spacing: Theme.Space.md) {
                ForEach(Leather.allCases) { option in
                    Swatch(leather: option, selected: option == leather) {
                        withAnimation(Theme.Motion.stateChange) { leather = option }
                    }
                }
                Spacer()
            }
        }
    }

    private var details: some View {
        VStack(alignment: .leading, spacing: 0) {
            SectionHeader(title: "Details")
            RuledStack {
                detailRow("Dimensions", "98 × 72 mm")
                detailRow("Weight", "38 g")
                detailRow("Leather", "Bridle, 1.2 mm")
                detailRow("Ships", "Dec 1 – 3")
            }
        }
    }

    private func detailRow(_ title: String, _ value: String) -> some View {
        LedgerRow(title: title) {
            Text(value)
                .ledgerType(.numeralMd)
                .foregroundStyle(Theme.onSurface)
        }
    }
}

// MARK: - Swatch

private struct Swatch: View {
    let leather: Leather
    let selected: Bool
    let action: () -> Void

    var body: some View {
        Button(action: action) {
            RoundedRectangle(cornerRadius: Theme.Radius.sm, style: .continuous)
                .fill(leather.color)
                .overlay(
                    RoundedRectangle(cornerRadius: Theme.Radius.sm, style: .continuous)
                        .strokeBorder(Theme.rule, lineWidth: 0.5)
                )
                .frame(width: 36, height: 36)
                .padding(4)
                .overlay(
                    RoundedRectangle(cornerRadius: Theme.Radius.md, style: .continuous)
                        .strokeBorder(selected ? Theme.primaryInk : Color.clear, lineWidth: 1.5)
                )
        }
        .buttonStyle(.plain)
        .accessibilityLabel(leather.name)
        .accessibilityAddTraits(selected ? .isSelected : [])
    }
}

// MARK: - Figure

/// Flat wallet drawn like a specification sheet: solid shapes, stitching and dimension lines.
private struct WalletFigure: View {
    let color: Color

    var body: some View {
        VStack(spacing: Theme.Space.md) {
            HStack(alignment: .center, spacing: Theme.Space.md) {
                wallet
                VerticalDimension(label: "72 MM")
                    .frame(height: 144)
            }
            HorizontalDimension(label: "98 MM")
                .frame(width: 196)
                .padding(.trailing, 36)
        }
        .frame(maxWidth: .infinity)
        .padding(.vertical, Theme.Space.xl)
        .ledgerCard()
        .accessibilityElement(children: .ignore)
        .accessibilityLabel("Slim card wallet, 98 by 72 millimetres")
    }

    private var wallet: some View {
        ZStack(alignment: .top) {
            // Cards peeking from the pocket.
            RoundedRectangle(cornerRadius: Theme.Radius.sm, style: .continuous)
                .fill(Theme.onSurfaceMuted.opacity(0.35))
                .frame(width: 156, height: 96)
                .offset(x: 10, y: -22)
            RoundedRectangle(cornerRadius: Theme.Radius.sm, style: .continuous)
                .fill(Theme.surface)
                .overlay(
                    RoundedRectangle(cornerRadius: Theme.Radius.sm, style: .continuous)
                        .strokeBorder(Theme.rule, lineWidth: 0.5)
                )
                .frame(width: 156, height: 96)
                .offset(x: -6, y: -12)

            // Body.
            RoundedRectangle(cornerRadius: Theme.Radius.lg, style: .continuous)
                .fill(color)
                .frame(width: 196, height: 144)
                .overlay(
                    RoundedRectangle(cornerRadius: Theme.Radius.md, style: .continuous)
                        .stroke(Color.white.opacity(0.4), style: StrokeStyle(lineWidth: 1, dash: [4, 3]))
                        .padding(7)
                )
                .overlay(alignment: .top) {
                    // Pocket mouth.
                    Rectangle()
                        .fill(Color.black.opacity(0.22))
                        .frame(height: 1)
                        .padding(.horizontal, 18)
                        .padding(.top, 30)
                }
                .overlay(alignment: .bottomTrailing) {
                    Text("~")
                        .font(.system(size: 22, weight: .semibold))
                        .foregroundStyle(Color.black.opacity(0.22))
                        .padding(.trailing, 20)
                        .padding(.bottom, 14)
                }
                .overlay(
                    RoundedRectangle(cornerRadius: Theme.Radius.lg, style: .continuous)
                        .strokeBorder(Theme.rule, lineWidth: 0.5)
                )
        }
        .padding(.top, 22)
        .frame(width: 196, height: 166, alignment: .bottom)
    }
}

private struct HorizontalDimension: View {
    let label: String

    var body: some View {
        HStack(spacing: Theme.Space.sm) {
            tick
            Rectangle().fill(Theme.onSurfaceMuted).frame(height: 0.5)
            Text(label)
                .ledgerType(.labelSm)
                .monospacedDigit()
                .foregroundStyle(Theme.onSurfaceMuted)
                .fixedSize()
            Rectangle().fill(Theme.onSurfaceMuted).frame(height: 0.5)
            tick
        }
    }

    private var tick: some View {
        Rectangle().fill(Theme.onSurfaceMuted).frame(width: 0.5, height: 8)
    }
}

private struct VerticalDimension: View {
    let label: String

    var body: some View {
        VStack(spacing: Theme.Space.sm) {
            tick
            Rectangle().fill(Theme.onSurfaceMuted).frame(width: 0.5)
            Text(label)
                .ledgerType(.labelSm)
                .monospacedDigit()
                .foregroundStyle(Theme.onSurfaceMuted)
                .fixedSize()
                .rotationEffect(.degrees(-90))
                .frame(width: 12, height: 40)
            Rectangle().fill(Theme.onSurfaceMuted).frame(width: 0.5)
            tick
        }
        .frame(width: 24)
    }

    private var tick: some View {
        Rectangle().fill(Theme.onSurfaceMuted).frame(width: 8, height: 0.5)
    }
}

#Preview("Light") {
    ProductDetailView()
}

#Preview("Dark") {
    ProductDetailView().preferredColorScheme(.dark)
}

More screens