Skip to content

Commit

Permalink
[feat] #157 컨텐츠 상세 변경사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Dec 1, 2024
1 parent 72cfdbb commit 4ae7e46
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 205 deletions.
27 changes: 17 additions & 10 deletions Projects/DSKit/Sources/Components/PokitListButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public struct PokitListButton: View {
VStack(alignment: .leading, spacing: 4) {
HStack {
switch type {
case let .default(icon),
let .bottomSheet(icon),
let .subText(icon, _):
case let .default(icon, iconColor),
let .bottomSheet(icon, iconColor),
let .subText(icon, iconColor, _):
Text(title)
.pokitFont(.b1(.m))
.foregroundStyle(.pokit(.text(.secondary)))
Expand All @@ -49,7 +49,7 @@ public struct PokitListButton: View {
Image(icon)
.resizable()
.frame(width: 24, height: 24)
.foregroundStyle(.pokit(.icon(.primary)))
.foregroundStyle(iconColor)
case .toggle:
Toggle(isOn: $isOn) {
Text(title)
Expand All @@ -61,7 +61,7 @@ public struct PokitListButton: View {

}

if case let .subText(_, subeText) = type {
if case let .subText(_, _, subeText) = type {
Text(subeText)
.pokitFont(.detail1)
.foregroundStyle(.pokit(.text(.tertiary)))
Expand Down Expand Up @@ -89,9 +89,9 @@ public struct PokitListButton: View {

extension PokitListButton {
public enum ListButtonType {
case `default`(icon: PokitImage)
case bottomSheet(icon: PokitImage)
case subText(icon: PokitImage, subeText: String)
case `default`(icon: PokitImage, iconColor: Color)
case bottomSheet(icon: PokitImage, iconColor: Color)
case subText(icon: PokitImage, iconColor: Color, subeText: String)
case toggle(subeText: String)

}
Expand All @@ -104,20 +104,27 @@ extension PokitListButton {

PokitListButton(
title: "공지사항",
type: .default(icon: .icon(.arrowRight)),
type: .default(
icon: .icon(.arrowRight),
iconColor: .pokit(.icon(.primary))
),
action: { }
)

PokitListButton(
title: "공지사항",
type: .bottomSheet(icon: .icon(.edit)),
type: .bottomSheet(
icon: .icon(.edit),
iconColor: .pokit(.icon(.primary))
),
action: { }
)

PokitListButton(
title: "공지사항",
type: .subText(
icon: .icon(.arrowRight),
iconColor: .pokit(.icon(.primary)),
subeText: "포킷에 저장된 링크가 다른 사용자에게 추천됩니다."
),
action: { }
Expand Down
18 changes: 12 additions & 6 deletions Projects/DSKit/Sources/Components/PokitPartTextArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ import SwiftUI
public struct PokitPartTextArea<Value: Hashable>: View {
@Binding private var text: String

@State private var state: PokitInputStyle.State
@Binding private var state: PokitInputStyle.State

private var focusState: FocusState<Value>.Binding

private let baseState: PokitInputStyle.State
private let equals: Value
private let placeholder: String
private let onSubmit: (() -> Void)?

public init(
text: Binding<String>,
state: PokitInputStyle.State = .default,
state: Binding<PokitInputStyle.State>,
baseState: PokitInputStyle.State = .default,
placeholder: String = "내용을 입력해주세요.",
focusState: FocusState<Value>.Binding,
equals: Value,
onSubmit: (() -> Void)? = nil
) {
self._text = text
self._state = State(initialValue: state)
self._state = state
self.baseState = baseState
self.focusState = focusState
self.equals = equals
self.placeholder = placeholder
Expand All @@ -47,7 +49,11 @@ public struct PokitPartTextArea<Value: Hashable>: View {
.foregroundStyle(.pokit(.text(.primary)))
.scrollContentBackground(.hidden)
.focused(focusState, equals: equals)
.disabled(state == .disable || state == .readOnly)
.disabled(
state == .disable ||
state == .readOnly ||
state == .memo(isReadOnly: true)
)
.onSubmit {
onSubmit?()
}
Expand Down Expand Up @@ -77,7 +83,7 @@ public struct PokitPartTextArea<Value: Hashable>: View {
case .error(message: let message):
state = .error(message: message)
default:
state = .default
state = baseState
}
}
}
Expand Down
62 changes: 31 additions & 31 deletions Projects/DSKit/Sources/Components/PokitTextArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ public struct PokitTextArea<Value: Hashable>: View {

private var focusState: FocusState<Value>.Binding

private let baseState: PokitInputStyle.State
private let errorMessage: String?
private let equals: Value
private let label: String
private let label: String?
private let placeholder: String
private let info: String?
private let maxLetter: Int
private let onSubmit: (() -> Void)?

public init(
text: Binding<String>,
label: String,
label: String? = nil,
state: Binding<PokitInputStyle.State>,
baseState: PokitInputStyle.State = .default,
errorMessage: String? = nil,
placeholder: String = "내용을 입력해주세요.",
info: String? = nil,
Expand All @@ -38,6 +40,7 @@ public struct PokitTextArea<Value: Hashable>: View {
self._text = text
self.label = label
self._state = state
self.baseState = baseState
self.errorMessage = errorMessage
self.focusState = focusState
self.equals = equals
Expand All @@ -49,18 +52,20 @@ public struct PokitTextArea<Value: Hashable>: View {

public var body: some View {
VStack(alignment: .leading, spacing: 0) {
PokitLabel(text: label, size: .large)
.padding(.bottom, 8)
if let label {
PokitLabel(text: label, size: .large)
.padding(.bottom, 8)
}

PokitPartTextArea(
text: $text,
state: state,
state: $state,
baseState: baseState,
placeholder: placeholder,
focusState: focusState,
equals: equals,
onSubmit: onSubmit
)
.onChange(of: focusState.wrappedValue) { onChangedFocuseState($0) }
.onChange(of: state) { onChangedState($0) }

infoLabel
Expand Down Expand Up @@ -94,23 +99,31 @@ public struct PokitTextArea<Value: Hashable>: View {

Spacer()

Group {
switch state {
case .error:
Text("\(text.count > maxLetter ? maxLetter : text.count)/\(maxLetter)")
.foregroundStyle(.pokit(.text(.error)))
default:
Text("\(text.count > maxLetter ? maxLetter : text.count)/\(maxLetter)")
.foregroundStyle(.pokit(.text(.tertiary)))
}
if state != .memo(isReadOnly: true) &&
state != .memo(isReadOnly: false) {
textCount
.pokitBlurReplaceTransition(.pokitDissolve)
}
.pokitFont(.detail1)
.contentTransition(.numericText())
.animation(.pokitDissolve, value: text)
}
.padding(.top, 4)
}

private var textCount: some View {
Group {
switch state {
case .error:
Text("\(text.count > maxLetter ? maxLetter : text.count)/\(maxLetter)")
.foregroundStyle(.pokit(.text(.error)))
default:
Text("\(text.count > maxLetter ? maxLetter : text.count)/\(maxLetter)")
.foregroundStyle(.pokit(.text(.tertiary)))
}
}
.pokitFont(.detail1)
.contentTransition(.numericText())
.animation(.pokitDissolve, value: text)
}

private func onChangedText(_ newValue: String) {
if isMaxLetters {
self.text = String(newValue.prefix(maxLetter + 1))
Expand All @@ -122,19 +135,6 @@ public struct PokitTextArea<Value: Hashable>: View {
state = newValue ? .error(message: "최대 \(maxLetter)자까지 입력가능합니다.") : .active
}

private func onChangedFocuseState(_ newValue: Value) {
if newValue == equals {
state = .active
} else {
switch state {
case .error(message: let message):
state = .error(message: message)
default:
state = .default
}
}
}

private func onChangedState(_ newValue: PokitInputStyle.State) {
switch newValue {
case .error:
Expand Down
13 changes: 9 additions & 4 deletions Projects/DSKit/Sources/Foundation/PokitInputStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum PokitInputStyle: Equatable {
case disable
case readOnly
case error(message: String)
case memo(isReadOnly: Bool)

var infoColor: Color {
switch self {
Expand All @@ -28,23 +29,27 @@ public enum PokitInputStyle: Equatable {
var backgroundColor: Color {
switch self {
case .default, .input, .active, .error:
return .pokit(.bg(.primary))
return .pokit(.bg(.base))
case .disable:
return .pokit(.bg(.disable))
case .readOnly:
return .pokit(.bg(.secondary))
case let .memo(isReadOnly):
return isReadOnly
? .pokit(.bg(.primary))
: Color(red: 1, green: 0.96, blue: 0.89)
}
}

var backgroundStrokeColor: Color {
switch self {
case .default, .input:
case .input, .memo:
return .clear
case .active:
return .pokit(.border(.brand))
case .disable:
return .pokit(.border(.disable))
case .readOnly:
case .readOnly, .default:
return .pokit(.border(.secondary))
case .error:
return .pokit(.border(.error))
Expand All @@ -53,7 +58,7 @@ public enum PokitInputStyle: Equatable {

var iconColor: Color {
switch self {
case .default, .readOnly:
case .default, .readOnly, .memo:
return .pokit(.icon(.secondary))
case .input, .active:
return .pokit(.icon(.primary))
Expand Down
2 changes: 1 addition & 1 deletion Projects/Domain/Sources/Base/BaseContentDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct BaseContentDetail: Equatable {
public let category: BaseCategoryInfo
public let title: String
public let data: String
public let memo: String
public var memo: String
public let createdAt: String
public var favorites: Bool?
public var alertYn: RemindState
Expand Down
2 changes: 1 addition & 1 deletion Projects/Domain/Sources/Base/BaseContentItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct BaseContentItem: Identifiable, Equatable, PokitLinkCardItem, Sorta
public let categoryName: String
public let categoryId: Int
public let title: String
public let memo: String?
public var memo: String?
public var thumbNail: String
public let data: String
public let domain: String
Expand Down
Loading

0 comments on commit 4ae7e46

Please sign in to comment.