From 42ac85dc4ba21afade4dee479c617b165cc28dc7 Mon Sep 17 00:00:00 2001 From: Vladimir Kaltyrin Date: Wed, 15 Jan 2025 15:06:51 +0300 Subject: [PATCH] fix: updated colors and paddins for textarea/textfield --- .../SDDSTextArea/SDDSTextArea+Preview.swift | 4 ++-- .../SDDSTextAreaAppearance+Extensions.swift | 8 ++++---- .../SDDSTextArea/SDDSTextAreaSize.swift | 4 ++++ .../ChipAppearance+SDDSTextField.swift | 8 ++++---- .../SDDSTextField/SDDSTextField+Preview.swift | 12 ++++++------ .../Components/SDDSTextArea/SDDSTextArea.swift | 14 ++++++-------- .../TextAreaSizeConfiguration.swift | 1 + .../SDDSTextField/SDDSTextField.swift | 18 ++++++++++++------ 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextArea+Preview.swift b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextArea+Preview.swift index 3d0d73fb..49b23266 100644 --- a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextArea+Preview.swift +++ b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextArea+Preview.swift @@ -29,9 +29,9 @@ struct SDDSTextAreaPreview: PreviewProvider { counter: "counter", disabled: false, readOnly: false, - style: .default, + style: .warning, labelPlacement: .inner, - required: true, + required: false, requiredPlacement: .left, dynamicHeight: true, appearance: .defaultAppearance, diff --git a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaAppearance+Extensions.swift b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaAppearance+Extensions.swift index 72a9cdbf..4aa1d9ba 100644 --- a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaAppearance+Extensions.swift +++ b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaAppearance+Extensions.swift @@ -124,11 +124,11 @@ extension TextAreaTypography { public extension ChipAppearance { static var textArea: ChipAppearance { ChipAppearance( - titleColor: .surfaceInverseSolidPrimary.withOpacity(0.96), + titleColor: .textDefaultPrimary, titleTypography: ChipTextFieldTypography.text, - imageTintColor: ColorToken.textDefaultPrimary, - buttonTintColor: ColorToken.textDefaultPrimary, - backgroundColor: .surfaceDefaultSolidPrimary, + imageTintColor: .textDefaultPrimary, + buttonTintColor: .textDefaultPrimary, + backgroundColor: .surfaceDefaultTransparentSecondary, disabledAlpha: 0.5 ) } diff --git a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaSize.swift b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaSize.swift index f26a4f50..7e72205d 100644 --- a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaSize.swift +++ b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextArea/SDDSTextAreaSize.swift @@ -101,6 +101,10 @@ public enum SDDSTextAreaSize: String, TextAreaSizeConfiguration { public var captionBottomPadding: CGFloat { 4 } + + public var optionalPadding: CGFloat { + 4 + } public var textInputPaddings: EdgeInsets { switch self { diff --git a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/ChipAppearance+SDDSTextField.swift b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/ChipAppearance+SDDSTextField.swift index f6321cea..056efbe3 100644 --- a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/ChipAppearance+SDDSTextField.swift +++ b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/ChipAppearance+SDDSTextField.swift @@ -6,11 +6,11 @@ import SDDSComponents public extension ChipAppearance { static var textField: ChipAppearance { ChipAppearance( - titleColor: .surfaceInverseSolidPrimary.withOpacity(0.96), + titleColor: .textDefaultPrimary, titleTypography: ChipTextFieldTypography.text, - imageTintColor: ColorToken.textDefaultPrimary, - buttonTintColor: ColorToken.textDefaultPrimary, - backgroundColor: .surfaceDefaultSolidPrimary, + imageTintColor: .textDefaultPrimary, + buttonTintColor: .textDefaultPrimary, + backgroundColor: .surfaceDefaultTransparentSecondary, disabledAlpha: 0.5 ) } diff --git a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/SDDSTextField+Preview.swift b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/SDDSTextField+Preview.swift index fc827893..f61de2b8 100644 --- a/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/SDDSTextField+Preview.swift +++ b/SDDSComponents/SDDSComponentsPreview/Components/SDDSTextField/SDDSTextField+Preview.swift @@ -25,20 +25,20 @@ struct SDDSTextFieldPreview: PreviewProvider { SDDSTextField( value: .constant(.single("")), title: "Title", - optionalTitle: "", + optionalTitle: "optional", placeholder: "Placeholder", caption: "caption", textBefore: "", textAfter: "", disabled: false, - readOnly: true, - style: .default, - labelPlacement: .outer, - required: true, + readOnly: false, + style: .warning, + labelPlacement: .inner, + required: false, requiredPlacement: .right, appearance: .defaultAppearance, size: SDDSTextFieldSize.medium, - layout: .default, + layout: .clear, iconViewProvider: ViewProvider(iconView), iconActionViewProvider: ViewProvider(iconActionView) ) diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/SDDSTextArea.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/SDDSTextArea.swift index 7d296119..21c50c77 100644 --- a/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/SDDSTextArea.swift +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/SDDSTextArea.swift @@ -246,12 +246,13 @@ public struct SDDSTextArea: View { @ViewBuilder private var optionalTitleView: some View { - Text(formattedOptionalTitle) + Text(optionalTitle) .typography(titleTypography) .frame(height: titleTypography.lineHeight) .foregroundColor(appearance.optionalTitleColor.color(for: colorScheme)) .multilineTextAlignment(appearance.titleTextAlignment) .debug(condition: debugConfiguration.title) + .padding(.leading, size.optionalPadding) } @ViewBuilder @@ -259,11 +260,12 @@ public struct SDDSTextArea: View { if required { EmptyView() } else { - Text(formattedOptionalTitle) + Text(optionalTitle) .typography(innerTitleTypography) .foregroundColor(appearance.optionalTitleColor.color(for: colorScheme)) .multilineTextAlignment(appearance.titleTextAlignment) .debug(condition: debugConfiguration.title) + .padding(.leading, size.optionalPadding) } } @@ -315,7 +317,6 @@ public struct SDDSTextArea: View { .frame(height: calculatedChipGroupHeight) .padding(.bottom, size.chipGroupVerticalBottomPadding) .padding(.top, size.chipGroupVerticalTopPadding) - .debug(color: .blue, condition: true) iconActionView .padding(.top, size.textInputPaddings.top) @@ -413,9 +414,10 @@ public struct SDDSTextArea: View { if required { EmptyView() } else { - Text(" \(optionalTitle)") + Text(optionalTitle) .typography(textTypography) .foregroundColor(appearance.optionalTitleColor.color(for: colorScheme)) + .padding(.leading, size.optionalPadding) } } @@ -769,10 +771,6 @@ public struct SDDSTextArea: View { return min(size.chipGroupHeight, chipGroupContentHeight) } - private var formattedOptionalTitle: String { - " \(optionalTitle)" - } - private var chipCornerRadius: CGFloat { switch value { case .single: diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/TextAreaSizeConfiguration.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/TextAreaSizeConfiguration.swift index c3cbdb07..d9129399 100644 --- a/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/TextAreaSizeConfiguration.swift +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextArea/TextAreaSizeConfiguration.swift @@ -9,6 +9,7 @@ public protocol TextAreaSizeConfiguration: CustomDebugStringConvertible { var boxTrailingPadding: CGFloat { get } var captionTopPadding: CGFloat { get } var captionBottomPadding: CGFloat { get } + var optionalPadding: CGFloat { get } var textInputPaddings: EdgeInsets { get } var cornerRadius: CGFloat { get } var borderWidth: CGFloat { get } diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextField/SDDSTextField.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextField/SDDSTextField.swift index 5446fec2..400efd32 100644 --- a/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextField/SDDSTextField.swift +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSTextField/SDDSTextField.swift @@ -247,6 +247,7 @@ public struct SDDSTextField: View { .foregroundColor(appearance.optionalTitleColor.color(for: colorScheme)) .multilineTextAlignment(appearance.titleTextAlignment) .debug(condition: debugConfiguration.title) + .padding(.leading, size.optionalPadding) } @ViewBuilder @@ -439,7 +440,7 @@ public struct SDDSTextField: View { @ViewBuilder private var innerOrNonePlacementOptionalTitleView: some View { - Text(" \(optionalTitle)") + Text(optionalTitle) .typography(textTypography) .foregroundColor(appearance.optionalTitleColor.color(for: colorScheme)) .padding(.leading, size.optionalPadding) @@ -582,12 +583,21 @@ public struct SDDSTextField: View { return appearance.lineColor.color(for: colorScheme) } } + + private var iconViewColor: Color { + switch style { + case .error, .success, .warning: + return appearance.placeholderColor(for: style, layout: layout).color(for: colorScheme) + case .default: + return appearance.startContentColor.color(for: colorScheme) + } + } @ViewBuilder private var iconView: some View { if let leftView = iconViewProvider?.view { leftView - .foregroundColor(appearance.startContentColor.color(for: colorScheme)) + .foregroundColor(iconViewColor) .frame(width: iconViewWidth, height: min(size.iconSize.height, size.fieldHeight), debug: debugConfiguration.icon) .padding(.trailing, size.iconPadding, debug: debugConfiguration.icon) } else { @@ -735,10 +745,6 @@ public struct SDDSTextField: View { } } - private var formattedOptionalTitle: String { - " \(optionalTitle)" - } - private var chipCornerRadius: CGFloat { switch value { case .single: