-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-skeletor-component.ts
119 lines (110 loc) · 2.49 KB
/
create-skeletor-component.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { createComponent } from 'react-fela';
const animation = {
userSelect: 'none',
animationName: {
'0%': {
opacity: 0.67,
},
'50%': {
opacity: 0.33,
},
'100%': {
opacity: 0.67,
},
},
animationDuration: '1.5s',
animationIterationCount: 'infinite',
animationTimingFunction: 'linear',
'& *': {
animationName: 'none', // prevent nested animations
},
};
const fill = color => ({
color: `${color} !important`,
backgroundColor: `${color} !important`,
background: `${color} !important`,
});
const createSkeletorComponent = (styles, component, propKeys) => {
class SkeletorComponent extends Component {
color = this.context.skeletorColor || this.context.theme.dark;
background = {
...fill(this.color),
...animation,
};
overlay = {
position: 'relative',
onBefore: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
...fill(this.color),
...animation,
},
};
text = {
'& h1': {
...fill(this.color),
},
'& h2': {
...fill(this.color),
},
'& h3': {
...fill(this.color),
},
'& h4': {
...fill(this.color),
},
'& h5': {
...fill(this.color),
},
'& h6': {
...fill(this.color),
},
'& p': {
...fill(this.color),
},
'& span': {
...fill(this.color),
},
'& a': {
...fill(this.color),
},
...animation,
};
render() {
const { skeletorLoading, theme, renderer } = this.context;
return createComponent(
p =>
styles({
...p,
skeletor: skeletorLoading
? {
background: this.background,
overlay: this.overlay,
text: this.text,
isLoading: true,
}
: {
background: () => ({}),
overlay: () => ({}),
text: () => ({}),
isLoading: false,
},
}),
component,
propKeys
)(this.props, { theme, renderer });
}
}
SkeletorComponent.contextTypes = {
renderer: PropTypes.object,
theme: PropTypes.object,
skeletorLoading: PropTypes.bool,
};
return SkeletorComponent;
};
export default createSkeletorComponent;