75 lines
1.7 KiB
Swift
75 lines
1.7 KiB
Swift
|
//
|
||
|
// FolderItem.swift
|
||
|
// Browse
|
||
|
//
|
||
|
// Created by Javier Cicchelli on 02/12/2022.
|
||
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import SwiftUI
|
||
|
|
||
|
struct FolderItem: View {
|
||
|
|
||
|
// MARK: Properties
|
||
|
|
||
|
let name: String
|
||
|
|
||
|
// MARK: Body
|
||
|
|
||
|
var body: some View {
|
||
|
HStack(spacing: 16) {
|
||
|
Image.folder
|
||
|
.icon(size: 32)
|
||
|
.foregroundColor(.red)
|
||
|
|
||
|
Text(name)
|
||
|
.font(.headline)
|
||
|
.foregroundColor(.primary)
|
||
|
.lineLimit(1)
|
||
|
.truncationMode(.middle)
|
||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||
|
|
||
|
Image.chevronRight
|
||
|
.icon(size: 16)
|
||
|
.foregroundColor(.secondary)
|
||
|
.font(.headline)
|
||
|
}
|
||
|
.padding(16)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// MARK: - Image
|
||
|
|
||
|
private extension Image {
|
||
|
|
||
|
// MARK: Constants
|
||
|
|
||
|
static let folder = Image(systemName: "folder.fill")
|
||
|
static let document = Image(systemName: "doc.fill")
|
||
|
static let chevronRight = Image(systemName: "chevron.right")
|
||
|
|
||
|
// MARK: Functions
|
||
|
|
||
|
func icon(size: CGFloat) -> some View {
|
||
|
self
|
||
|
.resizable()
|
||
|
.renderingMode(.template)
|
||
|
.scaledToFit()
|
||
|
.frame(width: size, height: size)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// MARK: - Previews
|
||
|
|
||
|
struct BrowseItem_Previews: PreviewProvider {
|
||
|
static var previews: some View {
|
||
|
FolderItem(name: "Some folder name goes in here...")
|
||
|
.previewDisplayName("Browse item for folders")
|
||
|
|
||
|
FolderItem(name: "Some very, extremely long folder name goes in here...")
|
||
|
.previewDisplayName("Browse item for folders with long name")
|
||
|
}
|
||
|
}
|