Skip to content

Commit bf002ff

Browse files
committed
move the old theming ideas to another document to have concise read in the readme
1 parent 8053c79 commit bf002ff

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

README.md

+7-32
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,7 @@ Provide a simple & handy way to apply a global theme for all the imported compon
4848

4949
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.
5050

51-
#### Module export
52-
53-
https://github.com/nikgraf/future-react-ui/tree/master/ui-lib
54-
55-
In this version the defaultTheme is exported through a named module export. On line 9, 10, 11 you can see how the default theme is patched with custom classes. (https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L8) Since this is not so hand it might be useful to have utility function for each library to apply a theme.
56-
57-
#### Static property
58-
59-
https://github.com/nikgraf/future-react-ui/blob/master/ui-lib/StaticProperty/Hint.js
60-
61-
In this version the defaultTheme is attached to the component itself as static property. Compared to the 'Module export' this is a bit more flexible as you can overwrite the whole `theme` object in one go. See line 13-20 for usage. (https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L13)
62-
63-
#### Theme Component leveraging Context
64-
65-
https://github.com/nikgraf/future-react-ui/blob/master/ui-lib/Context/Hint.js
66-
67-
In this version we leverage context to build a `<Theme />` component that takes a theme as property and passes it down to all child components via React's context. A theme is still a simple JS object as can be seen on line 25-30. (https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L22). See how it's used here: https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L56. On one hand this approach is powerful, because you can apply different themes various nesting levels in the render tree.
68-
69-
```
70-
<Theme theme={baseTheme}>
71-
<Theme theme={headerTheme}>
72-
<Menu items=['Home', 'About'] />
73-
</Theme>
74-
<Hint isOpen>Basic open hint without styling.</Hint>
75-
</Theme>
76-
```
77-
78-
There is one obvious concern with this approach. There could be name-clashing between libraries that use the same key in the `theme` object. This could be solved by following a namespace convention like prefixing the keys with the npm package name.
79-
80-
#### Factory Pattern
51+
### Factory Pattern
8152

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

@@ -97,7 +68,7 @@ export default (Component, theme, defaultProps) => (props) => {
9768

9869
For example these UI
9970

100-
##### Not styled components
71+
#### Not themed kits & components
10172

10273
- belle-core (unstyled kit)
10374
- elemental-core (unstyled kit)
@@ -106,7 +77,7 @@ For example these UI
10677
- react-autocomplete (unstyled component)
10778
- react-modal (unstyled component)
10879

109-
##### Themed
80+
#### Themed UI kits
11081

11182
- belle (themed with belle style and based on belle-core)
11283
- belle-flat (themed with a flat theme and based on belle-core)
@@ -136,6 +107,10 @@ export default (props) => {
136107
};
137108
```
138109

110+
### Factory Pattern
111+
112+
other patterns can be found here: https://github.com/nikgraf/future-react-ui/blob/master/global-theming.md
113+
139114
## Temporary Conclusion
140115

141116
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.

global-theming.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#### Module export
2+
3+
https://github.com/nikgraf/future-react-ui/tree/master/ui-lib
4+
5+
In this version the defaultTheme is exported through a named module export. On line 9, 10, 11 you can see how the default theme is patched with custom classes. (https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L8) Since this is not so hand it might be useful to have utility function for each library to apply a theme.
6+
7+
#### Static property
8+
9+
https://github.com/nikgraf/future-react-ui/blob/master/ui-lib/StaticProperty/Hint.js
10+
11+
In this version the defaultTheme is attached to the component itself as static property. Compared to the 'Module export' this is a bit more flexible as you can overwrite the whole `theme` object in one go. See line 13-20 for usage. (https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L13)
12+
13+
#### Theme Component leveraging Context
14+
15+
https://github.com/nikgraf/future-react-ui/blob/master/ui-lib/Context/Hint.js
16+
17+
In this version we leverage context to build a `<Theme />` component that takes a theme as property and passes it down to all child components via React's context. A theme is still a simple JS object as can be seen on line 25-30. (https://github.com/nikgraf/future-react-ui/blob/master/app/index.js#L22). On one hand this approach is powerful, because you can apply different themes various nesting levels in the render tree.
18+
19+
```
20+
<Theme theme={baseTheme}>
21+
<Theme theme={headerTheme}>
22+
<Menu items=['Home', 'About'] />
23+
</Theme>
24+
<Hint isOpen>Basic open hint without styling.</Hint>
25+
</Theme>
26+
```
27+
28+
There is one obvious concern with this approach. There could be name-clashing between libraries that use the same key in the `theme` object. This could be solved by following a namespace convention like prefixing the keys with the npm package name.

0 commit comments

Comments
 (0)