Files
sodalive-ios/SodaLive/Sources/V2/Component/SectionTitle.swift

64 lines
1.6 KiB
Swift

//
// SectionTitle.swift
// SodaLive
//
import SwiftUI
struct SectionTitle: View {
let title: String
let action: (() -> Void)?
init(
title: String,
action: (() -> Void)? = nil
) {
self.title = title
self.action = action
}
var body: some View {
content
}
private var content: some View {
HStack(alignment: .center, spacing: 0) {
Text(title)
.appFont(.heading3)
.foregroundColor(.white)
.lineLimit(1)
.truncationMode(.tail)
Spacer(minLength: 0)
if let action {
Button(action: action) {
Image("ic_chevron_right")
.resizable()
.renderingMode(.template)
.foregroundColor(.white)
.scaledToFit()
.frame(width: 24, height: 24)
}
.buttonStyle(.plain)
.accessibilityLabel(title)
.accessibilityAddTraits(.isButton)
}
}
.padding(.horizontal, SodaSpacing.s20)
.frame(maxWidth: .infinity)
.frame(height: 42, alignment: .center)
}
}
struct SectionTitle_Previews: PreviewProvider {
static var previews: some View {
VStack(spacing: SodaSpacing.s12) {
SectionTitle(title: "텍스트")
SectionTitle(title: "긴 섹션 타이틀은 한 줄로 줄임 처리됩니다 한 줄로 줄임 처리됩니다") {}
}
.background(Color.black)
.previewLayout(.sizeThatFits)
}
}