@@ -5,6 +5,7 @@ import struct WooFoundation.IndefiniteCircularProgressViewStyle
55enum POSButtonSize {
66 case normal
77 case extraSmall
8+ case compact
89}
910
1011/// Button state for different visual presentations
@@ -51,11 +52,37 @@ struct POSOutlinedButtonStyle: ButtonStyle {
5152 }
5253}
5354
55+ /// Info card button style with default and primary variants.
56+ /// Use with .compact size for info card buttons.
57+ struct POSInfoCardButtonStyle : ButtonStyle {
58+ enum Variant {
59+ case `default`
60+ case primary
61+ }
62+
63+ private let size : POSButtonSize
64+ private let variant : Variant
65+ private let state : POSButtonState
66+
67+ init ( size: POSButtonSize , variant: Variant , isLoading: Bool = false ) {
68+ self . size = size
69+ self . variant = variant
70+ self . state = isLoading ? . loading : . idle
71+ }
72+
73+ func makeBody( configuration: Configuration ) -> some View {
74+ let buttonVariant : POSButtonVariant = variant == . primary ? . filled : . infoCardOutlined
75+ return POSButtonStyleInternal ( configuration: configuration, variant: buttonVariant, size: size, state: state)
76+ . disabled ( state != . idle)
77+ }
78+ }
79+
5480
5581/// The visual variant of the POS button.
5682fileprivate enum POSButtonVariant {
5783 case filled
5884 case outlined
85+ case infoCardOutlined
5986}
6087
6188private struct POSButtonStyleInternal : View {
@@ -87,7 +114,7 @@ private struct POSButtonStyleInternal: View {
87114 . overlay ( borderOverlay)
88115 // Makes the entire area tappable, otherwise the area with clear background is not tappable.
89116 . contentShape ( Rectangle ( ) )
90- . cornerRadius ( Constants . cornerRadius)
117+ . cornerRadius ( size . cornerRadius)
91118 . opacity ( configuration. isPressed ? 0.7 : 1.0 )
92119 . animation ( . easeOut( duration: 0.15 ) , value: configuration. isPressed)
93120 }
@@ -101,7 +128,7 @@ private struct POSButtonStyleInternal: View {
101128 content ( )
102129 Spacer ( )
103130 }
104- case . extraSmall:
131+ case . extraSmall, . compact :
105132 content ( )
106133 }
107134 }
@@ -125,6 +152,8 @@ private struct POSButtonStyleInternal: View {
125152 state != . idle ? . posPrimaryContainer : . posDisabledContainer
126153 case ( . outlined, _) :
127154 . clear
155+ case ( . infoCardOutlined, _) :
156+ . posSurfaceContainerLowest
128157 }
129158 }
130159
@@ -138,15 +167,23 @@ private struct POSButtonStyleInternal: View {
138167 . posOnSurface
139168 case ( . outlined, false ) :
140169 . posOnDisabledContainer
170+ case ( . infoCardOutlined, true ) :
171+ . posOnSurface
172+ case ( . infoCardOutlined, false ) :
173+ . posOnDisabledContainer
141174 }
142175 }
143176
144177 @ViewBuilder
145178 private var borderOverlay : some View {
146179 if variant == . outlined {
147- RoundedRectangle ( cornerRadius: Constants . cornerRadius)
180+ RoundedRectangle ( cornerRadius: size . cornerRadius)
148181 . strokeBorder ( isEnabled ? Color . posInverseSurface : . posDisabledContainer,
149182 lineWidth: Constants . borderStrokeWidth)
183+ } else if variant == . infoCardOutlined {
184+ RoundedRectangle ( cornerRadius: size. cornerRadius)
185+ . strokeBorder ( isEnabled ? Color . posOnSurface : . posDisabledContainer,
186+ lineWidth: Constants . borderStrokeWidth)
150187 }
151188 }
152189}
@@ -169,6 +206,8 @@ private extension POSButtonSize {
169206 ( vertical: POSPadding . large, horizontal: POSPadding . large)
170207 case . extraSmall:
171208 ( vertical: POSPadding . small, horizontal: POSPadding . medium)
209+ case . compact:
210+ ( vertical: POSPadding . small, horizontal: POSPadding . medium)
172211 }
173212 }
174213
@@ -178,6 +217,17 @@ private extension POSButtonSize {
178217 . posBodyLargeBold
179218 case . extraSmall:
180219 . posBodyMediumBold
220+ case . compact:
221+ . posBodySmallBold( )
222+ }
223+ }
224+
225+ var cornerRadius : CGFloat {
226+ switch self {
227+ case . normal, . extraSmall:
228+ POSCornerRadiusStyle . medium. value
229+ case . compact:
230+ POSCornerRadiusStyle . small. value
181231 }
182232 }
183233}
@@ -189,6 +239,8 @@ private extension POSButtonSize {
189239 ( size: 32 , lineWidth: 10 )
190240 case . extraSmall:
191241 ( size: 20 , lineWidth: 6 )
242+ case . compact:
243+ ( size: 16 , lineWidth: 4 )
192244 }
193245 }
194246}
@@ -257,6 +309,13 @@ struct POSButtonStyle_Previews: View {
257309 Button ( " Disabled Button " ) { }
258310 . buttonStyle ( POSOutlinedButtonStyle ( size: size) )
259311 . disabled ( true )
312+ case . infoCardOutlined:
313+ Button ( " Enabled Button " ) { }
314+ . buttonStyle ( POSInfoCardButtonStyle ( size: size, variant: . default) )
315+
316+ Button ( " Disabled Button " ) { }
317+ . buttonStyle ( POSInfoCardButtonStyle ( size: size, variant: . default) )
318+ . disabled ( true )
260319 }
261320 }
262321 }
0 commit comments