From 5e5bbb4cbc445684dd9f75a6602b997b8569c9f8 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Fri, 24 Mar 2023 23:51:10 +0530 Subject: [PATCH] Adding line component --- VDS.xcodeproj/project.pbxproj | 12 ++++++ VDS/Components/Line/Line.swift | 67 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 VDS/Components/Line/Line.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 4d1107f5..5ece8b5a 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; }; 5F21D7BF28DCEB3D003E7CD6 /* Useable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */; }; 5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; }; EA0FC2C62914222900DF80B4 /* ButtonGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */; }; @@ -120,6 +121,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 44604AD629CE196600E62B51 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Useable.swift; sourceTree = ""; }; 5FC35BE228D51405004EBEAC /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroup.swift; sourceTree = ""; }; @@ -245,6 +247,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 44604AD529CE195300E62B51 /* Line */ = { + isa = PBXGroup; + children = ( + 44604AD629CE196600E62B51 /* Line.swift */, + ); + path = Line; + sourceTree = ""; + }; 5FC35BE128D513EB004EBEAC /* Button */ = { isa = PBXGroup; children = ( @@ -349,6 +359,7 @@ EA985BF3296C609E00F2FF2E /* Icon */, EA1F265F28B945070033E859 /* RadioSwatch */, EA3362412892EF700071C351 /* Label */, + 44604AD529CE195300E62B51 /* Line */, EA89200B28B530F0006B9984 /* RadioBox */, EAF7F11428A1470D00B287F5 /* RadioButton */, EAC925852911C9DE00091998 /* TextFields */, @@ -798,6 +809,7 @@ EA985C7D297DAED300F2FF2E /* Primitive.swift in Sources */, EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, + 44604AD729CE196600E62B51 /* Line.swift in Sources */, EA5E3058295105A40082B959 /* Tilelet.swift in Sources */, EA5E304E294CC7F00082B959 /* VDSColor.swift in Sources */, EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */, diff --git a/VDS/Components/Line/Line.swift b/VDS/Components/Line/Line.swift new file mode 100644 index 00000000..4ffd5b4f --- /dev/null +++ b/VDS/Components/Line/Line.swift @@ -0,0 +1,67 @@ +// +// Line.swift +// VDS +// +// Created by Nadigadda, Sumanth on 24/03/23. +// + +import Foundation +import UIKit +import VDSColorTokens + +@objc(VDSLine) +public class Line: View { + + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum Style: String, CaseIterable { + case primary, secondary + } + + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + open var lineView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + open var style: Style = .primary { didSet { didChange() } } + + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + + open override func setup() { + super.setup() + + addSubview(lineView) + lineView.height(1) + + lineView + .pinLeading() + .pinTrailing() + } + + open override func reset() { + super.reset() + style = .primary + } + + //-------------------------------------------------- + // MARK: - Configuration + //-------------------------------------------------- + private var lineViewColorConfig: AnyColorable = { + let config = KeyedColorConfiguration(keyPath: \.style) + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forKey: .primary) + config.setSurfaceColors(VDSColor.elementsLowContrastOnLight, VDSColor.elementsLowContrastOnDark, forKey: .secondary) + return config.eraseToAnyColorable() + }() + + //-------------------------------------------------- + // MARK: - State + //-------------------------------------------------- + open override func updateView() { + lineView.backgroundColor = lineViewColorConfig.getColor(self) + } +}