-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolors.js
53 lines (47 loc) · 1.14 KB
/
colors.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
import * as R from 'ramda';
/**
* Capitalize the first character of a string
*/
export function capitalize(str) {
if (!R.is(String, str)) { return str; }
return str.charAt(0).toUpperCase() + str.slice(1);
}
/**
* Map over the keys of an object
* mapKeys(R.toUpper, { a: 1, b: 2, c: 3 }); // { A: 1, B: 2, C: 3 }
*/
export const mapKeys = R.curry((fn, obj) =>
R.fromPairs(R.map(R.adjust(fn, 0), R.toPairs(obj))));
/**
* Text Colors
* for example: black would apply `color: '#515163'`
*/
export const textColors = R.map(R.objOf('color', R.__));
/**
* Background Colors
* for example:
* bgBlack would apply `backgroundColor: '#515163'`
*/
export const bgColors = R.compose(
R.map(R.objOf('backgroundColor', R.__)),
mapKeys(clr => `bg${ capitalize(clr) }`)
);
/**
* Border Colors
* for example:
* borderBlack would apply `borderColor: '#515163'`
*/
export const borderColors = R.compose(
R.map(R.objOf('borderColor', R.__)),
mapKeys(clr => `border${ capitalize(clr) }`)
);
/**
* Generate color classes
*/
export default function(clrs) {
return {
...textColors(clrs),
...bgColors(clrs),
...borderColors(clrs),
};
}