Skip to content

Commit f3473bc

Browse files
authored
[NL-35]: 디자인 시스템 - Banner 컴포넌트 구현 (#17)
* [NL-35]: Banner 컴포넌트 구현 * [NL-35]: Typography 공통 적용된 lineheight 제거 * [NL-35]: image rendering mode 설정
1 parent 7e0b9ba commit f3473bc

File tree

13 files changed

+253
-28
lines changed

13 files changed

+253
-28
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "alert-circle.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "alert-triangle.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "check-circle-2.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "info.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// Banner.swift
3+
// DesignSystem
4+
//
5+
// Created by ttozzi on 7/24/25.
6+
//
7+
8+
import SnapKit
9+
import Then
10+
import UIKit
11+
12+
public final class Banner: UIView {
13+
14+
public enum Style: CaseIterable {
15+
case notice
16+
case error
17+
case success
18+
case warning
19+
20+
fileprivate var backgroundColor: UIColor {
21+
switch self {
22+
case .notice:
23+
return STColors.primary8.color
24+
case .error:
25+
return STColors.red9.color
26+
case .success:
27+
return STColors.green9.color
28+
case .warning:
29+
return STColors.orange9.color
30+
}
31+
}
32+
33+
fileprivate var icon: UIImage? {
34+
switch self {
35+
case .notice:
36+
return STImages.info.image
37+
case .error:
38+
return STImages.alertTriangle.image
39+
case .success:
40+
return STImages.checkCircle2.image
41+
case .warning:
42+
return STImages.alertCircle.image
43+
}
44+
}
45+
46+
fileprivate var iconTintColor: UIColor {
47+
switch self {
48+
case .notice:
49+
return STColors.primary2.color
50+
case .error:
51+
return STColors.red3.color
52+
case .success:
53+
return STColors.green3.color
54+
case .warning:
55+
return STColors.orange3.color
56+
}
57+
}
58+
}
59+
60+
private lazy var contentStackView = UIStackView().then {
61+
$0.spacing = 8
62+
$0.alignment = .top
63+
}
64+
private lazy var iconImageView = UIImageView().then {
65+
$0.contentMode = .scaleAspectFit
66+
$0.setContentHuggingPriority(.defaultLow, for: .vertical)
67+
}
68+
private lazy var textStackView = UIStackView().then {
69+
$0.spacing = 4
70+
$0.axis = .vertical
71+
$0.alignment = .leading
72+
$0.setContentCompressionResistancePriority(.required, for: .vertical)
73+
}
74+
private lazy var titleLabel = UILabel().then {
75+
$0.style = Typography.Body_14_M
76+
$0.textColor = DesignSystemAsset.Colors.gray1.color
77+
}
78+
private lazy var descriptionLabel = UILabel().then {
79+
$0.style = Typography.Caption_12_R
80+
$0.textColor = DesignSystemAsset.Colors.gray4.color
81+
$0.numberOfLines = .zero
82+
}
83+
84+
public init(style: Style? = nil) {
85+
super.init(frame: .zero)
86+
setupUI()
87+
}
88+
89+
required init?(coder: NSCoder) {
90+
fatalError("init(coder:) has not been implemented")
91+
}
92+
93+
private func setupUI() {
94+
layer.cornerRadius = 8
95+
layer.masksToBounds = true
96+
97+
addSubview(contentStackView)
98+
contentStackView.snp.makeConstraints { make in
99+
make.verticalEdges.equalToSuperview().inset(12)
100+
make.leading.equalToSuperview().inset(12)
101+
make.trailing.equalToSuperview().inset(16)
102+
}
103+
contentStackView.addArrangedSubview(iconImageView)
104+
iconImageView.snp.makeConstraints { make in
105+
make.width.equalTo(16)
106+
make.height.equalTo(22)
107+
}
108+
contentStackView.addArrangedSubview(textStackView)
109+
110+
textStackView.addArrangedSubview(titleLabel)
111+
titleLabel.snp.makeConstraints { make in
112+
make.height.greaterThanOrEqualTo(21)
113+
}
114+
textStackView.addArrangedSubview(descriptionLabel)
115+
titleLabel.snp.makeConstraints { make in
116+
make.height.greaterThanOrEqualTo(18)
117+
}
118+
}
119+
120+
public func update(title: String, description: String? = nil) {
121+
titleLabel.styledText = title
122+
descriptionLabel.styledText = description
123+
descriptionLabel.isHidden = description == nil
124+
}
125+
126+
public func update(style: Style) {
127+
backgroundColor = style.backgroundColor
128+
iconImageView.image = style.icon?.withRenderingMode(.alwaysTemplate)
129+
iconImageView.tintColor = style.iconTintColor
130+
}
131+
}
132+
133+
@available(iOS 17.0, *)
134+
#Preview {
135+
let stackView = UIStackView().then {
136+
$0.axis = .vertical
137+
$0.spacing = 8
138+
}
139+
140+
Banner.Style.allCases.forEach {
141+
let titleOnlyBanner = Banner()
142+
titleOnlyBanner.update(style: $0)
143+
titleOnlyBanner.update(title: "Title")
144+
stackView.addArrangedSubview(titleOnlyBanner)
145+
let banner = Banner()
146+
banner.update(style: $0)
147+
banner.update(title: "Title", description: "Enter a secondary description for your guide")
148+
stackView.addArrangedSubview(banner)
149+
}
150+
return stackView
151+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Typealiases.swift
3+
// DesignSystem
4+
//
5+
// Created by ttozzi on 7/24/25.
6+
//
7+
8+
import Foundation
9+
10+
public typealias STColors = DesignSystemAsset.Colors
11+
public typealias STImages = DesignSystemAsset.Images

0 commit comments

Comments
 (0)