Skip to content

Commit

Permalink
feat: added segment-element include counter
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirDimitraki committed Jan 13, 2025
1 parent f6280a1 commit 85c6e7c
Show file tree
Hide file tree
Showing 46 changed files with 2,174 additions and 54 deletions.
104 changes: 104 additions & 0 deletions SDDSComponents/SDDSComponents.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
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 */; };
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 */; };
696843432D1EA12E002F8C7A /* SegmentElementAppearance+ButtonAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 696843422D1EA11A002F8C7A /* SegmentElementAppearance+ButtonAppearance.swift */; };
696843452D1EA35B002F8C7A /* SegmentElementAccessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 696843442D1EA348002F8C7A /* SegmentElementAccessibility.swift */; };
6969EADE2D1D5B8E008536E5 /* SegmentElementAppearanceVariations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6969EADD2D1D5B73008536E5 /* SegmentElementAppearanceVariations.swift */; };
697736FF2D26C23F0077D1A4 /* CounterAppearance+Variation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 697736FE2D26C2310077D1A4 /* CounterAppearance+Variation.swift */; };
697737852D2EB8030077D1A4 /* View+ErrorString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 697737842D2EB7F80077D1A4 /* View+ErrorString.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 */; };
698744622D1C367700559ABA /* CounterColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744572D1C367700559ABA /* CounterColor.swift */; };
698744632D1C367700559ABA /* CounterData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6987445C2D1C367700559ABA /* CounterData.swift */; };
698744642D1C367700559ABA /* CounterAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744562D1C367700559ABA /* CounterAppearance.swift */; };
698744672D1C368E00559ABA /* SDDSSegmentElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 698744652D1C368E00559ABA /* SDDSSegmentElement.swift */; };
8102BA2F2CBE9B3300C589D3 /* SDDSTextArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8102BA2A2CBE9B3300C589D3 /* SDDSTextArea.swift */; };
8102BA302CBE9B3300C589D3 /* TextAreaAccessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8102BA2B2CBE9B3300C589D3 /* TextAreaAccessibility.swift */; };
8102BA312CBE9B3300C589D3 /* TextAreaAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8102BA2C2CBE9B3300C589D3 /* TextAreaAppearance.swift */; };
Expand Down Expand Up @@ -146,6 +162,22 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
6950A1272D1D4C28001695C5 /* SegmentElementAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementAppearance.swift; sourceTree = "<group>"; };
6950A1292D1D4D4E001695C5 /* SegmentElementSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementSize.swift; sourceTree = "<group>"; };
69573D692D1D754400359D53 /* SegmentElementAppearance+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElementAppearance+Extensions.swift"; sourceTree = "<group>"; };
69573D6B2D1D7C4300359D53 /* SegmentElementAppearance+Variation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElementAppearance+Variation.swift"; sourceTree = "<group>"; };
696843422D1EA11A002F8C7A /* SegmentElementAppearance+ButtonAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SegmentElementAppearance+ButtonAppearance.swift"; sourceTree = "<group>"; };
696843442D1EA348002F8C7A /* SegmentElementAccessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementAccessibility.swift; sourceTree = "<group>"; };
6969EADD2D1D5B73008536E5 /* SegmentElementAppearanceVariations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentElementAppearanceVariations.swift; sourceTree = "<group>"; };
697736FE2D26C2310077D1A4 /* CounterAppearance+Variation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CounterAppearance+Variation.swift"; sourceTree = "<group>"; };
697737842D2EB7F80077D1A4 /* View+ErrorString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+ErrorString.swift"; sourceTree = "<group>"; };
698744562D1C367700559ABA /* CounterAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterAppearance.swift; sourceTree = "<group>"; };
698744572D1C367700559ABA /* CounterColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterColor.swift; sourceTree = "<group>"; };
698744582D1C367700559ABA /* CounterSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterSize.swift; sourceTree = "<group>"; };
6987445A2D1C367700559ABA /* CounterAppearance+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CounterAppearance+Extensions.swift"; sourceTree = "<group>"; };
6987445C2D1C367700559ABA /* CounterData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterData.swift; sourceTree = "<group>"; };
6987445D2D1C367700559ABA /* SDDSCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDDSCounter.swift; sourceTree = "<group>"; };
698744652D1C368E00559ABA /* SDDSSegmentElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDDSSegmentElement.swift; sourceTree = "<group>"; };
8102BA2A2CBE9B3300C589D3 /* SDDSTextArea.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SDDSTextArea.swift; sourceTree = "<group>"; };
8102BA2B2CBE9B3300C589D3 /* TextAreaAccessibility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextAreaAccessibility.swift; sourceTree = "<group>"; };
8102BA2C2CBE9B3300C589D3 /* TextAreaAppearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextAreaAppearance.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -324,6 +356,59 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
6950A1262D1D4BE1001695C5 /* SegmentAppearance */ = {
isa = PBXGroup;
children = (
696843442D1EA348002F8C7A /* SegmentElementAccessibility.swift */,
696843422D1EA11A002F8C7A /* SegmentElementAppearance+ButtonAppearance.swift */,
69573D6B2D1D7C4300359D53 /* SegmentElementAppearance+Variation.swift */,
69573D692D1D754400359D53 /* SegmentElementAppearance+Extensions.swift */,
6969EADD2D1D5B73008536E5 /* SegmentElementAppearanceVariations.swift */,
6950A1292D1D4D4E001695C5 /* SegmentElementSize.swift */,
6950A1272D1D4C28001695C5 /* SegmentElementAppearance.swift */,
);
path = SegmentAppearance;
sourceTree = "<group>";
};
698744592D1C367700559ABA /* CounterAppearance */ = {
isa = PBXGroup;
children = (
697736FE2D26C2310077D1A4 /* CounterAppearance+Variation.swift */,
698744562D1C367700559ABA /* CounterAppearance.swift */,
698744572D1C367700559ABA /* CounterColor.swift */,
698744582D1C367700559ABA /* CounterSize.swift */,
);
path = CounterAppearance;
sourceTree = "<group>";
};
6987445B2D1C367700559ABA /* CounterAppearance+Extensions */ = {
isa = PBXGroup;
children = (
6987445A2D1C367700559ABA /* CounterAppearance+Extensions.swift */,
);
path = "CounterAppearance+Extensions";
sourceTree = "<group>";
};
6987445E2D1C367700559ABA /* SDDSCounter */ = {
isa = PBXGroup;
children = (
698744592D1C367700559ABA /* CounterAppearance */,
6987445B2D1C367700559ABA /* CounterAppearance+Extensions */,
6987445C2D1C367700559ABA /* CounterData.swift */,
6987445D2D1C367700559ABA /* SDDSCounter.swift */,
);
path = SDDSCounter;
sourceTree = "<group>";
};
698744662D1C368E00559ABA /* SDDSSegmentElement */ = {
isa = PBXGroup;
children = (
6950A1262D1D4BE1001695C5 /* SegmentAppearance */,
698744652D1C368E00559ABA /* SDDSSegmentElement.swift */,
);
path = SDDSSegmentElement;
sourceTree = "<group>";
};
8102BA282CBE9B3300C589D3 /* SDDSTextArea */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -611,6 +696,8 @@
818C03AF2C418705002C6D0A /* Components */ = {
isa = PBXGroup;
children = (
698744662D1C368E00559ABA /* SDDSSegmentElement */,
6987445E2D1C367700559ABA /* SDDSCounter */,
8102BA282CBE9B3300C589D3 /* SDDSTextArea */,
81E9FA8D2C92B12C0041B5FF /* SDDSTextField */,
81CBC09B2C82326600FBDAC8 /* SDDSAvatarGroup */,
Expand Down Expand Up @@ -728,6 +815,7 @@
81998FF72C355033009074B7 /* Extensions */ = {
isa = PBXGroup;
children = (
697737842D2EB7F80077D1A4 /* View+ErrorString.swift */,
81998FF82C35503D009074B7 /* View+Modifiers.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -1145,6 +1233,12 @@
818C03BF2C43C371002C6D0A /* DebugModifier.swift in Sources */,
817339D72D033C0A0092608A /* ProgressBarAccessibility.swift in Sources */,
814E30392C99AFB3004601F7 /* SDDSAvatarGroup.swift in Sources */,
6987445F2D1C367700559ABA /* SDDSCounter.swift in Sources */,
698744602D1C367700559ABA /* CounterAppearance+Extensions.swift in Sources */,
698744612D1C367700559ABA /* CounterSize.swift in Sources */,
698744622D1C367700559ABA /* CounterColor.swift in Sources */,
698744632D1C367700559ABA /* CounterData.swift in Sources */,
698744642D1C367700559ABA /* CounterAppearance.swift in Sources */,
814E307E2C99CEE1004601F7 /* View+DebugModifiers.swift in Sources */,
817339D52D033BF50092608A /* ProgressBarSizeConfiguration.swift in Sources */,
818FE9312C3C1CDC00F64958 /* Components.swift in Sources */,
Expand All @@ -1162,21 +1256,26 @@
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 */,
817339E62D033E650092608A /* RadioboxData.swift in Sources */,
816C62A22CB80EC400352891 /* Opacity.swift in Sources */,
697736FF2D26C23F0077D1A4 /* CounterAppearance+Variation.swift in Sources */,
814E30382C99AFB0004601F7 /* SDDSAvatarModifiers.swift in Sources */,
81D2B1992C32B3E400CAA7FD /* SDDSButton.swift in Sources */,
817339E22D033DA30092608A /* ChipBorderStyle.swift in Sources */,
81F753222CF467CC000156D9 /* ButtonLayoutMode.swift in Sources */,
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 */,
697737852D2EB8030077D1A4 /* View+ErrorString.swift in Sources */,
81F7531C2CF46755000156D9 /* ButtonStyle.swift in Sources */,
81F753282CF46831000156D9 /* ButtonColor.swift in Sources */,
811DE1582C5017C3000DD354 /* ProgressBarAppearance.swift in Sources */,
Expand All @@ -1187,19 +1286,24 @@
818C03C92C451424002C6D0A /* RadioboxAppearance.swift in Sources */,
8102BA312CBE9B3300C589D3 /* TextAreaAppearance.swift in Sources */,
8159F7302C5D1CFE00622836 /* FillStyle.swift in Sources */,
696843432D1EA12E002F8C7A /* SegmentElementAppearance+ButtonAppearance.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 */,
816AA9A72C97280400C3347C /* PlaceholderTextField.swift in Sources */,
698744672D1C368E00559ABA /* SDDSSegmentElement.swift in Sources */,
811DE1542C50098D000DD354 /* SDDSChip.swift in Sources */,
8102BA3C2CBEB32700C589D3 /* ExpandingTextEditor.swift in Sources */,
81F7531E2CF46793000156D9 /* ButtonAlignment.swift in Sources */,
81733A0D2D0367BD0092608A /* ProgressBarAppearance+Extensions.swift in Sources */,
81F7532E2CF4689C000156D9 /* ButtonAccessibility.swift in Sources */,
81685C2B2CFF898D00278446 /* SwitchAppearance+Extensions.swift in Sources */,
818C03B92C43B99B002C6D0A /* ColorToken+Extensions.swift in Sources */,
696843452D1EA35B002F8C7A /* SegmentElementAccessibility.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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public struct BasicButton: View {
appearance: appearance,
layoutMode: layoutMode,
accessibility: accessibility,
counterView: nil,
action: action
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ public protocol ButtonSizeConfiguration: SizeConfiguration, CustomDebugStringCon
/**
Внутренние отступы кнопки.
*/
var paddings: EdgeInsets { get }
func paddings(style: ComponentShapeStyle) -> EdgeInsets

/**
Размер иконки, отображаемой в кнопке.
*/
var iconSize: CGSize { get }

/**
Размер счетчика, отображаемой в кнопке.
*/
var counterSize: CounterSizeConfiguration { get }

/**
Размер спиннера загрузки в кнопке.
*/
Expand All @@ -54,8 +59,9 @@ public protocol ButtonSizeConfiguration: SizeConfiguration, CustomDebugStringCon
public struct DefaultButtonSize: ButtonSizeConfiguration {
public var height: CGFloat = 0
public func cornerRadius(style: ComponentShapeStyle) -> CGFloat { 0 }
public var paddings: EdgeInsets = .init()
public func paddings(style: ComponentShapeStyle) -> EdgeInsets { .init() }
public var iconSize: CGSize = .zero
public var counterSize: CounterSizeConfiguration = DefaultCounterSize()
public var spinnerSize: CGSize = .zero
public var iconHorizontalGap: CGFloat = 0
public var titleHorizontalGap: CGFloat = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public struct IconButton: View {
appearance: appearance,
layoutMode: layoutMode,
accessibility: accessibility,
counterView: nil,
action: action
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public struct LinkButton: View {
appearance: appearance,
layoutMode: layoutMode,
accessibility: accessibility,
counterView: nil,
action: action
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ public struct SDDSButton: View {
public let iconAttributes: ButtonIconAttributes?
public let isDisabled: Bool
public let isLoading: Bool
public let spinnerImage: Image
public let spinnerImage: Image?
public let buttonStyle: SDDSComponents.ButtonStyle
public let appearance: ButtonAppearance
public let layoutMode: ButtonLayoutMode
public let accessibility: ButtonAccessibility
public let counterView: SDDSCounter?

@Environment(\.colorScheme) var colorScheme
@State private var isAnimating: Bool = false
Expand All @@ -28,11 +29,12 @@ public struct SDDSButton: View {
iconAttributes: ButtonIconAttributes? = nil,
isDisabled: Bool = false,
isLoading: Bool = false,
spinnerImage: Image = Image("spinner", bundle: Bundle(for: Components.self)),
spinnerImage: Image? = Image("spinner", bundle: Bundle(for: Components.self)),
buttonStyle: SDDSComponents.ButtonStyle = .basic,
appearance: ButtonAppearance,
layoutMode: ButtonLayoutMode = .wrapContent,
accessibility: ButtonAccessibility = ButtonAccessibility(),
counterView: SDDSCounter? = nil,
action: @escaping () -> Void
) {
self.title = title
Expand All @@ -45,6 +47,7 @@ public struct SDDSButton: View {
self.appearance = appearance
self.layoutMode = layoutMode
self.accessibility = accessibility
self.counterView = counterView
self.action = action
}

Expand Down Expand Up @@ -106,7 +109,7 @@ public struct SDDSButton: View {
if isSideBySide {
Spacer()
}
if !subtitle.isEmpty {
if !subtitle.isEmpty && counterView == nil {
if !title.isEmpty {
Spacer().frame(width: appearance.size.titleHorizontalGap)
}
Expand All @@ -121,13 +124,14 @@ public struct SDDSButton: View {
}
icon
}
counter
if isCentered {
Spacer()
}
}
.frame(height: appearance.size.height)
.padding(.leading, appearance.size.paddings.leading)
.padding(.trailing, appearance.size.paddings.trailing)
.padding(.leading, appearance.size.paddings(style: appearance.shapeStyle).leading)
.padding(.trailing, appearance.size.paddings(style: appearance.shapeStyle).trailing)
}

@ViewBuilder
Expand Down Expand Up @@ -161,7 +165,7 @@ public struct SDDSButton: View {

@ViewBuilder
private var spinner: some View {
if isLoading {
if let spinnerImage = spinnerImage, isLoading {
SpinnerView(
image: spinnerImage,
foregroundColor: currentColor(for: appearance.spinnerColor)
Expand All @@ -170,6 +174,21 @@ public struct SDDSButton: View {
EmptyView()
}
}

@ViewBuilder
private var counter: some View {
if let counter = counterView {
SDDSCounter(
data: counter.data,
appearance: counter.appearance,
isAnimating: isAnimating,
isHighlighted: isHighlighted,
isHovered: isHovered
)
} else {
EmptyView()
}
}
}

private extension SDDSButton {
Expand Down
Loading

0 comments on commit 85c6e7c

Please sign in to comment.