-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e676db4
commit 3d352ee
Showing
2 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Sources/OversizeComponents/CurrencyPicker/CurrencyPicker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Copyright © 2023 Alexander Romanov | ||
// CurrencyPicker.swift, created on 14.07.2023 | ||
// | ||
|
||
import OversizeCore | ||
import OversizeUI | ||
import SwiftUI | ||
|
||
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) | ||
public struct CurrencyPicker: View { | ||
@Environment(\.theme) private var theme: ThemeSettings | ||
@Binding private var selection: Locale.Currency | ||
private let label: String | ||
private let currencies: [Locale.Currency] | ||
@State private var showModal = false | ||
|
||
public init( | ||
_ sheetTitle: String = "Currency", | ||
currencies: [Locale.Currency] = Locale.Currency.countryCurrencies, | ||
selection: Binding<Locale.Currency> | ||
) { | ||
label = sheetTitle | ||
_selection = selection | ||
self.currencies = currencies | ||
} | ||
|
||
public var body: some View { | ||
Select(label, currencies, selection: $selection) { element, _ in | ||
Row(element.dispalyName ?? element.identifier) { | ||
ZStack { | ||
RoundedRectangle(cornerRadius: .small, style: .continuous) | ||
.fill(Color.surfaceSecondary) | ||
.frame(width: 52, height: 36) | ||
Text(element.dispalySymbol ?? element.identifier) | ||
} | ||
} | ||
} selectionView: { element in | ||
Text(element.dispalyName ?? label) | ||
} | ||
} | ||
} | ||
|
||
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) | ||
struct CurrencyPicker_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CurrencyPicker(selection: .constant("USD")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters