-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathgetStyles.ts
More file actions
83 lines (81 loc) · 3.08 KB
/
getStyles.ts
File metadata and controls
83 lines (81 loc) · 3.08 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
75
76
77
78
79
80
81
82
83
import type { IterableEmbeddedViewConfig } from '../../types/IterableEmbeddedViewConfig';
import { embeddedStyles } from '../../constants/embeddedViewDefaults';
import { IterableEmbeddedViewType } from '../../enums';
/**
* Get the default style for the embedded view type.
*
* @param viewType - The type of view to render.
* @param colors - The colors to use for the default style.
* @returns The default style.
*/
const getDefaultStyle = <T>(
viewType: IterableEmbeddedViewType,
colors: {
banner: T;
card: T;
notification: T;
}
): T => {
switch (viewType) {
case IterableEmbeddedViewType.Notification:
return colors.notification;
case IterableEmbeddedViewType.Card:
return colors.card;
default:
return colors.banner;
}
};
/**
* Get the style for the embedded view type.
*
* If a style is provided in the config, it will take precedence over the default style.
*
* @param viewType - The type of view to render.
* @param c - The config to use for the styles.
* @returns The styles.
*
* @example
* ```ts
* const styles = getStyles(IterableEmbeddedViewType.Notification, {
* backgroundColor: '#000000',
* borderColor: '#000000',
* borderWidth: 1,
* borderCornerRadius: 10,
* primaryBtnBackgroundColor: '#000000',
* primaryBtnTextColor: '#000000',
* });
* ```
*/
export const getStyles = (
viewType: IterableEmbeddedViewType,
c?: IterableEmbeddedViewConfig | null
) => {
return {
backgroundColor:
c?.backgroundColor ??
getDefaultStyle<IterableEmbeddedViewConfig['backgroundColor']>(viewType, embeddedStyles.backgroundColor),
borderColor:
c?.borderColor ?? getDefaultStyle<IterableEmbeddedViewConfig['borderColor']>(viewType, embeddedStyles.borderColor),
borderWidth:
c?.borderWidth ?? getDefaultStyle<IterableEmbeddedViewConfig['borderWidth']>(viewType, embeddedStyles.borderWidth),
borderCornerRadius:
c?.borderCornerRadius ??
getDefaultStyle<IterableEmbeddedViewConfig['borderCornerRadius']>(viewType, embeddedStyles.borderCornerRadius),
primaryBtnBackgroundColor:
c?.primaryBtnBackgroundColor ??
getDefaultStyle<IterableEmbeddedViewConfig['primaryBtnBackgroundColor']>(viewType, embeddedStyles.primaryBtnBackgroundColor),
primaryBtnTextColor:
c?.primaryBtnTextColor ??
getDefaultStyle<IterableEmbeddedViewConfig['primaryBtnTextColor']>(viewType, embeddedStyles.primaryBtnTextColor),
secondaryBtnBackgroundColor:
c?.secondaryBtnBackgroundColor ??
getDefaultStyle<IterableEmbeddedViewConfig['secondaryBtnBackgroundColor']>(viewType, embeddedStyles.secondaryBtnBackground),
secondaryBtnTextColor:
c?.secondaryBtnTextColor ??
getDefaultStyle<IterableEmbeddedViewConfig['secondaryBtnTextColor']>(viewType, embeddedStyles.secondaryBtnTextColor),
titleTextColor:
c?.titleTextColor ?? getDefaultStyle<IterableEmbeddedViewConfig['titleTextColor']>(viewType, embeddedStyles.titleText),
bodyTextColor:
c?.bodyTextColor ?? getDefaultStyle<IterableEmbeddedViewConfig['bodyTextColor']>(viewType, embeddedStyles.bodyText),
};
};