SPB Git

Repository Public MIT

glass-sidebar.md 3.5 KB 89 lines markdown

1# GlassSidebar23| | |4|---|---|5| Identifier | `glass-sidebar` |6| Module | `SPGlassNavigation` |7| Kind | `native-wrapper` — a `NavigationSplitView` whose sidebar is a system `List` with `.searchable` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Navigation/GlassSidebarExample.swift` |1011## Minimal usage1213```swift14@State private var selection: String?1516GlassSidebar("Mail", sections: [17    GlassSidebarSection(id: "boxes", title: "Mailboxes", items: [18        GlassSidebarItem(id: "inbox", title: "Inbox", systemImage: "tray", badge: 12),19        GlassSidebarItem(id: "sent", title: "Sent", systemImage: "paperplane"),20    ]),21], selection: $selection) { id in22    if let id { MailboxView(id: id) } else { Text("Select a mailbox") }23}24```2526## Variants2728| Variant | Use |29|---|---|30| Section with `title: nil` | Rows without a header. |31| `badge:` | Count at the trailing edge of a row; zero shows nothing. |32| `keywords:` | Extra words the search matches (synonyms, translations). |33| `isSearchable: false` | No search field. |34| `columnVisibility:` | Collapse or show the sidebar from code. |3536## Parameters3738| Parameter | Type | Default | Meaning |39|---|---|---|---|40| `title` | `LocalizedStringKey` | — | Title of the sidebar column. |41| `sections` | `[GlassSidebarSection<ID>]` | — | Rows, grouped. |42| `selection` | `Binding<ID?>` | — | Selected row. |43| `searchText` | `Binding<String>?` | `nil` | Search text when the host needs it; otherwise owned by the sidebar. |44| `columnVisibility` | `Binding<NavigationSplitViewVisibility>?` | `nil` | Sidebar visibility when the host drives it. |45| `isSearchable` | `Bool` | `true` | Adds the system search field (`placement: .sidebar`). |46| `searchPrompt` | `LocalizedStringKey?` | "Search" | Placeholder of the search field. |47| `detail` | `(ID?) -> Detail` | — | Detail column for the selection. |4849## States5051Selected row: `selection`. Searching: rows are filtered by `GlassSidebarFilter.filter(_:query:)`; a search without result shows the system's `ContentUnavailableView.search`. Collapsed: on a compact width the system turns the split view into a stack and pushes the detail when a row is selected.5253## Advanced example5455```swift56@State private var selection: Folder.ID?57@State private var query = ""58@State private var visibility: NavigationSplitViewVisibility = .all5960GlassSidebar("Files", sections: model.sections, selection: $selection,61             searchText: $query, columnVisibility: $visibility, searchPrompt: "Search folders") { id in62    FolderView(id: id)63        .toolbar {64            Button("Focus", systemImage: "rectangle.expand.vertical") { visibility = .detailOnly }65        }66}67.onChange(of: query) { model.logRecentSearch($1) }68```6970The filter is public and pure, so the host can reuse it:7172```swift73GlassSidebarFilter.filter(sections, query: "evenements")   // matches "Événements"74```7576## Accessibility7778- Rows are system list rows: selection, headers and badges are announced by the system; the list is fully keyboard navigable.79- Symbols are decorative; the title is always present.80- Search ignores case, accents and character width, and matches every word of the query in any order.81- Row titles wrap at large text sizes.8283## Limits8485- Row and section titles are `String`s supplied already localised, because the search needs their text.86- One level of sections; no nested outline.87- A section whose title matches the query keeps all its rows.88- Collapse behaviour and the search field placement were compiled for both platforms but not exercised on a running device here.89
Files main
Menu

Theme