| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import SwiftUI
- struct SettingInputSection: View {
- enum InputType {
- case decimal
- case boolean
- case conditionalDecimal
- }
- @Binding var decimalValue: Decimal
- @Binding var booleanValue: Bool
- @Binding var shouldDisplayHint: Bool
- @Binding var selectedVerboseHint: String?
- var type: InputType
- var label: String
- var conditionalLabel: String?
- var miniHint: String
- var verboseHint: String
- var headerText: String?
- var footerText: String?
- private var formatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- return formatter
- }
- var body: some View {
- Section(
- content: {
- VStack {
- if type == .decimal {
- HStack {
- Text(label)
- TextFieldWithToolBar(
- text: Binding(
- get: { decimalValue },
- set: { decimalValue = $0 }
- ),
- placeholder: decimalValue.description,
- numberFormatter: formatter
- )
- }.padding(.top)
- } else if type == .boolean {
- HStack {
- Toggle(isOn: $booleanValue) {
- Text(label)
- }
- }
- } else if type == .conditionalDecimal, let secondLabel = conditionalLabel {
- HStack {
- Toggle(isOn: $booleanValue) {
- Text(label)
- }
- }.padding(.vertical)
- if $booleanValue.wrappedValue {
- HStack {
- Text(secondLabel)
- TextFieldWithToolBar(
- text: Binding(
- get: { decimalValue },
- set: { decimalValue = $0 }
- ),
- placeholder: decimalValue.description,
- numberFormatter: formatter
- )
- }.padding(.bottom)
- }
- }
- HStack(alignment: .top) {
- Text(miniHint)
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- shouldDisplayHint.toggle()
- selectedVerboseHint = shouldDisplayHint ? verboseHint : nil
- },
- label: {
- HStack {
- Image(systemName: "questionmark.circle")
- }
- }
- )
- }.padding(type == .boolean ? .vertical : .bottom)
- }
- },
- header: {
- if let headerText = headerText {
- Text(headerText)
- }
- },
- footer: {
- if let footerText = footerText {
- Text(footerText)
- }
- }
- ).listRowBackground(Color.chart)
- }
- }
|