Skip to content

Commit a54f635

Browse files
committed
chore: unified textfield and textarea api
1 parent 186ee6b commit a54f635

13 files changed

+179
-60
lines changed

Diff for: SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaAppearance+Extensions.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public extension TextAreaAppearance {
4949
placeholderColorDefault: .textDefaultSecondary,
5050
placeholderColorError: .textDefaultNegative,
5151
placeholderColorWarning: .textDefaultWarning,
52-
placeholderColorSuccess: .textDefaultAccent
52+
placeholderColorSuccess: .textDefaultAccent,
53+
endContentColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
54+
textColorReadOnly: .surfaceInverseSolidPrimary.withOpacity(0.96),
55+
captionColorReadOnly: .surfaceInverseSolidPrimary.withOpacity(0.56),
56+
placeholderColorReadOnly: .textDefaultSecondary
5357
)
5458
}
5559
}

Diff for: SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaSize.swift

+15-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,21 @@ public enum SDDSTextAreaSize: String, TextAreaSizeConfiguration {
4949
public var textAfterTrailingPadding: CGFloat {
5050
return 2
5151
}
52-
53-
public var fieldHorizontalPadding: CGFloat {
52+
53+
public var boxLeadingPadding: CGFloat {
54+
switch self {
55+
case .large:
56+
16
57+
case .medium:
58+
8
59+
case .small:
60+
8
61+
case .extraSmall:
62+
8
63+
}
64+
}
65+
66+
public var boxTrailingPadding: CGFloat {
5467
switch self {
5568
case .large:
5669
16

Diff for: SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/ChipAppearance+SDDSTextField.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public extension ChipAppearance {
1010
titleTypography: ChipTextFieldTypography.text,
1111
imageTintColor: ColorToken.textDefaultPrimary,
1212
buttonTintColor: ColorToken.textDefaultPrimary,
13-
backgroundColor: .surfaceDefaultTransparentSecondary,
13+
backgroundColor: .surfaceDefaultSolidPrimary,
1414
disabledAlpha: 0.5
1515
)
1616
}

Diff for: SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/SDDSTextField+Preview.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct SDDSTextFieldPreview: PreviewProvider {
1313
isEnabled: true,
1414
iconImage: nil,
1515
buttonImage: Image.image("textFieldChipIcon"),
16-
appearance: .textField,
16+
appearance: SDDSChip.accent.medium.pilled.appearance,
1717
accessibility: ChipAccessibility(),
1818
removeAction: {}
1919
)
@@ -76,7 +76,7 @@ struct SDDSTextFieldPreview: PreviewProvider {
7676
disabled: false,
7777
style: .default,
7878
labelPlacement: .inner,
79-
required: true,
79+
required: false,
8080
requiredPlacement: .left,
8181
appearance: .defaultAppearance,
8282
size: SDDSTextFieldSize.large,
@@ -144,7 +144,7 @@ struct SDDSTextFieldPreview: PreviewProvider {
144144
appearance: .defaultAppearance,
145145
size: SDDSTextFieldSize.large,
146146
layout: .default,
147-
iconViewProvider: ViewProvider(iconView),
147+
iconViewProvider: nil,
148148
iconActionViewProvider: ViewProvider(iconActionView)
149149
)
150150
.previewDisplayName("Multiple – Default Label")

Diff for: SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/TextFieldAppearance+Extensions.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ public extension TextFieldAppearance {
5353
placeholderColorWarning: .textDefaultWarning,
5454
placeholderColorSuccess: .textDefaultAccent,
5555
textBeforeColor: .textDefaultTertiary,
56-
textAfterColor: .textDefaultTertiary
56+
textAfterColor: .textDefaultTertiary,
57+
startContentColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
58+
endContentColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
59+
textColorReadOnly: .surfaceInverseSolidPrimary.withOpacity(0.96),
60+
captionColorReadOnly: .surfaceInverseSolidPrimary.withOpacity(0.56),
61+
placeholderColorReadOnly: .textDefaultSecondary
5762
)
5863
}
5964
}

Diff for: SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/TextFieldDefaultSize.swift

+21-8
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,21 @@ public enum SDDSTextFieldSize: String, TextFieldSizeConfiguration {
5353
public var textAfterTrailingPadding: CGFloat {
5454
return 2
5555
}
56+
57+
public var boxLeadingPadding: CGFloat {
58+
switch self {
59+
case .large:
60+
16
61+
case .medium:
62+
8
63+
case .small:
64+
8
65+
case .extraSmall:
66+
8
67+
}
68+
}
5669

57-
public var fieldHorizontalPadding: CGFloat {
70+
public var boxTrailingPadding: CGFloat {
5871
switch self {
5972
case .large:
6073
16
@@ -70,13 +83,9 @@ public enum SDDSTextFieldSize: String, TextFieldSizeConfiguration {
7083
public var captionTopPadding: CGFloat {
7184
4
7285
}
73-
74-
public var textInputPaddings: EdgeInsets {
75-
.init(top: 2, leading: 0, bottom: 0, trailing: 0)
76-
}
7786

78-
public var textHorizontalPadding: CGFloat {
79-
return 1.0
87+
public var optionalPadding: CGFloat {
88+
4
8089
}
8190

8291
public var cornerRadius: CGFloat {
@@ -237,12 +246,16 @@ public enum SDDSTextFieldSize: String, TextFieldSizeConfiguration {
237246
CGSize(width: 16, height: 16)
238247
}
239248
}
249+
250+
public var chipsPadding: CGFloat {
251+
6
252+
}
240253

241254
public var multipleValueHorizontalPadding: CGFloat {
242255
2
243256
}
244257

245-
public var lineWidth: CGFloat {
258+
public var dividerHeight: CGFloat {
246259
1
247260
}
248261

Diff for: SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/SDDSTextArea.swift

+40-14
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public enum TextAreaValue: Equatable {
8686
- style: Стиль текстового поля (`default`, `error`, `warning`, `success`).
8787
- labelPlacement: Размещение метки (`outer`, `inner`, `none`).
8888
- required: Флаг, указывающий, является ли поле обязательным.
89+
- divider: Флаг, указывающий, показывать ли линию разделителя.
8990
- requiredPlacement: Размещение обязательного индикатора (`left`, `right`).
9091
- dynamicHeight: Флаг, указывающий, расширяется ли текстовое поле по высоте в зависимости от высоты текста.
9192
- appearance: Параметры внешнего вида текстового поля.
@@ -108,6 +109,7 @@ public struct SDDSTextArea: View {
108109
public let style: TextAreaStyle
109110
public let labelPlacement: TextAreaLabelPlacement
110111
public let required: Bool
112+
public let divider: Bool
111113
public let requiredPlacement: TextAreaRequiredPlacement
112114
public let dynamicHeight: Bool
113115
public let appearance: TextAreaAppearance
@@ -135,6 +137,7 @@ public struct SDDSTextArea: View {
135137
style: TextAreaStyle = .default,
136138
labelPlacement: TextAreaLabelPlacement = .outer,
137139
required: Bool = false,
140+
divider: Bool = true,
138141
requiredPlacement: TextAreaRequiredPlacement = .left,
139142
dynamicHeight: Bool = false,
140143
appearance: TextAreaAppearance,
@@ -166,6 +169,7 @@ public struct SDDSTextArea: View {
166169
self.readOnly = readOnly
167170
self.style = style
168171
self.required = required
172+
self.divider = divider
169173
self.requiredPlacement = requiredPlacement
170174
self.title = title
171175
self.optionalTitle = optionalTitle
@@ -287,14 +291,14 @@ public struct SDDSTextArea: View {
287291
.padding(.trailing, size.textInputPaddings.trailing)
288292

289293
iconActionView
290-
.padding(.trailing, fieldHorizontalPadding)
294+
.padding(.trailing, boxTrailingPadding)
291295
} else {
292296
textEditor(id: textAreaOuterTitleId)
293297
.padding(size.textInputPaddings)
294298

295299
iconActionView
296300
.padding(.top, size.textInputPaddings.top)
297-
.padding(.trailing, fieldHorizontalPadding)
301+
.padding(.trailing, boxTrailingPadding)
298302
}
299303
}
300304
case .multiple(_, let chips):
@@ -310,7 +314,7 @@ public struct SDDSTextArea: View {
310314

311315
iconActionView
312316
.padding(.top, size.textInputPaddings.top)
313-
.padding(.trailing, layout == .clear ? size.iconActionClearTrailingPadding : fieldHorizontalPadding)
317+
.padding(.trailing, layout == .clear ? size.iconActionClearTrailingPadding : boxTrailingPadding)
314318
}
315319

316320
textEditor(id: textAreaMultipleId)
@@ -431,8 +435,8 @@ public struct SDDSTextArea: View {
431435
.frame(maxWidth: .infinity)
432436
}
433437
.frame(height: size.fieldHeight(layout: layout), debug: debugConfiguration.fieldHeight)
434-
.padding(.leading, fieldHorizontalPadding, debug: debugConfiguration.fieldHorizontalPadding)
435-
.padding(.trailing, fieldTrailingPadding, debug: debugConfiguration.fieldHorizontalPadding)
438+
.padding(.leading, boxLeadingPadding, debug: debugConfiguration.boxLeadingPadding)
439+
.padding(.trailing, fieldTrailingPadding, debug: debugConfiguration.boxTrailingPadding)
436440

437441
VStack(alignment: .leading, spacing: 0) {
438442
VStack(alignment: .leading, spacing: 0) {
@@ -464,8 +468,8 @@ public struct SDDSTextArea: View {
464468
bottomLineView
465469
}
466470
}
467-
.padding(.leading, fieldHorizontalPadding, debug: debugConfiguration.fieldHorizontalPadding)
468-
.padding(.trailing, fieldTrailingPadding, debug: debugConfiguration.fieldHorizontalPadding)
471+
.padding(.leading, boxLeadingPadding, debug: debugConfiguration.boxLeadingPadding)
472+
.padding(.trailing, fieldTrailingPadding, debug: debugConfiguration.boxTrailingPadding)
469473

470474
if shouldShowIndicatorForInnerLabelDefaultLayout || shouldShowIndicatorForNoneLabelDefaultLayout {
471475
indicatorOverlayView
@@ -541,12 +545,15 @@ public struct SDDSTextArea: View {
541545
}
542546

543547
private var counterColor: Color {
548+
if readOnly {
549+
return appearance.counterColorReadOnly.color(for: colorScheme)
550+
}
544551
return appearance.counterColorDefault.color(for: colorScheme)
545552
}
546553

547554
private var backgroundColor: Color {
548555
if readOnly {
549-
return appearance.backgroundColorDefault.color(for: colorScheme)
556+
return appearance.backgroundColorReadOnly.color(for: colorScheme)
550557
}
551558
return appearance.backgroundColor(for: style, isFocused: isFocused).color(for: colorScheme)
552559
}
@@ -559,10 +566,16 @@ public struct SDDSTextArea: View {
559566
}
560567

561568
private var placeholderColor: Color {
569+
if readOnly {
570+
return appearance.placeholderColorReadOnly.color(for: colorScheme)
571+
}
562572
return appearance.placeholderColor(for: isFocused ? .default : style, layout: layout).color(for: colorScheme)
563573
}
564574

565575
private var textColor: Color {
576+
if readOnly {
577+
return appearance.textColorReadOnly.color(for: colorScheme)
578+
}
566579
return appearance.textColor(for: isFocused ? .default : style, layout: layout).color(for: colorScheme)
567580
}
568581

@@ -583,6 +596,7 @@ public struct SDDSTextArea: View {
583596
private var iconActionView: some View {
584597
if let rightView = iconActionViewProvider?.view {
585598
rightView
599+
.foregroundColor(appearance.endContentColor.color(for: colorScheme))
586600
.frame(width: iconActionViewWidth, height: iconActionViewHeight, debug: debugConfiguration.iconAction)
587601
.padding(.leading, size.iconActionPadding, debug: debugConfiguration.iconAction)
588602
} else {
@@ -639,9 +653,13 @@ public struct SDDSTextArea: View {
639653

640654
@ViewBuilder
641655
private var bottomLineView: some View {
642-
Rectangle()
643-
.fill(bottomLineColor)
644-
.frame(height: size.lineWidth, debug: debugConfiguration.fieldView)
656+
if divider {
657+
Rectangle()
658+
.fill(bottomLineColor)
659+
.frame(height: size.lineWidth, debug: debugConfiguration.fieldView)
660+
} else {
661+
EmptyView()
662+
}
645663
}
646664

647665
// MARK: - Computed Properties for Conditions
@@ -663,7 +681,7 @@ public struct SDDSTextArea: View {
663681
}
664682

665683
private var captionTrailingPadding: CGFloat {
666-
fieldHorizontalPadding
684+
boxTrailingPadding
667685
}
668686

669687
private var fieldTrailingPadding: CGFloat {
@@ -825,8 +843,16 @@ public struct SDDSTextArea: View {
825843
return typography
826844
}
827845

828-
private var fieldHorizontalPadding: CGFloat {
829-
layout == .clear ? 0 : size.fieldHorizontalPadding
846+
private var boxLeadingPadding: CGFloat {
847+
if displayChips {
848+
return size.chipsPadding
849+
}
850+
851+
return layout == .clear ? 0 : size.boxLeadingPadding
852+
}
853+
854+
private var boxTrailingPadding: CGFloat {
855+
layout == .clear ? 0 : size.boxTrailingPadding
830856
}
831857

832858
}

Diff for: SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/TextAreaAppearance.swift

+19-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public struct TextAreaAppearance {
4646
public let placeholderColorError: ColorToken
4747
public let placeholderColorWarning: ColorToken
4848
public let placeholderColorSuccess: ColorToken
49+
public let endContentColor: ColorToken
50+
public let textColorReadOnly: ColorToken
51+
public let captionColorReadOnly: ColorToken
52+
public let counterColorReadOnly: ColorToken
53+
public let placeholderColorReadOnly: ColorToken
54+
public let backgroundColorReadOnly: ColorToken
4955

5056
public init(
5157
textTypography: TypographyConfiguration,
@@ -89,7 +95,13 @@ public struct TextAreaAppearance {
8995
placeholderColorDefault: ColorToken,
9096
placeholderColorError: ColorToken,
9197
placeholderColorWarning: ColorToken,
92-
placeholderColorSuccess: ColorToken
98+
placeholderColorSuccess: ColorToken,
99+
endContentColor: ColorToken,
100+
textColorReadOnly: ColorToken,
101+
captionColorReadOnly: ColorToken,
102+
counterColorReadOnly: ColorToken,
103+
placeholderColorReadOnly: ColorToken,
104+
backgroundColorReadOnly: ColorToken
93105
) {
94106
self.textTypography = textTypography
95107
self.titleTypography = titleTypography
@@ -133,6 +145,12 @@ public struct TextAreaAppearance {
133145
self.placeholderColorError = placeholderColorError
134146
self.placeholderColorWarning = placeholderColorWarning
135147
self.placeholderColorSuccess = placeholderColorSuccess
148+
self.endContentColor = endContentColor
149+
self.textColorReadOnly = textColorReadOnly
150+
self.captionColorReadOnly = captionColorReadOnly
151+
self.placeholderColorReadOnly = placeholderColorReadOnly
152+
self.backgroundColorReadOnly = backgroundColorReadOnly
153+
self.counterColorReadOnly = counterColorReadOnly
136154
}
137155

138156
public func borderColor(for style: TextAreaStyle) -> ColorToken {

Diff for: SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/TextAreaSizeConfiguration.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import SwiftUI
55
public protocol TextAreaSizeConfiguration: CustomDebugStringConvertible {
66
var titleBottomPadding: CGFloat { get }
77
var titleInnerPadding: CGFloat { get }
8-
var fieldHorizontalPadding: CGFloat { get }
8+
var boxLeadingPadding: CGFloat { get }
9+
var boxTrailingPadding: CGFloat { get }
910
var captionTopPadding: CGFloat { get }
1011
var captionBottomPadding: CGFloat { get }
1112
var textInputPaddings: EdgeInsets { get }
@@ -27,6 +28,7 @@ public protocol TextAreaSizeConfiguration: CustomDebugStringConvertible {
2728
var chipGroupVerticalBottomPadding: CGFloat { get }
2829
var textInputBottomPadding: CGFloat { get }
2930
var iconActionClearTrailingPadding: CGFloat { get }
31+
var chipsPadding: CGFloat { get }
3032

3133
func fieldHeight(layout: TextAreaLayout) -> CGFloat
3234
func indicatorPadding(labelPlacement: TextAreaLabelPlacement, requiredPlacement: TextAreaRequiredPlacement, layout: TextAreaLayout) -> CGFloat

0 commit comments

Comments
 (0)