diff --git a/SDDSComponents/SDDSComponents.xcodeproj/project.pbxproj b/SDDSComponents/SDDSComponents.xcodeproj/project.pbxproj index 366d9588..932a32f1 100644 --- a/SDDSComponents/SDDSComponents.xcodeproj/project.pbxproj +++ b/SDDSComponents/SDDSComponents.xcodeproj/project.pbxproj @@ -7,6 +7,16 @@ objects = { /* Begin PBXBuildFile section */ + 6950A1282D1D4C47001695C5 /* SegmentElementAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6950A1272D1D4C28001695C5 /* SegmentElementAppearance.swift */; }; + 6950A12A2D1D4D56001695C5 /* SegmentElementSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6950A1292D1D4D4E001695C5 /* SegmentElementSize.swift */; }; + 69573D682D1D638600359D53 /* AppearanceConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69573D672D1D637D00359D53 /* AppearanceConfiguration.swift */; }; + 69573D6A2D1D756000359D53 /* SegmentElementAppearance+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69573D692D1D754400359D53 /* SegmentElementAppearance+Extensions.swift */; }; + 69573D6C2D1D7C5D00359D53 /* SegmentElementAppearance+Variation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69573D6B2D1D7C4300359D53 /* SegmentElementAppearance+Variation.swift */; }; + 6968433D2D1D934F002F8C7A /* SegmentElement+Exstensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6968433C2D1D9338002F8C7A /* SegmentElement+Exstensions.swift */; }; + 6968433F2D1DC003002F8C7A /* SegmentElementShapeStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6968433E2D1DBFF8002F8C7A /* SegmentElementShapeStyle.swift */; }; + 696843412D1E720B002F8C7A /* SegmentElement+ShapeStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 696843402D1E71FE002F8C7A /* SegmentElement+ShapeStyle.swift */; }; + 6969EADC2D1D5A74008536E5 /* SegmentElementColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6969EADB2D1D5A6C008536E5 /* SegmentElementColor.swift */; }; + 6969EADE2D1D5B8E008536E5 /* SegmentElementAppearanceVariations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6969EADD2D1D5B73008536E5 /* SegmentElementAppearanceVariations.swift */; }; 6987445F2D1C367700559ABA /* SDDSCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6987445D2D1C367700559ABA /* SDDSCounter.swift */; }; 698744602D1C367700559ABA /* CounterAppearance+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6987445A2D1C367700559ABA /* CounterAppearance+Extensions.swift */; }; 698744612D1C367700559ABA /* CounterSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744582D1C367700559ABA /* CounterSize.swift */; }; @@ -153,6 +163,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 6950A1272D1D4C28001695C5 /* SegmentElementAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementAppearance.swift; sourceTree = ""; }; + 6950A1292D1D4D4E001695C5 /* SegmentElementSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementSize.swift; sourceTree = ""; }; + 69573D672D1D637D00359D53 /* AppearanceConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceConfiguration.swift; sourceTree = ""; }; + 69573D692D1D754400359D53 /* SegmentElementAppearance+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElementAppearance+Extensions.swift"; sourceTree = ""; }; + 69573D6B2D1D7C4300359D53 /* SegmentElementAppearance+Variation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElementAppearance+Variation.swift"; sourceTree = ""; }; + 6968433C2D1D9338002F8C7A /* SegmentElement+Exstensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElement+Exstensions.swift"; sourceTree = ""; }; + 6968433E2D1DBFF8002F8C7A /* SegmentElementShapeStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementShapeStyle.swift; sourceTree = ""; }; + 696843402D1E71FE002F8C7A /* SegmentElement+ShapeStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElement+ShapeStyle.swift"; sourceTree = ""; }; + 6969EADB2D1D5A6C008536E5 /* SegmentElementColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementColor.swift; sourceTree = ""; }; + 6969EADD2D1D5B73008536E5 /* SegmentElementAppearanceVariations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementAppearanceVariations.swift; sourceTree = ""; }; 698744562D1C367700559ABA /* CounterAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterAppearance.swift; sourceTree = ""; }; 698744572D1C367700559ABA /* CounterColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterColor.swift; sourceTree = ""; }; 698744582D1C367700559ABA /* CounterSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterSize.swift; sourceTree = ""; }; @@ -338,6 +358,22 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 6950A1262D1D4BE1001695C5 /* SegmentAppearance */ = { + isa = PBXGroup; + children = ( + 696843402D1E71FE002F8C7A /* SegmentElement+ShapeStyle.swift */, + 6968433E2D1DBFF8002F8C7A /* SegmentElementShapeStyle.swift */, + 6968433C2D1D9338002F8C7A /* SegmentElement+Exstensions.swift */, + 69573D6B2D1D7C4300359D53 /* SegmentElementAppearance+Variation.swift */, + 69573D692D1D754400359D53 /* SegmentElementAppearance+Extensions.swift */, + 6969EADD2D1D5B73008536E5 /* SegmentElementAppearanceVariations.swift */, + 6969EADB2D1D5A6C008536E5 /* SegmentElementColor.swift */, + 6950A1292D1D4D4E001695C5 /* SegmentElementSize.swift */, + 6950A1272D1D4C28001695C5 /* SegmentElementAppearance.swift */, + ); + path = SegmentAppearance; + sourceTree = ""; + }; 698744592D1C367700559ABA /* CounterAppearance */ = { isa = PBXGroup; children = ( @@ -370,6 +406,7 @@ 698744662D1C368E00559ABA /* SDDSSegmentElement */ = { isa = PBXGroup; children = ( + 6950A1262D1D4BE1001695C5 /* SegmentAppearance */, 698744652D1C368E00559ABA /* SDDSSegmentElement.swift */, ); path = SDDSSegmentElement; @@ -662,6 +699,7 @@ 818C03AF2C418705002C6D0A /* Components */ = { isa = PBXGroup; children = ( + 69573D672D1D637D00359D53 /* AppearanceConfiguration.swift */, 698744662D1C368E00559ABA /* SDDSSegmentElement */, 6987445E2D1C367700559ABA /* SDDSCounter */, 8102BA282CBE9B3300C589D3 /* SDDSTextArea */, @@ -1194,6 +1232,7 @@ 8102BA322CBE9B3300C589D3 /* TextAreaSizeConfiguration.swift in Sources */, 818C03E62C47BCDC002C6D0A /* SDDSProgressBar.swift in Sources */, 817339DE2D033D860092608A /* ChipAccessibility.swift in Sources */, + 69573D682D1D638600359D53 /* AppearanceConfiguration.swift in Sources */, 817339F12D033EF30092608A /* AvatarImageSource.swift in Sources */, 818C03BF2C43C371002C6D0A /* DebugModifier.swift in Sources */, 817339D72D033C0A0092608A /* ProgressBarAccessibility.swift in Sources */, @@ -1221,12 +1260,15 @@ 814E303A2C99AFBD004601F7 /* BackportAsyncImage.swift in Sources */, 81CF12192C6E686D0074174F /* SDDSRadioboxGroup.swift in Sources */, 814185CA2C34260300D8E524 /* ButtonSize.swift in Sources */, + 69573D6A2D1D756000359D53 /* SegmentElementAppearance+Extensions.swift in Sources */, 817339ED2D033EC90092608A /* AvatarSizeConfiguration.swift in Sources */, 81733A3A2D0733460092608A /* ChipAppearance+Extensions.swift in Sources */, 81F753422CF505DE000156D9 /* IconButton+Extensions.swift in Sources */, 81F752E22CECD40A000156D9 /* BasicButton.swift in Sources */, 814E30412C99B090004601F7 /* Text+FillModifier.swift in Sources */, + 6969EADC2D1D5A74008536E5 /* SegmentElementColor.swift in Sources */, 817339E62D033E650092608A /* RadioboxData.swift in Sources */, + 6968433F2D1DC003002F8C7A /* SegmentElementShapeStyle.swift in Sources */, 816C62A22CB80EC400352891 /* Opacity.swift in Sources */, 814E30382C99AFB0004601F7 /* SDDSAvatarModifiers.swift in Sources */, 81D2B1992C32B3E400CAA7FD /* SDDSButton.swift in Sources */, @@ -1235,7 +1277,9 @@ 81F753262CF467F6000156D9 /* ButtonIconAttributes.swift in Sources */, 817339EB2D033EB90092608A /* AvatarStatus.swift in Sources */, 81F7532C2CF46885000156D9 /* ButtonShapeStyle.swift in Sources */, + 6950A12A2D1D4D56001695C5 /* SegmentElementSize.swift in Sources */, 81A901532CF6EAA800992B04 /* LinkButton.swift in Sources */, + 69573D6C2D1D7C5D00359D53 /* SegmentElementAppearance+Variation.swift in Sources */, 81F7531C2CF46755000156D9 /* ButtonStyle.swift in Sources */, 81F753282CF46831000156D9 /* ButtonColor.swift in Sources */, 811DE1582C5017C3000DD354 /* ProgressBarAppearance.swift in Sources */, @@ -1247,6 +1291,7 @@ 8102BA312CBE9B3300C589D3 /* TextAreaAppearance.swift in Sources */, 8159F7302C5D1CFE00622836 /* FillStyle.swift in Sources */, 81F753242CF467E5000156D9 /* ButtonContentAlignment.swift in Sources */, + 6969EADE2D1D5B8E008536E5 /* SegmentElementAppearanceVariations.swift in Sources */, 816AA9B02C97424000C3347C /* TextFieldSizeConfiguration.swift in Sources */, 818C03CE2C4515ED002C6D0A /* SDDSRadiobox.swift in Sources */, 81998FF92C35503D009074B7 /* View+Modifiers.swift in Sources */, @@ -1260,11 +1305,13 @@ 81685C2B2CFF898D00278446 /* SwitchAppearance+Extensions.swift in Sources */, 818C03B92C43B99B002C6D0A /* ColorToken+Extensions.swift in Sources */, 817339E92D033E8E0092608A /* AvatarAppearance.swift in Sources */, + 6950A1282D1D4C47001695C5 /* SegmentElementAppearance.swift in Sources */, 811DE1712C5783B6000DD354 /* HierarchicalList.swift in Sources */, 818C03D02C451651002C6D0A /* SelectionControlAppearance.swift in Sources */, 814E30362C99AFAB004601F7 /* SDDSAvatar.swift in Sources */, 81F753392CF50015000156D9 /* ButtonAppearance+Variations.swift in Sources */, 816AA9AE2C97421F00C3347C /* TextFieldAppearance.swift in Sources */, + 696843412D1E720B002F8C7A /* SegmentElement+ShapeStyle.swift in Sources */, 8154644B2C96FDE600DAD8EA /* ViewProvider.swift in Sources */, 81F7532A2CF4684F000156D9 /* ButtonAppearance.swift in Sources */, 818C03C52C4512A6002C6D0A /* SelectionControl.swift in Sources */, @@ -1273,6 +1320,7 @@ 81733A2B2D072FB70092608A /* AvatarAppearance+Extensions.swift in Sources */, 811DE15B2C5017FE000DD354 /* SDDSChipGroup.swift in Sources */, 81E9FA8F2C92B13E0041B5FF /* SDDSTextField.swift in Sources */, + 6968433D2D1D934F002F8C7A /* SegmentElement+Exstensions.swift in Sources */, 8102BA3A2CBEAFB800C589D3 /* PlaceholderTextEditor.swift in Sources */, 818C03C72C45140B002C6D0A /* CheckboxAppearance.swift in Sources */, 814E30372C99AFAE004601F7 /* SDDSAvatarData.swift in Sources */, diff --git a/SDDSComponents/Sources/SDDSComponents/Components/AppearanceConfiguration.swift b/SDDSComponents/Sources/SDDSComponents/Components/AppearanceConfiguration.swift new file mode 100644 index 00000000..37937494 --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/AppearanceConfiguration.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol AppearanceConfiguration { + var size: SizeConfiguration { get } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSCounter/SDDSCounter.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSCounter/SDDSCounter.swift index 74940949..9b90a2f8 100644 --- a/SDDSComponents/Sources/SDDSComponents/Components/SDDSCounter/SDDSCounter.swift +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSCounter/SDDSCounter.swift @@ -28,6 +28,7 @@ public struct SDDSCounter: View { counterMinimumSize } } + .padding(appearance.size.paddings) .background(currentColor(for: appearance.backgroundColor)) .cornerRadius(cornerRadius) .frame(maxWidth: dynamicWidth, minHeight: appearance.size.height) @@ -37,7 +38,7 @@ public struct SDDSCounter: View { Text(text) .typography(dataTypography) .foregroundColor(currentColor(for: appearance.dataColor)) - .padding(appearance.size.paddings) +// .padding(appearance.size.paddings) } @ViewBuilder @@ -47,7 +48,7 @@ public struct SDDSCounter: View { Text(text) .typography(dataTypography) .foregroundColor(currentColor(for: appearance.dataColor)) - .padding(appearance.size.paddings) +// .padding(appearance.size.paddings) } } diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SDDSSegmentElement.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SDDSSegmentElement.swift index c74aae37..7f6ccd9d 100644 --- a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SDDSSegmentElement.swift +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SDDSSegmentElement.swift @@ -1,6 +1,26 @@ import Foundation import SwiftUI +public struct SegmentElementSizeToButtonSizeConfigurationMapper: ButtonSizeConfiguration, SegmentElementSizeConfiguration { + public var height: CGFloat + + public var cornerRadius: CGFloat + + public var paddings: EdgeInsets + + public var iconSize: CGSize + + public var spinnerSize: CGSize = .zero + + public var iconHorizontalGap: CGFloat + + public var titleHorizontalGap: CGFloat + + public var debugDescription: String { + "SizeExample" + } +} + public enum SegmentElementContentRight { case icon(Image) case subtitle(String) @@ -17,18 +37,18 @@ public struct SDDSSegmentElement: View { public let title: String public let contentType: SegmentElementContent public let isDisabled: Bool - public let appearance: ButtonAppearance - public let layoutMode: ButtonLayoutMode - public let accessibility: ButtonAccessibility + public let appearance: SegmentElementAppearance + public let content: SegmentElementContentRight = .subtitle("") + // public let layoutMode: ButtonLayoutMode + // public let accessibility: ButtonAccessibility public var action: () -> Void public init( title: String, contentType: SegmentElementContent, isDisabled: Bool = false, - isLoading: Bool = false, - appearance: ButtonAppearance, - layoutMode: ButtonLayoutMode = .wrapContent, + appearance: SegmentElementAppearance, + // layoutMode: ButtonLayoutMode = .wrapContent, accessibility: ButtonAccessibility = ButtonAccessibility(), action: @escaping () -> Void ) { @@ -36,15 +56,41 @@ public struct SDDSSegmentElement: View { self.contentType = contentType self.isDisabled = isDisabled self.appearance = appearance - self.layoutMode = layoutMode - self.accessibility = accessibility + // self.layoutMode = layoutMode + // self.accessibility = accessibility self.action = action } - + + @ViewBuilder public var body: some View { switch contentType { + case .left(let image): + SDDSButton( + title: title, + subtitle: "", + iconAttributes: .init(image: image, alignment: .leading), + isDisabled: isDisabled, + isLoading: false, + spinnerImage: nil, + buttonStyle: .basic, + appearance: ButtonAppearance( + size: size, + titleTypography: appearance.titleTypography, + titleColor: titleColor, + subtitleTypography: appearance.subtitleTypography, + subtitleColor: subtitleColor, + iconColor: iconColor, + backgroundColor: backgroundColor, + disabledAlpha: appearance.disabledAlpha + ), + // layoutMode: layoutMode, + counter: nil, + action: action + ) + case .right(let segmentElementContentRight): + EmptyView() case .none: - SDDSButton( + SDDSButton( title: title, subtitle: "", iconAttributes: nil, @@ -52,73 +98,99 @@ public struct SDDSSegmentElement: View { isLoading: false, spinnerImage: nil, buttonStyle: .basic, - appearance: appearance, - layoutMode: layoutMode, + appearance: ButtonAppearance( + size: size, + titleTypography: appearance.titleTypography, + titleColor: titleColor, + subtitleTypography: appearance.subtitleTypography, + subtitleColor: subtitleColor, + iconColor: iconColor, + backgroundColor: backgroundColor, + disabledAlpha: appearance.disabledAlpha + ), + // layoutMode: layoutMode, counter: nil, action: action ) - case .left(let image): - SDDSButton( + } + } +} + +extension SDDSSegmentElement { + func caseRightView(_ content: SegmentElementContentRight) -> some View { + switch content { + case .icon(let image): + return SDDSButton( title: title, subtitle: "", - iconAttributes: .init(image: image, alignment: .leading), + iconAttributes: .init(image: image, alignment: .trailing), isDisabled: isDisabled, isLoading: false, spinnerImage: nil, buttonStyle: .basic, - appearance: appearance, - layoutMode: layoutMode, + appearance: ButtonAppearance( + size: size, + titleTypography: appearance.titleTypography, + titleColor: titleColor, + subtitleTypography: appearance.subtitleTypography, + subtitleColor: subtitleColor, + iconColor: iconColor, + backgroundColor: backgroundColor, + disabledAlpha: appearance.disabledAlpha + ), + // layoutMode: layoutMode, + accessibility: accessibility, + counter: nil, + action: action + ) + case .counter(let counterData): + return SDDSButton( + title: title, + subtitle: "", + iconAttributes: nil, + isDisabled: isDisabled, + isLoading: false, + spinnerImage: nil, + buttonStyle: .basic, + appearance: ButtonAppearance( + size: size, + titleTypography: appearance.titleTypography, + titleColor: titleColor, + subtitleTypography: appearance.subtitleTypography, + subtitleColor: subtitleColor, + iconColor: iconColor, + backgroundColor: backgroundColor, + disabledAlpha: appearance.disabledAlpha + ), + // layoutMode: layoutMode, + accessibility: accessibility, + counter: ViewProvider(counterData), + action: action + ) + case .subtitle(let subtitle): + return SDDSButton( + title: title, + subtitle: subtitle, + iconAttributes: nil, + isDisabled: isDisabled, + isLoading: false, + spinnerImage: nil, + buttonStyle: .basic, + appearance: ButtonAppearance( + size: size, + titleTypography: appearance.titleTypography, + titleColor: titleColor, + subtitleTypography: appearance.subtitleTypography, + subtitleColor: subtitleColor, + iconColor: iconColor, + backgroundColor: backgroundColor, + disabledAlpha: appearance.disabledAlpha + ), + // layoutMode: layoutMode, + accessibility: accessibility, counter: nil, action: action ) - case .right(let contentRight): - switch contentRight { - case .icon(let image): - SDDSButton( - title: title, - subtitle: "", - iconAttributes: .init(image: image, alignment: .trailing), - isDisabled: isDisabled, - isLoading: false, - spinnerImage: nil, - buttonStyle: .basic, - appearance: appearance, - layoutMode: layoutMode, - accessibility: accessibility, - counter: nil, - action: action - ) - case .counter(let counterData): - SDDSButton( - title: title, - subtitle: "", - iconAttributes: nil, - isDisabled: isDisabled, - isLoading: false, - spinnerImage: nil, - buttonStyle: .basic, - appearance: appearance, - layoutMode: layoutMode, - accessibility: accessibility, - counter: ViewProvider(counterData), - action: action - ) - case .subtitle(let subtitle): - SDDSButton( - title: title, - subtitle: subtitle, - iconAttributes: nil, - isDisabled: isDisabled, - isLoading: false, - spinnerImage: nil, - buttonStyle: .basic, - appearance: appearance, - layoutMode: layoutMode, - accessibility: accessibility, - counter: nil, - action: action - ) - } } } } diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElement+Exstensions.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElement+Exstensions.swift new file mode 100644 index 00000000..c4576816 --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElement+Exstensions.swift @@ -0,0 +1,42 @@ +import Foundation + +extension SDDSSegmentElement { + var size: ButtonSizeConfiguration { + SegmentElementSizeToButtonSizeConfigurationMapper( + height: appearance.size.height, + cornerRadius: appearance.size.cornerRadius, + paddings: appearance.size.paddings, + iconSize: appearance.size.iconSize, + iconHorizontalGap: appearance.size.iconHorizontalGap, + titleHorizontalGap: appearance.size.titleHorizontalGap) + as ButtonSizeConfiguration + } + var titleColor: ButtonColor { + return ButtonColor( + defaultColor: appearance.titleColor.defaultColor, + highlightedColor: appearance.titleColor.highlightedColor, + hoveredColor: appearance.titleColor.hoveredColor + ) + } + var subtitleColor: ButtonColor { + return ButtonColor( + defaultColor: appearance.subtitleColor.defaultColor, + highlightedColor: appearance.subtitleColor.highlightedColor, + hoveredColor: appearance.subtitleColor.hoveredColor + ) + } + var iconColor: ButtonColor { + return ButtonColor( + defaultColor: appearance.iconColor.defaultColor, + highlightedColor: appearance.iconColor.highlightedColor, + hoveredColor: appearance.iconColor.hoveredColor + ) + } + var backgroundColor: ButtonColor { + return ButtonColor( + defaultColor: appearance.backgroundColor.defaultColor, + highlightedColor: appearance.backgroundColor.highlightedColor, + hoveredColor: appearance.backgroundColor.hoveredColor + ) + } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElement+ShapeStyle.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElement+ShapeStyle.swift new file mode 100644 index 00000000..fb669c05 --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElement+ShapeStyle.swift @@ -0,0 +1,18 @@ +import Foundation +import SDDSComponents + +public extension SegmentElementAppearanceVariation { + var pilled: Self { + .init( + appearance: appearance.shapeStyle(.pilled) + ) + } +} + +public extension SDDSSegmentElement { + static var pilled: SegmentElementAppearanceVariation { + .init( + appearance: SegmentElementAppearance().shapeStyle(.pilled) + ) + } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance+Extensions.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance+Extensions.swift new file mode 100644 index 00000000..5fe905da --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance+Extensions.swift @@ -0,0 +1,143 @@ +import Foundation + +public extension SegmentElementAppearance { + func size(_ size: SegmentElementSizeConfiguration) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func shapeStyle(_ shapeStyle: SegmentElementShapeStyle) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func titleTypography(_ titleTypography: TypographyConfiguration) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func titleColor(_ titleColor: SegmentElementColor) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func subtitleTypography(_ subtitleTypography: TypographyConfiguration) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func subtitleColor(_ subtitleColor: SegmentElementColor) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func iconColor(_ iconColor: SegmentElementColor) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func backgroundColor(_ backgroundColor: SegmentElementColor) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } + + func disabledAlpha(_ disabledAlpha: CGFloat) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: disabledAlpha + ) + } + + func loadingAlpha(_ loadingAlpha: CGFloat) -> SegmentElementAppearance { + return SegmentElementAppearance( + size: self.size, + shapeStyle: self.shapeStyle, + titleTypography: self.titleTypography, + titleColor: self.titleColor, + subtitleTypography: self.subtitleTypography, + subtitleColor: self.subtitleColor, + iconColor: self.iconColor, + backgroundColor: self.backgroundColor, + disabledAlpha: self.disabledAlpha + ) + } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance+Variation.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance+Variation.swift new file mode 100644 index 00000000..a66bea9a --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance+Variation.swift @@ -0,0 +1,19 @@ +import Foundation + +public extension SegmentElementAppearance { + func applyColorVariation(variation: SegmentElementAppearance) -> SegmentElementAppearance { + SegmentElementAppearance( + size: size, +// shapeStyle: shapeStyle, + titleTypography: titleTypography, + titleColor: variation.titleColor, + subtitleTypography: subtitleTypography, + subtitleColor: variation.subtitleColor, + iconColor: variation.iconColor, + backgroundColor: variation.backgroundColor, + disabledAlpha: variation.disabledAlpha + ) + } +} + + diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance.swift new file mode 100644 index 00000000..34e749e5 --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearance.swift @@ -0,0 +1,44 @@ +import Foundation +@_exported import SDDSThemeCore + +public struct SegmentElementAppearance { + public let size: SegmentElementSizeConfiguration + + public let shapeStyle: SegmentElementShapeStyle + + public let titleTypography: TypographyConfiguration + + public let titleColor: SegmentElementColor + + public let subtitleTypography: TypographyConfiguration + + public let subtitleColor: SegmentElementColor + + public let iconColor: SegmentElementColor + + public let backgroundColor: SegmentElementColor + + public let disabledAlpha: CGFloat + + public init( + size: SegmentElementSizeConfiguration = DefaultSegmentElementSize(), + shapeStyle: SegmentElementShapeStyle = .pilled, + titleTypography: TypographyConfiguration = .default, + titleColor: SegmentElementColor = SegmentElementColor(), + subtitleTypography: TypographyConfiguration = .default, + subtitleColor: SegmentElementColor = SegmentElementColor(), + iconColor: SegmentElementColor = SegmentElementColor(), + backgroundColor: SegmentElementColor = SegmentElementColor(), + disabledAlpha: CGFloat = 0 + ) { + self.size = size + self.shapeStyle = shapeStyle + self.titleTypography = titleTypography + self.titleColor = titleColor + self.subtitleTypography = subtitleTypography + self.subtitleColor = subtitleColor + self.iconColor = iconColor + self.backgroundColor = backgroundColor + self.disabledAlpha = disabledAlpha + } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearanceVariations.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearanceVariations.swift new file mode 100644 index 00000000..2e19889e --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementAppearanceVariations.swift @@ -0,0 +1,19 @@ +import Foundation + +public struct SegmentElementAppearanceVariation: Hashable { + public let name: String + public let appearance: SegmentElementAppearance + + public init(name: String = "", appearance: SegmentElementAppearance = SegmentElementAppearance()) { + self.name = name + self.appearance = appearance + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(name) + } + + public static func == (lhs: SegmentElementAppearanceVariation, rhs: SegmentElementAppearanceVariation) -> Bool { + return lhs.name == rhs.name + } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementColor.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementColor.swift new file mode 100644 index 00000000..a116258d --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementColor.swift @@ -0,0 +1,25 @@ +import Foundation +@_exported import SDDSThemeCore + +public struct SegmentElementColor { + /** + Цвет для стандартного состояния кнопки. + */ + public let defaultColor: ColorToken + + /** + Цвет для состояния, когда кнопка нажата. + */ + public let highlightedColor: ColorToken + + /** + Цвет для состояния, когда кнопка находится под курсором. + */ + public let hoveredColor: ColorToken + + public init(defaultColor: ColorToken = .clearColor, highlightedColor: ColorToken = .clearColor, hoveredColor: ColorToken = .clearColor) { + self.defaultColor = defaultColor + self.highlightedColor = highlightedColor + self.hoveredColor = hoveredColor + } +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementShapeStyle.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementShapeStyle.swift new file mode 100644 index 00000000..00911e96 --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementShapeStyle.swift @@ -0,0 +1,5 @@ +import Foundation + +public enum SegmentElementShapeStyle { + case pilled +} diff --git a/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementSize.swift b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementSize.swift new file mode 100644 index 00000000..342c2ff1 --- /dev/null +++ b/SDDSComponents/Sources/SDDSComponents/Components/SDDSSegmentElement/SegmentAppearance/SegmentElementSize.swift @@ -0,0 +1,31 @@ +import Foundation +import SwiftUI + +public protocol SegmentElementSizeConfiguration: SizeConfiguration, CustomDebugStringConvertible { + var height: CGFloat { get } + + var cornerRadius: CGFloat { get } + + var paddings: EdgeInsets { get } + + var iconSize: CGSize { get } + + var iconHorizontalGap: CGFloat { get } + + var titleHorizontalGap: CGFloat { get } +} + +public struct DefaultSegmentElementSize: SegmentElementSizeConfiguration { + public var height: CGFloat = 0 + public var cornerRadius: CGFloat = 0 + public var paddings: EdgeInsets = .init() + public var iconSize: CGSize = .zero + public var iconHorizontalGap: CGFloat = 0 + public var titleHorizontalGap: CGFloat = 0 + + public var debugDescription: String { + return "Default SegmentElement Size" + } + + public init() {} +} diff --git a/SDDSDemoApp/SDDSDemoApp.xcodeproj/project.pbxproj b/SDDSDemoApp/SDDSDemoApp.xcodeproj/project.pbxproj index 6a65e128..dcc87f8d 100644 --- a/SDDSDemoApp/SDDSDemoApp.xcodeproj/project.pbxproj +++ b/SDDSDemoApp/SDDSDemoApp.xcodeproj/project.pbxproj @@ -15,6 +15,8 @@ 24C154232BB3020B00963FAA /* PlasmaDemoAppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C154222BB3020B00963FAA /* PlasmaDemoAppUITestsLaunchTests.swift */; }; 6987446B2D1C3B6400559ABA /* CounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744692D1C3B6400559ABA /* CounterView.swift */; }; 6987446C2D1C3B6400559ABA /* CounterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6987446A2D1C3B6400559ABA /* CounterViewModel.swift */; }; + 698744742D1C6EC300559ABA /* SegmentElementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744732D1C6EB800559ABA /* SegmentElementView.swift */; }; + 698744762D1C6F0100559ABA /* SegmentElementViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744752D1C6EC600559ABA /* SegmentElementViewModel.swift */; }; 8104243D2CFDB83F0009B6E9 /* SDDSServTheme in Frameworks */ = {isa = PBXBuildFile; productRef = 8104243C2CFDB83F0009B6E9 /* SDDSServTheme */; }; 810424402CFDB8E10009B6E9 /* SDDSComponents in Frameworks */ = {isa = PBXBuildFile; productRef = 8104243F2CFDB8E10009B6E9 /* SDDSComponents */; }; 810424422CFDB8FD0009B6E9 /* SDDSComponentsPreview in Frameworks */ = {isa = PBXBuildFile; productRef = 810424412CFDB8FD0009B6E9 /* SDDSComponentsPreview */; }; @@ -91,6 +93,8 @@ 24C154222BB3020B00963FAA /* PlasmaDemoAppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlasmaDemoAppUITestsLaunchTests.swift; sourceTree = ""; }; 698744692D1C3B6400559ABA /* CounterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterView.swift; sourceTree = ""; }; 6987446A2D1C3B6400559ABA /* CounterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterViewModel.swift; sourceTree = ""; }; + 698744732D1C6EB800559ABA /* SegmentElementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementView.swift; sourceTree = ""; }; + 698744752D1C6EC600559ABA /* SegmentElementViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementViewModel.swift; sourceTree = ""; }; 811C684C2CC8024A00480F89 /* TextAreaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextAreaView.swift; sourceTree = ""; }; 811C684E2CC8027600480F89 /* TextAreaViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextAreaViewModel.swift; sourceTree = ""; }; 811C68502CC8059800480F89 /* ChipGroupViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipGroupViewModel.swift; sourceTree = ""; }; @@ -247,6 +251,15 @@ path = CounterView; sourceTree = ""; }; + 698744722D1C6E9C00559ABA /* SegmentElementView */ = { + isa = PBXGroup; + children = ( + 698744752D1C6EC600559ABA /* SegmentElementViewModel.swift */, + 698744732D1C6EB800559ABA /* SegmentElementView.swift */, + ); + path = SegmentElementView; + sourceTree = ""; + }; 811C684B2CC8023600480F89 /* TextAreaView */ = { isa = PBXGroup; children = ( @@ -267,6 +280,7 @@ 811DE1362C4D0EB2000DD354 /* Views */ = { isa = PBXGroup; children = ( + 698744722D1C6E9C00559ABA /* SegmentElementView */, 698744682D1C38A200559ABA /* CounterView */, 811C684B2CC8023600480F89 /* TextAreaView */, 819A382D2CC6927700A1377F /* ChipGroupView */, @@ -605,6 +619,7 @@ 817580EC2C383BA500E45207 /* ButtonViewModel.swift in Sources */, 811DE1422C4D15FA000DD354 /* RadioboxView.swift in Sources */, 811C68512CC8059800480F89 /* ChipGroupViewModel.swift in Sources */, + 698744762D1C6F0100559ABA /* SegmentElementViewModel.swift in Sources */, 811DE1472C4D19D3000DD354 /* ProgressBarView.swift in Sources */, 8162435B2CB9418B00506E1C /* RadioboxGroupView.swift in Sources */, 816243512CB93EC800506E1C /* AvatarGroupViewModel.swift in Sources */, @@ -628,6 +643,7 @@ 811DE14E2C4D1DAD000DD354 /* SwitchViewModel.swift in Sources */, 8199A1722C3BF94E00AD650A /* Spacing.swift in Sources */, 816243492CB90FA800506E1C /* GradientPickerView.swift in Sources */, + 698744742D1C6EC300559ABA /* SegmentElementView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/SDDSDemoApp/SDDSDemoApp/Views/Components/ComponentsView.swift b/SDDSDemoApp/SDDSDemoApp/Views/Components/ComponentsView.swift index 203b9c26..a930cc26 100644 --- a/SDDSDemoApp/SDDSDemoApp/Views/Components/ComponentsView.swift +++ b/SDDSDemoApp/SDDSDemoApp/Views/Components/ComponentsView.swift @@ -15,7 +15,8 @@ struct ComponentsView: View { ("SDDSSwitch", AnyView(SwitchView())), ("SDDSTextArea", AnyView(TextAreaView())), ("SDDSTextField", AnyView(TextFieldView())), - ("SDDSCounter", AnyView(CounterView())) + ("SDDSCounter", AnyView(CounterView())), + ("SDDSSegmentElement", AnyView(SegmentElementView())) ] var body: some View { diff --git a/SDDSDemoApp/SDDSDemoApp/Views/SegmentElementView/SegmentElementView.swift b/SDDSDemoApp/SDDSDemoApp/Views/SegmentElementView/SegmentElementView.swift new file mode 100644 index 00000000..9423a159 --- /dev/null +++ b/SDDSDemoApp/SDDSDemoApp/Views/SegmentElementView/SegmentElementView.swift @@ -0,0 +1,125 @@ +import Foundation +import SwiftUI +import Combine +import SDDSComponents +import SDDSComponentsPreview +import SDDSServTheme + +final class SegmentElementViewModel: ObservableObject { + @Published var title: String = "" + @Published var size: SegmentElementSizeConfiguration = SegmentElementSize.medium + @Published var contentType: SegmentElementContent = .none + @Published var iconAttributes: ButtonIconAttributes? = nil + @Published var isDisabled: Bool = false + @Published var appearance: SegmentElementAppearance = SDDSSegmentElement.default.appearance +// @Published var layoutMode: ButtonLayoutMode = .wrapContent + @Published var variationName: String = SDDSSegmentElement.clear.name + + var cancellables: Set = [] + + init() { + observeSizeChange() + } + + private func observeSizeChange() { + $size + .sink { [weak self] value in + guard let self = self else { + return + } + self.appearance = self.appearance.size(value) + } + .store(in: &cancellables) + } +} + +public struct SegmentElementView: View { + @ObservedObject private var viewModel: SegmentElementViewModel + + init(viewModel: SegmentElementViewModel = SegmentElementViewModel()) { + self.viewModel = viewModel + } + + public var body: some View { + List { + segmentView + Section { + title + size + appearance + } + } + } + + public var segmentView: some View { + HStack { + Spacer() + SDDSSegmentElement(title: viewModel.title, + contentType: .none, + appearance: viewModel.appearance, + action: {} + ) + Spacer() + } + } + + public var title: some View { + HStack { + Text("Title") + TextField("Title", text: $viewModel.title) + .multilineTextAlignment(.trailing) + } + } + +// public var subtitle: some View { +// HStack { +// Text("Value") +// TextField("Subtitle", text: $viewModel) +// .multilineTextAlignment(.trailing) +// } +// } + + public var size: some View { + HStack { + Text("Size") + Spacer() + Menu { + ForEach(SegmentElementSize.allCases, id: \.self) { size in + Button(size.rawValue) { + viewModel.size = size + } + } + } label: { + if let size = viewModel.size as? SegmentElementSize { + Text(size.rawValue) + } + } + } + } + + public var appearance: some View { + HStack { + Text("Appearance") + Spacer() + Menu { + ForEach(SDDSSegmentElement.all, id: \.self) { variation in + Button(variation.name) { + viewModel.appearance = variation.appearance.size(viewModel.size) + viewModel.variationName = variation.name + } + } + } label: { + Text(viewModel.variationName) + } + } + } + +// public var contentType: some View { +// +// } + +} + +#Preview { + SegmentElementView(viewModel: SegmentElementViewModel()) +} diff --git a/SDDSDemoApp/SDDSDemoApp/Views/SegmentElementView/SegmentElementViewModel.swift b/SDDSDemoApp/SDDSDemoApp/Views/SegmentElementView/SegmentElementViewModel.swift new file mode 100644 index 00000000..d2770241 --- /dev/null +++ b/SDDSDemoApp/SDDSDemoApp/Views/SegmentElementView/SegmentElementViewModel.swift @@ -0,0 +1,8 @@ +import Foundation +import SwiftUI +import Combine +import SDDSComponents +import SDDSComponentsPreview +import SDDSServTheme + + diff --git a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ButtonSizeConfiguration.swift b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ButtonSizeConfiguration.swift index 1e967f18..bf26b1ab 100644 --- a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ButtonSizeConfiguration.swift +++ b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ButtonSizeConfiguration.swift @@ -9,7 +9,7 @@ public enum SegmentElementSize: String, CaseIterable { case extraSmall } -extension SegmentElementSize: ButtonSizeConfiguration { +extension SegmentElementSize: SegmentElementSizeConfiguration { public var height: CGFloat { switch self { @@ -21,12 +21,7 @@ extension SegmentElementSize: ButtonSizeConfiguration { } public var cornerRadius: CGFloat { - switch self { - case .large: return ShapeToken.roundL.cornerRadius - 2.0 - case .medium: return ShapeToken.roundM.cornerRadius - case .small: return ShapeToken.roundM.cornerRadius - 2.0 - case .extraSmall: return ShapeToken.roundS.cornerRadius - } + 0 } public var paddings: EdgeInsets { diff --git a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ColorVariations.swift b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ColorVariations.swift index 17875aa9..fe9fa84f 100644 --- a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ColorVariations.swift +++ b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+ColorVariations.swift @@ -2,433 +2,86 @@ import Foundation import SDDSComponents import SDDSThemeCore -public extension ButtonAppearanceVariation { - var accent: Self { - .init( - appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.accent.appearance) - ) - } - var black: Self { - .init( - appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.black.appearance) - ) - } +public extension SegmentElementAppearanceVariation { var clear: Self { .init( appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.clear.appearance) ) } - var dark: Self { - .init( - appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.dark.appearance) - ) - } var `default`: Self { .init( appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.default.appearance) ) } - var negative: Self { - .init( - appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.negative.appearance) - ) - } - var positive: Self { - .init( - appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.positive.appearance) - ) - } - var white: Self { - .init( - appearance: appearance.applyColorVariation(variation: SDDSSegmentElement.white.appearance) - ) - } } public extension SDDSSegmentElement { - static var accent: ButtonAppearanceVariation { - .init( - name: "accent", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnDarkSecondary, - highlightedColor: .textOnDarkSecondaryActive, - hoveredColor: .textOnDarkSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceDefaultAccent, - highlightedColor: .surfaceDefaultAccentActive, - hoveredColor: .surfaceDefaultAccentHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - static var black: ButtonAppearanceVariation { - .init( - name: "black", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnDarkSecondary, - highlightedColor: .textOnDarkSecondaryActive, - hoveredColor: .textOnDarkSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceOnLightSolidDefault, - highlightedColor: .surfaceOnLightSolidDefaultActive, - hoveredColor: .surfaceOnLightSolidDefaultHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - static var clear: ButtonAppearanceVariation { + static var clear: SegmentElementAppearanceVariation { .init( name: "clear", - appearance: ButtonAppearance( + appearance: SegmentElementAppearance( titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( + titleColor: SegmentElementColor( defaultColor: .textDefaultPrimary, highlightedColor: .textDefaultPrimaryActive, hoveredColor: .textDefaultPrimaryHover ), subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( + subtitleColor: SegmentElementColor( defaultColor: .textDefaultSecondary, highlightedColor: .textDefaultSecondaryActive, hoveredColor: .textDefaultSecondaryHover ), - iconColor: ButtonColor( - defaultColor: .textDefaultPrimary, - highlightedColor: .textDefaultPrimaryActive, - hoveredColor: .textDefaultPrimaryHover - ), - spinnerColor: ButtonColor( + iconColor: SegmentElementColor( defaultColor: .textDefaultPrimary, highlightedColor: .textDefaultPrimaryActive, hoveredColor: .textDefaultPrimaryHover ), - backgroundColor: ButtonColor( + backgroundColor: SegmentElementColor( defaultColor: .surfaceDefaultClear, highlightedColor: .surfaceDefaultClearActive, hoveredColor: .surfaceDefaultClearHover ), - disabledAlpha: 0.4, - loadingAlpha: 0.06 - ) - ) - } - static var dark: ButtonAppearanceVariation { - .init( - name: "dark", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnDarkSecondary, - highlightedColor: .textOnDarkSecondaryActive, - hoveredColor: .textOnDarkSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceOnLightTransparentDeep, - highlightedColor: .surfaceOnLightTransparentDeepActive, - hoveredColor: .surfaceOnLightTransparentDeepHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 + disabledAlpha: 0.4 ) ) } - static var `default`: ButtonAppearanceVariation { + static var `default`: SegmentElementAppearanceVariation { .init( name: "default", - appearance: ButtonAppearance( + appearance: SegmentElementAppearance( titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( + titleColor: SegmentElementColor( defaultColor: .textInversePrimary, highlightedColor: .textInversePrimaryActive, hoveredColor: .textInversePrimaryHover ), subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textInverseSecondary, - highlightedColor: .textInverseSecondaryActive, - hoveredColor: .textInverseSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textInversePrimary, - highlightedColor: .textInversePrimaryActive, - hoveredColor: .textInversePrimaryHover + subtitleColor: SegmentElementColor( + defaultColor: .textDefaultSecondary, + highlightedColor: .textDefaultSecondaryActive, + hoveredColor: .textDefaultSecondaryHover ), - spinnerColor: ButtonColor( + iconColor: SegmentElementColor( defaultColor: .textInversePrimary, highlightedColor: .textInversePrimaryActive, hoveredColor: .textInversePrimaryHover ), - backgroundColor: ButtonColor( + backgroundColor: SegmentElementColor( defaultColor: .surfaceDefaultSolidDefault, highlightedColor: .surfaceDefaultSolidDefaultActive, hoveredColor: .surfaceDefaultSolidDefaultHover ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - static var negative: ButtonAppearanceVariation { - .init( - name: "negative", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnDarkSecondary, - highlightedColor: .textOnDarkSecondaryActive, - hoveredColor: .textOnDarkSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceDefaultNegative, - highlightedColor: .surfaceDefaultNegativeActive, - hoveredColor: .surfaceDefaultNegativeHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - static var positive: ButtonAppearanceVariation { - .init( - name: "positive", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnDarkSecondary, - highlightedColor: .textOnDarkSecondaryActive, - hoveredColor: .textOnDarkSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceDefaultPositive, - highlightedColor: .surfaceDefaultPositiveActive, - hoveredColor: .surfaceDefaultPositiveHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 + disabledAlpha: 0.4 ) ) } - static var secondary: ButtonAppearanceVariation { - .init( - name: "secondary", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textDefaultPrimary, - highlightedColor: .textDefaultPrimaryActive, - hoveredColor: .textDefaultPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textDefaultSecondary, - highlightedColor: .textDefaultSecondaryActive, - hoveredColor: .textDefaultSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textDefaultPrimary, - highlightedColor: .textDefaultPrimaryActive, - hoveredColor: .textDefaultPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textDefaultPrimary, - highlightedColor: .textDefaultPrimaryActive, - hoveredColor: .textDefaultPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceDefaultTransparentSecondary, - highlightedColor: .surfaceDefaultTransparentSecondaryActive, - hoveredColor: .surfaceDefaultTransparentSecondaryHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - static var warning: ButtonAppearanceVariation { - .init( - name: "warning", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnDarkSecondary, - highlightedColor: .textOnDarkSecondaryActive, - hoveredColor: .textOnDarkSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnDarkPrimary, - highlightedColor: .textOnDarkPrimaryActive, - hoveredColor: .textOnDarkPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceDefaultWarning, - highlightedColor: .surfaceDefaultWarningActive, - hoveredColor: .surfaceDefaultWarningHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - static var white: ButtonAppearanceVariation { - .init( - name: "white", - appearance: ButtonAppearance( - titleTypography: SDDSSegmentElement.titleTypography, - titleColor: ButtonColor( - defaultColor: .textOnLightPrimary, - highlightedColor: .textOnLightPrimaryActive, - hoveredColor: .textOnLightPrimaryHover - ), - subtitleTypography: SDDSSegmentElement.subtitleTypography, - subtitleColor: ButtonColor( - defaultColor: .textOnLightSecondary, - highlightedColor: .textOnLightSecondaryActive, - hoveredColor: .textOnLightSecondaryHover - ), - iconColor: ButtonColor( - defaultColor: .textOnLightPrimary, - highlightedColor: .textOnLightPrimaryActive, - hoveredColor: .textOnLightPrimaryHover - ), - spinnerColor: ButtonColor( - defaultColor: .textOnLightPrimary, - highlightedColor: .textOnLightPrimaryActive, - hoveredColor: .textOnLightPrimaryHover - ), - backgroundColor: ButtonColor( - defaultColor: .surfaceOnLightSolidDefault, - highlightedColor: .surfaceOnLightSolidDefaultActive, - hoveredColor: .surfaceOnLightSolidDefaultHover - ), - disabledAlpha: 0.4, - loadingAlpha: 0 - ) - ) - } - - static var all: [ButtonAppearanceVariation] { + static var all: [SegmentElementAppearanceVariation] { [ - SDDSSegmentElement.accent, - - SDDSSegmentElement.black, - SDDSSegmentElement.clear, - SDDSSegmentElement.dark, - - SDDSSegmentElement.`default`, - - SDDSSegmentElement.negative, - - SDDSSegmentElement.positive, - - SDDSSegmentElement.secondary, - - SDDSSegmentElement.warning, - - SDDSSegmentElement.white + SDDSSegmentElement.default ] } diff --git a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+SizeVariations.swift b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+SizeVariations.swift index b2c7975d..2c27a5b6 100644 --- a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+SizeVariations.swift +++ b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElement+SizeVariations.swift @@ -2,7 +2,7 @@ import Foundation import SDDSComponents import SDDSThemeCore -public extension ButtonAppearanceVariation { +public extension SegmentElementAppearanceVariation { var large: Self { .init( appearance: appearance @@ -38,16 +38,16 @@ public extension ButtonAppearanceVariation { } public extension SDDSSegmentElement { - static var large: ButtonAppearanceVariation { - return ButtonAppearanceVariation().large + static var large: SegmentElementAppearanceVariation { + return SegmentElementAppearanceVariation().large } - static var medium: ButtonAppearanceVariation { - return ButtonAppearanceVariation().medium + static var medium: SegmentElementAppearanceVariation { + return SegmentElementAppearanceVariation().medium } - static var small: ButtonAppearanceVariation { - return ButtonAppearanceVariation().small + static var small: SegmentElementAppearanceVariation { + return SegmentElementAppearanceVariation().small } - static var extraSmall: ButtonAppearanceVariation { - return ButtonAppearanceVariation().extraSmall + static var extraSmall: SegmentElementAppearanceVariation { + return SegmentElementAppearanceVariation().extraSmall } } diff --git a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElementTypography.swift b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElementTypography.swift index 1f65e300..22dbff9c 100644 --- a/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElementTypography.swift +++ b/Themes/SDDSservTheme/SDDSSegmentElement/SegmentElementTypography.swift @@ -2,7 +2,7 @@ import Foundation import SDDSComponents public struct SegmentElementTypography: GeneralTypographyConfiguration { - typealias S = ButtonSizeConfiguration + typealias S = SegmentElementSizeConfiguration let large: TypographyToken? let medium: TypographyToken? @@ -22,7 +22,7 @@ public struct SegmentElementTypography: GeneralTypographyConfiguration { - Parameter size: Размер кнопки. - Returns: Типографика для заданного размера кнопки или nil, если не задана. */ - public func typography(with size: ButtonSizeConfiguration) -> TypographyToken? { + public func typography(with size: SegmentElementSizeConfiguration) -> TypographyToken? { switch size as? SegmentElementSize { case .large: return large