Created
March 1, 2023 01:15
-
-
Save joemasilotti/4d78c97931f6b8f51e21c3ee3ef33424 to your computer and use it in GitHub Desktop.
An idea to make interaction with design constants more natural
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ExampleView: View { | |
var body: some View { | |
VStack(spacing: .default) { | |
HStack(spacing: .xl) { | |
Text("Is this crazy?") | |
.font(.system(size: .lg, weight: .semibold)) | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension Font { | |
enum Size: CGFloat { | |
case xs = 12 | |
case sm = 14 | |
case `default` = 16 | |
case lg = 18 | |
case xl = 20 | |
case xl2 = 24 | |
case xl3 = 30 | |
case xl4 = 36 | |
case xl5 = 48 | |
} | |
} | |
extension Font { | |
static func system(size: Size, weight: Font.Weight? = nil) -> Font { | |
Font.system(size: size.rawValue, weight: weight) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public enum Spacing: CGFloat { | |
case xs = 4 | |
case sm = 8 | |
case `default` = 16 | |
case lg = 24 | |
case xl = 32 | |
} | |
extension View { | |
func padding(_ edges: Edge.Set = .all, _ spacing: Spacing) -> some View { | |
self.padding(edges, spacing.rawValue) | |
} | |
} | |
extension VStack { | |
@inlinable init(alignment: HorizontalAlignment = .center, spacing: Spacing = Spacing.default, @ViewBuilder content: () -> Content) { | |
self.init(alignment: alignment, spacing: spacing.rawValue, content: content) | |
} | |
} | |
extension HStack { | |
@inlinable init(alignment: VerticalAlignment = .center, spacing: Spacing = Spacing.default, @ViewBuilder content: () -> Content) { | |
self.init(alignment: alignment, spacing: spacing.rawValue, content: content) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment