view LazyBear/Views/Home/Helpers/StockSheetRow.swift @ 457:c6913f0ce46e

Minor UI Updates
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 28 Jun 2021 14:03:50 +0200
parents 4effac4733b0
children
line wrap: on
line source

//
//  StockSheetRow.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 13/6/21.
//

import SwiftUI
import StockCharts

struct StockSheetRow: View {
    var company: CompanyModel
    
    var body: some View {
        HStack {
            VStack(alignment: .leading) {
                Text(company.symbol.uppercased())
                    .fontWeight(.semibold)
                
                Text(company.companyName.capitalized)
                    .font(.callout)
                    .fontWeight(.semibold)
                    .opacity(0.6)
                    .lineLimit(1)
            }
            
            Spacer()
            LineChartView(data: company.intradayPrices, dates: nil, hours: nil, dragGesture: false)
                .frame(width: 80)
                .padding(.vertical, 10)
                .padding(.horizontal)
            
            
            if let latestPrice = company.latestPrice, let changePercent = company.changePercent {
                VStack(alignment: .trailing) {
                    Text("\(latestPrice, specifier: "%.2f")")
                        .foregroundColor(changePercent < 0 ? .red: .green)
                        .fontWeight(.semibold)

                    Text("\(changePercent * 100, specifier: "%.2f")%")
                        .foregroundColor(changePercent < 0 ? .red: .green)
                        .font(.callout)
                        .fontWeight(.semibold)
                }
            }
        }
    }
}

struct StockSheetRow_Previews: PreviewProvider {
    static var previews: some View {
        StockSheetRow(company: CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3]))
    }
}