@@ -29,61 +29,52 @@ private struct PillButtonBarDemoView: View {
2929 ScrollView ( . vertical) {
3030 VStack ( spacing: 30 ) {
3131 VStack ( spacing: 20 ) {
32- Text ( " onBrand bar " )
33- . multilineTextAlignment ( . center)
34- . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
35- PillButtonBarView ( style: . onBrand,
36- viewModels: indexSelectionViewModels,
37- selected: $onBrandSelectedIndex,
38- centerAlignIfContentFits: true ,
39- tokenOverrides: tokenOverrides)
40- . disabled ( disablePills)
41- . background {
42- fluentTheme. swiftUIColor ( . brandBackground1)
32+ PillBarDemoSection ( title: " onBrand bar " ) {
33+ PillButtonBarView ( style: . onBrand,
34+ viewModels: indexSelectionViewModels,
35+ selected: $onBrandSelectedIndex,
36+ centerAlignIfContentFits: true ,
37+ tokenOverrides: tokenOverrides)
38+ . disabled ( disablePills)
39+ . background {
40+ fluentTheme. swiftUIColor ( . brandBackground1)
41+ }
42+ }
43+
44+ PillBarDemoSection ( title: " Primary bar " ) {
45+ PillButtonBarView ( style: . primary,
46+ viewModels: titleSelectionViewModels,
47+ selected: $primarySelectedTitle,
48+ centerAlignIfContentFits: true ,
49+ tokenOverrides: tokenOverrides)
50+ . disabled ( disablePills)
51+ }
52+
53+ PillBarDemoSection ( title: " Bar with deselection " ,
54+ subtitle: " This pill button bar supports having no selected pill button. If the currently selected pill button is tapped, it will be deselected. " ) {
55+ PillButtonBarView ( style: . primary,
56+ viewModels: titleDeselectionViewModels,
57+ selected: $deselectionBarTitle,
58+ tokenOverrides: tokenOverrides)
59+ . disabled ( disablePills)
60+ }
61+
62+ PillBarDemoSection ( title: " Leading aligned " ) {
63+ PillButtonBarView ( style: . primary,
64+ viewModels: titleSelectionLeadingViewModels,
65+ selected: $leadingAlignedBarSelectedTitle,
66+ tokenOverrides: tokenOverrides)
67+ . disabled ( disablePills)
68+ }
69+
70+ PillBarDemoSection ( title: " Center aligned " ) {
71+ PillButtonBarView ( style: . primary,
72+ viewModels: titleSelectionCenterViewModels,
73+ selected: $centerAlignedBarSelectedTitle,
74+ centerAlignIfContentFits: true ,
75+ tokenOverrides: tokenOverrides)
76+ . disabled ( disablePills)
4377 }
44-
45- Text ( " Primary bar " )
46- . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
47- . multilineTextAlignment ( . center)
48- PillButtonBarView ( style: . primary,
49- viewModels: titleSelectionViewModels,
50- selected: $primarySelectedTitle,
51- centerAlignIfContentFits: true ,
52- tokenOverrides: tokenOverrides)
53- . disabled ( disablePills)
54-
55- Text ( " Bar with deselection " )
56- . multilineTextAlignment ( . center)
57- . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
58- Text ( " This pill button bar supports having no selected pill button. If the currently selected pill button is tapped, it will be deselected. " )
59- . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
60- . multilineTextAlignment ( . center)
61- . padding ( . horizontal)
62- . frame ( maxWidth: . infinity, alignment: . center)
63- . fixedSize ( horizontal: false , vertical: true )
64- . font ( . caption)
65- PillButtonBarView ( style: . primary,
66- viewModels: titleDeselectionViewModels,
67- selected: $deselectionBarTitle,
68- tokenOverrides: tokenOverrides)
69- . disabled ( disablePills)
70-
71- Text ( " Leading aligned " )
72- . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
73- PillButtonBarView ( style: . primary,
74- viewModels: titleSelectionLeadingViewModels,
75- selected: $leadingAlignedBarSelectedTitle,
76- tokenOverrides: tokenOverrides)
77- . disabled ( disablePills)
78-
79- Text ( " Center aligned " )
80- . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
81- PillButtonBarView ( style: . primary,
82- viewModels: titleSelectionCenterViewModels,
83- selected: $centerAlignedBarSelectedTitle,
84- centerAlignIfContentFits: true ,
85- tokenOverrides: tokenOverrides)
86- . disabled ( disablePills)
8778 }
8879 . fluentTheme ( theme)
8980 }
@@ -202,3 +193,43 @@ private struct PillButtonBarDemoView: View {
202193 static let leadingImage = Image ( systemName: " circle.fill " )
203194 }
204195}
196+
197+ private struct PillBarDemoSection < PillButtonBar: View > : View {
198+ let title : String
199+ let subtitle : String ?
200+ let titleColor : Color ?
201+ let pillBar : ( ) -> PillButtonBar
202+
203+ fileprivate init ( title: String ,
204+ subtitle: String ? = nil ,
205+ titleColor: Color ? = nil ,
206+ pillBar: @escaping ( ) -> PillButtonBar ) {
207+ self . title = title
208+ self . subtitle = subtitle
209+ self . titleColor = titleColor
210+ self . pillBar = pillBar
211+ }
212+
213+ var body : some View {
214+ VStack ( spacing: 20 ) {
215+ Text ( title)
216+ . multilineTextAlignment ( . center)
217+ . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
218+
219+ if let subtitle {
220+ Text ( subtitle)
221+ . foregroundStyle ( fluentTheme. swiftUIColor ( . foreground1) )
222+ . multilineTextAlignment ( . center)
223+ . padding ( . horizontal)
224+ . frame ( maxWidth: . infinity, alignment: . center)
225+ . fixedSize ( horizontal: false , vertical: true )
226+ . font ( . caption)
227+ }
228+
229+ pillBar ( )
230+ . accessibilityIdentifier ( title)
231+ }
232+ }
233+
234+ @Environment ( \. fluentTheme) private var fluentTheme : FluentTheme
235+ }
0 commit comments