Tusker/Packages/TTTKit/Sources/TTTKit/UI/Separator.swift

40 lines
864 B
Swift
Raw Normal View History

2022-12-22 16:54:23 +00:00
//
// SwiftUIView.swift
//
//
// Created by Shadowfacts on 12/21/22.
//
import SwiftUI
@available(iOS 16.0, *)
struct Separator: View {
let axis: Axis
@Environment(\.separatorColor) private var separatorColor
var body: some View {
rect
.foregroundColor(separatorColor)
.gridCellUnsizedAxes(axis == .vertical ? .vertical : .horizontal)
}
private var rect: some View {
if axis == .vertical {
return Rectangle().frame(width: 1)
} else {
return Rectangle().frame(height: 1)
}
}
}
private struct SeparatorColorKey: EnvironmentKey {
static var defaultValue = Color.black
}
extension EnvironmentValues {
var separatorColor: Color {
get { self[SeparatorColorKey.self] }
set { self[SeparatorColorKey.self] = newValue }
}
}