WIP: Sidebar improvements, working on other views.
This commit is contained in:
31
Sources/Styleguide/Number.swift
Normal file
31
Sources/Styleguide/Number.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import Elementary
|
||||
import Foundation
|
||||
|
||||
public struct Number: HTML, Sendable {
|
||||
let fractionDigits: Int
|
||||
let value: Double
|
||||
|
||||
private var formatter: NumberFormatter {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.maximumFractionDigits = fractionDigits
|
||||
return formatter
|
||||
}
|
||||
|
||||
public init(
|
||||
_ value: Double,
|
||||
digits fractionDigits: Int = 2
|
||||
) {
|
||||
self.value = value
|
||||
self.fractionDigits = fractionDigits
|
||||
}
|
||||
|
||||
public init(
|
||||
_ value: Int
|
||||
) {
|
||||
self.init(Double(value), digits: 0)
|
||||
}
|
||||
|
||||
public var body: some HTML<HTMLTag.span> {
|
||||
span { formatter.string(for: value) ?? "N/A" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user