Skip to content

Commit

Permalink
Merge pull request #35 from payan-app/buttons-style
Browse files Browse the repository at this point in the history
refactor: update button styles
  • Loading branch information
juandahurt authored Nov 7, 2022
2 parents d1ad696 + 65d1bc6 commit 6c903d3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
36 changes: 25 additions & 11 deletions PuraceDemo/PuraceDemo/Examples/Basic/ButtonExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,30 @@ import Purace

struct ButtonExample: View {
var body: some View {
Text("`PuraceButtonView('title', type: .loud)`")
PuraceButtonView("Font size: 12", fontSize: 12)
PuraceButtonView("Font size: 14", fontSize: 14)
PuraceButtonView("Font size: 16", fontSize: 16)
.padding(.bottom)

Text("`PuraceButtonView('title', type: .quiet)`")
PuraceButtonView("Font size: 12", fontSize: 12, type: .quiet)
PuraceButtonView("Font size: 14", fontSize: 14, type: .quiet)
PuraceButtonView("Font size: 16", fontSize: 16, type: .quiet)
Spacer()
VStack(spacing: 0) {
VStack {
Text("`PuraceButtonView('title', type: .loud)`")
PuraceButtonView("Font size: 12", fontSize: 12)
PuraceButtonView("Font size: 14", fontSize: 14)
PuraceButtonView("Font size: 16", fontSize: 16)
.padding(.bottom)
}

VStack {
Text("`PuraceButtonView('title', type: .quiet)`")
PuraceButtonView("Font size: 12", fontSize: 12, type: .quiet)
PuraceButtonView("Font size: 14", fontSize: 14, type: .quiet)
PuraceButtonView("Font size: 16", fontSize: 16, type: .quiet)
.padding(.bottom)
}

VStack {
Text("`PuraceButtonView('title', type: .transparent)`")
PuraceButtonView("Font size: 12", fontSize: 12, type: .transparent)
PuraceButtonView("Font size: 14", fontSize: 14, type: .transparent)
PuraceButtonView("Font size: 16", fontSize: 16, type: .transparent)
Spacer()
}
}
}
}
3 changes: 2 additions & 1 deletion Sources/Purace/Views/Basic/Button/PuraceButtonType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import Foundation
import SwiftUI

public enum PuraceButtonType {
case loud, quiet, custom(Color, Color, Color) // 0: background, 1: on pressed, 2: text color
case loud, quiet, transparent
case custom(Color, Color, Color) // 0: background, 1: on pressed, 2: text color
}
19 changes: 11 additions & 8 deletions Sources/Purace/Views/Basic/Button/PuraceButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import Foundation
import SwiftUI

public struct PuraceButtonView: View {
@State var backgroundColor: Color = .blue
@State var isBeingPressed = false

let title: String
let fontSize: Int
let type: PuraceButtonType
Expand Down Expand Up @@ -39,9 +36,11 @@ struct PuraceButtonStyle: ButtonStyle {
private func getBackgroundColor() -> Color {
switch type {
case .loud:
return PuraceStyle.Color.G2
return PuraceStyle.Color.B2
case .quiet:
return .black.opacity(0.05)
return PuraceStyle.Color.B5
case .transparent:
return .white.opacity(0.01)
case .custom(let backgroundColor, _, _):
return backgroundColor
}
Expand All @@ -52,7 +51,9 @@ struct PuraceButtonStyle: ButtonStyle {
case .loud:
return .white
case .quiet:
return PuraceStyle.Color.G1
return PuraceStyle.Color.B1
case .transparent:
return PuraceStyle.Color.B1
case .custom(_, _, let textColor):
return textColor
}
Expand All @@ -61,9 +62,11 @@ struct PuraceButtonStyle: ButtonStyle {
private func getOnPressedBackgroundColor() -> Color {
switch type {
case .loud:
return PuraceStyle.Color.G1
return PuraceStyle.Color.B1
case .quiet:
return .black.opacity(0.15)
return PuraceStyle.Color.B4
case .transparent:
return PuraceStyle.Color.B5
case .custom(_, let onPressedColor, _):
return onPressedColor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public struct PuraceImageViewer: View {
topBar

TabView(selection: $currentIndex) {
ForEach(0..<numberOfImages) { index in
ForEach(0..<numberOfImages, id: \.self) { index in
PuraceImageView(url: urls[index])
.scaledToFit()
.tag(index)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Purace/Views/Complex/Story/PuraceStoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct PuraceStoryView: View {

var indicators: some View {
HStack(spacing: 3) {
ForEach(stories.indices) { index in
ForEach(stories.indices, id: \.self) { index in
Color.white.opacity(index <= currentIndex ? 0.8 : 0.3)
.cornerRadius(1)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Purace/Views/Complex/Tab/PuraceTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct PuraceTabView<T: View>: View {

func headers(in size: CGSize) -> some View {
HStack(spacing: 0) {
ForEach(0..<titles.count) { index in
ForEach(0..<titles.count, id: \.self) { index in
PuraceTextView(titles[index], fontSize: 12, textColor: selectedIndex == index ? PuraceStyle.Color.N1 : PuraceStyle.Color.N4, weight: selectedIndex == index ? .medium : .regular)
.frame(width: size.width / CGFloat(titles.count))
.background(Color.gray.opacity(0.001))
Expand Down Expand Up @@ -58,7 +58,7 @@ public struct PuraceTabView<T: View>: View {
headers(in: reader.size)
indicator(in: reader.size)
ZStack {
ForEach(0..<titles.count) { index in
ForEach(0..<titles.count, id: \.self) { index in
viewForIndex(index)
.opacity(index == selectedIndex ? 1 : 0)
}
Expand Down

0 comments on commit 6c903d3

Please sign in to comment.