diff --git a/Sources/Luminare/Components/Auxiliary/LuminareButtonStyles.swift b/Sources/Luminare/Components/Auxiliary/LuminareButtonStyles.swift index 8c533bc..842307a 100644 --- a/Sources/Luminare/Components/Auxiliary/LuminareButtonStyles.swift +++ b/Sources/Luminare/Components/Auxiliary/LuminareButtonStyles.swift @@ -293,6 +293,7 @@ public struct LuminareCompactButtonStyle: ButtonStyle { public struct LuminareFilled: ViewModifier { @Environment(\.isEnabled) private var isEnabled + @Environment(\.luminareHasBackground) private var hasBackground @Environment(\.luminareButtonMaterial) private var material @Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover @@ -344,27 +345,31 @@ public struct LuminareFilled: ViewModifier { } public func body(content: Content) -> some View { - content - .background(with: material) { - Group { - if isEnabled { - if isPressed { - Rectangle() - .foregroundStyle(pressed) - } else if highlightOnHover, isHovering { - Rectangle() - .foregroundStyle(hovering) + if hasBackground { + content + .background(with: material) { + Group { + if isEnabled { + if isPressed { + Rectangle() + .foregroundStyle(pressed) + } else if highlightOnHover, isHovering { + Rectangle() + .foregroundStyle(hovering) + } else { + Rectangle() + .foregroundStyle(fill) + } } else { Rectangle() .foregroundStyle(fill) } - } else { - Rectangle() - .foregroundStyle(fill) } + .opacity(isEnabled ? 1 : 0.5) } - .opacity(isEnabled ? 1 : 0.5) - } + } else { + content + } } } diff --git a/Sources/Luminare/Components/LuminareTextEditor.swift b/Sources/Luminare/Components/LuminareTextEditor.swift index de6bf44..b9c5e2b 100644 --- a/Sources/Luminare/Components/LuminareTextEditor.swift +++ b/Sources/Luminare/Components/LuminareTextEditor.swift @@ -105,21 +105,13 @@ public struct LuminareTextEditor: View { "LuminareTextEditor", traits: .sizeThatFitsLayout ) { - @Previewable @State var text = """ - Cupidatat ipsum consequat est cupidatat veniam sint et voluptate commodo. - Incididunt elit commodo culpa officia sint quis ullamco qui deserunt consequat. - Cillum et ullamco cupidatat. Dolore id ea culpa labore Lorem commodo esse. - Adipisicing dolore officia exercitation dolor occaecat do esse non occaecat reprehenderit duis magna. - Labore eu culpa tempor adipisicing qui incididunt tempor in nostrud dolore velit magna veniam ex. - Veniam et incididunt amet Lorem sit irure. - Anim duis enim enim velit exercitation. - """ + @Previewable @State var text = "" @Previewable @State var selection: TextSelection? = .none LuminareTextEditor(text: $text) - LuminareTextEditor(text: $text, selection: $selection) - - LuminareTextEditor(text: $text, selection: $selection) - .disabled(true) +// LuminareTextEditor(text: $text, selection: $selection) +// +// LuminareTextEditor(text: $text, selection: $selection) +// .disabled(true) } diff --git a/Sources/Luminare/Utilities/EnvironmentValues.swift b/Sources/Luminare/Utilities/EnvironmentValues.swift index 077b74d..19a3fcf 100644 --- a/Sources/Luminare/Utilities/EnvironmentValues.swift +++ b/Sources/Luminare/Utilities/EnvironmentValues.swift @@ -72,6 +72,7 @@ public extension EnvironmentValues { @Entry var luminareMinHeight: CGFloat = 34 @Entry var luminareHorizontalPadding: CGFloat = 8 @Entry var luminareIsBordered: Bool = true + @Entry var luminareHasBackground: Bool = true @Entry var luminareHasDividers: Bool = true // MARK: Button Styles diff --git a/Sources/Luminare/Utilities/Extensions/Text+Extensions.swift b/Sources/Luminare/Utilities/Extensions/Text+Extensions.swift new file mode 100644 index 0000000..362d025 --- /dev/null +++ b/Sources/Luminare/Utilities/Extensions/Text+Extensions.swift @@ -0,0 +1,34 @@ +// +// Text+Extensions.swift +// Luminare +// +// Created by KrLite on 2024/12/18. +// + +import SwiftUI + +extension Text.Case: Codable { + enum CodingKeys: String, CodingKey { + case rawValue + } + + public init(from decoder: any Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + switch try values.decode(String.self, forKey: .rawValue) { + case "uppercase": + self = .uppercase + case "lowercase": + self = .lowercase + default: + throw DecodingError.dataCorrupted(.init( + codingPath: [CodingKeys.rawValue], + debugDescription: "Unknown case" + )) + } + } + + public func encode(to encoder: any Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self, forKey: .rawValue) + } +} diff --git a/Sources/Luminare/Utilities/Extensions/View+Extensions.swift b/Sources/Luminare/Utilities/Extensions/View+Extensions.swift index d1e564d..8a3268d 100644 --- a/Sources/Luminare/Utilities/Extensions/View+Extensions.swift +++ b/Sources/Luminare/Utilities/Extensions/View+Extensions.swift @@ -221,6 +221,10 @@ public extension View { environment(\.luminareIsBordered, bordered) } + @ViewBuilder func luminareHasBackground(_ hasBackground: Bool = true) -> some View { + environment(\.luminareHasBackground, hasBackground) + } + @ViewBuilder func luminareHasDividers(_ hasDividers: Bool = true) -> some View { environment(\.luminareHasDividers, hasDividers) } diff --git a/Sources/Luminare/Utilities/StringFormatStyle.swift b/Sources/Luminare/Utilities/StringFormatStyle.swift index 5e4fad5..7354fc2 100644 --- a/Sources/Luminare/Utilities/StringFormatStyle.swift +++ b/Sources/Luminare/Utilities/StringFormatStyle.swift @@ -77,7 +77,7 @@ public struct StringFormatStyle: Equatable, Hashable, Codable, Sendable, Parseab /// /// - `.custom(.uppercased, "@@")` /// - Parses `#42ab0e` to `@@42AB0E`. - case custom(TextCase, String) + case custom(Text.Case, String) /// Parse a hex value using a specified strategy. /// - Parameter value: The hex value to parse. @@ -100,6 +100,9 @@ public struct StringFormatStyle: Equatable, Hashable, Codable, Sendable, Parseab Self.uppercased case .lowercase: Self.lowercased + @unknown default: + // Unknown! + Self.lowercased } return try prefix + branch.parse(value) @@ -117,14 +120,4 @@ public struct StringFormatStyle: Equatable, Hashable, Codable, Sendable, Parseab // don't need conversions value } - - /// Represents a text case. - public enum TextCase: String, Equatable, Hashable, Identifiable, CaseIterable, Codable, Sendable { - /// The uppercase. - case uppercase - /// The lowercase. - case lowercase - - public var id: Self { self } - } }