// // CapsuleTabBar.swift // SodaLive // import SwiftUI struct CapsuleTabBar: View { let items: [Item] @Binding var selectedItem: Item let title: (Item) -> String var body: some View { ScrollView(.horizontal, showsIndicators: false) { LazyHStack(alignment: .center, spacing: SodaSpacing.s8) { ForEach(items, id: \.self) { item in CapsuleTabBarItem( title: title(item), isSelected: selectedItem == item, action: { selectedItem = item } ) } } .padding(.horizontal, SodaSpacing.s20) } .frame(maxWidth: .infinity) .frame(height: 52, alignment: .center) .background(Color.black) } } private struct CapsuleTabBarItem: View { let title: String let isSelected: Bool let action: () -> Void var body: some View { Button { action() } label: { Text(title) .appFont(.body5) .foregroundColor(Color.white) .lineLimit(1) .padding(.horizontal, SodaSpacing.s12) .padding(.vertical, SodaSpacing.s8) .frame(height: 34) .background(isSelected ? Color.soda400 : Color.black) .clipShape(Capsule()) .overlay( Capsule() .stroke(isSelected ? Color.soda400 : Color.gray700, lineWidth: 1) ) } .buttonStyle(.plain) } } struct CapsuleTabBar_Previews: PreviewProvider { private enum PreviewTab: String, CaseIterable { case recommended = "추천" case ranking = "랭킹" case following = "팔로잉" case live = "라이브" case content = "콘텐츠" case audition = "오디션" } static var previews: some View { CapsuleTabBar( items: PreviewTab.allCases, selectedItem: .constant(.recommended), title: { $0.rawValue } ) } }