-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassNameImplementation.js
More file actions
74 lines (67 loc) · 1.67 KB
/
ClassNameImplementation.js
File metadata and controls
74 lines (67 loc) · 1.67 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { Component } from 'react'
import { styles } from './styles'
import { Theme, Text, View } from 'react-native-themeable'
const withClassNames = propsDefs => (type, props) => {
const def = propsDefs.find(s => s.$type === type &&
s.$className === props.className)
if (def) {
const { $className, $type, style, ...themeProps } = def // eslint-disable-line
return {
...themeProps,
...props,
style: [ style, props.style ],
}
}
return props
}
const theme = withClassNames([
{
$type: Text,
$className: 'primary',
style: {
color: 'blue',
},
},
{
$type: Text,
$className: 'success',
style: {
color: 'green',
},
},
{
$type: Text,
$className: 'error',
style: {
color: 'red',
fontWeight: 'bold',
},
},
{
$type: Text,
style: {
color: 'black',
fontStyle: 'italic',
},
},
])
export default class ClassNameImplementation extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.description}>
This is demonstration how can be apply function used to integrate simple
style classes to native components.
</Text>
<Theme apply={theme}>
<View>
<Text className='primary'>This is primary text (className='primary')</Text>
<Text className='success'>This is success (className='success')</Text>
<Text className='error'>This is error class (className='error')</Text>
<Text>This is default text styled without class name</Text>
</View>
</Theme>
</View>
)
}
}