Skip to content

Commit

Permalink
feat(sddsdemo): added text alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
vkaltyrin committed Dec 24, 2024
1 parent e8ba647 commit 6785849
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct SDDSButton: View {
}
.buttonStyle(NoHighlightButtonStyle())
.opacity(contentOpacity)
.background(currentColor(for: appearance.backgroundColor))
.background(currentColor(for: appearance.backgroundColor).opacity(backgroundOpacity))
.cornerRadius(cornerRadius)
.frame(height: appearance.size.height)
.disabled(isDisabled)
Expand Down Expand Up @@ -99,6 +99,7 @@ public struct SDDSButton: View {
}
if !title.isEmpty {
Text(title)
.lineLimit(1)
.typography(titleTypography)
.foregroundColor(currentColor(for: appearance.titleColor))
}
Expand All @@ -110,6 +111,7 @@ public struct SDDSButton: View {
Spacer().frame(width: appearance.size.titleHorizontalGap)
}
Text(subtitle)
.lineLimit(1)
.typography(subtitleTypography)
.foregroundColor(currentColor(for: appearance.subtitleColor))
}
Expand Down Expand Up @@ -198,10 +200,6 @@ private extension SDDSButton {
isDisabled ? Opacity.fourty : 1.0
}

func backgroundColor(for colorScheme: ColorScheme) -> Color {
currentColor(for: appearance.backgroundColor).opacity(backgroundOpacity)
}

var contentOpacity: Double {
if isDisabled {
return appearance.disabledAlpha
Expand Down
21 changes: 21 additions & 0 deletions SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ struct ButtonView: View {
HStack {
Toggle("Icon", isOn: $viewModel.isIconVisible)
}
if viewModel.buttonType == .icon {
HStack {
Toggle("Pilled", isOn: $viewModel.isPilled)
}
}
if viewModel.buttonType != .icon {
HStack {
Text("Icon Alignment")
Spacer()
.frame(maxWidth: .infinity)
Menu {
ForEach(ButtonAlignment.allCases, id: \.self) { alignment in
Button(alignment.rawValue) {
viewModel.alignment = alignment
}
}
} label: {
Text(viewModel.alignment.rawValue)
}
}
}
HStack {
Text("Size")
Spacer()
Expand Down
14 changes: 14 additions & 0 deletions SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class ButtonViewModel: ObservableObject {

// MARK: - Screen properties
@Published var isIconVisible: Bool = false
@Published var isPilled: Bool = false
@Published var alignment: SDDSComponents.ButtonAlignment = .leading
@Published var colorStyle: SDDSServeB2CStyle = .accent

Expand All @@ -48,6 +49,19 @@ final class ButtonViewModel: ObservableObject {
}
.store(in: &cancellables)

$isPilled
.sink { [weak self] value in
guard let self = self else {
return
}
if value {
self.appearance = self.appearance.shapeStyle(.pilled)
} else {
self.appearance = self.appearance.shapeStyle(.default)
}
}
.store(in: &cancellables)

$alignment
.sink { [weak self] value in
guard let self = self, isIconVisible else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ public extension BasicButton {
hoveredColor: .textOnLightPrimaryHover
),
backgroundColor: ButtonColor(
defaultColor: .surfaceOnLightSolidDefault,
highlightedColor: .surfaceOnLightSolidDefaultActive,
hoveredColor: .surfaceOnLightSolidDefaultHover
defaultColor: .surfaceOnDarkSolidDefault,
highlightedColor: .surfaceOnDarkSolidDefaultActive,
hoveredColor: .surfaceOnDarkSolidDefaultHover
),
disabledAlpha: 0.4,
loadingAlpha: 0
Expand Down

0 comments on commit 6785849

Please sign in to comment.