2021-10-25 08:15:02 -07:00
|
|
|
//
|
|
|
|
// PhraseChip.swift
|
|
|
|
// secant-testnet
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 10/25/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PhraseChip: View {
|
2021-10-26 16:14:03 -07:00
|
|
|
enum Kind: Hashable {
|
2021-10-25 08:15:02 -07:00
|
|
|
case empty
|
|
|
|
case unassigned(word: String)
|
|
|
|
case ordered(position: Int, word: String)
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:29:23 -07:00
|
|
|
var kind: Kind
|
2021-10-25 08:15:02 -07:00
|
|
|
|
|
|
|
var body: some View {
|
2021-10-27 12:29:23 -07:00
|
|
|
chipFor(for: kind)
|
2021-10-25 08:15:02 -07:00
|
|
|
.frame(
|
|
|
|
minWidth: 0,
|
|
|
|
maxWidth: 120,
|
|
|
|
minHeight: 30,
|
|
|
|
idealHeight: 40
|
|
|
|
)
|
|
|
|
.animation(.easeIn)
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:29:23 -07:00
|
|
|
@ViewBuilder func chipFor(for kind: Kind) -> some View {
|
2021-10-25 08:15:02 -07:00
|
|
|
switch kind {
|
|
|
|
case .empty:
|
|
|
|
EmptyChip()
|
2021-10-27 12:29:23 -07:00
|
|
|
|
2021-10-25 08:15:02 -07:00
|
|
|
case let .ordered(position, word):
|
|
|
|
EnumeratedChip(index: position, text: word)
|
2021-10-27 12:29:23 -07:00
|
|
|
|
2021-10-25 08:15:02 -07:00
|
|
|
case .unassigned(let word):
|
|
|
|
BlueChip(word: word)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PhraseChip_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
|
|
|
PhraseChip(kind: .unassigned(word: "negative"))
|
|
|
|
.frame(height: 40)
|
2021-10-27 12:29:23 -07:00
|
|
|
|
2021-10-25 08:15:02 -07:00
|
|
|
PhraseChip(kind: .empty)
|
|
|
|
.frame(height: 40)
|
2021-10-27 12:29:23 -07:00
|
|
|
|
2021-10-25 08:15:02 -07:00
|
|
|
PhraseChip(kind: .ordered(position: 23, word: "mutual"))
|
|
|
|
.frame(height: 40)
|
|
|
|
}
|
|
|
|
.applyScreenBackground()
|
|
|
|
}
|
|
|
|
}
|