Skip to content

Commit

Permalink
feat: unified indicator API for textfield
Browse files Browse the repository at this point in the history
  • Loading branch information
vkaltyrin committed Jan 15, 2025
1 parent 1a5a3e4 commit aa2c2cc
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 257 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ disabled_rules: # rule identifiers turned on by default to exclude from running
- file_length
- empty_count
- type_body_length
- function_body_length
- cyclomatic_complexity
opt_in_rules: # some rules are turned off by default, so you need to opt-in
- empty_count # find all the available rules by running: `swiftlint rules`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct SDDSTextAreaPreview: PreviewProvider {
static var previews: some View {
let chips = (1...12).map { index in
ChipData(
title: "Label",
title: "ChipTitle",
isEnabled: true,
iconImage: nil,
buttonImage: Image.image("textFieldChipIcon"),
Expand All @@ -21,21 +21,21 @@ struct SDDSTextAreaPreview: PreviewProvider {

return Group {
SDDSTextArea(
value: .constant(.single("hi")),
value: .constant(.single("Value")),
title: "Title",
optionalTitle: "optional",
placeholder: "Placeholder",
caption: "caption",
counter: "counter",
disabled: false,
readOnly: false,
style: .default,
style: .warning,
labelPlacement: .inner,
required: true,
required: false,
requiredPlacement: .left,
dynamicHeight: true,
appearance: .defaultAppearance,
size: SDDSTextAreaSize.large,
size: SDDSTextAreaSize.medium,
chipGroupSize: SDDSTextAreaSize.large.chipGroupSize,
layout: .clear,
iconActionViewProvider: ViewProvider(iconActionView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ extension TextAreaTypography {
public extension ChipAppearance {
static var textArea: ChipAppearance {
ChipAppearance(
size: ZeroChipSize(),
titleColor: .surfaceInverseSolidPrimary.withOpacity(0.96),
titleTypography: ChipTextAreaTypography.text,
imageTintColor: Color.clear.token,
buttonTintColor: Color.clear.token,
titleColor: .textDefaultPrimary,
titleTypography: ChipTextFieldTypography.text,
imageTintColor: .textDefaultPrimary,
buttonTintColor: .textDefaultPrimary,
backgroundColor: .surfaceDefaultTransparentSecondary,
disabledAlpha: 0.5
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -162,65 +166,122 @@ public enum SDDSTextAreaSize: String, TextAreaSizeConfiguration {
}
}

public func indicatorYOffset(labelPlacement: TextAreaLabelPlacement, requiredPlacement: TextAreaRequiredPlacement, layout: TextAreaLayout) -> CGFloat {
switch (self, labelPlacement, requiredPlacement, layout) {
case (.large, .outer, .left, _):
return 7
case (.medium, .outer, .left, _):
return 6
case (.small, .outer, .left, _):
return 5
case (.extraSmall, .outer, .left, _):
return 4
case (.large, .inner, .right, .clear), (.large, .inner, .left, .clear):
return 25
case (.medium, .inner, .right, .clear), (.medium, .inner, .left, .clear):
return 22
case (.small, .inner, .right, .clear), (.small, .inner, .left, .clear):
return 19
case (.extraSmall, .inner, .right, .clear), (.extraSmall, .inner, .left, .clear):
return 12
case (.large, .none, .left, .clear), (.large, .none, .right, .clear):
return 20
case (.medium, .none, .left, .clear), (.medium, .none, .right, .clear):
return 19
case (.small, .none, .left, .clear), (.small, .none, .right, .clear):
return 18
case (.extraSmall, .none, .left, .clear), (.extraSmall, .none, .right, .clear):
return 17
case (.large, .outer, .right, _), (.medium, .outer, .right, _), (.small, .outer, .right, _):
return -2
case (.extraSmall, .outer, .right, _):
return 0
default:
break
}

return 0
}

public func indicatorPadding(labelPlacement: TextAreaLabelPlacement, requiredPlacement: TextAreaRequiredPlacement, layout: TextAreaLayout) -> CGFloat {
switch (self, labelPlacement, requiredPlacement, layout) {
case (.large, .outer, .left, _), (.medium, .outer, .left, _):
return 6
case (.small, .outer, .left, _), (.extraSmall, .outer, .left, _):
return 4
case (.large, .outer, .right, _), (.medium, .outer, .right, .default), (.small, .outer, .right, _), (.extraSmall, .outer, .right, _):
return 4
case (.large, .inner, .left, .clear), (.medium, .inner, .left, .clear):
return 6
case (.small, .inner, .left, .clear), (.extraSmall, .inner, .left, .clear):
return 4
case (.large, .inner, .right, .clear), (.medium, .inner, .right, .clear), (.small, .inner, .right, .clear), (.extraSmall, .inner, .right, .clear):
return 4
case (.large, .none, .right, .clear), (.medium, .none, .right, .clear):
return 6
case (.small, .none, .right, .clear), (.extraSmall, .none, .right, .clear):
return 4
default:
return 6
public func indicatorOffset(labelPlacement: TextAreaLabelPlacement, requiredPlacement: TextAreaRequiredPlacement, layout: TextAreaLayout) -> CGPoint {
switch layout {
case .default:
switch labelPlacement {
case .none:
return .zero
case .inner:
return .zero
case .outer:
switch requiredPlacement {
case .left:
switch self {
case .large:
return CGPoint(x: 6, y: 8)
case .medium:
return CGPoint(x: 6, y: 7)
case .small:
return CGPoint(x: 4, y: 6)
case .extraSmall:
return CGPoint(x: 4, y: 4)
}
case .right:
switch self {
case .large:
return CGPoint(x: 4, y: 4)
case .medium:
return CGPoint(x: 4, y: 4)
case .small:
return CGPoint(x: 4, y: 4)
case .extraSmall:
return CGPoint(x: 4, y: 2)
}
}
}
case .clear:
switch labelPlacement {
case .none:
switch requiredPlacement {
case .left:
switch self {
case .large:
return CGPoint(x: 6, y: 24)
case .medium:
return CGPoint(x: 6, y: 20)
case .small:
return CGPoint(x: 6, y: 17)
case .extraSmall:
return CGPoint(x: 4, y: 13)
}
case .right:
switch self {
case .large:
return CGPoint(x: 4, y: 24)
case .medium:
return CGPoint(x: 4, y: 20)
case .small:
return CGPoint(x: 6, y: 17)
case .extraSmall:
return CGPoint(x: 4, y: 13)
}
}
case .inner:
switch requiredPlacement {
case .left:
switch self {
case .large:
return CGPoint(x: 6, y: 24)
case .medium:
return CGPoint(x: 6, y: 20)
case .small:
return CGPoint(x: 6, y: 17)
case .extraSmall:
return CGPoint(x: 4, y: 13)
}
case .right:
switch self {
case .large:
return CGPoint(x: 4, y: 24)
case .medium:
return CGPoint(x: 4, y: 20)
case .small:
return CGPoint(x: 6, y: 17)
case .extraSmall:
return CGPoint(x: 4, y: 13)
}
}
case .outer:
switch requiredPlacement {
case .left:
switch self {
case .large:
return CGPoint(x: 6, y: 8)
case .medium:
return CGPoint(x: 6, y: 7)
case .small:
return CGPoint(x: 4, y: 6)
case .extraSmall:
return CGPoint(x: 4, y: 4)
}
case .right:
switch self {
case .large:
return CGPoint(x: 4, y: 4)
case .medium:
return CGPoint(x: 4, y: 4)
case .small:
return CGPoint(x: 4, y: 4)
case .extraSmall:
return CGPoint(x: 4, y: 2)
}
}
}
}
}


public func fieldHeight(layout: TextAreaLayout) -> CGFloat {
switch layout {
case .default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ struct SDDSTextFieldPreview: PreviewProvider {
textBefore: "",
textAfter: "",
disabled: false,
readOnly: true,
style: .default,
labelPlacement: .none,
readOnly: false,
style: .warning,
labelPlacement: .inner,
required: false,
requiredPlacement: .right,
appearance: .defaultAppearance,
size: SDDSTextFieldSize.large,
layout: .default,
size: SDDSTextFieldSize.medium,
layout: .clear,
iconViewProvider: ViewProvider(iconView),
iconActionViewProvider: ViewProvider(iconActionView)
)
Expand All @@ -54,8 +54,8 @@ struct SDDSTextFieldPreview: PreviewProvider {
caption: "caption",
disabled: false,
style: .default,
labelPlacement: .outer,
required: false,
labelPlacement: .none,
required: true,
requiredPlacement: .left,
appearance: .defaultAppearance,
size: SDDSTextFieldSize.large,
Expand Down
Loading

0 comments on commit aa2c2cc

Please sign in to comment.