Skip to content
Search Field preview
Rendered from the SwiftUI source on this page.

Search Field

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

A search field input — self-contained SwiftUI, styled from system tokens.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

SearchField.swift
// Search Field · syxUI · https://syxui.dev/components/input-search
// 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)
    }
}

// 15. Search field
struct SearchField: View {
    var body: some View {
        VStack(spacing: 12) {
            HStack(spacing: 10) {
                Image(systemName: "magnifyingglass").foregroundStyle(.secondary)
                Text("Search tools, makers…").font(.system(size: 16)).foregroundStyle(.tertiary)
                Spacer()
                Image(systemName: "mic.fill").foregroundStyle(.secondary)
            }
            .padding(.horizontal, 14).padding(.vertical, 13)
            .background(Color.primary.opacity(0.06), in: Capsule())
            HStack(spacing: 8) {
                ForEach(["All", "Video", "Code", "Design"].indices, id: \.self) { i in
                    Text(["All", "Video", "Code", "Design"][i]).font(.system(size: 13, weight: .medium))
                        .foregroundStyle(i == 0 ? Color(.systemBackground) : Color.primary)
                        .padding(.horizontal, 14).padding(.vertical, 8)
                        .background(i == 0 ? Color.primary : Color.primary.opacity(0.06), in: Capsule())
                }
                Spacer()
            }
        }
        .formaCard()
    }
}
iOS 17 · 1 dependencies

Dependencies

SwiftUI
  • formaCard

Requires iOS 17