• Stars
    star
    166
  • Rank 223,408 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Playground to investigate third-party React UI Lib Architecture

A Playground to investigate a good third-party React UI Lib Architecture

My goal is to find an architecture which could be common ground a base for quality React UI libraries. A consistent theming/styling API would make the lives of many developers way more comfortable.

HELP/FEEDBACK/YOUR OPINION WANTED! :) Feel free to join the ongoing discussion here or open up a new issue.

How to setup & run

npm install
cd app
npm install
npm start

Basic Ideas

Self-contained

Make components self contained (no global UI lib dependencies) so you can import them and avoid importing the whole library e.g.

// import the whole lib and get Toggle
import { Toggle } from 'ui-lib';

// just import toggle without importing the whole library
import Toggle from 'ui-lib/Toggle';

react-themeable

Leverage react-themeable. It's a nice way of providing many styling classes to a single component. I believe establishing this as a convention would benefit the React community due the consistent API over many libs.

ClassName based

Component styles should be class based. It's more performant & responsive styling doesn't work with server-side rendering. I myself went down the inline-styles path in the past, but switched back to classes. A component using react-themeable could actually work with both (class-names & inline-styles), but I believe this is an unnecessary overhead. Your thoughts?

Ship without a theme

Ship without a global theme so people don't have to import the styling code. This might not be relevant to company internal or in general libraries that a opinionated about styling.

Global theming utility

Provide a simple & handy way to apply a global theme for all the imported components.

Global Theming

While react-themeable is super useful I believe having a way to set a default styling is a crucial feature for a UI library. Most of the time you will use the default theme specific to your product. This avoids adding a lot of theme props through the whole application.

Factory Pattern

https://github.com/nikgraf/future-react-ui/tree/master/ui-lib/Factory

In this version we assume there is a package which includes a completely unstyled version of the UI kits while there is a second one which takes all the needed components and return themed components buy leveraging a factory function.

/**
 * Returns a the provided component as themed component.
 *
 * Note: defaultProps could be useful for default special behavioural in
 * different ui libraries.
 */
export default (Component, theme, defaultProps) => (props) => {
  return <Component {...defaultProps} theme={theme} {...props} />;
};

For example these UI

Not themed kits & components

  • material-ui-core (unstyled kit)
  • belle-core (unstyled kit)
  • elemental-core (unstyled kit)
  • react-toolbox-core (unstyled kit)
  • react-select (unstyled component)
  • react-autocomplete (unstyled component)
  • react-modal (unstyled component)

Themed UI kits

  • material-ui (themed with material ui style and based on material-ui-core)
  • belle (themed with belle style and based on belle-core)
  • belle-flat (themed with a flat theme and based on belle-core)
  • elemental (themed with the elemental theme and based on elemental-core)
  • react-toolbox (themed with the material theme and based on react-toolbox-core)
  • your-product-ui-lib (themed with your company style and based on belle-core[Toggle, Rating] & react-select & react-modal)
  • your-friends-product-ui-lib (themed with their company style and based on react-select & react-modal & react-autocomplete)

Usage:

import Hint from 'elemental/Hint';

const customTheme = {
  questionMark: 'custom-class-for-question-mark-gold',
  visibleContent: 'custom-class-visible-content',
};

export default (props) => {
  return (
    <div>
      {/* Globally theme component */}
      <Hint />
      {/* Overwriting the theme locally for this case */}
      <Hint theme={theme}/>
    </div>
  );
};

Other Global Theming Patterns

other patterns can be found here: https://github.com/nikgraf/future-react-ui/blob/master/global-theming.md

Temporary Conclusion

While the Theme component based idea is pretty powerful the issues make me not like it as a default. For some time I was convinced that Module export or Static property would be one of the winners. Right now I'm pretty convinced the Factory Pattern is the clear winner. It is super flexible and allows people to create their own company UI kits. They can easily provide their own styling as well as set other props as default suited to their needs. Another benefit is that you can easily get started with prototyping by using an already style version (e.g. belle-flat) and replace it later with your custom product style.

If you have some ideas/feedback please reach out to me and let's discuss. (Github Issues might be best, but Twitter, Email, Skype, Hangout works as well)

License

MIT

More Repositories

1

belle

Configurable React Components with great UX
JavaScript
2,510
star
2

awesome-draft-js

Awesome list of Draft.js resources
2,482
star
3

react-hooks

Collection of React Hooks
JavaScript
1,109
star
4

webvr-experiments

A collection of React VR & A-Frame experiments
JavaScript
680
star
5

awesome-react-360

Awesome list of React VR resources
515
star
6

CarteJaune

A React Native/Redux (+Saga) app to keep track of your vaccinations.
JavaScript
209
star
7

graphiql-spark

Demo a GraphQL schema without a GraphQL endpoint
TypeScript
83
star
8

react-reduce-stress

The name says it all
TypeScript
56
star
9

graphql-apollo-client-course

JavaScript
54
star
10

2020-05-react-advanced

TypeScript
48
star
11

2020-06-react-advanced

TypeScript
43
star
12

vienna-guide

A simple City Guide for Vienna built with Reason & React
OCaml
28
star
13

serverless-framework-course

JavaScript
22
star
14

exploring-angular.dart

Exploring Angular.dart while pairing with Edi
19
star
15

2023-react-advanced

TypeScript
18
star
16

webassembly-rust-course

Rust
16
star
17

2019-10-reason-workshop

React Advanced Reason Workshop
JavaScript
13
star
18

2019-react-finland-workshop

JavaScript
12
star
19

react-vr-course

Build Virtual Reality Experiences Using React VR
JavaScript
12
star
20

revery-memory-dojo

OCaml
12
star
21

vimfiles

Vimfiles for mainly Python/Javascript/Ruby Programming
Vim Script
10
star
22

reason-apollo-hooks

OCaml
10
star
23

2022-09-react-advanced

TypeScript
10
star
24

design-graphql-schemas-workshop

JavaScript
8
star
25

ar-app

AR App using React & ViewAR SDK
JavaScript
8
star
26

designing-graphql-schemas-course

JavaScript
8
star
27

reasonconf-workshop

Feedback form: https://docs.google.com/forms/d/e/1FAIpQLSduti27Gold0T3WDtSe04Hi3V-yaBG0ChqAbS-t3-qoe4qsbA/viewform
C++
8
star
28

2020-03-graphql-schema-design

JavaScript
7
star
29

upleveled-lessons

JavaScript
7
star
30

2022-06-react-advanced

TypeScript
6
star
31

gae-path

Small Helper to find your App Engine SDK Path
6
star
32

2020-03-graphql-errors-and-security

JavaScript
5
star
33

redux-universal-app

JavaScript
5
star
34

revery-memory

OCaml
5
star
35

brunch-with-backbone-relational

An example how to use brunch with backbone-relational.js
JavaScript
4
star
36

js-codemod

A collection of codemods
JavaScript
4
star
37

2019-11-graphql-beginner-workshop

JavaScript
4
star
38

reason-react-examples

OCaml
4
star
39

reason-workshop-2

OCaml
4
star
40

workshop

JavaScript
4
star
41

2019-11-react-beginner-workshop

JavaScript
3
star
42

datepicker-polymer-dart-example

Demonstration how to wrap a jQuery UI Widget inside a Polymer.dart component
Dart
3
star
43

2020-01-graphql-workshop

TypeScript
3
star
44

2023-02-react-all-the-things-workshop

TypeScript
2
star
45

plugin-architecture-prototype

JavaScript
2
star
46

workshop-examples

Set of simple examples for my workshops
JavaScript
2
star
47

nesting-components

Example to point our my issue nesting components in packages
Dart
2
star
48

my-first-ai

JavaScript
2
star
49

2019-05-reason-workshop

React Europe Reason Workshop
C++
2
star
50

serenity-macos-test

Objective-C
1
star
51

2019-11-redux-workshop

JavaScript
1
star
52

belle-playground

Playground for Belle
1
star
53

sam-workshop

JavaScript
1
star
54

alarm

A small example app using Dart's polymer package
Dart
1
star
55

String

Exploring how Belt's String implementation could look like
1
star
56

upleveled-exercise

JavaScript
1
star
57

server-experiment

JavaScript
1
star
58

jest-bug-example

JavaScript
1
star
59

js-template-comparison

This project contains different implementations of various JavaScript template engines.
CoffeeScript
1
star
60

router-6

1
star
61

cryptography-benchmark

TypeScript
1
star
62

2024-react-workshop

TypeScript
1
star