mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 03:06:37 +00:00
f7dd9cdcf8
* Update copyright holding and dates * compound IDE Macros updated * update copyright * update copyrights done * update templates and README
89 lines
2.5 KiB
Swift
89 lines
2.5 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2024-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
struct BadgeLabel: View {
|
|
enum Style {
|
|
case accent
|
|
case info
|
|
case `default`
|
|
}
|
|
|
|
let title: String
|
|
let icon: KeyPath<CompoundIcons, Image>
|
|
let style: Style
|
|
|
|
var body: some View {
|
|
Label(title,
|
|
icon: icon,
|
|
iconSize: .xSmall,
|
|
relativeTo: .compound.bodySM)
|
|
.labelStyle(LabelStyle(style: style))
|
|
}
|
|
|
|
private struct LabelStyle: SwiftUI.LabelStyle {
|
|
let style: Style
|
|
|
|
var titleColor: Color {
|
|
switch style {
|
|
case .accent: .compound.textBadgeAccent
|
|
case .info: .compound.textBadgeInfo
|
|
case .default: .compound.textPrimary
|
|
}
|
|
}
|
|
|
|
var iconColor: Color {
|
|
switch style {
|
|
case .accent: .compound.iconAccentPrimary
|
|
case .info: .compound.iconInfoPrimary
|
|
case .default: .compound.iconPrimary
|
|
}
|
|
}
|
|
|
|
var backgroundColor: Color {
|
|
switch style {
|
|
case .accent: .compound.bgBadgeAccent
|
|
case .info: .compound.bgBadgeInfo
|
|
case .default: .compound.bgBadgeDefault
|
|
}
|
|
}
|
|
|
|
func makeBody(configuration: Configuration) -> some View {
|
|
HStack(spacing: 4) {
|
|
configuration.icon
|
|
.foregroundStyle(iconColor)
|
|
configuration.title
|
|
.foregroundStyle(titleColor)
|
|
}
|
|
.font(.compound.bodySM)
|
|
.padding(.leading, 8)
|
|
.padding(.trailing, 12)
|
|
.padding(.vertical, 4)
|
|
.background(Capsule().fill(backgroundColor))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct BadgeLabel_Previews: PreviewProvider, TestablePreview {
|
|
static var previews: some View {
|
|
VStack(spacing: 10) {
|
|
BadgeLabel(title: "Encrypted",
|
|
icon: \.lockSolid,
|
|
style: .accent)
|
|
BadgeLabel(title: "Not encrypted",
|
|
icon: \.lockSolid,
|
|
style: .info)
|
|
BadgeLabel(title: "1234",
|
|
icon: \.userProfile,
|
|
style: .default)
|
|
}
|
|
}
|
|
}
|