-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: SegmentConrtolButtonStyle 구현 * feat: SegmentControlButton 구현 * feat PingPongDetailView SegmentControlButton 적용
- Loading branch information
1 parent
152573a
commit ba3706a
Showing
3 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ed/DesignSystem/Sources/Components/Button/SegmentControlButton/SegmentControlButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// SegmentControlButton.swift | ||
// SharedDesignSystem | ||
// | ||
// Created by 임현규 on 10/1/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct SegmentControlButton: View { | ||
private let title: String | ||
private let buttonType: ButtonType | ||
private let isSelected: Bool? | ||
private let _action: (() -> Void)? | ||
private var action: () -> Void { | ||
return _action ?? {} | ||
} | ||
|
||
public init( | ||
title: String, | ||
buttonType: ButtonType, | ||
isSelected: Bool? = nil, | ||
action: (() -> Void)? = nil | ||
) { | ||
self.title = title | ||
self.buttonType = buttonType | ||
self.isSelected = isSelected | ||
self._action = action | ||
} | ||
|
||
public var body: some View { | ||
segmentControlButton | ||
.buttonStyle(SegmentControlButtonStyle(isSelected: isSelected)) | ||
} | ||
} | ||
|
||
// MARK: - Private Views | ||
private extension SegmentControlButton { | ||
var titleText: some View { | ||
Text(title) | ||
.font(to: .wantedSans(.body)) | ||
} | ||
|
||
@ViewBuilder | ||
var segmentControlButton: some View { | ||
switch buttonType { | ||
case .debounce: | ||
titleText.asDebounceButton(action: action) | ||
case .throttle: | ||
titleText.asThrottleButton(action: action) | ||
case .normal: | ||
titleText.asButton(action: action) | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...signSystem/Sources/Components/Button/SegmentControlButton/SegmentControlButtonStyle.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// SegmentControlButtonStyle.swift | ||
// SharedDesignSystem | ||
// | ||
// Created by 임현규 on 10/1/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SegmentControlButtonStyle: ButtonStyle { | ||
@Environment(\.isEnabled) private var isEnabled: Bool | ||
private let isSelected: Bool? | ||
|
||
public init(isSelected: Bool? = nil) { | ||
self.isSelected = isSelected | ||
} | ||
|
||
func makeBody(configuration: Configuration) -> some View { | ||
let buttonState = makeButtonState(configuration) | ||
|
||
return configuration.label | ||
.padding(.horizontal, .sm) | ||
.frame(height: 42) | ||
.foregroundStyle(foregroundColor(buttonState)) | ||
.overlay(alignment: .bottom) { | ||
switch buttonState { | ||
case .enabled: | ||
EmptyView() | ||
case .selected: | ||
Divider() | ||
.frame(height: 2) | ||
.background(to: ColorToken.border(.selected)) | ||
case .disabled: | ||
EmptyView() | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Private Methods | ||
private extension SegmentControlButtonStyle { | ||
func makeButtonState(_ configuration: Configuration) -> ButtonStateType { | ||
return !isEnabled ? .disabled : configuration.isPressed || isSelected == true ? .selected : .enabled | ||
} | ||
|
||
func foregroundColor(_ buttonState: ButtonStateType) -> Color { | ||
switch buttonState { | ||
case .enabled: | ||
return ColorToken.text(.enableSecondary).color | ||
case .selected: | ||
return ColorToken.text(.selectPrimary).color | ||
case .disabled: | ||
return ColorToken.text(.disableSecondary).color | ||
} | ||
} | ||
} | ||
|