feat(component): 재사용 타이틀 탭 바를 추가한다
This commit is contained in:
51
SodaLive/Sources/V2/Component/TextTabBar.swift
Normal file
51
SodaLive/Sources/V2/Component/TextTabBar.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// 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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user