Skip to content

Commit

Permalink
chore: unified textfield and textarea api
Browse files Browse the repository at this point in the history
  • Loading branch information
vkaltyrin committed Jan 14, 2025
1 parent 186ee6b commit 1a5a3e4
Show file tree
Hide file tree
Showing 39 changed files with 368 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 'latest'
xcode-version: '16.1'

- name: Install the Apple certificate and provisioning profile
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public extension TextAreaAppearance {
innerTitleTypography: TextAreaTypography.innerTitle,
captionTypography: TextAreaTypography.caption,
counterTypography: TextAreaTypography.counter,
titleColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
optionalTitleColor: .surfaceInverseSolidPrimary.withOpacity(0.28),
textColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
titleColor: .textDefaultPrimary,
optionalTitleColor: .textDefaultTertiary,
textColor: .textDefaultPrimary,
textColorError: .textDefaultNegative,
textColorWarning: .textDefaultWarning,
textColorSuccess: .textDefaultAccent,
Expand All @@ -32,24 +32,24 @@ public extension TextAreaAppearance {
borderColorWarning: Color.clear.token,
borderColorSuccess: Color.clear.token,
backgroundColorDefault: .surfaceDefaultTransparentPrimary,
backgroundColorError: ColorToken(
darkColor: Color(UIColor(hex: "#FF293E").withAlphaComponent(0.2)),
lightColor: Color(UIColor(hex: "#FF293E").withAlphaComponent(0.12))
),
backgroundColorWarning: .surfaceDefaultTransparentWarning.inverted,
backgroundColorSuccess: ColorToken(
darkColor: Color(UIColor(hex: "#1A9E32").withAlphaComponent(0.2)),
lightColor: Color(UIColor(hex: "#1A9E32").withAlphaComponent(0.12))
),
captionColorDefault: .surfaceInverseSolidPrimary.withOpacity(0.56),
backgroundColorError: .surfaceDefaultTransparentNegative,
backgroundColorWarning: .surfaceDefaultTransparentWarning,
backgroundColorSuccess: .surfaceDefaultTransparentPositive,
captionColorDefault: .textDefaultSecondary,
captionColorError: .textDefaultNegative,
captionColorWarning: .textDefaultWarning,
captionColorSuccess: .textDefaultAccent,
counterColorDefault: .surfaceInverseSolidPrimary.withOpacity(0.56),
counterColorDefault: .textDefaultSecondary,
placeholderColorDefault: .textDefaultSecondary,
placeholderColorError: .textDefaultNegative,
placeholderColorWarning: .textDefaultWarning,
placeholderColorSuccess: .textDefaultAccent
placeholderColorSuccess: .textDefaultAccent,
endContentColor: .textDefaultSecondary,
textColorReadOnly: .textDefaultPrimary,
captionColorReadOnly: .textDefaultSecondary,
counterColorReadOnly: .textDefaultSecondary,
placeholderColorReadOnly: .textDefaultSecondary,
backgroundColorReadOnly: .surfaceDefaultSolidPrimary
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
import SDDSComponents

public enum SDDSTextAreaSize: String, TextAreaSizeConfiguration {

case large
case medium
case small
Expand Down Expand Up @@ -34,6 +35,10 @@ public enum SDDSTextAreaSize: String, TextAreaSizeConfiguration {
}
}

public var chipsPadding: CGFloat {
6
}

public var textBeforeLeadingPadding: CGFloat {
return 0
}
Expand All @@ -49,8 +54,21 @@ public enum SDDSTextAreaSize: String, TextAreaSizeConfiguration {
public var textAfterTrailingPadding: CGFloat {
return 2
}

public var fieldHorizontalPadding: CGFloat {

public var boxLeadingPadding: CGFloat {
switch self {
case .large:
16
case .medium:
8
case .small:
8
case .extraSmall:
8
}
}

public var boxTrailingPadding: CGFloat {
switch self {
case .large:
16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,23 @@ public enum TextAreaChipSize: String, ChipSizeConfiguration {
}
}

public var borderStyle: ChipBorderStyle {
switch self {
case .large:
return .default(8)
case .medium:
return .default(6)
case .small:
return .default(4)
case .extraSmall:
return .default(2)
public func cornerRadius(style: ComponentShapeStyle) -> CGFloat {
switch style {
case .cornered:
switch self {
case .large:
return 8
case .medium:
return 6
case .small:
return 4
case .extraSmall:
return 2
}
case .pilled:
return height / 2
}
}

}

#Preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public extension ChipAppearance {
titleTypography: ChipTextFieldTypography.text,
imageTintColor: ColorToken.textDefaultPrimary,
buttonTintColor: ColorToken.textDefaultPrimary,
backgroundColor: .surfaceDefaultTransparentSecondary,
backgroundColor: .surfaceDefaultSolidPrimary,
disabledAlpha: 0.5
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SDDSTextFieldPreview: PreviewProvider {
isEnabled: true,
iconImage: nil,
buttonImage: Image.image("textFieldChipIcon"),
appearance: .textField,
appearance: SDDSChip.accent.medium.pilled.appearance,
accessibility: ChipAccessibility(),
removeAction: {}
)
Expand Down Expand Up @@ -76,7 +76,7 @@ struct SDDSTextFieldPreview: PreviewProvider {
disabled: false,
style: .default,
labelPlacement: .inner,
required: true,
required: false,
requiredPlacement: .left,
appearance: .defaultAppearance,
size: SDDSTextFieldSize.large,
Expand Down Expand Up @@ -144,7 +144,7 @@ struct SDDSTextFieldPreview: PreviewProvider {
appearance: .defaultAppearance,
size: SDDSTextFieldSize.large,
layout: .default,
iconViewProvider: ViewProvider(iconView),
iconViewProvider: nil,
iconActionViewProvider: ViewProvider(iconActionView)
)
.previewDisplayName("Multiple – Default Label")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public extension TextFieldAppearance {
captionTypography: TextFieldTypography.caption,
textBeforeTypography: TextFieldTypography.text,
textAfterTypography: TextFieldTypography.text,
titleColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
optionalTitleColor: .surfaceInverseSolidPrimary.withOpacity(0.28),
textColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
titleColor: .textDefaultPrimary,
optionalTitleColor: .textDefaultTertiary,
textColor: .textDefaultPrimary,
textColorError: .textDefaultNegative,
textColorWarning: .textDefaultWarning,
textColorSuccess: .textDefaultAccent,
Expand All @@ -34,17 +34,11 @@ public extension TextFieldAppearance {
borderColorWarning: Color.clear.token,
borderColorSuccess: Color.clear.token,
backgroundColorDefault: .surfaceDefaultTransparentPrimary,
backgroundColorReadOnly: .surfaceDefaultTransparentPrimary,
backgroundColorError: ColorToken(
darkColor: Color(UIColor(hex: "#FF293E").withAlphaComponent(0.2)),
lightColor: Color(UIColor(hex: "#FF293E").withAlphaComponent(0.12))
),
backgroundColorWarning: .surfaceDefaultTransparentWarning.inverted,
backgroundColorSuccess: ColorToken(
darkColor: Color(UIColor(hex: "#1A9E32").withAlphaComponent(0.2)),
lightColor: Color(UIColor(hex: "#1A9E32").withAlphaComponent(0.12))
),
captionColorDefault: .surfaceInverseSolidPrimary.withOpacity(0.56),
backgroundColorReadOnly: .surfaceDefaultSolidPrimary,
backgroundColorError: .surfaceDefaultTransparentNegative,
backgroundColorWarning: .surfaceDefaultTransparentWarning,
backgroundColorSuccess: .surfaceDefaultTransparentPositive,
captionColorDefault: .textDefaultSecondary,
captionColorError: .textDefaultNegative,
captionColorWarning: .textDefaultWarning,
captionColorSuccess: .textDefaultAccent,
Expand All @@ -53,7 +47,12 @@ public extension TextFieldAppearance {
placeholderColorWarning: .textDefaultWarning,
placeholderColorSuccess: .textDefaultAccent,
textBeforeColor: .textDefaultTertiary,
textAfterColor: .textDefaultTertiary
textAfterColor: .textDefaultTertiary,
startContentColor: .textDefaultSecondary,
endContentColor: .textDefaultSecondary,
textColorReadOnly: .textDefaultPrimary,
captionColorReadOnly: .textDefaultSecondary,
placeholderColorReadOnly: .textDefaultSecondary
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,23 @@ public enum TextFieldChipSize: ChipSizeConfiguration {
}
}

public var borderStyle: ChipBorderStyle {
switch self {
case .large:
return .default(8)
case .medium:
return .default(6)
case .small:
return .default(4)
case .extraSmall:
return .default(2)
public func cornerRadius(style: SDDSComponents.ComponentShapeStyle) -> CGFloat {
switch style {
case .cornered:
switch self {
case .large:
return 8
case .medium:
return 6
case .small:
return 4
case .extraSmall:
return 2
}
case .pilled:
return height / 2
}
}

}

#Preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,21 @@ public enum SDDSTextFieldSize: String, TextFieldSizeConfiguration {
public var textAfterTrailingPadding: CGFloat {
return 2
}

public var boxLeadingPadding: CGFloat {
switch self {
case .large:
16
case .medium:
8
case .small:
8
case .extraSmall:
8
}
}

public var fieldHorizontalPadding: CGFloat {
public var boxTrailingPadding: CGFloat {
switch self {
case .large:
16
Expand All @@ -70,13 +83,9 @@ public enum SDDSTextFieldSize: String, TextFieldSizeConfiguration {
public var captionTopPadding: CGFloat {
4
}

public var textInputPaddings: EdgeInsets {
.init(top: 2, leading: 0, bottom: 0, trailing: 0)
}

public var textHorizontalPadding: CGFloat {
return 1.0
public var optionalPadding: CGFloat {
4
}

public var cornerRadius: CGFloat {
Expand Down Expand Up @@ -237,12 +246,16 @@ public enum SDDSTextFieldSize: String, TextFieldSizeConfiguration {
CGSize(width: 16, height: 16)
}
}

public var chipsPadding: CGFloat {
6
}

public var multipleValueHorizontalPadding: CGFloat {
2
}

public var lineWidth: CGFloat {
public var dividerHeight: CGFloat {
1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public extension ColorToken {
}
}

public extension ShapeToken {
static var `default`: ShapeToken {
.default
}
}

public extension ColorToken {
func withOpacity(_ opacity: Double) -> ColorToken {
return ColorToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public struct ButtonAppearance {
public let size: ButtonSizeConfiguration

/**
Стиль формы кнопки (например, закругленная или овальная), определяемый `ButtonShapeStyle`.
Стиль формы кнопки (например, закругленная или овальная), определяемый `ComponentShapeStyle`.
*/
public let shapeStyle: ButtonShapeStyle
public let shapeStyle: ComponentShapeStyle

/**
Типографика для текста заголовка кнопки, определяемая `TypographyConfiguration`.
Expand Down Expand Up @@ -95,7 +95,7 @@ public struct ButtonAppearance {
*/
public init(
size: ButtonSizeConfiguration = DefaultButtonSize(),
shapeStyle: ButtonShapeStyle = .default,
shapeStyle: ComponentShapeStyle = .cornered,
titleTypography: TypographyConfiguration = .default,
titleColor: ButtonColor = ButtonColor(),
subtitleTypography: TypographyConfiguration = .default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public protocol ButtonSizeConfiguration: SizeConfiguration, CustomDebugStringCon
/**
Радиус скругления углов кнопки.
*/
var cornerRadius: CGFloat { get }
func cornerRadius(style: ComponentShapeStyle) -> CGFloat

/**
Внутренние отступы кнопки.
Expand All @@ -48,11 +48,12 @@ public protocol ButtonSizeConfiguration: SizeConfiguration, CustomDebugStringCon
Горизонтальный промежуток между заголовком и подзаголовком кнопки.
*/
var titleHorizontalGap: CGFloat { get }

}

public struct DefaultButtonSize: ButtonSizeConfiguration {
public var height: CGFloat = 0
public var cornerRadius: CGFloat = 0
public func cornerRadius(style: ComponentShapeStyle) -> CGFloat { 0 }
public var paddings: EdgeInsets = .init()
public var iconSize: CGSize = .zero
public var spinnerSize: CGSize = .zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public extension ButtonAppearance {
)
}

func shapeStyle(_ shapeStyle: ButtonShapeStyle) -> ButtonAppearance {
func shapeStyle(_ shapeStyle: ComponentShapeStyle) -> ButtonAppearance {
return ButtonAppearance(
size: self.size,
shapeStyle: shapeStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ public struct SDDSButton: View {

private extension SDDSButton {
var cornerRadius: CGFloat {
switch appearance.shapeStyle {
case .default:
return appearance.size.cornerRadius
case .pilled:
return appearance.size.height / 2
}
return appearance.size.cornerRadius(style: appearance.shapeStyle)
}

func currentColor(for buttonColor: ButtonColor) -> Color {
Expand Down
Loading

0 comments on commit 1a5a3e4

Please sign in to comment.