-
Notifications
You must be signed in to change notification settings - Fork 480
Extract design system into HADesignSystem SPM package #5007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bgoncal
wants to merge
6
commits into
main
Choose a base branch
from
bgoncal/design-system-package
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc1239e
Extract design system into HADesignSystem SPM package
bgoncal 55db2b7
Address review: make color division explicit, fix package tests
bgoncal a4130ef
Merge branch 'main' into bgoncal/design-system-package
bgoncal cb12aee
Fix build: define semantic colors on ShapeStyle where Self == Color
bgoncal 59ba1fd
Add components library explorer to HADesignSystem + agent guidance
bgoncal 1ab4fa2
Merge remote-tracking branch 'origin/main' into bgoncal/design-system…
bgoncal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // swift-tools-version:5.9 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "HADesignSystem", | ||
| platforms: [ | ||
| .iOS(.v16), | ||
| .watchOS(.v9), | ||
| ], | ||
| products: [ | ||
| .library(name: "HADesignSystem", targets: ["HADesignSystem"]), | ||
| ], | ||
| dependencies: [ | ||
| .package(url: "https://github.com/SFSafeSymbols/SFSafeSymbols", .upToNextMajor(from: "5.3.0")), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "HADesignSystem", | ||
| dependencies: ["SFSafeSymbols"], | ||
| path: "Sources" | ||
| ), | ||
| .testTarget( | ||
| name: "HADesignSystemTests", | ||
| dependencies: ["HADesignSystem"], | ||
| path: "Tests" | ||
| ), | ||
| ] | ||
| ) | ||
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions
57
Sources/HADesignSystem/Sources/Colors/Color+Semantic.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import SwiftUI | ||
| #if canImport(UIKit) | ||
| import UIKit | ||
| #endif | ||
|
|
||
| public extension ShapeStyle where Self == Color { | ||
| static var haPrimary: Color { srgb(0x00, 0x9A, 0xC7, opacity: 1) } | ||
|
|
||
| static var track: Color { displayP3(0, 0, 0, opacity: 0.12) } | ||
|
|
||
| static var onSurface: Color { | ||
| adaptive( | ||
| light: srgb(0x1A, 0x1C, 0x1E, opacity: 0.16), | ||
| dark: srgb(0xE2, 0xE2, 0xE5, opacity: 0.16) | ||
| ) | ||
| } | ||
|
|
||
| static var tileBorder: Color { | ||
| adaptive( | ||
| light: displayP3(0xE0, 0xE0, 0xE0, opacity: 1), | ||
| dark: displayP3(0x34, 0x37, 0x37, opacity: 1) | ||
| ) | ||
| } | ||
|
|
||
| static var haColorBorderPrimaryQuiet: Color { | ||
| adaptive( | ||
| light: srgb(0xB9, 0xE6, 0xFC, opacity: 1), | ||
| dark: srgb(0x00, 0x9A, 0xC7, opacity: 1) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private func srgb(_ red: Double, _ green: Double, _ blue: Double, opacity: Double) -> Color { | ||
| Color(.sRGB, red: red / 255.0, green: green / 255.0, blue: blue / 255.0, opacity: opacity) | ||
| } | ||
|
|
||
| private func displayP3(_ red: Double, _ green: Double, _ blue: Double, opacity: Double) -> Color { | ||
| Color(.displayP3, red: red / 255.0, green: green / 255.0, blue: blue / 255.0, opacity: opacity) | ||
| } | ||
|
|
||
| private func adaptive(light: Color, dark: Color) -> Color { | ||
| #if os(watchOS) | ||
| return dark | ||
| #elseif canImport(UIKit) | ||
| return Color(UIColor { traits in | ||
| traits.userInterfaceStyle == .dark ? UIColor(dark) : UIColor(light) | ||
| }) | ||
| #else | ||
| return light | ||
| #endif | ||
| } | ||
|
|
||
| #if canImport(UIKit) | ||
| public extension UIColor { | ||
| static let haPrimary = UIColor(red: 0x00 / 255.0, green: 0x9A / 255.0, blue: 0xC7 / 255.0, alpha: 1) | ||
| } | ||
| #endif |
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
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
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
File renamed without changes.
File renamed without changes.
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
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
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
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
Sources/HADesignSystem/Sources/Gallery/BottomSheetGalleryDemo.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #if !os(watchOS) | ||
| import SwiftUI | ||
|
|
||
| struct BottomSheetGalleryDemo: View { | ||
| @State private var state: AppleLikeBottomSheetViewState? | ||
| @State private var isPresented = false | ||
|
|
||
| var body: some View { | ||
| Button("Present bottom sheet") { | ||
| isPresented = true | ||
| } | ||
| .buttonStyle(.secondaryButton) | ||
| .fullScreenCover(isPresented: $isPresented) { | ||
| AppleLikeBottomSheet( | ||
| title: "Example sheet", | ||
| content: { | ||
| Text("This AppleLikeBottomSheet is rendered from the components library.") | ||
| .multilineTextAlignment(.center) | ||
| .foregroundStyle(.secondary) | ||
| }, | ||
| state: $state, | ||
| customDismiss: { isPresented = false } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| BottomSheetGalleryDemo() | ||
| } | ||
| #endif |
23 changes: 23 additions & 0 deletions
23
Sources/HADesignSystem/Sources/Gallery/ComponentCategory.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #if !os(watchOS) | ||
| import Foundation | ||
|
|
||
| public enum ComponentCategory: String, CaseIterable, Identifiable { | ||
| case buttons | ||
| case controls | ||
| case inputs | ||
| case containers | ||
| case indicators | ||
|
|
||
| public var id: String { rawValue } | ||
|
|
||
| public var title: String { | ||
| switch self { | ||
| case .buttons: "Buttons" | ||
| case .controls: "Controls" | ||
| case .inputs: "Inputs" | ||
| case .containers: "Containers" | ||
| case .indicators: "Indicators" | ||
| } | ||
| } | ||
| } | ||
| #endif |
33 changes: 33 additions & 0 deletions
33
Sources/HADesignSystem/Sources/Gallery/ComponentsLibraryView.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #if !os(watchOS) | ||
| import SwiftUI | ||
|
|
||
| public struct ComponentsLibraryView: View { | ||
| public init() {} | ||
|
|
||
| public var body: some View { | ||
| List { | ||
| ForEach(ComponentCategory.allCases) { category in | ||
| Section(category.title) { | ||
| ForEach(DesignSystemComponent.allCases.filter { $0.category == category }) { component in | ||
| VStack(alignment: .leading, spacing: DesignSystem.Spaces.one) { | ||
| Text(component.title) | ||
| .font(DesignSystem.Font.subheadline) | ||
| .foregroundStyle(.secondary) | ||
| component.preview | ||
| } | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .padding(.vertical, DesignSystem.Spaces.half) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| .navigationTitle("Components") | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| NavigationStack { | ||
| ComponentsLibraryView() | ||
| } | ||
| } | ||
| #endif |
86 changes: 86 additions & 0 deletions
86
Sources/HADesignSystem/Sources/Gallery/DesignSystemComponent.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #if !os(watchOS) | ||
| import SwiftUI | ||
|
|
||
| public enum DesignSystemComponent: String, CaseIterable, Identifiable { | ||
| case primaryButton | ||
| case secondaryButton | ||
| case outlinedButton | ||
| case neutralButton | ||
| case negativeButton | ||
| case secondaryNegativeButton | ||
| case criticalButton | ||
| case linkButton | ||
| case textButton | ||
| case closeButton | ||
| case sheetCloseButton | ||
| case textField | ||
| case card | ||
| case bottomSheet | ||
| case progressView | ||
| case pill | ||
|
|
||
| public var id: String { rawValue } | ||
|
|
||
| public var title: String { | ||
| switch self { | ||
| case .primaryButton: "Primary Button" | ||
| case .secondaryButton: "Secondary Button" | ||
| case .outlinedButton: "Outlined Button" | ||
| case .neutralButton: "Neutral Button" | ||
| case .negativeButton: "Negative Button" | ||
| case .secondaryNegativeButton: "Secondary Negative Button" | ||
| case .criticalButton: "Critical Button" | ||
| case .linkButton: "Link Button" | ||
| case .textButton: "Text Button" | ||
| case .closeButton: "Close Button" | ||
| case .sheetCloseButton: "Sheet Close Button" | ||
| case .textField: "Text Field" | ||
| case .card: "Card" | ||
| case .bottomSheet: "Bottom Sheet" | ||
| case .progressView: "Progress View" | ||
| case .pill: "Pill" | ||
| } | ||
| } | ||
|
|
||
| public var category: ComponentCategory { | ||
| switch self { | ||
| case .primaryButton, .secondaryButton, .outlinedButton, .neutralButton, .negativeButton, | ||
| .secondaryNegativeButton, .criticalButton, .linkButton, .textButton: | ||
| .buttons | ||
| case .closeButton, .sheetCloseButton: | ||
| .controls | ||
| case .textField: | ||
| .inputs | ||
| case .card, .bottomSheet: | ||
| .containers | ||
| case .progressView, .pill: | ||
| .indicators | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder public var preview: some View { | ||
| switch self { | ||
| case .primaryButton: Button("Primary") {}.buttonStyle(.primaryButton) | ||
| case .secondaryButton: Button("Secondary") {}.buttonStyle(.secondaryButton) | ||
| case .outlinedButton: Button("Outlined") {}.buttonStyle(.outlinedButton) | ||
| case .neutralButton: Button("Neutral") {}.buttonStyle(.neutralButton) | ||
| case .negativeButton: Button("Negative") {}.buttonStyle(.negativeButton) | ||
| case .secondaryNegativeButton: Button("Secondary Negative") {}.buttonStyle(.secondaryNegativeButton) | ||
| case .criticalButton: Button("Critical") {}.buttonStyle(.criticalButton) | ||
| case .linkButton: Button("Link") {}.buttonStyle(.linkButton) | ||
| case .textButton: Button("Text") {}.buttonStyle(.textButton) | ||
| case .closeButton: CloseButton {} | ||
| case .sheetCloseButton: SheetCloseButton {} | ||
| case .textField: HATextField(placeholder: "Placeholder", text: .constant("Example")) | ||
| case .card: CardView { Text("Card content").frame(maxWidth: .infinity, alignment: .leading) } | ||
| case .bottomSheet: BottomSheetGalleryDemo() | ||
| case .progressView: HAProgressView(style: .medium) | ||
| case .pill: | ||
| HStack(spacing: DesignSystem.Spaces.one) { | ||
| PillView(text: "Selected", selected: true) | ||
| PillView(text: "Normal", selected: false) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| #endif |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.