-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmergeProps.ts
69 lines (66 loc) · 2.42 KB
/
mergeProps.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
import type { ImageSourcePropType } from 'react-native'
import { themeBase } from './components/theme'
import { chooseDefaultAccentColor } from './stylesUtils'
import { chooseDefaultIcon } from './choseDefaultIcon'
import type {
MergedNotificationStyleConfig,
NotificationProps,
NotificationStyleConfig,
NotificationVariants,
} from './types'
export const mergeProps = (
props: NotificationProps,
notificationType: NotificationVariants,
darkMode: boolean,
defaultGlobalConfig?: NotificationStyleConfig,
defaultNotificationTypeConfig?: NotificationStyleConfig
): NotificationProps & MergedNotificationStyleConfig => {
const customIconSource: ImageSourcePropType | undefined | JSX.Element =
props.style?.leftIconSource ??
defaultNotificationTypeConfig?.leftIconSource ??
defaultGlobalConfig?.leftIconSource
const chooseProps = <Property extends keyof NotificationStyleConfig>(
property: Property
): NotificationStyleConfig[Property] => {
return (
props.style?.[property] ??
defaultNotificationTypeConfig?.[property] ??
defaultGlobalConfig?.[property] ??
undefined
)
}
return {
title: props.title ?? '',
description: props.description ?? '',
hideCloseButton: props.hideCloseButton,
theme: darkMode ? 'dark' : 'regular',
titleSize: chooseProps('titleSize'),
titleColor: chooseProps('titleColor'),
descriptionColor: chooseProps('descriptionColor'),
descriptionSize: chooseProps('descriptionSize'),
bgColor: chooseProps('bgColor'),
borderWidth: chooseProps('borderWidth') ?? 1,
multiline: chooseProps('multiline'),
defaultIconType: chooseProps('defaultIconType'),
borderType: chooseProps('borderType') ?? 'border',
borderRadius:
props.style?.borderRadius ??
defaultNotificationTypeConfig?.borderRadius ??
(defaultGlobalConfig?.borderRadius || themeBase.borderRadius.regular),
accentColor:
props.style?.accentColor ??
defaultNotificationTypeConfig?.accentColor ??
(defaultGlobalConfig?.accentColor || chooseDefaultAccentColor(notificationType)),
leftIconSource:
customIconSource ??
chooseDefaultIcon(
notificationType,
darkMode,
props.style?.defaultIconType ??
defaultNotificationTypeConfig?.defaultIconType ??
defaultGlobalConfig?.defaultIconType
),
onPress: props.onPress ?? undefined,
imageStyle: chooseProps('imageStyle'),
}
}