forked from vasanthk/react-bits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.stateless-ui-components.jsx
59 lines (56 loc) · 1.48 KB
/
01.stateless-ui-components.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Styling in stateless UI components
* Keep styles separated from the parts of the app that are tied to state.
* That means routes, views, containers, forms, layouts, etc. should not have any styling or classes in them.
* Instead, these heavy-lifting components should be composed of primarily stateless functional UI components.
*
* @Reference:
* http://jxnblk.com/writing/posts/patterns-for-style-composition-in-react/
*/
// Form component (with no styles/classNames) - just pure composed components
class SampleComponent extends Component {
render() {
return (
<form onSubmit={this.handleSubmit}>
<Heading children='Sign In'/>
<Input
name='username'
value={username}
onChange={this.handleChange}/>
<Input
type='password'
name='password'
value={password}
onChange={this.handleChange}/>
<Button
type='submit'
children='Sign In'/>
</form>
)
}
}
// Presentational component (with Styles)
const Button = ({
...props
}) => {
const sx = {
fontFamily: 'inherit',
fontSize: 'inherit',
fontWeight: 'bold',
textDecoration: 'none',
display: 'inline-block',
margin: 0,
paddingTop: 8,
paddingBottom: 8,
paddingLeft: 16,
paddingRight: 16,
border: 0,
color: 'white',
backgroundColor: 'blue',
WebkitAppearance: 'none',
MozAppearance: 'none'
}
return (
<button {...props} style={sx}/>
)
}