Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

refactor: add fluid button wrapper

altic-dev39e740bf3084
diff --git a/Sources/Fluid/Theme/NativeButtonStyles.swift b/Sources/Fluid/Theme/NativeButtonStyles.swift
index 84a3f0a6..af32b38b 100644
--- a/Sources/Fluid/Theme/NativeButtonStyles.swift
+++ b/Sources/Fluid/Theme/NativeButtonStyles.swift
@@ -12,6 +12,36 @@ enum FluidInteractionVisuals {
}
}
+enum FluidButtonRole {
+ case primary
+ case secondary
+ case glass
+ case compact
+ case accent
+ case inline
+}
+
+enum FluidButtonSize: Equatable {
+ case small
+ case medium
+ case large
+
+ var controlHeight: CGFloat {
+ switch self {
+ case .small:
+ return 32
+ case .medium:
+ return 36
+ case .large:
+ return 44
+ }
+ }
+
+ var accentCompact: Bool {
+ self == .small
+ }
+}
+
extension View {
func fluidControlSurface(
isSelected: Bool,
@@ -26,6 +56,28 @@ extension View {
cornerRadius: cornerRadius
))
}
+
+ @ViewBuilder
+ func fluidButton(
+ _ role: FluidButtonRole,
+ size: FluidButtonSize = .medium,
+ isRecording: Bool = false
+ ) -> some View {
+ switch role {
+ case .primary:
+ self.buttonStyle(PremiumButtonStyle(isRecording: isRecording, height: size.controlHeight))
+ case .secondary:
+ self.buttonStyle(SecondaryButtonStyle(height: size.controlHeight))
+ case .glass:
+ self.buttonStyle(GlassButtonStyle(height: size.controlHeight))
+ case .compact:
+ self.buttonStyle(CompactButtonStyle(height: size.controlHeight))
+ case .accent:
+ self.buttonStyle(AccentButtonStyle(compact: size.accentCompact))
+ case .inline:
+ self.buttonStyle(InlineButtonStyle())
+ }
+ }
}
private struct FluidControlSurfaceModifier: ViewModifier {
@@ -201,14 +253,17 @@ struct PremiumButtonStyle: ButtonStyle {
// MARK: - Secondary Button
struct SecondaryButtonStyle: ButtonStyle {
+ var height: CGFloat = 42
+
func makeBody(configuration: Configuration) -> some View {
- SecondaryButton(configuration: configuration)
+ SecondaryButton(configuration: configuration, height: self.height)
}
private struct SecondaryButton: View {
@Environment(\.theme) private var theme
@State private var isHovered = false
let configuration: ButtonStyle.Configuration
+ let height: CGFloat
private var shape: RoundedRectangle {
RoundedRectangle(cornerRadius: self.theme.metrics.corners.lg, style: .continuous)
@@ -218,7 +273,7 @@ struct SecondaryButtonStyle: ButtonStyle {
self.configuration.label
.fontWeight(.semibold)
.frame(maxWidth: .infinity)
- .frame(height: 42)
+ .frame(height: self.height)
.foregroundStyle(self.theme.palette.primaryText)
.background(self.theme.materials.card, in: self.shape)
.background(
@@ -251,13 +306,15 @@ struct CompactButtonStyle: ButtonStyle {
var isReady: Bool = false
var foreground: Color? = nil
var borderColor: Color? = nil
+ var height: CGFloat = 34
func makeBody(configuration: Configuration) -> some View {
CompactButton(
configuration: configuration,
isReady: self.isReady,
foreground: self.foreground,
- borderColor: self.borderColor
+ borderColor: self.borderColor,
+ height: self.height
)
}
@@ -268,6 +325,7 @@ struct CompactButtonStyle: ButtonStyle {
let isReady: Bool
let foreground: Color?
let borderColor: Color?
+ let height: CGFloat
private var shape: RoundedRectangle {
RoundedRectangle(cornerRadius: self.theme.metrics.corners.sm, style: .continuous)
@@ -280,7 +338,7 @@ struct CompactButtonStyle: ButtonStyle {
self.configuration.label
.fontWeight(.medium)
.padding(.horizontal, self.theme.metrics.spacing.md)
- .frame(height: 34)
+ .frame(height: self.height)
.foregroundStyle(foregroundColor)
.background(self.theme.materials.card, in: self.shape)
.background(
diff --git a/Sources/Fluid/UI/RecordingView.swift b/Sources/Fluid/UI/RecordingView.swift
index 0d0a78ef..3c627d42 100644
--- a/Sources/Fluid/UI/RecordingView.swift
+++ b/Sources/Fluid/UI/RecordingView.swift
@@ -70,7 +70,7 @@ struct RecordingView: View {
}
.frame(maxWidth: .infinity)
}
- .buttonStyle(PremiumButtonStyle(isRecording: self.asr.isRunning))
+ .fluidButton(.primary, size: .large, isRecording: self.asr.isRunning)
.buttonHoverEffect()
.scaleEffect(self.asr.isRunning ? 1.05 : 1.0)
.animation(.spring(response: 0.3), value: self.asr.isRunning)
diff --git a/Sources/Fluid/UI/StatsView.swift b/Sources/Fluid/UI/StatsView.swift
index 58ad2cfe..ac525ed0 100644
--- a/Sources/Fluid/UI/StatsView.swift
+++ b/Sources/Fluid/UI/StatsView.swift
@@ -104,7 +104,7 @@ struct StatsView: View {
Button("Cancel") {
self.showWPMEditor = false
}
- .buttonStyle(.bordered)
+ .fluidButton(.compact, size: .small)
Button("Save") {
if let wpm = Int(editingWPM), wpm > 0 {
@@ -112,7 +112,7 @@ struct StatsView: View {
}
self.showWPMEditor = false
}
- .buttonStyle(.borderedProminent)
+ .fluidButton(.accent, size: .small)
}
}
.padding(16)