Fix Sidebar section headers to match macOS

This commit is contained in:
Carson Katri 2020-08-04 14:54:35 -04:00
parent aae1686bae
commit ccd2035026
3 changed files with 21 additions and 8 deletions

View File

@ -81,7 +81,8 @@ extension Section: View, SectionView where Parent: View, Content: View, Footer:
headerView(style)
sectionContent(style)
footerView(style)
})
}
.frame(minWidth: 0, maxWidth: .infinity))
}
}

View File

@ -43,13 +43,10 @@ struct NavItem: View {
destination = nil
}
@ViewBuilder var body: some View {
@ViewBuilder
var body: some View {
if let dest = destination {
NavigationLink(id, destination: HStack {
Spacer(minLength: 0)
dest
Spacer(minLength: 0)
})
NavigationLink(id, destination: dest)
} else {
#if os(WASI)
Text(id)
@ -76,7 +73,8 @@ struct TokamakDemoView: View {
Counter(count: Count(value: 5), limit: 15)
.padding()
.background(Color(red: 0.9, green: 0.9, blue: 0.9, opacity: 1.0))
.border(Color.red, width: 3))
.border(Color.red, width: 3)
.foregroundColor(.black))
NavItem("ButtonStyle", destination: ButtonStyleDemo())
}
Section(header: Text("Containers")) {

View File

@ -89,7 +89,21 @@ extension InsetGroupedListStyle: ListStyleDeferredToRenderer {
}
}
// TODO: Make sections collabsible (see Section.swift for more impl. details)
extension SidebarListStyle: ListStyleDeferredToRenderer {
public func sectionHeader<Header>(_ header: Header) -> AnyView where Header: View {
AnyView(header
.font(.system(size: 11, weight: .medium))
.foregroundColor(Color._withScheme {
switch $0 {
case .light: return Color(.sRGB, white: 0, opacity: 0.4)
case .dark: return Color(.sRGB, white: 1, opacity: 0.4)
}
})
.padding(.vertical, 2)
.padding(.leading, 4))
}
public func listRow<Row>(_ row: Row) -> AnyView where Row: View {
AnyView(row.frame(minWidth: 0, maxWidth: .infinity))
}