forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap-colors.ts
33 lines (29 loc) · 1.23 KB
/
map-colors.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
import { StyleSheet } from 'react-native'
import _ from 'lodash'
import { Colors, ColorsDeclaration, ColorsBrightness, ColorsStyles } from './types'
export const mapColor = <T extends {}>(v: string, map: (v: string) => T, opacity = '') =>
map(v + opacity)
export const mapColorsDeclarationBasic = <T extends {}>(
decl: Colors<string>,
map: (v: string) => T,
opacity?: string,
): Colors<T> => StyleSheet.create(_.mapValues(decl, (v) => mapColor(v, map, opacity)))
export const mapColorsDeclarationStylesBasic = <T extends {}>(
decl: ColorsDeclaration,
map: (value: string) => T,
opacity?: string,
): Colors<T> & ColorsBrightness<T> => ({
...mapColorsDeclarationBasic(decl.default, map, opacity),
default: mapColorsDeclarationBasic(decl.default, map, opacity),
light: mapColorsDeclarationBasic(decl.light, map, opacity),
dark: mapColorsDeclarationBasic(decl.dark, map, opacity),
})
export const mapColorsDeclaration = <T extends {}>(
decl: ColorsDeclaration,
map: (value: string) => T,
): ColorsStyles<T> => ({
...mapColorsDeclarationStylesBasic(decl, map),
transparent: mapColorsDeclarationStylesBasic(decl, map, '20'),
blur: mapColorsDeclarationStylesBasic(decl, map, '80'),
opaque: mapColorsDeclarationStylesBasic(decl, map, 'd0'),
})