Giter VIP home page Giter VIP logo

nicecomponents's Introduction

NiceComponents

NiceComponents is a simple library with some nice looking SwiftUI components to get your next project started. 🚀

Jumpstart your prototypes with some sensible default components, then come back later and customize the look and feel of your app exactly how you want – all in one place.

Usage

Example Project

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, and demos of how to customize each component.

Prototyping

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

NiceComponents are made up of a couple fundamental pieces:

  • Components are the Views you'll construct and the bits that your users will see, like NiceButton or NiceText.
  • Styles are the set of colors, fonts, etc that describe a specific components, like a Primary button or some Detail text.
  • Themes are interfaces that describe a set of colors, fonts, etc needed to describe a component.
import NiceComponents

struct DemoView: View {
    var body: some View {
        NiceText("I'm a nice big title!", style: .screenTitle)
        
        NiceButton("And I'm a nice little button", style: .primary) {
            doTheThing()
        }
    }
}

We provide the following text and button styles to get you started:

Customizing Components

Once you're ready to start putting your own touch on components, you've got a couple options, based on how much you'd like to change.

Setting a Global Config at Startup

If you'd like to change all instances of a component, or change global variables like your ColorTheme or ColorStyle 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.

import NiceComponents

@main struct ExampleApp: App {
   init() {
        var newConfig = Config()
       
       newConfig.bodyTextStyle = NiceTextStyle(
           color: Color(hex: "FFA71A"),
           size: 16
       )
       Config.current = newConfig
   }
}

Extending an Existing Component

If you want to create a new component, or extend an existing one, all you need to do is add a new Style:

extension NiceTextStyle {
    static var bodyBold: NiceTextStyle {
        Config.current.bodyTextStyle
            .with(weight: .bold)
    }
}

Customizing a Single Instance of a Component

If you just need to change something for a one-off UI element, each Style comes with a handy mutator function to allow you to customize it.

    NiceText(
        "Customize it with `with`", 
        style: .body.with(weight: .semibold)
    )

    NiceText(
        "Customize it with `with`", 
        style: NiceTextStyle(
            color: Color(hex: "FFA71A")
            with: .body,
            font: "Impact",
            size: 20
        )
    )
}

Setting a Color Palette

In addition to being able to customize or extend each of the pre-set styles provided by NiceComponents, we provide two ways to change your color palette.

You can set a ColorTheme and/or ColorStyle when you create your custom Config by passing them into the constructor.

ColorTheme

Of the two options, ColorTheme is the more general option, allowing you to change colors that are applied to a variety of different components and places at once. The naming and usage here is indluenced heavily by the wonderful Material Design palettes.

ColorTheme takes the colors declared in your asset catalog and gives them a semantic meaning not tied to specific UI elements.

We recommend declaring your colors in an Asset Catalog and pulling them in from there to make supporting light and dark mode a breeze.

ColorStyle

ColorStyle describes the colors applied to all components by default semantically, changes here will take precedence over changes made to a ColorTheme, though will default to your ColorTheme if not specified.

In most cases, you'll probably be fine just changing your ColorTheme and allowing those changes to cascade into the different UI elements, but if you need a little more control over what colors things like specific buttons are, this is your place to do it.

Customizing your TextStyle

If you want to globally change the font in your app, you can change the Config's textStyle, and all the preset styles will respect your new styling.

Note that only bodyText will use the default textStyle size and weight.

Installation

NiceComponents is available through Swift Package Manager. To install it, follow these steps:

  1. In Xcode, click File, then Swift Package Manager, then Add Package Dependency
  2. Choose your project
  3. Enter this URL in the search bar [email protected]:steamclock/niceComponents.git

Building with CI

Since NiceComponents uses some macros to automatically generate initializers for some classes, you may need to add -skipMacroValidation to your xcodebuild call to make it work.

Migrating from Nice Components 1.0

Given the size and scope of changes from Nice Components 1 to 2, migrating may be a somewhat big process. The good news, a lot of that work can be done with good ol' Find and Replace.

To migrate, you'll want to:

  1. Change any references to Components like PrimaryButton, BodyText, etc to use NiceText and NiceButton
  2. Change any custom Components you've created into custom styles, extending either NiceTextStyle or NiceButtonStyle
  3. Update your Config to use the new NiceButtonStyle and NiceTextStyles.

nicecomponents's People

Contributors

brendanlensink avatar azielinsky95 avatar mauriceschenk avatar apike avatar amyoulton avatar

Stargazers

Christian Fleschhut avatar Jon Hjelle avatar  avatar Dilantha Nanayakkara avatar Gopal Sharma avatar Bryan Clark avatar  avatar David Penaskovic avatar Hiroki Nagasawa avatar Sam Lu avatar Brandon Evans avatar Narcis avatar Patrick Lafleur avatar irdz avatar

Watchers

Nigel Brooke avatar Felipe Peña avatar Jenn Cooper avatar Phileo avatar James Cloos avatar  avatar Shayla Sawchenko avatar Corbin Thomas avatar  avatar  avatar

nicecomponents's Issues

Split ResizableImage into two components

Right now ResizableImage handles async and sync images which is great, however, ideally, the async version should allow for a generic placeholder view as well as a generic error view. Adding this functionality to the current component would cause generic constraint errors in any places that define it as a required property. Therefore, it's best we split this component into a synchronous and asynchronous version.

Proposal: NiceImage & AsyncNiceImage to fit with the naming convention of the Nice components in this lib

Consider adding partial overlay view

ios 16 will give us an improved version of this, but it might be handy to add an ios 15 friendly version using .overlay as we're probably stuck with 15 for a while

Investigate Figma plugins

  1. Build a Steamclock Components plugin
  2. Can Steamclock Components be copied into a new project as local components
  3. Export local components into "Nice Components" SwiftUI config that can be pasted into the code
  4. Automate step 3 (ie. build a connection between Figma and XCode)

Do Documentation Pass

  1. Update the example library documentation to explain more about setup and config
  2. Review config class and make clarity improvements

Improve activity indicator

The way the constructor works is really weird for passing in text, and we should be allowing users to set the style themselves.

Also ActivityIndicator needs a public init

Finish README

Build README up to be usable as an open source lib

Improve ResizableImage

Right now there is no way to change the content mode and the default should be .aspectFit instead of scaleToFill. There's also a bug where if a async image fails to load, we show the spinner indefinitely. We should be handling error cases and allowing for a fallback image

Add image carousel

I remember we built a fairly nice image carousel in one of our client apps, and I think we could include that in this library.

Specifying style can be a bit wordy

For example:
DetailText(equity, style: Config.current.detailTextStyle.with(color: .platinum))

It would be nice to find a way to write something like:
DetailText(equity, style: .color(.platinum))

Where the default behaviour is to use Config.current plus the corresponding style, and we only specify what's different; in this case just the color.

Add AttributedString extension for Text components

Helper method: https://github.com/steamclock/ridwell-ios/blob/main/ridwell-ios/Helper/Text%2BAttributedString.swift

Add the above extension to the library along with initializers for our Text Components that take in an NSAttributedString.

This allows us to have flexibility when styling Text without needing to add every type of config option manually.
Also it's a great helper in general to avoid needing to manually concatenate Text components with different modifiers.

From Slack discussion

Improve Buttons

Just like NiceText implements functionality for all Text components we should have a NiceButton that does the same for buttons. We should also find a way to improve styling and height adjustment

Improve StatefulView

  • The order that you pass in params is weird, IMO it should be load state, then all the views
  • It would be nice if you can pass in some View rather than AnyView
  • The loading indicator doesn't size properly all the time, it should have some vertical padding by default

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.