Skip to content

sentryco/SideBarKit

Repository files navigation

Tests codebeat badge Platform License Swift Version

SideBarKit

Plug and play modular SideBar for macOS / iPad

img

Description

SideBarKit is a customizable Sidebar framework. Decouple the sidebar implementation. This results in cleaner, more manageable code.

Features:

  • 🔄 Toggleable groups (hide / show)
  • 🏷️ Reactive tag labels (count change reactively)
  • 🌗 Dark / Light mode support
  • 🧩 BYO (Bring your own) enum models

Example:

@State var selectedIdx: CombinedIndex? = .init(group: 0, item: 0) // Track selection
let model = [Top(), Middle(), Bottom()] // Define your model
MenuStack(selectedIndex: $selectedIdx, groups: model) // Add sidebar view

Defining a Custom Group:

struct CustomGroup: GroupKind {
    let title: String = "Custom Group"
    typealias EnumType = Items

    enum Items: String, CaseIterable {
        case first = "First Item"
        case second = "Second Item"
    }

    func getItem(item: Items) -> any RowKind {
        // Return your custom row
    }
}

Defining a Custom Row:

struct CustomRowModel: RowKind {
    let title: String
    let action: () -> Void

    // Additional properties and methods
}

Installation:

To install SideBarKit using Swift Package Manager, add the following dependency to your Package.swift file:

.package(url: "https://github.com/sentryco/SideBarKit", branch: "main")

Dependencies:

Todo:

  • Add a way to customize metrics a bit. paddings, offsets etc to match original component
  • Consider removing binding from selection var. Bidning might not be needed
  • Remove unit-tests
  • Add UITests
  • Tag count may not need to be a binding
  • Tweak padding around groups. Looks too tall when collapsed
  • Make sure icons keeps its aspect ratio, double check this

Future considerations:

  • Consider implementing toggle compact-mode / expanded-mode functionality etc, or not? at least wait and do it later when things are 👉 more stable 👈 etc (align icons to support compact mode)
  • Consider persisting collapsed state
  • Consider persisting selected index
  • start refactoring to use async/await where appropriate.
  • reorg files:
Sources/
└── SideBarKit/
    ├── style/
    │   ├── MenuTagStyle.swift
    │   └── RowTextStyle.swift

About

Plug and play modular SideBar for macOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages