Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 80d12fd

Browse files
committed
Add icon
1 parent b488d9a commit 80d12fd

File tree

9 files changed

+141
-9
lines changed

9 files changed

+141
-9
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "checkmark circle (1).svg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "1.000",
9+
"green" : "1.000",
10+
"red" : "1.000"
11+
}
12+
},
13+
"idiom" : "universal"
14+
},
15+
{
16+
"appearances" : [
17+
{
18+
"appearance" : "luminosity",
19+
"value" : "dark"
20+
}
21+
],
22+
"color" : {
23+
"color-space" : "srgb",
24+
"components" : {
25+
"alpha" : "1.000",
26+
"blue" : "0x00",
27+
"green" : "0x00",
28+
"red" : "0x00"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}

samples/discovery/ios/ios/ComponentBoxUI/Sources/ComponentBoxUI/ComponentBoxUI.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ enum ComponentBoxUI {
4040
contentScale: componentbox.ContentScale?
4141
)
4242

43+
case Icon(
44+
id: String,
45+
name: String?,
46+
modifier: componentbox.Modifier?,
47+
alignment: componentbox.Alignment?,
48+
contentScale: componentbox.ContentScale?,
49+
color: componentbox.Color?
50+
)
51+
4352
case Row(
4453
id: String,
4554
components: [componentbox.Component]?,
@@ -68,6 +77,9 @@ enum ComponentBoxUI {
6877
case let .Image(id, name, url, contentDescription, modifier, alignment, contentScale):
6978
return AnyView(ComponentBoxUIImage(id: id, name: name, url: url, contentDescription: contentDescription, modifier: modifier, alignment: alignment, contentScale: contentScale))
7079

80+
case let .Icon(id, name, modifier, alignment, contentScale, color):
81+
return AnyView(ComponentBoxUIIcon(id: id, name: name, modifier: modifier, alignment: alignment, contentScale: contentScale, color: color))
82+
7183
case let .Row(id, components, modifier, horizontalArrangement, verticalAlignment, action, isLazy):
7284
return AnyView(ComponentBoxUIRow(id: id, components: components, modifier: modifier, horizontalArrangement: horizontalArrangement, verticalAlignment: verticalAlignment, action: action, isLazy: isLazy))
7385

samples/discovery/ios/ios/ComponentBoxUI/Sources/ComponentBoxUI/components/Button.swift

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,36 @@ struct ComponentBoxUIButton: View, Identifiable {
1616
let isEnabled: Bool?
1717
let action: String?
1818
let variant: String?
19-
19+
20+
func log() {
21+
print(components?.count ?? "NO components")
22+
}
2023

2124
var body: some View {
22-
SwiftUI.Button {
25+
26+
SwiftUI.Button(action: {}, label: {
27+
28+
if (self.components != nil) {
29+
ForEach(self.components!, id: \.self) { component in
30+
component.inflate()
31+
}
32+
}}).buttonStyle(PrimaryButton(fillMaxWidth: modifier?.fillMaxWidth as? Bool ?? false))
33+
}
34+
}
2335

24-
} label: {
2536

26-
ForEach(self.components!, id: \.self) { component in
27-
component.inflate()
2837

29-
}}.padding().frame(maxWidth: .infinity)
38+
@available(iOS 14.0, *)
39+
struct PrimaryButton: ButtonStyle {
40+
41+
let fillMaxWidth: Bool
42+
43+
func makeBody(configuration: Self.Configuration) -> some View {
44+
configuration.label
45+
.padding(12)
46+
.frame(maxWidth: fillMaxWidth ? .infinity : .none)
47+
.foregroundColor(Color.ui.onPrimary)
48+
.font(.sharpGroteskBook(withStyle: .title3, size: 16))
49+
.background(Color.ui.primary)
3050
}
3151
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Created by Matt Ramotar on 3/27/22.
3+
// Copyright (c) 2022 Dropbox, Inc. All rights reserved.
4+
//
5+
6+
import Foundation
7+
import SwiftUI
8+
import componentbox
9+
10+
@available(iOS 14.0, *)
11+
struct ComponentBoxUIIcon: View, Identifiable {
12+
let id: String
13+
let name: String?
14+
let modifier: componentbox.Modifier?
15+
let alignment: componentbox.Alignment?
16+
let contentScale: componentbox.ContentScale?
17+
let color: componentbox.Color?
18+
19+
func getForegroundColor() -> SwiftUI.Color {
20+
return color?.title != nil ? color!.title.ui() : "On background".ui()
21+
}
22+
23+
var body: some View {
24+
if (name != nil) {
25+
SwiftUI.Image(name!).renderingMode(.template).foregroundColor(getForegroundColor())
26+
}
27+
}
28+
}

samples/discovery/ios/ios/ComponentBoxUI/Sources/ComponentBoxUI/components/Text.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ struct ComponentBoxUIText: View, Identifiable {
1414
let text: String?
1515
let color: componentbox.Color?
1616
let textStyle: String?
17+
18+
func getColor() -> SwiftUI.Color {
19+
color != nil ? color!.title.ui() : textStyle == "button" ? Color.ui.onPrimary : Color.ui.onBackground
20+
}
1721

1822
var body: some View {
1923

2024
let isHeading = ["h1", "h2", "h3", "h4", "h5", "h6"].contains(self.textStyle)
21-
let color = color != nil ? color!.title.ui() : "On background".ui()
25+
let isButton = ["button"].contains(self.textStyle)
2226

2327
if (isHeading) {
24-
SwiftUI.Text(text ?? "").sharpGroteskBold(style: .title3, color: color)
28+
SwiftUI.Text(text ?? "").sharpGroteskBold(style: .title3, color: getColor())
29+
} else if (isButton) {
30+
SwiftUI.Text(text ?? "").sharpGroteskBold(style: .body, color: getColor())
2531
} else {
26-
SwiftUI.Text(text ?? "").atlasGrotesk(style: .body, weight: .regular, color: color)
32+
SwiftUI.Text(text ?? "").atlasGrotesk(style: .body, weight: .regular, color: getColor() )
2733
}
2834
}
2935
}

samples/discovery/ios/ios/ComponentBoxUI/Sources/ComponentBoxUI/extensions/component.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public extension Component {
4646
let ui = ComponentBoxUI.Image(id: image.id, name: image.name, url: image.url, contentDescription: image.contentDescription, modifier: image.modifier, alignment: image.alignment, contentScale: image.contentScale)
4747
return AnyView(ui.inflate())
4848

49+
case let icon as Component.Vector:
50+
let ui = ComponentBoxUI.Icon(id: icon.id, name: icon.name, modifier: icon.modifier, alignment: icon.alignment, contentScale: icon.contentScale, color: icon.color)
51+
return AnyView(ui.inflate())
52+
4953
case let row as Component.Row:
5054
let ui = ComponentBoxUI.Row(
5155
id: row.id,

0 commit comments

Comments
 (0)