forked from microsoft/fluentui-apple
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Implementation of FluentListSectionHeader and FluentListSecti…
…onFooter (microsoft#2020) * setup basic header / footer * update comments * Add comment
- Loading branch information
1 parent
036dac7
commit 58cb675
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// This component is a work in progress. Expect changes to be made to it on a somewhat regular basis. | ||
/// | ||
/// It is intended to be used in conjunction with `FluentUI.FluentListSection` and `FluentUI.ListItem` | ||
public struct FluentListSectionFooter<Description: StringProtocol>: View { | ||
|
||
// MARK: Initializer | ||
|
||
/// Creates a `FluentListSectionFooter` | ||
/// - Parameters: | ||
/// - description: description of the section to be shown in the footer. | ||
public init(description: Description) { | ||
self.description = description | ||
} | ||
|
||
public var body: some View { | ||
Text(description) | ||
.textCase(nil) | ||
} | ||
|
||
// MARK: Private variables | ||
|
||
private let description: Description | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// This component is a work in progress. Expect changes to be made to it on a somewhat regular basis. | ||
/// | ||
/// It is intended to be used in conjunction with `FluentUI.FluentListSection` and `FluentUI.ListItem` | ||
public struct FluentListSectionHeader<Title: StringProtocol, TrailingContent: View>: View { | ||
|
||
// MARK: Initializer | ||
|
||
/// Creates a `FluentListSectionHeader` | ||
/// - Parameters: | ||
/// - title: title of the section to be shown in the header. | ||
/// - trailingContent: content that appears on the trailing edge of the view. | ||
public init(title: Title, | ||
@ViewBuilder trailingContent: @escaping () -> TrailingContent) { | ||
self.title = title | ||
self.trailingContent = trailingContent | ||
} | ||
|
||
public var body: some View { | ||
@ViewBuilder var titleView: some View { | ||
Text(title) | ||
// By default uppercasing is applied, setting nil to not enforce casing | ||
.textCase(nil) | ||
} | ||
|
||
@ViewBuilder var contentView: some View { | ||
if let trailingContent { | ||
HStack { | ||
titleView | ||
Spacer(minLength: 0) | ||
trailingContent() | ||
} | ||
} else { | ||
titleView | ||
} | ||
} | ||
|
||
return contentView | ||
} | ||
|
||
// MARK: Private variables | ||
|
||
private var trailingContent: (() -> TrailingContent)? | ||
private let title: Title | ||
} | ||
|
||
// MARK: Additional Initializers | ||
|
||
public extension FluentListSectionHeader where TrailingContent == EmptyView { | ||
init(title: Title) { | ||
self.title = title | ||
} | ||
} |