-
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.
- Loading branch information
1 parent
585b358
commit 88840ef
Showing
13 changed files
with
329 additions
and
121 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
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
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
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
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
67 changes: 67 additions & 0 deletions
67
Projects/Shared/DesignSystem/Sources/Component/Button/Icon/IconButtonStyle.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,67 @@ | ||
// | ||
// IconButtonStyle.swift | ||
// DesignSystem | ||
// | ||
// Created by devMinseok on 8/12/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct IconButtonStyle: ButtonStyle { | ||
@Environment(\.isEnabled) var isEnabled | ||
let isFilled: Bool | ||
let level: IconButtonStyleLevel | ||
|
||
public init( | ||
isFilled: Bool, | ||
level: IconButtonStyleLevel | ||
) { | ||
self.isFilled = isFilled | ||
self.level = level | ||
} | ||
|
||
public func makeBody(configuration: Configuration) -> some View { | ||
configuration.label | ||
.padding(Alias.Spacing.small) | ||
.background( | ||
getBackgroundColor(isFilled: isFilled, isPressed: configuration.isPressed), | ||
in: RoundedRectangle(cornerRadius: Alias.BorderRadius.small) | ||
) | ||
.foregroundColor( | ||
getForegroundColor(isFilled: isFilled) | ||
) | ||
.labelStyle(SingleIconButtonLabelStyle()) | ||
.singleIconButtonDetailStyle(DefaultSingleIconButtonDetailStyle()) | ||
.opacity(isEnabled ? 1 : 0.6) | ||
} | ||
|
||
private func getBackgroundColor(isFilled: Bool, isPressed: Bool) -> Color { | ||
if isEnabled { | ||
if isPressed { | ||
return isFilled ? level.pressedBackground : Global.Color.black.opacity(Alias.Interaction.pressed) | ||
} else { | ||
return isFilled ? level.defaultBackground : .clear | ||
} | ||
} else { | ||
return isFilled ? level.disabledBackground : .clear | ||
} | ||
} | ||
|
||
private func getForegroundColor(isFilled: Bool) -> Color? { | ||
if isFilled { | ||
return level.defaultForeground | ||
} else { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
extension ButtonStyle where Self == IconButtonStyle { | ||
public static func icon( | ||
isFilled: Bool, | ||
level: IconButtonStyleLevel | ||
) -> Self { | ||
return IconButtonStyle(isFilled: isFilled, level: level) | ||
} | ||
} |
Oops, something went wrong.