60 lines
1.8 KiB
Swift
60 lines
1.8 KiB
Swift
import Elementary
|
|||
|
|
import Persistence
|
||
|
|
|
||
|
|
/// A placeholder cover: lettering on a toned ground, scaling with its width. Stands in until listings carry photos.
|
||
|
|
struct Cover: HTML {
|
||
|
|
|
||
|
|
// MARK: Properties
|
||
|
|
|
||
|
|
/// The cover's lettering and tone.
|
||
|
|
let cover: Listing.Cover
|
||
|
|
|
||
|
|
/// A modifier class positioning or sizing the cover, or `nil` for none.
|
||
|
|
let modifier: String?
|
||
|
|
|
||
|
|
// MARK: Initializers
|
||
|
|
|
||
|
|
/// Creates a placeholder cover.
|
||
|
|
/// - Parameters:
|
||
|
|
/// - cover: the cover's lettering and tone.
|
||
|
|
/// - modifier: a modifier class positioning or sizing the cover, or `nil` (the default) for none.
|
||
|
|
init(
|
||
|
|
_ cover: Listing.Cover,
|
||
|
|
modifier: String? = nil
|
||
|
|
) {
|
||
|
|
self.cover = cover
|
||
|
|
self.modifier = modifier
|
||
|
|
}
|
||
|
|
|
||
|
|
// MARK: Computed
|
||
|
|
|
||
|
|
/// Decorative: whatever links to the listing names it.
|
||
|
|
var body: some HTML {
|
||
|
|
div(
|
||
|
|
.class(["cover", "cover--\(cover.tone)", modifier].compactMap(\.self).joined(separator: " ")),
|
||
|
|
.custom(
|
||
|
|
name: "aria-hidden",
|
||
|
|
value: "true"
|
||
|
|
)
|
||
|
|
) {
|
||
|
|
div(.class("cover__face")) {
|
||
|
|
div(.class("cover__title")) {
|
||
|
|
for line in cover.title.split(separator: "\n") {
|
||
|
|
span {
|
||
|
|
String(line)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
div(.class("cover__foot")) {
|
||
|
|
span(.class("cover__imprint")) {
|
||
|
|
cover.imprint
|
||
|
|
}
|
||
|
|
span(.class(cover.number.allSatisfy(\.isNumber) ? "cover__number" : "cover__number cover__number--text")) {
|
||
|
|
cover.number
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|