diff --git a/Sources/FluentUI_iOS/Components/List/FluentList.swift b/Sources/FluentUI_iOS/Components/List/FluentList.swift index bee4edd8e..524289d77 100644 --- a/Sources/FluentUI_iOS/Components/List/FluentList.swift +++ b/Sources/FluentUI_iOS/Components/List/FluentList.swift @@ -48,16 +48,14 @@ public struct FluentList: View { list .listStyle(.insetGrouped) .scrollContentBackground(.hidden) - // TODO: Directly use `FluentList` token set instead of `ListItem` - .background(ListItem.listBackgroundColor(for: .grouped)) + .background(ListItemTokenSet.listBackgroundColor(for: .grouped)) .listSectionSpacing(GlobalTokens.spacing(.size160)) .environment(\.defaultMinListHeaderHeight, GlobalTokens.spacing(.size320)) case .plain: list .listStyle(.plain) .scrollContentBackground(.hidden) - // TODO: Directly use `FluentList` token set instead of `ListItem` - .background(ListItem.listBackgroundColor(for: .plain)) + .background(ListItemTokenSet.listBackgroundColor(for: .plain)) } } diff --git a/Sources/FluentUI_iOS/Components/List/ListItem.swift b/Sources/FluentUI_iOS/Components/List/ListItem.swift index bc6f10f1b..7995e16d7 100644 --- a/Sources/FluentUI_iOS/Components/List/ListItem.swift +++ b/Sources/FluentUI_iOS/Components/List/ListItem.swift @@ -8,12 +8,6 @@ import FluentUI_common #endif import SwiftUI -public typealias ListItemAccessoryType = TableViewCellAccessoryType -public typealias ListItemBackgroundStyleType = TableViewCellBackgroundStyleType -public typealias ListItemLeadingContentSize = MSFTableViewCellCustomViewSize -public typealias ListItemTokenSet = TableViewCellTokenSet -public typealias ListItemToken = TableViewCellToken - /// View that represents an item in a List. public struct ListItem Color { let tokenSet = ListItemTokenSet(customViewSize: { .default }) switch backgroundStyle { diff --git a/Sources/FluentUI_iOS/Components/TableViewListShared/ListItemTokenSet.swift b/Sources/FluentUI_iOS/Components/TableViewListShared/ListItemTokenSet.swift new file mode 100644 index 000000000..358fcfe84 --- /dev/null +++ b/Sources/FluentUI_iOS/Components/TableViewListShared/ListItemTokenSet.swift @@ -0,0 +1,47 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// + +#if canImport(FluentUI_common) +import FluentUI_common +#endif +import SwiftUI + +public typealias ListItemAccessoryType = TableViewCellAccessoryType +public typealias ListItemBackgroundStyleType = TableViewCellBackgroundStyleType +public typealias ListItemLeadingContentSize = MSFTableViewCellCustomViewSize +public typealias ListItemTokenSet = TableViewCellTokenSet +public typealias ListItemToken = TableViewCellToken + +extension ListItemTokenSet { + /// The background color of `List` based on the style. + /// - Parameter backgroundStyle: The background style of the `List`. + /// - Returns: The color to use for the background of `List`. + static func listBackgroundColor(for backgroundStyle: ListItemBackgroundStyleType) -> Color { + let tokenSet = ListItemTokenSet(customViewSize: { .default }) + switch backgroundStyle { + case .grouped: + return Color(uiColor: tokenSet[.backgroundGroupedColor].uiColor) + case .plain: + return Color(uiColor: tokenSet[.backgroundColor].uiColor) + case .clear, .custom: + return .clear + } + } + + /// The background color of `ListItem` based on the style. + /// - Parameter backgroundStyle: The background style of the `List`. + /// - Returns: The color to use for the background of `ListItem`. + static func listItemBackgroundColor(for backgroundStyle: ListItemBackgroundStyleType) -> Color { + let tokenSet = ListItemTokenSet(customViewSize: { .default }) + switch backgroundStyle { + case .grouped: + return Color(uiColor: tokenSet[.cellBackgroundGroupedColor].uiColor) + case .plain: + return Color(uiColor: tokenSet[.cellBackgroundColor].uiColor) + case .clear, .custom: + return .clear + } + } +}