From f68e8e6260569c447867ed6b716e00d714b1b183 Mon Sep 17 00:00:00 2001 From: Vladimir Kaltyrin Date: Fri, 20 Dec 2024 09:13:22 +0300 Subject: [PATCH] feat(sddsdemo): added text alignment --- .../Components/SDDSButton/SDDSButton.swift | 8 +++---- .../Views/ButtonView/ButtonView.swift | 21 +++++++++++++++++++ .../Views/ButtonView/ButtonViewModel.swift | 14 +++++++++++++ .../BasicButton+ColorVariations.swift | 6 +++--- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSButton/SDDSButton.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSButton/SDDSButton.swift index 66d53076..611b74ed 100644 --- a/SDDSComponents/Sources/SDDSComponents/Components/SDDSButton/SDDSButton.swift +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSButton/SDDSButton.swift @@ -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) @@ -99,6 +99,7 @@ public struct SDDSButton: View { } if !title.isEmpty { Text(title) + .lineLimit(1) .typography(titleTypography) .foregroundColor(currentColor(for: appearance.titleColor)) } @@ -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)) } @@ -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 diff --git a/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonView.swift b/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonView.swift index cef15945..7bc50e4e 100644 --- a/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonView.swift +++ b/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonView.swift @@ -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() diff --git a/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonViewModel.swift b/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonViewModel.swift index ad9a88c2..b1ab857d 100644 --- a/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonViewModel.swift +++ b/SDDSDemoApp/SDDSDemoApp/Views/ButtonView/ButtonViewModel.swift @@ -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 @@ -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 { diff --git a/Themes/SDDSservTheme/SDDSButton/BasicButton+ColorVariations.swift b/Themes/SDDSservTheme/SDDSButton/BasicButton+ColorVariations.swift index 05fe99fc..435a381a 100644 --- a/Themes/SDDSservTheme/SDDSButton/BasicButton+ColorVariations.swift +++ b/Themes/SDDSservTheme/SDDSButton/BasicButton+ColorVariations.swift @@ -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