Skip to content

Instantly share code, notes, and snippets.

@jacobsapps
Created January 8, 2026 16:06
Show Gist options
  • Select an option

  • Save jacobsapps/b28c1bbba3c1ff944e8359404e33f318 to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/b28c1bbba3c1ff944e8359404e33f318 to your computer and use it in GitHub Desktop.
//
// CompositionFilledButtonStyle.swift
// DesignSystemWar
//
// Created by Jacob Bartlett on 07/05/2023.
//
import SwiftUI
/// Filled capsule button style.
struct CompositionFilledButtonStyle: ButtonStyle {
let color: ButtonColor
let size: ButtonSize
let icon: ButtonIcon?
@Environment(\.isEnabled) private var isEnabled
/// Creates a filled button style.
/// - Parameters:
/// - color: Semantic color for the fill and text.
/// - size: Height and icon scale for the button.
/// - icon: Optional leading or trailing icon.
init(color: ButtonColor = .default,
size: ButtonSize = .large,
icon: ButtonIcon? = nil) {
self.color = color
self.size = size
self.icon = icon
}
func makeBody(configuration: Configuration) -> some View {
ButtonLabelContent(label: configuration.label, size: size, icon: icon)
.foregroundColor(color.textColor)
.frame(height: size.height)
.buttonBackground(fillColor: color.mainColor)
.opacity(isEnabled ? 1 : 0.5)
}
}
extension ButtonStyle where Self == CompositionFilledButtonStyle {
static func compositionFilled(
color: ButtonColor = .default,
size: ButtonSize = .large,
icon: ButtonIcon? = nil
) -> CompositionFilledButtonStyle {
CompositionFilledButtonStyle(color: color, size: size, icon: icon)
}
}
#Preview("Composition Filled") {
let sizes: [ButtonSize] = [.large, .small]
let colors = ButtonColor.standardColors
VStack(spacing: 12) {
ForEach(Array(colors.enumerated()), id: \.offset) { _, color in
ForEach(Array(sizes.enumerated()), id: \.offset) { _, size in
Button("\(color.label) \(size.label)", action: {})
.buttonStyle(
.compositionFilled(color: color,
size: size,
icon: .leading(.AppIcon.bolt)))
}
}
}
.padding()
.frame(maxWidth: .infinity)
.background(Color(.secondarySystemBackground))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment