@codeleap/mobile 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/components/Button/index.d.ts +0 -1
  2. package/dist/components/Button/index.js +5 -12
  3. package/dist/components/Button/index.js.map +1 -1
  4. package/dist/components/List/styles.js +1 -1
  5. package/dist/components/List/styles.js.map +1 -1
  6. package/dist/components/Touchable/index.js +11 -9
  7. package/dist/components/Touchable/index.js.map +1 -1
  8. package/dist/utils/theme.d.ts +1 -0
  9. package/dist/utils/theme.js +7 -2
  10. package/dist/utils/theme.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/components/ActionIcon/index.tsx +32 -0
  13. package/src/components/ActionIcon/styles.ts +97 -0
  14. package/src/components/ActivityIndicator/index.tsx +50 -0
  15. package/src/components/ActivityIndicator/styles.ts +68 -0
  16. package/src/components/Animated.tsx +34 -0
  17. package/src/components/AutoComplete/index.tsx +163 -0
  18. package/src/components/AutoComplete/styles.ts +44 -0
  19. package/src/components/Backdrop/index.tsx +48 -0
  20. package/src/components/Backdrop/styles.ts +33 -0
  21. package/src/components/Button/index.tsx +154 -0
  22. package/src/components/Button/styles.ts +129 -0
  23. package/src/components/Calendar/index.tsx +65 -0
  24. package/src/components/Calendar/style.ts +35 -0
  25. package/src/components/Calendar/types.ts +102 -0
  26. package/src/components/Checkbox/index.tsx +91 -0
  27. package/src/components/Checkbox/styles.ts +81 -0
  28. package/src/components/ContentView/index.tsx +63 -0
  29. package/src/components/ContentView/styles.ts +24 -0
  30. package/src/components/Drawer/index.tsx +33 -0
  31. package/src/components/Drawer/styles.ts +43 -0
  32. package/src/components/EmptyPlaceholder/index.tsx +88 -0
  33. package/src/components/EmptyPlaceholder/styles.ts +58 -0
  34. package/src/components/FileInput/index.tsx +181 -0
  35. package/src/components/FileInput/styles.ts +15 -0
  36. package/src/components/Grid/index.tsx +117 -0
  37. package/src/components/Grid/styles.ts +11 -0
  38. package/src/components/Icon/index.tsx +69 -0
  39. package/src/components/Icon/styles.ts +57 -0
  40. package/src/components/Image/index.tsx +91 -0
  41. package/src/components/Image/styles.ts +20 -0
  42. package/src/components/ImageView/Spotlight.tsx +157 -0
  43. package/src/components/ImageView/component.tsx +38 -0
  44. package/src/components/ImageView/index.ts +2 -0
  45. package/src/components/InputLabel/index.tsx +38 -0
  46. package/src/components/InputLabel/styles.ts +19 -0
  47. package/src/components/List/PaginationIndicator.tsx +71 -0
  48. package/src/components/List/index.tsx +114 -0
  49. package/src/components/List/styles.ts +19 -0
  50. package/src/components/Modal/index.tsx +218 -0
  51. package/src/components/Modal/styles.ts +153 -0
  52. package/src/components/MultiSelect/index.tsx +138 -0
  53. package/src/components/MultiSelect/styles.ts +18 -0
  54. package/src/components/MultiSelect/types.ts +42 -0
  55. package/src/components/Navigation/Navigation.tsx +54 -0
  56. package/src/components/Navigation/constants.ts +8 -0
  57. package/src/components/Navigation/index.tsx +3 -0
  58. package/src/components/Navigation/types.ts +35 -0
  59. package/src/components/Navigation/utils.tsx +57 -0
  60. package/src/components/Pager/index.tsx +121 -0
  61. package/src/components/Pager/styles.ts +81 -0
  62. package/src/components/RadioInput/index.tsx +106 -0
  63. package/src/components/RadioInput/styles.ts +67 -0
  64. package/src/components/Scroll/index.tsx +124 -0
  65. package/src/components/Scroll/styles.ts +18 -0
  66. package/src/components/Sections/index.tsx +91 -0
  67. package/src/components/SegmentedControl/index.tsx +204 -0
  68. package/src/components/SegmentedControl/styles.ts +89 -0
  69. package/src/components/Select/index.tsx +167 -0
  70. package/src/components/Select/styles.ts +62 -0
  71. package/src/components/Select/types.ts +43 -0
  72. package/src/components/Slider/Mark.tsx +46 -0
  73. package/src/components/Slider/Thumb.tsx +29 -0
  74. package/src/components/Slider/index.tsx +130 -0
  75. package/src/components/Slider/styles.ts +76 -0
  76. package/src/components/Slider/types.ts +30 -0
  77. package/src/components/Switch/index.tsx +91 -0
  78. package/src/components/Switch/styles.ts +38 -0
  79. package/src/components/Text/index.tsx +97 -0
  80. package/src/components/Text/styles.ts +50 -0
  81. package/src/components/TextInput/index.tsx +319 -0
  82. package/src/components/TextInput/styles.ts +127 -0
  83. package/src/components/Touchable/index.tsx +174 -0
  84. package/src/components/Touchable/styles.ts +28 -0
  85. package/src/components/View/index.tsx +103 -0
  86. package/src/components/View/styles.ts +24 -0
  87. package/src/components/components.ts +42 -0
  88. package/src/components/defaultStyles.ts +62 -0
  89. package/src/components/legacy/Modal/index.tsx +163 -0
  90. package/src/components/legacy/Modal/styles.ts +125 -0
  91. package/src/components/legacy/Pager/index.tsx +242 -0
  92. package/src/components/legacy/Pager/styles.ts +51 -0
  93. package/src/components/legacy/index.ts +2 -0
  94. package/src/modules/documentPicker.ts +7 -0
  95. package/src/modules/fastImage.ts +2 -0
  96. package/src/modules/imageCropPicker.d.ts +497 -0
  97. package/src/modules/index.d.ts +682 -0
  98. package/src/modules/reactNavigation.ts +15 -0
  99. package/src/modules/textInputMask.ts +11 -0
  100. package/src/modules/types/documentPicker.d.ts +215 -0
  101. package/src/modules/types/fileTypes.ts +138 -0
  102. package/src/modules/types/textInputMask.ts +9 -0
  103. package/src/types/index.ts +1 -0
  104. package/src/types/utility.ts +9 -0
  105. package/src/utils/KeyboardAware/context.tsx +75 -0
  106. package/src/utils/KeyboardAware/index.ts +17 -0
  107. package/src/utils/KeyboardAware/keyboardHooks.ts +124 -0
  108. package/src/utils/KeyboardAware/lib/KeyboardAwareFlatList.ts +4 -0
  109. package/src/utils/KeyboardAware/lib/KeyboardAwareHOC.tsx +618 -0
  110. package/src/utils/KeyboardAware/lib/KeyboardAwareInterface.ts +13 -0
  111. package/src/utils/KeyboardAware/lib/KeyboardAwareScrollView.ts +6 -0
  112. package/src/utils/KeyboardAware/lib/KeyboardAwareSectionList.ts +6 -0
  113. package/src/utils/KeyboardAware/types.ts +159 -0
  114. package/src/utils/ModalManager/components.tsx +112 -0
  115. package/src/utils/ModalManager/context.tsx +260 -0
  116. package/src/utils/ModalManager/index.ts +16 -0
  117. package/src/utils/OSAlert.ts +180 -0
  118. package/src/utils/PermissionManager/context.tsx +302 -0
  119. package/src/utils/PermissionManager/index.ts +20 -0
  120. package/src/utils/PermissionManager/types.ts +24 -0
  121. package/src/utils/hooks.ts +163 -0
  122. package/src/utils/index.ts +11 -0
  123. package/src/utils/input.ts +51 -0
  124. package/src/utils/misc.ts +83 -0
  125. package/src/utils/notifications.ts +206 -0
  126. package/src/utils/theme.ts +58 -0
@@ -0,0 +1,102 @@
1
+ import { FilterKeys } from '@codeleap/common'
2
+ import { Paths } from '@codeleap/common/dist/types/pathMapping'
3
+ import { TextStyle, ViewStyle } from 'react-native';
4
+
5
+ type CalendarTheme = {
6
+ timelineContainer?: object;
7
+ contentStyle?: ViewStyle;
8
+ event?: object;
9
+ eventTitle?: object;
10
+ eventSummary?: object;
11
+ eventTimes?: object;
12
+ line?: object;
13
+ verticalLine?: object;
14
+ nowIndicatorLine?: object;
15
+ nowIndicatorKnob?: object;
16
+ timeLabel?: object;
17
+ todayTextColor?: string;
18
+ calendarBackground?: string;
19
+ indicatorColor?: string;
20
+ textSectionTitleColor?: string;
21
+ textSectionTitleDisabledColor?: string;
22
+ dayTextColor?: string;
23
+ selectedDayTextColor?: string;
24
+ monthTextColor?: string;
25
+ selectedDayBackgroundColor?: string;
26
+ arrowColor?: string;
27
+ textDisabledColor?: string;
28
+ textInactiveColor?: string;
29
+ backgroundColor?: string; //TODO: remove in V2
30
+ dotColor?: string;
31
+ selectedDotColor?: string;
32
+ disabledArrowColor?: string;
33
+ textDayFontFamily?: TextStyle['fontFamily'];
34
+ textMonthFontFamily?: TextStyle['fontFamily'];
35
+ textDayHeaderFontFamily?: TextStyle['fontFamily'];
36
+ textDayFontWeight?: TextStyle['fontWeight'];
37
+ textMonthFontWeight?: TextStyle['fontWeight'];
38
+ textDayHeaderFontWeight?: TextStyle['fontWeight'];
39
+ textDayFontSize?: number;
40
+ textMonthFontSize?: number;
41
+ textDayHeaderFontSize?: number;
42
+ agendaDayTextColor?: string;
43
+ agendaDayNumColor?: string;
44
+ agendaTodayColor?: string;
45
+ agendaKnobColor?: string;
46
+ todayButtonFontFamily?: TextStyle['fontFamily'];
47
+ todayButtonFontWeight?: TextStyle['fontWeight'];
48
+ todayButtonFontSize?: number;
49
+ textDayStyle?: TextStyle;
50
+ dotStyle?: object;
51
+ arrowStyle?: ViewStyle;
52
+ todayBackgroundColor?: string;
53
+ disabledDotColor?: string;
54
+ inactiveDotColor?: string;
55
+ todayDotColor?: string;
56
+ todayButtonTextColor?: string;
57
+ todayButtonPosition?: string;
58
+ arrowHeight?: number;
59
+ arrowWidth?: number;
60
+ weekVerticalMargin?: number;
61
+ stylesheet?: {
62
+ calendar?: {
63
+ main?: object;
64
+ header?: object;
65
+ };
66
+ day?: {
67
+ basic?: object;
68
+ period?: object;
69
+ };
70
+ dot?: object;
71
+ marking?: object;
72
+ 'calendar-list'?: {
73
+ main?: object;
74
+ };
75
+ agenda?: {
76
+ main?: object;
77
+ list?: object;
78
+ };
79
+ expandable?: {
80
+ main?: object;
81
+ };
82
+ };
83
+ }
84
+
85
+ type FlatStyleKeys = 'dot' | 'marking'
86
+
87
+ type StyleSheetKeys = Exclude<keyof CalendarTheme['stylesheet'], FlatStyleKeys>
88
+
89
+ type ThemeObjPrimitiveKeys = FilterKeys<CalendarTheme, string|number>
90
+
91
+ type ThemeObjCompositionKeys = Exclude<keyof CalendarTheme, ThemeObjPrimitiveKeys | 'stylesheet'>
92
+
93
+ type StyleSheetObjKeys = Exclude<Paths<CalendarTheme['stylesheet']>, StyleSheetKeys>
94
+
95
+ export type CalendarStyleGen<TCSS = any> = {
96
+ theme?: Partial<{
97
+ [P in ThemeObjPrimitiveKeys]: CalendarTheme[P]
98
+ }>
99
+ } & Partial<Record<StyleSheetObjKeys | 'wrapper' | ThemeObjCompositionKeys, TCSS>>
100
+
101
+ export type CalendarComposition = keyof CalendarStyleGen
102
+ export type TCalendarStyles = CalendarStyleGen<any>
@@ -0,0 +1,91 @@
1
+ import * as React from 'react'
2
+ import {
3
+ ComponentVariants,
4
+ useDefaultComponentStyle,
5
+ StylesOf,
6
+ Form,
7
+ useValidate,
8
+ GetRefType,
9
+ PropsOf,
10
+ } from '@codeleap/common'
11
+ import { ComponentPropsWithRef, forwardRef, ReactNode } from 'react'
12
+ import { StyleSheet, Switch as NativeCheckbox } from 'react-native'
13
+ import { FormError } from '../TextInput'
14
+ import { View } from '../View'
15
+ import { Touchable } from '../Touchable'
16
+ import {
17
+ CheckboxStyles,
18
+ CheckboxComposition,
19
+ } from './styles'
20
+ import { InputLabel } from '../InputLabel'
21
+ export * from './styles'
22
+
23
+ type NativeCheckboxProps = Omit<
24
+ ComponentPropsWithRef<typeof NativeCheckbox>,
25
+ 'thumbColor' | 'trackColor'
26
+ >
27
+ type CheckboxProps = NativeCheckboxProps & {
28
+ variants?: ComponentVariants<typeof CheckboxStyles>['variants']
29
+ label?: ReactNode
30
+ styles?: StylesOf<CheckboxComposition>
31
+ validate?: Form.ValidatorFunctionWithoutForm | string
32
+ required?: boolean
33
+ }
34
+
35
+ export const Checkbox = forwardRef<GetRefType<PropsOf<typeof View>['ref']>, CheckboxProps>(
36
+ (checkboxProps, ref) => {
37
+ const {
38
+ variants = [],
39
+ style = {},
40
+ styles = {},
41
+ label,
42
+ value,
43
+ onValueChange,
44
+ validate,
45
+ required,
46
+ ...props
47
+ } = checkboxProps
48
+
49
+ const variantStyles = useDefaultComponentStyle<'u:Checkbox', typeof CheckboxStyles>('u:Checkbox', {
50
+ variants,
51
+ styles,
52
+ transform: StyleSheet.flatten,
53
+ })
54
+
55
+ const { error, showError } = useValidate(value, validate)
56
+
57
+ function getStyles(key: CheckboxComposition, styleObj = variantStyles) {
58
+ return [
59
+ styleObj[key],
60
+ value ? styleObj[key + ':checked'] : {},
61
+ showError ? styleObj[key + ':error'] : {},
62
+ checkboxProps.disabled ? styleObj[key + ':disabled'] : {},
63
+ ]
64
+ }
65
+
66
+ return (
67
+ <View style={[getStyles('wrapper'), style]} ref={ref} {...props}>
68
+ <Touchable
69
+ debugName={`Set checkbox value to ${!value}`}
70
+ style={getStyles('input')}
71
+ onPress={() => onValueChange(!value)}
72
+ styles={{
73
+ feedback: getStyles('inputFeedback'),
74
+ }}
75
+ >
76
+ <View style={getStyles('checkmarkWrapper')}>
77
+ <View style={getStyles('checkmark')} />
78
+ </View>
79
+
80
+ <InputLabel label={label} styles={{
81
+ asterisk: getStyles('labelAsterisk'),
82
+ wrapper: getStyles('labelWrapper'),
83
+ text: getStyles('labelText'),
84
+ }} required={required}/>
85
+
86
+ </Touchable>
87
+ <FormError text={error.message} style={getStyles('error')} />
88
+ </View>
89
+ )
90
+ },
91
+ )
@@ -0,0 +1,81 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { InputLabelComposition } from '../InputLabel'
3
+
4
+ type CheckboxParts =
5
+ | 'wrapper'
6
+ | 'input'
7
+ | 'inputFeedback'
8
+ | 'checkmark'
9
+ | 'checkmarkWrapper'
10
+ | 'error'
11
+ | `label${Capitalize<InputLabelComposition>}`
12
+
13
+ export type CheckboxComposition =
14
+ | CheckboxParts
15
+ | `${CheckboxParts}:checked`
16
+ | `${CheckboxParts}:disabled`
17
+ | `${CheckboxParts}:error`
18
+ const createCheckboxStyle =
19
+ createDefaultVariantFactory<CheckboxComposition>()
20
+
21
+ const presets = includePresets((styles) => createCheckboxStyle(() => ({ wrapper: styles })),
22
+ )
23
+
24
+ export const CheckboxStyles = {
25
+ ...presets,
26
+ default: createCheckboxStyle((theme) => {
27
+ const size = theme.typography.baseFontSize * 1.2
28
+
29
+ const markHeight = size * 0.5
30
+ const markWidth = size * 0.25
31
+
32
+ const translateX = -(markWidth / 2)
33
+ const translateY = -(markHeight / 2)
34
+ return {
35
+ wrapper: {},
36
+ input: {
37
+ flexDirection: 'row',
38
+ ...theme.presets.alignCenter,
39
+
40
+ },
41
+ labelWrapper: {
42
+ // flex: 1,
43
+ ...theme.spacing.marginLeft(1),
44
+
45
+ },
46
+ inputFeedback: {
47
+ type: 'opacity',
48
+ value: 0.5,
49
+ },
50
+
51
+ checkmark: {
52
+ position: 'absolute',
53
+ top: '40%',
54
+ left: '50%',
55
+
56
+ height: markHeight,
57
+ width: markWidth,
58
+ transform: [{ translateX }, { translateY }, { rotate: '45deg' }],
59
+ },
60
+ 'checkmark:checked': {
61
+ ...theme.border.white({
62
+ width: 2,
63
+ directions: ['right', 'bottom'],
64
+ }),
65
+ },
66
+ checkmarkWrapper: {
67
+ position: 'relative',
68
+ width: size,
69
+ borderRadius: theme.borderRadius.small,
70
+ height: size,
71
+ ...theme.border.neutral(1),
72
+ },
73
+ 'checkmarkWrapper:checked': {
74
+ backgroundColor: theme.colors.primary,
75
+ },
76
+ error: {
77
+ color: theme.colors.negative,
78
+ },
79
+ }
80
+ }),
81
+ }
@@ -0,0 +1,63 @@
1
+ import React from 'react'
2
+ import {
3
+
4
+ ComponentVariants,
5
+ useDefaultComponentStyle,
6
+
7
+ } from '@codeleap/common'
8
+ import {
9
+ ContentViewStyles,
10
+ } from './styles'
11
+ import { ViewProps, View, ViewComposition } from '../View'
12
+ import { Text } from '../Text'
13
+ import { StylesOf } from '../../types'
14
+ import { ActivityIndicator } from '../ActivityIndicator'
15
+ import { StyleSheet } from 'react-native'
16
+
17
+ export * from './styles'
18
+
19
+ export type ContentViewProps = Omit<
20
+ ViewProps,
21
+ 'variants' | 'responsiveVariants'
22
+ > & {
23
+ message?: string
24
+ loading?: boolean
25
+ styles?: StylesOf<ViewComposition>
26
+ } & ComponentVariants<typeof ContentViewStyles>
27
+
28
+ const WrapContent = ({ children, ...props }) => (
29
+ <View {...props}>{children}</View>
30
+ )
31
+
32
+ export const ContentView: React.FC<ContentViewProps> = (rawProps) => {
33
+ const { children, message, loading, variants, styles, ...props } =
34
+ rawProps
35
+
36
+ const variantStyle = useDefaultComponentStyle('ContentView', {
37
+ variants,
38
+ transform: StyleSheet.flatten,
39
+ styles,
40
+ })
41
+
42
+ if (loading) {
43
+ return (
44
+ <WrapContent {...props} style={variantStyle.wrapper}>
45
+ <ActivityIndicator styles={{ wrapper: variantStyle.loader }} />
46
+ </WrapContent>
47
+ )
48
+ }
49
+ const hasChildren = Object.keys(children || {}).length > 0
50
+ if (hasChildren) {
51
+ return (
52
+ <WrapContent {...props} style={variantStyle.wrapper}>
53
+ {children}
54
+ </WrapContent>
55
+ )
56
+ }
57
+
58
+ return (
59
+ <WrapContent {...props} style={styles}>
60
+ <Text text={message} />
61
+ </WrapContent>
62
+ )
63
+ }
@@ -0,0 +1,24 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type ContentViewComposition = 'placeholder' | 'wrapper' | 'loader'
4
+
5
+ const createContentViewStyle =
6
+ createDefaultVariantFactory<ContentViewComposition>()
7
+
8
+ const presets = includePresets((styles) => createContentViewStyle(() => ({ wrapper: styles })),
9
+ )
10
+
11
+ export const ContentViewStyles = {
12
+ ...presets,
13
+ default: createContentViewStyle((theme) => ({
14
+ wrapper: {
15
+ display: 'flex',
16
+ ...theme.presets.column,
17
+ },
18
+ loader: {
19
+ alignSelf: 'center',
20
+ height: theme.values.width * 0.15,
21
+ width: theme.values.width * 0.15,
22
+ },
23
+ })),
24
+ }
@@ -0,0 +1,33 @@
1
+ import * as React from 'react'
2
+
3
+ import { ComponentVariants, useDefaultComponentStyle } from '@codeleap/common'
4
+ import { StyleSheet } from 'react-native'
5
+ import Modal, { ModalProps } from '../Modal'
6
+ import { DrawerStyles } from './styles'
7
+ export * from './styles'
8
+ export type DrawerProps = Omit<ModalProps, 'variants'> & ComponentVariants<typeof DrawerStyles>
9
+
10
+ export const Drawer:React.FC<DrawerProps> = (props) => {
11
+ const { variants, styles, scrollProps, ...modalProps } = props
12
+
13
+ const variantStyles = useDefaultComponentStyle('u:Drawer', {
14
+ variants,
15
+ styles,
16
+ transform: StyleSheet.flatten,
17
+ })
18
+
19
+ return <Modal
20
+ styles={variantStyles}
21
+ scroll={false}
22
+
23
+ {...modalProps}
24
+ scrollProps={{
25
+ ...scrollProps,
26
+ keyboardAware: {
27
+
28
+ enabled: false,
29
+ ...scrollProps?.keyboardAware,
30
+ },
31
+ }}
32
+ />
33
+ }
@@ -0,0 +1,43 @@
1
+ import { createDefaultVariantFactory } from '@codeleap/common'
2
+ import { ModalComposition, ModalStyles } from '../Modal'
3
+
4
+ export type DrawerComposition = ModalComposition
5
+ const createDrawerStyle = createDefaultVariantFactory<DrawerComposition>()
6
+
7
+ export const DrawerStyles = {
8
+ ...ModalStyles,
9
+ default: createDrawerStyle((theme) => {
10
+ const defaultStyle = ModalStyles.default(theme)
11
+
12
+ return {
13
+ ...defaultStyle,
14
+ box: {
15
+ width: '100%',
16
+ paddingBottom: 0,
17
+ paddingTop: 0,
18
+ borderBottomLeftRadius: 0,
19
+ borderBottomRightRadius: 0,
20
+ maxHeight: '100%',
21
+
22
+ },
23
+ innerWrapper: {
24
+ ...theme.presets.justifyEnd,
25
+
26
+ },
27
+
28
+ 'box:hidden': {
29
+ translateY: theme.values.height,
30
+ opacity: 1,
31
+ scale: 1,
32
+ },
33
+ 'box:visible': {
34
+ translateY: 0,
35
+ scale: 1,
36
+ opacity: 1,
37
+ },
38
+ 'box:transition': {
39
+ translateY: theme.values.transitions.modal,
40
+ },
41
+ }
42
+ }),
43
+ }
@@ -0,0 +1,88 @@
1
+ import React, { useMemo } from 'react'
2
+ import { Icon } from '../Icon'
3
+ import { View } from '../View'
4
+ import { Text } from '../Text'
5
+ import { ActivityIndicator, ActivityIndicatorComposition } from '../ActivityIndicator'
6
+ import {
7
+ ComponentVariants,
8
+
9
+ getNestedStylesByKey,
10
+ IconPlaceholder,
11
+ useDefaultComponentStyle,
12
+ } from '@codeleap/common'
13
+
14
+ import {
15
+ EmptyPlaceholderComposition,
16
+ EmptyPlaceholderStyles,
17
+ } from './styles'
18
+
19
+ import { StyleSheet } from 'react-native'
20
+ import { StylesOf } from '../../types'
21
+
22
+ export * from './styles'
23
+
24
+ export type EmptyPlaceholderProps = {
25
+ itemName?: string
26
+ title?: React.ReactElement
27
+ loading?: boolean
28
+ styles?: StylesOf<EmptyPlaceholderComposition>
29
+ variants?: ComponentVariants<typeof EmptyPlaceholderStyles>['variants']
30
+ emptyIconName?: IconPlaceholder
31
+ renderEmpty?: (props: {
32
+ emptyText:string | React.ReactElement
33
+ emptyIconName?: IconPlaceholder
34
+ styles: StylesOf<EmptyPlaceholderComposition> & {activityIndicatorStyles: StylesOf<ActivityIndicatorComposition>}
35
+ }) => React.ReactElement
36
+ }
37
+
38
+ export const EmptyPlaceholder:React.FC<EmptyPlaceholderProps> = (props: EmptyPlaceholderProps) => {
39
+ const {
40
+ itemName,
41
+ title,
42
+ loading,
43
+ styles = {},
44
+ variants = [],
45
+ emptyIconName = 'placeholder',
46
+ renderEmpty,
47
+ } = props
48
+ const emptyText = title || (itemName && `No ${itemName} found.`) || 'No items.'
49
+
50
+ const componentStyles = useDefaultComponentStyle('EmptyPlaceholder', {
51
+ variants,
52
+ transform: StyleSheet.flatten,
53
+ styles,
54
+ })
55
+
56
+ const activityIndicatorStyles = useMemo(() => getNestedStylesByKey('loader', componentStyles)
57
+ , [componentStyles])
58
+
59
+ if (loading) {
60
+ return (
61
+ <View style={[componentStyles.wrapper, componentStyles['wrapper:loading']]} >
62
+ <ActivityIndicator styles={activityIndicatorStyles}/>
63
+ </View>
64
+ )
65
+ }
66
+
67
+ if (renderEmpty) {
68
+ return (
69
+ <View style={componentStyles.wrapper}>
70
+ {renderEmpty({
71
+ emptyText,
72
+ emptyIconName: emptyIconName as IconPlaceholder,
73
+ styles: {
74
+ ...componentStyles,
75
+ activityIndicatorStyles,
76
+ },
77
+ })}
78
+ </View>
79
+ )
80
+ }
81
+
82
+ return (
83
+ <View style={componentStyles.wrapper}>
84
+ <Icon name={emptyIconName as IconPlaceholder} style={componentStyles.icon}/>
85
+ <Text text={emptyText} style={componentStyles.text}/>
86
+ </View>
87
+ )
88
+ }
@@ -0,0 +1,58 @@
1
+ import { assignTextStyle, createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { ActivityIndicatorComposition } from '../ActivityIndicator'
3
+
4
+ export type EmptyPlaceholderComposition =
5
+ | 'wrapper:loading'
6
+ | `loader${Capitalize<ActivityIndicatorComposition>}`
7
+ | 'wrapper'
8
+ | 'text'
9
+ | 'icon'
10
+
11
+ const createEmptyPlaceholderStyle = createDefaultVariantFactory<EmptyPlaceholderComposition>()
12
+
13
+ const presets = includePresets((styles) => createEmptyPlaceholderStyle(() => ({ wrapper: styles })),
14
+ )
15
+
16
+ export const EmptyPlaceholderStyles = {
17
+ ...presets,
18
+ default: createEmptyPlaceholderStyle((theme) => ({
19
+ wrapper: {
20
+ ...theme.presets.center,
21
+ minHeight: theme.values.window.height / 2,
22
+ height: '100%',
23
+ flex: 1,
24
+ },
25
+ loaderWrapper: {
26
+
27
+ ...theme.spacing.marginVertical(8),
28
+ ...theme.presets.center,
29
+ ...theme.presets.flex,
30
+ },
31
+ icon: {
32
+ color: theme.colors.placeholder,
33
+ size: theme.spacing.value(24),
34
+ },
35
+ text: {
36
+ ...assignTextStyle('p1')(theme).text,
37
+ ...theme.presets.textCenter,
38
+ },
39
+ })),
40
+ compact: createEmptyPlaceholderStyle((theme) => ({
41
+ wrapper: {
42
+ ...theme.spacing.marginVertical(0),
43
+ marginBottom: theme.spacing.value(6),
44
+ },
45
+ })),
46
+ absolute: createEmptyPlaceholderStyle((theme) => ({
47
+ 'wrapper:loading': {
48
+ ...theme.presets.absolute,
49
+ ...theme.presets.whole,
50
+ backgroundColor: theme.colors.background,
51
+ },
52
+ wrapper: {
53
+ ...theme.presets.absolute,
54
+ ...theme.presets.whole,
55
+ backgroundColor: theme.colors.background,
56
+ },
57
+ })),
58
+ }