-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
99 lines (82 loc) · 2.61 KB
/
example.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// we're not even getting into some other advanced functionality like namespacing stylesheets and referencing
// stylesheets with different namespaces so check out the docs for other features
var reactCSSBuilder = require('react-css-builder');
var stylesheet = module.exports = reactCSSBuilder.create({
// the simplest style class definition
myClass: {
border: 'solid 1px #000',
margin: '6px'
},
// class hierarchies can be as many levels deep as you want. each parent object
// must have an "attributes" property which references the style returned
// for the parent if requested
myClassGroup: {
attributes: {},
// retrieved using stylesheet.css('myClassGroup.groupChild1')
groupChild1: {
padding: "2px"
},
// retrieved using stylesheet.css('myClassGroup.groupChild2')
groupChild2: {
margin: "2px"
},
moreNesting: {
attributes: {
color: '#fff'
},
grandChild1: {
padding: '3px'
},
grandChild2: {
padding: '4px'
}
}
},
// include the styles from other classes into this one
myClassWithIncludes: function(css) {
return css
.include('myClass')
.include('myClassGroup.groupChild1')
.css();
},
// use a mixin to provide additional style attributes based on the function arguments
myClassWithMixin: function(css) {
return css
.mixin('myMixin', 'param1', 'as many params as I want')
.css();
},
// reference variables (global, stylesheet specific, or specific to an individual style class reference)
myClassUsingVariables: function() {
return {
border: this.get('primaryBorder')
};
},
// the kitchen sink
myClassWithEverything: function(css) {
return css
.include('myClass')
.mixin('myMixin', 'param1', 'as many params as I want')
.attr({
// include additional attributes to be returned
border: this.get('primaryBorder')
})
.css();
}
});
// add a mixin
reactCSSBuilder.mixin('myMixin', function(param1, param2) {
return {
// We're not even using the parameters here but we could...
width: '100%'
};
});
// add a global variable
reactCSSBuilder.vars({
primaryBorder: 'solid 5px #000'
});
// this is how we retreive style values
var styleAttributes = stylesheet.css('myClassWithEverything');
// now override the border variable (used by the myClassWithEverything) styleset definition
var styleAttributes = stylesheet.get('myClassWithEverything').vars({ primaryBorder: 'solid 1px #000' }).css();
// this is how you apply the styles to a React component
<MyReactComponent style={styleAttributes}/>