Skip to content

Commit

Permalink
Clean up, document and prepare for 1.0 release (#42)
Browse files Browse the repository at this point in the history
* remove stateful view and view+if helpers, we're going to move them into a different utils library and keep nice components nice and simple

* save pointing a bunch of polish

* clean up documentation for lots more files

* finish up updating documentation

* shadowStyle -> NiceShadowStyle

* fix up readme a little

* fix needing to declare color

* update changelog

* undo change from niceFontStyle -> fontStyle, shouldn't be needed

* add copyright notice to all file headers
  • Loading branch information
brendanlensink authored Nov 24, 2022
1 parent 2297d34 commit d83b84f
Show file tree
Hide file tree
Showing 51 changed files with 1,189 additions and 738 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0]
- Lots of prep for initial public release!
- Added a bunch of documentation, comments and clarification.
- Removed some unused, or outdated components that have SwiftUI equivalents now.
- Renamed a handful of components and helpers to be more clear or avoid potential collisions.

## [0.6.0]
- Removed stateful view and view+if helpers, to be moved into a separate utils library.

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome!

Our project is small, so we're happy to receive feedback and bug reports via Github issues. @apike or @brendanlensink will work to triage and respond. You can also email us, [email protected].
Our project is small, so we're happy to receive feedback and bug reports via Github issues. @brendanlensink will work to triage and respond. You can also email us, [email protected].

If you'd like to submit a pull request that doesn't fix something there's already an open issue for, it's probably best to start with filing an issue about what change you'd like to make.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Steamclock Software
Copyright (c) 2022 Steamclock Software

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
C614E74126E12DAB00F7F87C /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
C628F0D125C4A08B001331AB /* NotoSerif-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSerif-Bold.ttf"; sourceTree = "<group>"; };
C628F0D225C4A08B001331AB /* NotoSerif-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSerif-Regular.ttf"; sourceTree = "<group>"; };
C65289F226CF0DFF009D486B /* StatefulExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatefulExampleView.swift; sourceTree = "<group>"; };
C671309A25C4948800F75E44 /* NiceComponentsExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NiceComponentsExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
C671309D25C4948800F75E44 /* NiceComponentsExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NiceComponentsExampleApp.swift; sourceTree = "<group>"; };
C671309F25C4948800F75E44 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -111,7 +110,6 @@
children = (
C6CD255725D6F01C008026D5 /* AllComponentsView.swift */,
C6CD255C25D6F0B1008026D5 /* SampleSignInView.swift */,
C65289F226CF0DFF009D486B /* StatefulExampleView.swift */,
D204536F28860ABC00174C13 /* NiceButtonExampleView.swift */,
);
path = View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// ContentView.swift
// NiceComponentsExample
//
// Created by Brendan on 2021-01-29.
// Created by Brendan on 2021-02-12.
// Copyright © 2022 Steamclock Software. All rights reserved.
//

import NiceComponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// NiceComponentsExampleApp.swift
// NiceComponentsExample
//
// Created by Brendan on 2021-01-29.
// Created by Brendan on 2021-02-12.
// Copyright © 2022 Steamclock Software. All rights reserved.
//

import NiceComponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import SwiftUI
enum Theme {
static var config: Config {
var newConfig = Config()
newConfig.primaryButtonStyle = NiceComponents.NiceButtonStyle(
newConfig.primaryButtonStyle = NiceButtonStyle(
surfaceColor: Color.orange,
onSurfaceColor: .black,
border: .capsule(borderWidth: 1, borderColor: .clear)
onSurfaceColor: Color.black,
border: .capsule(color: .clear, width: 1)
)
newConfig.secondaryButtonStyle = NiceComponents.NiceButtonStyle(
newConfig.secondaryButtonStyle = NiceButtonStyle(
surfaceColor: Color.yellow,
onSurfaceColor: .black,
border: .rounded(radius: 12, borderWidth: 1.5, borderColor: .black)
onSurfaceColor: Color.black,
border: .rounded(color: .black, cornerRadius: 12, width: 1.5)
)

return newConfig
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//
// AllComponentsView.swift
//
// NiceComponentsExample
//
// Created by Brendan on 2021-02-12.
// Copyright © 2022 Steamclock Software. All rights reserved.
//

import NiceComponents
Expand All @@ -25,14 +26,14 @@ struct AllComponentsView: View {
}
}

ThemedDivider()
NiceDivider()

VStack(alignment: .leading, spacing: 2) {
BodyText("Body Text")
DetailText("Detail Text")
}

ThemedDivider()
NiceDivider()

VStack(alignment: .leading, spacing: 2) {
PrimaryButton("Primary Button") { }
Expand All @@ -41,18 +42,10 @@ struct AllComponentsView: View {
DestructiveButton("Destructive Button") { }
}

ThemedDivider()
NiceDivider()

HStack {
Spacer()

LoadingView()

Spacer()
}

ResizableImage(URL(string: "https://placekitten.com/200/300"), width: 200, height: 300)
NiceImage(URL(string: "https://placekitten.com/200/300"), width: 200, height: 300)
}
}.padding(Layout.Spacing.standard)
}.padding(NiceSpacing.standard)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//
// NiceButtonExampleView.swift
// NiceComponentsExample
//
// Created by Alejandro Zielinsky on 2022-07-18.
// Created by Brendan on 2021-02-12.
// Copyright © 2022 Steamclock Software. All rights reserved.
//

import NiceComponents
Expand All @@ -17,34 +19,34 @@ struct NiceButtonExampleView: View {
PrimaryButton("Primary") {
print("Tapped")
}.withRightImage(
ResizableImage.init(systemIcon: "heart.fill", width: 14, height: 14, tintColor: .red)
NiceImage(systemIcon: "heart.fill", width: 14, height: 14, tintColor: .red)
)

PrimaryButton("Bigger Primary", height: 56) { }

PrimaryButton("Disabled Primary", disabled: true) { }
PrimaryButton("Inactive Primary", inactive: true) { }

PrimaryButton(
"Like Button",
surfaceColor: .white,
border: .rounded(
radius: 4,
borderWidth: 1.5,
borderColor: .black
color: .black,
cornerRadius: 4,
width: 1.5
)
) { }.withRightImage(
ResizableImage.init(systemIcon: "heart.fill", width: 14, height: 14, tintColor: .red)
NiceImage(systemIcon: "heart.fill", width: 14, height: 14, tintColor: .red)
)

SecondaryButton("Left Image Button") { }.withLeftImage(
ResizableImage.init(systemIcon: "pencil", width: 14, height: 14, tintColor: .black)
NiceImage(systemIcon: "pencil", width: 14, height: 14, tintColor: .black)
)

BorderlessButton("Borderless Button") { }

BorderlessButton("Stroked Button", border: .stroke(strokeStyle: StrokeStyle(lineWidth: 1.5, lineCap: .round, lineJoin: .round, dash: [8]))) { }
}
}.padding(Layout.Spacing.standard)
}.padding(NiceSpacing.standard)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Nice Button Examples")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// NiceComponentsExample
//
// Created by Brendan on 2021-02-12.
// Copyright © 2022 Steamclock Software. All rights reserved.
//

import NiceComponents
Expand All @@ -13,7 +14,7 @@ public struct SampleSignInView: View {
@State private var passwordField: String = ""

public var body: some View {
VStack(alignment: .leading, spacing: Layout.Spacing.standard) {
VStack(alignment: .leading, spacing: NiceSpacing.standard) {
ScreenTitle("Sign In")

DetailText("Email")
Expand All @@ -27,6 +28,6 @@ public struct SampleSignInView: View {

SecondaryButton("Create an Account") {}
Spacer()
}.padding(Layout.Spacing.standard)
}.padding(NiceSpacing.standard)
}
}
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
"state": {
"branch": null,
"revision": "44e891bdb61426a95e31492a67c7c0dfad1f87c5",
"version": "7.4.1"
}
}
]
},
"version": 1
}
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Nice Components
![Nice Components](nice_components.png)

A simple library with some nice looking SwiftUI components to get your next project started 🚀

Expand All @@ -12,14 +12,20 @@ Help jump start your prototypes with some sensible default components, then come

You can clone and run the example project to see examples of all the default components, plus a little sample of a more customized sign in screen.

### Straight out of the Box
### Straight Out of the Box

When you're just starting out with your project, you should be able to get some reasonable results just dropping in our components straight out of the box.

```swift
import NiceComponents

struct DemoView: View {
var body: some View {
ScreenTitle("I'm a nice big title!")

PrimaryButton("And I'm a nice little button") {
doTheThing()
}
}
}

Expand All @@ -31,7 +37,7 @@ Once you're ready to start putting your own touch on components, you've got a co

#### Setting a Global Config at Startup

If you'd like to change _all_ instances of a component, we recommend creating a custom config that you can set when your app first starts. Note that you once you've set this config, you'll be unable to update it.
If you'd like to change _all_ instances of a component, we recommend creating a custom config that you can set when your app first starts. Note that you once you've set this config once, you'll be unable to update it.


In the case of multiple customizations applying to the same component, the _most specific_ one will take precedence.
Expand All @@ -51,7 +57,6 @@ import NiceComponents
}
```


#### Extending an Existing Component

```swift
Expand All @@ -62,9 +67,9 @@ public struct CustomPrimaryButton: View {
var body: some View {
PrimaryButton(
text,
style: NiceComponents.ButtonStyle(
textStyle: Config.current.typeTheme.body1,
surfaceColor: Color.red,
style: NiceButtonStyle(
fontStyle: FontStyle(size: 16),
surfaceColor: .red,
onSurfaceColor: .black
)
onClick: onClick
Expand All @@ -82,9 +87,9 @@ var body: some View {
PrimaryButton(
"Tap me!",
style: NiceComponents.ButtonStyle(
textStyle: Config.current.typeTheme.body1,
surfaceColor: Color.red,
onSurfaceColor: .black
fontStyle: FontStyle(size: 16),
surfaceColor: .red,
onSurfaceColor: .black
)
) {
print("I've been tapped!")
Expand Down Expand Up @@ -128,22 +133,22 @@ import NiceComponents

#### Setting a Custom Font

Just like how you can set a `colorTheme`, you can also set a `typeTheme` that defines the default font, size and weight for all components.
Just like how you can set a `colorTheme`, you can also set a `fontTheme` that defines the default font, size and weight for all components.

| Component | Type Name |
| ------------- | ------ |
| Primary Button | button |
| Secondary Button | button |
| Inactive Button | button |
| Destructive Button | button |
| Body Text | body1 |
| Detail Text | body1 |
| Body Text | body |
| Detail Text | detail |

```swift
var newConfig = Config()
newConfig.primaryButtonStyle.textStyle = TypeTheme.Text(
name: "Comic Sans MS",
size: 16,
newConfig.primaryButtonStyle.fontStyle = FontStyle(
"Comic Sans MS",
size: 16,
weight: .semibold
)
Config.current = newConfig
Expand Down
26 changes: 19 additions & 7 deletions Sources/NiceComponents/Button/BorderlessButton.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
//
// BorderlessButton.swift
//
// NiceComponents
//
// Created by Brendan on 2021-07-13.
// Copyright © 2022 Steamclock Software. All rights reserved.
//

import SwiftUI

/// A themed button with no border.
public struct BorderlessButton: NiceButton {
public let text: String
public let inactive: Bool
public let style: NiceButtonStyle
public let action: () -> Void
public let inactive: Bool

public var leftImage: ResizableImage?
public var rightImage: ResizableImage?
public var rightImageOffset: CGFloat?
public var leftImage: NiceImage?
public var rightImage: NiceImage?

public var leftImageOffset: CGFloat?
public var rightImageOffset: CGFloat?

public static var defaultStyle: NiceButtonStyle {
Config.current.borderlessButtonStyle
}

/**
* Create a new borderless button.
*
* - Parameters:
* - text: The body text of the button.
* - inactive: Whether the button should be interactable or not. Default is `false`.
* - style: The styling to apply to the button. Defaults to the current `borderlessButtonStyle` in your config.
* - action: The action to be performed when the button is tapped.
*/
public init(
_ text: String,
inactive: Bool = false,
style: NiceButtonStyle? = nil,
disabled: Bool = false,
action: @escaping () -> Void
) {
self.text = text
self.inactive = inactive
self.style = style ?? Config.current.borderlessButtonStyle
self.inactive = disabled
self.action = action
}
}
Loading

0 comments on commit d83b84f

Please sign in to comment.