52 lines
1.4 KiB
Swift
52 lines
1.4 KiB
Swift
//
|
|
// TextTabBar.swift
|
|
// SodaLive
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct TextTabBar<Item: Hashable>: View {
|
|
let items: [Item]
|
|
@Binding var selectedItem: Item
|
|
let title: (Item) -> String
|
|
|
|
var body: some View {
|
|
HStack(alignment: .center, spacing: SodaSpacing.s20) {
|
|
ForEach(items.prefix(3), id: \.self) { item in
|
|
Button {
|
|
selectedItem = item
|
|
} label: {
|
|
Text(title(item))
|
|
.appFont(.heading3)
|
|
.foregroundColor(selectedItem == item ? Color.white : Color.gray600)
|
|
.frame(height: 52, alignment: .center)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.padding(.horizontal, SodaSpacing.s20)
|
|
.frame(maxWidth: .infinity)
|
|
.frame(height: 52, alignment: .leading)
|
|
.background(Color.black)
|
|
}
|
|
}
|
|
|
|
struct TextTabBar_Previews: PreviewProvider {
|
|
private enum PreviewTab: String, CaseIterable {
|
|
case recommended = "추천"
|
|
case ranking = "랭킹"
|
|
case following = "팔로잉"
|
|
}
|
|
|
|
static var previews: some View {
|
|
TextTabBar(
|
|
items: PreviewTab.allCases,
|
|
selectedItem: .constant(.recommended),
|
|
title: { $0.rawValue }
|
|
)
|
|
}
|
|
}
|