Skip to content

Commit

Permalink
refactor: BoxButtonStyle에 width hugging priority를 설정할 수 있도록 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok committed Aug 9, 2024
1 parent 06dfd9c commit c8cd82f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,19 @@ struct ButtonDetailView: View {
.disabled(false)
}
}

// VStack {
// Text("Secondary")
// .frame(maxWidth: .infinity)
// .foregroundStyle(Global.Color.white)
// .background(Global.Color.black)
// HStack(spacing: 10) {
// Button(
// icon: Image(systemName: "center"),
// action: { /*action*/ }
// )
// .buttonStyle(.round(color: .secondary))
//
// Button(
// icon: Image(systemName: "center"),
// action: { /*action*/ }
// )
// .buttonStyle(.round(color: .primary))
// }
// }



}

VStack(spacing: 40) {
Text("Bottom CTA")
.font(.title)
VStack {
Button(
title: "Button",
action: { /*action*/ }
)
.buttonStyle(.box(size: .large, color: .primary, width: .low))
.padding(.horizontal, 20)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ public struct BoxButtonStyle: ButtonStyle {
@Environment(\.isEnabled) var isEnabled
let size: BoxButtonStyleSize
let color: BoxButtonStyleColor
let width: ButtonHuggingPriorityHorizontal

public init(
size: BoxButtonStyleSize,
color: BoxButtonStyleColor
color: BoxButtonStyleColor,
width: ButtonHuggingPriorityHorizontal
) {
self.size = size
self.color = color
self.width = width
}

public func makeBody(configuration: Configuration) -> some View {
configuration.label
.frame(height: size.buttonHeight)
.frame(maxWidth: width.width)
.font(size.font)
.padding(.horizontal, size.horizontalSideSpacing)
.background(
Expand Down Expand Up @@ -65,9 +69,10 @@ public struct BoxButtonStyle: ButtonStyle {
extension ButtonStyle where Self == BoxButtonStyle {
public static func box(
size: BoxButtonStyleSize,
color: BoxButtonStyleColor
color: BoxButtonStyleColor,
width: ButtonHuggingPriorityHorizontal = .high
) -> Self {
return BoxButtonStyle(size: size, color: color)
return BoxButtonStyle(size: size, color: color, width: width)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ButtonHuggingPriorityHorizontal.swift
// DesignSystem
//
// Created by devMinseok on 8/10/24.
// Copyright © 2024 PomoNyang. All rights reserved.
//

import Foundation

public enum ButtonHuggingPriorityHorizontal {
case high
case low
}

extension ButtonHuggingPriorityHorizontal {
var width: CGFloat? {
switch self {
case .high:
return nil
case .low:
return .infinity
}
}
}

0 comments on commit c8cd82f

Please sign in to comment.