2021-08-18 08:33:56 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 New Vector Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2021-09-13 10:36:33 +00:00
|
|
|
|
|
|
|
/// A single rounded rect chip to be rendered within `Chips` collection
|
2021-08-18 08:33:56 +00:00
|
|
|
@available(iOS 14.0, *)
|
|
|
|
struct Chip: View {
|
|
|
|
|
2021-08-25 12:03:36 +00:00
|
|
|
@Environment(\.isEnabled) var isEnabled
|
2021-09-01 11:34:38 +00:00
|
|
|
@Environment(\.theme) var theme: ThemeSwiftUI
|
2021-08-18 08:33:56 +00:00
|
|
|
|
2021-08-25 18:24:33 +00:00
|
|
|
let title: String
|
2021-08-25 12:03:36 +00:00
|
|
|
let onDelete: () -> Void
|
|
|
|
|
|
|
|
var backgroundColor: Color {
|
|
|
|
if !isEnabled {
|
2021-09-01 11:34:38 +00:00
|
|
|
return theme.colors.quinaryContent
|
2021-08-25 12:03:36 +00:00
|
|
|
}
|
2021-09-01 11:34:38 +00:00
|
|
|
return theme.colors.accent
|
2021-08-25 12:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var foregroundColor: Color {
|
|
|
|
if !isEnabled {
|
2021-09-01 11:34:38 +00:00
|
|
|
return theme.colors.tertiaryContent
|
2021-08-25 12:03:36 +00:00
|
|
|
}
|
2021-08-25 13:13:04 +00:00
|
|
|
return Color.white
|
2021-08-25 12:03:36 +00:00
|
|
|
}
|
2021-08-18 08:33:56 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack {
|
2021-08-25 18:24:33 +00:00
|
|
|
Text(title)
|
2021-09-01 11:34:38 +00:00
|
|
|
.font(theme.fonts.body)
|
2021-08-18 08:33:56 +00:00
|
|
|
.lineLimit(1)
|
2021-08-25 18:24:33 +00:00
|
|
|
Button(action: onDelete) {
|
|
|
|
Image(systemName: "xmark.circle.fill")
|
|
|
|
.frame(width: 16, height: 16, alignment: .center)
|
|
|
|
}
|
2021-08-18 08:33:56 +00:00
|
|
|
}
|
|
|
|
.padding(.leading, 12)
|
|
|
|
.padding(.top, 6)
|
|
|
|
.padding(.bottom, 6)
|
|
|
|
.padding(.trailing, 8)
|
2021-08-25 12:03:36 +00:00
|
|
|
.background(backgroundColor)
|
|
|
|
.foregroundColor(foregroundColor)
|
2021-08-18 08:33:56 +00:00
|
|
|
.cornerRadius(20)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@available(iOS 14.0, *)
|
|
|
|
struct Chip_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-08-25 13:13:04 +00:00
|
|
|
Group {
|
2021-08-25 18:24:33 +00:00
|
|
|
Chip(title: "My great chip", onDelete: { })
|
|
|
|
Chip(title: "My great chip", onDelete: { })
|
2021-08-25 13:13:04 +00:00
|
|
|
.theme(.dark)
|
|
|
|
}
|
2021-08-18 08:33:56 +00:00
|
|
|
}
|
|
|
|
}
|