@codeleap/mobile 3.24.2 → 3.25.0

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 (131) hide show
  1. package/package.json +6 -4
  2. package/src/Registry.ts +52 -0
  3. package/src/components/ActionIcon/index.tsx +55 -37
  4. package/src/components/ActionIcon/styles.ts +2 -4
  5. package/src/components/ActionIcon/types.ts +15 -0
  6. package/src/components/ActivityIndicator/index.tsx +42 -64
  7. package/src/components/ActivityIndicator/styles.ts +1 -10
  8. package/src/components/ActivityIndicator/types.ts +9 -0
  9. package/src/components/Autocomplete/index.tsx +46 -54
  10. package/src/components/Autocomplete/styles.ts +2 -5
  11. package/src/components/Autocomplete/types.ts +13 -23
  12. package/src/components/Avatar/index.tsx +59 -71
  13. package/src/components/Avatar/styles.ts +1 -9
  14. package/src/components/Avatar/types.ts +23 -0
  15. package/src/components/AvatarGroup/index.tsx +30 -44
  16. package/src/components/AvatarGroup/styles.ts +0 -6
  17. package/src/components/AvatarGroup/types.ts +10 -0
  18. package/src/components/Backdrop/index.tsx +51 -34
  19. package/src/components/Backdrop/styles.ts +5 -10
  20. package/src/components/Backdrop/types.ts +14 -0
  21. package/src/components/Badge/index.tsx +36 -62
  22. package/src/components/Badge/styles.ts +3 -11
  23. package/src/components/Badge/types.ts +27 -0
  24. package/src/components/Button/index.tsx +55 -82
  25. package/src/components/Button/styles.ts +13 -14
  26. package/src/components/Button/types.ts +20 -0
  27. package/src/components/Calendar/index.tsx +35 -29
  28. package/src/components/Checkbox/index.tsx +43 -64
  29. package/src/components/Checkbox/styles.ts +1 -6
  30. package/src/components/Checkbox/types.ts +13 -0
  31. package/src/components/DatePickerModal/index.tsx +50 -65
  32. package/src/components/DatePickerModal/styles.ts +9 -10
  33. package/src/components/DatePickerModal/types.ts +36 -54
  34. package/src/components/EmptyPlaceholder/index.tsx +40 -63
  35. package/src/components/EmptyPlaceholder/styles.ts +0 -5
  36. package/src/components/EmptyPlaceholder/types.ts +21 -0
  37. package/src/components/FileInput/index.tsx +11 -49
  38. package/src/components/FileInput/types.ts +27 -0
  39. package/src/components/Grid/index.tsx +84 -116
  40. package/src/components/Grid/styles.ts +0 -5
  41. package/src/components/Grid/types.ts +20 -0
  42. package/src/components/Icon/index.tsx +44 -79
  43. package/src/components/Icon/styles.ts +0 -6
  44. package/src/components/Icon/types.ts +15 -0
  45. package/src/components/Image/index.tsx +58 -78
  46. package/src/components/Image/styles.ts +1 -6
  47. package/src/components/Image/types.ts +18 -0
  48. package/src/components/ImageView/Spotlight.tsx +1 -4
  49. package/src/components/ImageView/component.tsx +1 -2
  50. package/src/components/InputBase/index.tsx +33 -24
  51. package/src/components/InputBase/styles.ts +66 -75
  52. package/src/components/InputBase/types.ts +3 -4
  53. package/src/components/InputBase/utils.ts +6 -4
  54. package/src/components/List/index.tsx +99 -151
  55. package/src/components/List/styles.ts +0 -6
  56. package/src/components/List/types.ts +41 -0
  57. package/src/components/LoadingOverlay/index.tsx +42 -29
  58. package/src/components/LoadingOverlay/styles.ts +7 -7
  59. package/src/components/LoadingOverlay/types.ts +9 -0
  60. package/src/components/Modal/index.tsx +80 -127
  61. package/src/components/Modal/styles.ts +0 -8
  62. package/src/components/Modal/types.ts +41 -0
  63. package/src/components/Navigation/Navigation.tsx +1 -0
  64. package/src/components/Navigation/types.ts +2 -9
  65. package/src/components/NumberIncrement/index.tsx +50 -60
  66. package/src/components/NumberIncrement/styles.ts +0 -5
  67. package/src/components/NumberIncrement/types.ts +32 -39
  68. package/src/components/Pager/index.tsx +42 -94
  69. package/src/components/Pager/styles.ts +1 -13
  70. package/src/components/Pager/types.ts +37 -0
  71. package/src/components/PaginationIndicator/index.tsx +51 -0
  72. package/src/components/PaginationIndicator/styles.ts +3 -0
  73. package/src/components/PaginationIndicator/types.ts +10 -0
  74. package/src/components/RadioInput/index.tsx +32 -57
  75. package/src/components/RadioInput/styles.ts +5 -7
  76. package/src/components/RadioInput/types.ts +31 -0
  77. package/src/components/RefreshControl/index.tsx +39 -19
  78. package/src/components/RefreshControl/styles.ts +1 -6
  79. package/src/components/RefreshControl/types.ts +9 -0
  80. package/src/components/Scroll/index.tsx +89 -105
  81. package/src/components/Scroll/styles.ts +0 -5
  82. package/src/components/Scroll/types.ts +21 -0
  83. package/src/components/SearchInput/index.tsx +90 -0
  84. package/src/components/Sections/index.tsx +111 -161
  85. package/src/components/Sections/styles.ts +0 -5
  86. package/src/components/Sections/types.ts +39 -0
  87. package/src/components/SegmentedControl/Option.tsx +46 -31
  88. package/src/components/SegmentedControl/index.tsx +86 -121
  89. package/src/components/SegmentedControl/styles.ts +15 -22
  90. package/src/components/SegmentedControl/types.ts +31 -0
  91. package/src/components/Select/index.tsx +71 -82
  92. package/src/components/Select/styles.ts +3 -5
  93. package/src/components/Select/types.ts +20 -25
  94. package/src/components/Slider/index.tsx +58 -43
  95. package/src/components/Slider/styles.ts +15 -6
  96. package/src/components/Slider/types.ts +9 -14
  97. package/src/components/Switch/index.tsx +43 -56
  98. package/src/components/Switch/styles.ts +1 -7
  99. package/src/components/Switch/types.ts +12 -0
  100. package/src/components/Text/index.tsx +56 -52
  101. package/src/components/Text/styles.ts +1 -7
  102. package/src/components/Text/types.ts +18 -0
  103. package/src/components/TextInput/index.tsx +49 -162
  104. package/src/components/TextInput/styles.ts +2 -8
  105. package/src/components/TextInput/types.ts +23 -0
  106. package/src/components/Touchable/index.tsx +44 -87
  107. package/src/components/Touchable/styles.ts +0 -9
  108. package/src/components/Touchable/types.ts +27 -0
  109. package/src/components/View/index.tsx +23 -92
  110. package/src/components/View/styles.ts +0 -6
  111. package/src/components/View/types.ts +13 -0
  112. package/src/components/components.ts +2 -6
  113. package/src/hooks/index.ts +13 -0
  114. package/src/index.ts +2 -0
  115. package/src/modules/PressableRipple/type.ts +1 -0
  116. package/src/utils/KeyboardAware/context.tsx +0 -2
  117. package/src/utils/KeyboardAware/keyboardHooks.ts +1 -2
  118. package/src/utils/ModalManager/components.tsx +1 -30
  119. package/src/utils/ModalManager/context.tsx +4 -4
  120. package/src/utils/ModalManager/index.ts +1 -4
  121. package/src/utils/hooks.ts +12 -1
  122. package/src/components/Calendar/style.ts +0 -6
  123. package/src/components/ContentView/index.tsx +0 -63
  124. package/src/components/ContentView/styles.ts +0 -8
  125. package/src/components/Drawer/index.tsx +0 -28
  126. package/src/components/Drawer/styles.ts +0 -8
  127. package/src/components/FileInput/styles.ts +0 -8
  128. package/src/components/InputLabel/index.tsx +0 -38
  129. package/src/components/InputLabel/styles.ts +0 -7
  130. package/src/components/List/PaginationIndicator.tsx +0 -54
  131. package/src/components/defaultStyles.ts +0 -77
@@ -1,17 +1,19 @@
1
1
  import React, { useRef } from 'react'
2
- import { useState, useCodeleapContext, useDefaultComponentStyle, TypeGuards, useBooleanToggle, useNestedStylesByKey, useI18N } from '@codeleap/common'
3
- import { DatePickerModalPresets } from './styles'
2
+ import { TypeGuards, useBooleanToggle, useI18N } from '@codeleap/common'
4
3
  import DatePicker from 'react-native-date-picker'
4
+ import Modal from '../Modal'
5
5
  import { TextInput } from '../TextInput'
6
6
  import { ModalManager } from '../../utils'
7
7
  import { Button } from '../Button'
8
- import { StyleSheet } from 'react-native'
9
8
  import { DatePickerModalProps } from './types'
9
+ import { AnyRecord, IJSX, StyledComponentProps, useCompositionStyles } from '@codeleap/styles'
10
+ import { MobileStyleRegistry } from '../../Registry'
11
+ import { useStylesFor } from '../../hooks'
10
12
 
11
13
  export * from './styles'
12
14
  export * from './types'
13
15
 
14
- const OuterInputComponent:DatePickerModalProps['outerInputComponent'] = (props) => {
16
+ const OuterInputComponent: DatePickerModalProps['outerInputComponent'] = (props) => {
15
17
  const {
16
18
  debugName,
17
19
  toggle,
@@ -29,43 +31,42 @@ const OuterInputComponent:DatePickerModalProps['outerInputComponent'] = (props)
29
31
  />
30
32
  }
31
33
 
32
- const defaultFormatDate:DatePickerModalProps['formatDate'] = (date) => {
34
+ const defaultFormatDate: DatePickerModalProps['formatDate'] = (date) => {
33
35
  if (!date) return null
34
36
  return `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`
35
37
  }
36
38
 
37
- const DefaultFooter:DatePickerModalProps['footerComponent'] = (props) => {
39
+ const DefaultFooter: DatePickerModalProps['footerComponent'] = (props) => {
38
40
  const {
39
41
  debugName,
40
42
  commitDate,
41
43
  showDoneButton,
42
- styles,
43
44
  confirm,
44
45
  confirmButtonProps = {},
45
46
  cancelButtonProps = {},
46
47
  toggle,
48
+ cancelStyles,
49
+ confirmStyles,
50
+ doneStyles,
47
51
  } = props
48
52
 
49
53
  if (commitDate == 'onConfirm') {
50
54
  return <>
51
55
  <Button
52
56
  debugName={`${debugName} cancel button`}
53
- styles={styles.cancel}
54
- variants={['flex']}
57
+ style={cancelStyles}
55
58
  text={`Cancel`}
56
59
  onPress={toggle}
57
60
  {...cancelButtonProps}
58
61
  />
59
62
  <Button
60
63
  debugName={`${debugName} confirm button`}
61
- variants={['flex']}
62
- styles={styles.confirm}
64
+ style={confirmStyles}
63
65
  text={`Confirm`}
64
66
  onPress={confirm}
65
67
  {...confirmButtonProps}
66
68
  />
67
69
  </>
68
-
69
70
  }
70
71
 
71
72
  if (!showDoneButton) return null
@@ -74,28 +75,13 @@ const DefaultFooter:DatePickerModalProps['footerComponent'] = (props) => {
74
75
  debugName={`${debugName} done button`}
75
76
  onPress={confirm}
76
77
  text={'Done'}
77
- styles={styles.done}
78
-
78
+ style={doneStyles}
79
79
  />
80
80
  }
81
81
 
82
- const defaultProps:Partial<DatePickerModalProps> = {
83
- outerInputComponent: OuterInputComponent,
84
- formatDate: defaultFormatDate,
85
- footerComponent: DefaultFooter,
86
- mode: 'date',
87
- commitDate: 'onConfirm',
88
- showDoneButton: true,
89
- isCustomModal: true,
90
- toggleOnConfirm: true,
91
- }
92
-
93
82
  export const DatePickerModal = (props: DatePickerModalProps) => {
94
-
95
- const { currentTheme } = useCodeleapContext()
96
-
97
83
  const allProps = {
98
- ...defaultProps,
84
+ ...DatePickerModal.defaultProps,
99
85
  ...props,
100
86
  }
101
87
 
@@ -110,10 +96,8 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
110
96
  debugName,
111
97
  cancelButtonProps = {},
112
98
  confirmButtonProps = {},
113
- outerInputComponent,
99
+ outerInputComponent: OuterInput,
114
100
  footer,
115
- variants = [],
116
- styles = {},
117
101
  datePickerProps,
118
102
  mode,
119
103
  label,
@@ -124,37 +108,25 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
124
108
  minimumDate,
125
109
  maximumDate,
126
110
  initialDate,
127
- footerComponent,
111
+ footerComponent: Footer,
128
112
  toggleOnConfirm,
129
113
  onConfirm: _onConfirm,
130
114
  ...modalProps
131
115
  } = allProps
132
116
 
133
- const variantStyles = useDefaultComponentStyle<'u:DatePickerModal', typeof DatePickerModalPresets>('u:DatePickerModal', {
134
- variants,
135
- styles,
136
- rootElement: 'inputWrapper',
137
- transform: StyleSheet.flatten,
138
- })
117
+ const styles = useStylesFor(DatePickerModal.styleRegistryName, style)
139
118
 
140
119
  const [visible, toggle] = !TypeGuards.isNil(_visible) && !!_toggle ? [_visible, _toggle] : useBooleanToggle(false)
141
120
  const [value, setValue] = [_value, onValueChange]
142
- //const [value, setValue] = _value && onValueChange ? [_value, onValueChange] : useState(_value ?? new Date())
143
121
 
144
122
  const Wrapper = isCustomModal ? ModalManager.Modal : React.Fragment
145
123
 
146
- const OuterInput = outerInputComponent
147
- const Footer = footerComponent
148
-
149
- const inputStyle = useNestedStylesByKey('input', variantStyles)
150
- const doneStyle = useNestedStylesByKey('doneButton', variantStyles)
151
- const cancelStyle = useNestedStylesByKey('cancelButton', variantStyles)
152
- const confirmStyle = useNestedStylesByKey('confirmButton', variantStyles)
124
+ const compositionStyles = useCompositionStyles(['input', 'doneButton', 'cancelButton', 'confirmButton'], styles)
153
125
 
154
126
  const formattedDate = value ? formatDate(value) : ''
155
127
  const { locale } = useI18N()
156
128
 
157
- const tempDate = useRef<Date|null>(null)
129
+ const tempDate = useRef<Date | null>(null)
158
130
 
159
131
  const onConfirm = () => {
160
132
  if (commitDate == 'onConfirm' && !!tempDate.current) {
@@ -173,11 +145,9 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
173
145
  const modalFooter = footer || <Footer
174
146
  {...allProps}
175
147
  confirm={onConfirm}
176
- styles={{
177
- done: doneStyle,
178
- cancel: cancelStyle,
179
- confirm: confirmStyle,
180
- }}
148
+ doneStyles={compositionStyles?.doneButton}
149
+ cancelStyles={compositionStyles?.cancelButton}
150
+ confirmStyles={compositionStyles?.confirmButton}
181
151
  confirmButtonProps={confirmButtonProps}
182
152
  cancelButtonProps={cancelButtonProps}
183
153
  showDoneButton={showDoneButton}
@@ -195,7 +165,7 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
195
165
  debugName: `${debugName} Modal`,
196
166
  visible: visible,
197
167
  toggle: toggle,
198
- styles: variantStyles,
168
+ style: styles,
199
169
  footer: modalFooter,
200
170
  ...modalProps,
201
171
  id: null,
@@ -203,20 +173,18 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
203
173
 
204
174
  return (
205
175
  <>
206
- {!hideInput && <OuterInput
176
+ {!hideInput ? <OuterInput
207
177
  {...allProps}
208
- styles={inputStyle}
178
+ style={compositionStyles?.input}
209
179
  value={value}
210
180
  debugName={debugName}
211
181
  visible={visible}
212
182
  toggle={toggle}
213
183
  onValueChange={setValue}
214
184
  valueLabel={formattedDate}
215
- style={style}
185
+ /> : null}
216
186
 
217
- />}
218
- {/* @ts-expect-error */}
219
- <Wrapper {...wrapperProps} >
187
+ <Wrapper {...wrapperProps}>
220
188
  <DatePicker
221
189
  modal={!isCustomModal}
222
190
  open={visible}
@@ -231,21 +199,38 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
231
199
  tempDate.current = date
232
200
  }}
233
201
  locale={locale}
234
- theme={currentTheme === 'dark' ? 'dark' : 'light' }
235
- textColor={variantStyles?.picker?.color}
202
+ // @ts-expect-error
203
+ textColor={styles?.picker?.color}
204
+ theme='light'
236
205
  androidVariant='iosClone'
237
206
  onConfirm={setValue}
238
207
  minimumDate={minimumDate}
239
208
  maximumDate={maximumDate}
240
209
  {...datePickerProps}
241
210
  mode={mode}
242
-
243
211
  />
244
212
  </Wrapper>
245
-
246
213
  </>
247
214
  )
215
+ }
248
216
 
217
+ DatePickerModal.styleRegistryName = 'DatePickerModal'
218
+ DatePickerModal.elements = [...Modal.elements, 'input', 'picker', 'doneButton', 'confirmButton', 'cancelButton']
219
+ DatePickerModal.rootElement = 'inputWrapper'
220
+
221
+ DatePickerModal.withVariantTypes = <S extends AnyRecord>(styles: S) => {
222
+ return DatePickerModal as (props: StyledComponentProps<DatePickerModalProps, typeof styles>) => IJSX
249
223
  }
250
224
 
251
- DatePickerModal.defaultProps = defaultProps
225
+ DatePickerModal.defaultProps = {
226
+ outerInputComponent: OuterInputComponent,
227
+ formatDate: defaultFormatDate,
228
+ footerComponent: DefaultFooter,
229
+ mode: 'date',
230
+ commitDate: 'onConfirm',
231
+ showDoneButton: true,
232
+ isCustomModal: true,
233
+ toggleOnConfirm: true,
234
+ } as Partial<DatePickerModalProps>
235
+
236
+ MobileStyleRegistry.registerComponent(DatePickerModal)
@@ -1,15 +1,14 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { ButtonComposition } from '../Button'
3
2
  import { ModalComposition } from '../Modal'
4
3
  import { TextInputComposition } from '../TextInput'
5
4
 
6
- export type DatePickerModalComposition =
7
- ModalComposition |
8
- `input${Capitalize<TextInputComposition>}` |
9
- `picker` |
10
- `doneButton${Capitalize<ButtonComposition>}` |
11
- `confirmButton${Capitalize<ButtonComposition>}` |
12
- `cancelButton${Capitalize<ButtonComposition>}`
5
+ export type DatePickerModalButtonCompositions =
6
+ `doneButton${Capitalize<ButtonComposition>}` |
7
+ `confirmButton${Capitalize<ButtonComposition>}` |
8
+ `cancelButton${Capitalize<ButtonComposition>}`
13
9
 
14
- const createDatePickerModalStyle = createDefaultVariantFactory<DatePickerModalComposition>()
15
- export const DatePickerModalPresets = includePresets((styles) => createDatePickerModalStyle(() => ({ inputWrapper: styles })))
10
+ export type DatePickerModalComposition =
11
+ ModalComposition |
12
+ `input${Capitalize<TextInputComposition>}` |
13
+ `picker` |
14
+ DatePickerModalButtonCompositions
@@ -1,64 +1,46 @@
1
1
  import React from 'react'
2
- import { ComponentVariants, StylesOf, FormTypes, AnyFunction } from '@codeleap/common'
3
- import { DatePickerModalComposition, DatePickerModalPresets } from './styles'
2
+ import { FormTypes, StylesOf } from '@codeleap/common'
3
+ import { DatePickerModalButtonCompositions, DatePickerModalComposition } from './styles'
4
4
  import { DatePickerProps } from 'react-native-date-picker'
5
- import { TextInputComposition } from '../TextInput'
6
- import { ButtonComposition, ButtonProps } from '../Button'
5
+ import { ButtonProps } from '../Button'
7
6
  import { ModalProps } from '../Modal'
7
+ import { StyledProp } from '@codeleap/styles'
8
8
 
9
- export type DatePickerModalOuterInputProps = Omit<DatePickerModalProps, 'outerInputComponent' | 'styles'> & {
10
- valueLabel: FormTypes.Label
11
- styles?: StylesOf<TextInputComposition>
9
+ export type DatePickerModalOuterInputProps = Omit<DatePickerModalProps, 'outerInputComponent'> & {
10
+ valueLabel: FormTypes.Label
12
11
  }
13
12
 
14
- type DatePickerModalFooterProps = Omit<DatePickerModalProps, 'outerInputComponent' | 'styles'> & {
13
+ type DatePickerModalFooterProps = Omit<DatePickerModalProps, 'outerInputComponent' | 'style'> & {
15
14
  valueLabel: FormTypes.Label
16
- styles?: Record<
17
- 'confirm' | 'cancel' | 'done',
18
- StylesOf<ButtonComposition>
19
- >
20
15
  confirm: () => void
16
+ cancelStyles: StylesOf<DatePickerModalButtonCompositions>
17
+ confirmStyles: StylesOf<DatePickerModalButtonCompositions>
18
+ doneStyles: StylesOf<DatePickerModalButtonCompositions>
21
19
  }
22
20
 
23
- export type DatePickerModalProps = Omit<ModalProps, 'styles' | 'variants' | 'ref'> & {
24
- hideInput?: boolean
25
- debugName: string
26
-
27
- value: Date
28
-
29
- label?: FormTypes.Label
30
-
31
- placeholder?: FormTypes.Label
32
-
33
- onValueChange: (date: Date) => void
34
-
35
- styles?: StylesOf<DatePickerModalComposition>
36
-
37
- isCustomModal?: boolean
38
- mode?: DatePickerProps['mode']
39
-
40
- cancelButtonProps?: Partial<ButtonProps>
41
- confirmButtonProps?: Partial<ButtonProps>
42
-
43
- datePickerProps?: Partial<DatePickerProps>
44
-
45
- outerInputComponent?: React.ComponentType<DatePickerModalOuterInputProps>
46
-
47
- formatDate?: (date: Date) => FormTypes.Label
48
-
49
- commitDate?: 'onConfirm' | 'onChange'
50
-
51
- showDoneButton?: boolean
52
-
53
- footerComponent?: React.ComponentType<DatePickerModalFooterProps>
54
-
55
- minimumDate?: DatePickerProps['minimumDate']
56
-
57
- maximumDate?: DatePickerProps['maximumDate']
58
-
59
- initialDate?: Date
60
-
61
- toggleOnConfirm?: boolean
62
-
63
- onConfirm?: (value: Date) => void
64
- } & ComponentVariants<typeof DatePickerModalPresets>
21
+ export type DatePickerModalProps =
22
+ Omit<ModalProps, 'style' | 'ref'> &
23
+ {
24
+ hideInput?: boolean
25
+ debugName: string
26
+ value: Date
27
+ label?: FormTypes.Label
28
+ placeholder?: FormTypes.Label
29
+ onValueChange: (date: Date) => void
30
+ isCustomModal?: boolean
31
+ mode?: DatePickerProps['mode']
32
+ cancelButtonProps?: Partial<ButtonProps>
33
+ confirmButtonProps?: Partial<ButtonProps>
34
+ datePickerProps?: Partial<DatePickerProps>
35
+ outerInputComponent?: React.ComponentType<DatePickerModalOuterInputProps>
36
+ formatDate?: (date: Date) => FormTypes.Label
37
+ commitDate?: 'onConfirm' | 'onChange'
38
+ showDoneButton?: boolean
39
+ footerComponent?: React.ComponentType<DatePickerModalFooterProps>
40
+ initialDate?: Date
41
+ minimumDate?: DatePickerProps['minimumDate']
42
+ maximumDate?: DatePickerProps['maximumDate']
43
+ toggleOnConfirm?: boolean
44
+ onConfirm?: (value: Date) => void
45
+ style?: StyledProp<DatePickerModalComposition>
46
+ }
@@ -1,88 +1,53 @@
1
- import React, { useMemo } from 'react'
1
+ import React from 'react'
2
2
  import { Icon } from '../Icon'
3
3
  import { View } from '../View'
4
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
- EmptyPlaceholderPresets,
17
- } from './styles'
18
-
19
- import { StyleSheet } from 'react-native'
20
- import { StylesOf } from '../../types'
21
- import { Image, ImageProps } from '../Image'
5
+ import { ActivityIndicator } from '../ActivityIndicator'
6
+ import { Image } from '../Image'
7
+ import { EmptyPlaceholderProps } from './types'
8
+ import { AnyRecord, AppIcon, useNestedStylesByKey, IJSX, StyledComponentProps } from '@codeleap/styles'
9
+ import { MobileStyleRegistry } from '../../Registry'
10
+ import { useStylesFor } from '../../hooks'
22
11
 
23
12
  export * from './styles'
13
+ export * from './types'
24
14
 
25
- export type EmptyPlaceholderProps = {
26
- itemName?: string
27
-
28
- title?: React.ReactElement | string
29
- description?: React.ReactElement | string
30
- image?: ImageProps['source']
31
- icon?: IconPlaceholder
32
-
33
- loading?: boolean
34
-
35
- styles?: StylesOf<EmptyPlaceholderComposition>
36
- variants?: ComponentVariants<typeof EmptyPlaceholderPresets>['variants']
37
-
38
- renderEmpty?: (props: {
39
- emptyText:string | React.ReactElement
40
- emptyIconName?: IconPlaceholder
41
- styles: StylesOf<EmptyPlaceholderComposition> & {activityIndicatorStyles: StylesOf<ActivityIndicatorComposition>}
42
- }) => React.ReactElement
43
- }
44
-
45
- export const EmptyPlaceholder:React.FC<EmptyPlaceholderProps> = (props: EmptyPlaceholderProps) => {
15
+ export const EmptyPlaceholder = (props: EmptyPlaceholderProps) => {
46
16
  const {
47
17
  itemName,
48
18
  title,
49
19
  loading,
50
20
  description,
51
21
  image,
52
- styles = {},
53
- variants = [],
54
22
  icon = null,
55
23
  renderEmpty,
56
- } = props
24
+ style,
25
+ } = {
26
+ ...EmptyPlaceholder.defaultProps,
27
+ ...props,
28
+ }
29
+
57
30
  const emptyText = title || (itemName && `No ${itemName} found.`) || 'No items.'
58
31
 
59
- const componentStyles = useDefaultComponentStyle<'u:EmptyPlaceholder', typeof EmptyPlaceholderPresets>('u:EmptyPlaceholder', {
60
- variants,
61
- transform: StyleSheet.flatten,
62
- styles,
63
- })
32
+ const styles = useStylesFor(EmptyPlaceholder.styleRegistryName, style)
64
33
 
65
- const activityIndicatorStyles = useMemo(() => getNestedStylesByKey('loader', componentStyles)
66
- , [componentStyles])
34
+ const activityIndicatorStyles = useNestedStylesByKey('loader', styles)
67
35
 
68
36
  if (loading) {
69
37
  return (
70
- <View style={[componentStyles.wrapper, componentStyles['wrapper:loading']]} >
71
- <ActivityIndicator styles={activityIndicatorStyles}/>
38
+ <View style={[styles.wrapper, styles['wrapper:loading']]} >
39
+ <ActivityIndicator style={activityIndicatorStyles} />
72
40
  </View>
73
41
  )
74
42
  }
75
43
 
76
44
  if (renderEmpty) {
77
45
  return (
78
- <View style={componentStyles.wrapper}>
46
+ <View style={styles.wrapper}>
79
47
  {renderEmpty({
80
48
  emptyText,
81
- emptyIconName: icon as IconPlaceholder,
82
- styles: {
83
- ...componentStyles,
84
- activityIndicatorStyles,
85
- },
49
+ emptyIconName: icon as AppIcon,
50
+ style: styles,
86
51
  })}
87
52
  </View>
88
53
  )
@@ -91,21 +56,33 @@ export const EmptyPlaceholder:React.FC<EmptyPlaceholderProps> = (props: EmptyPla
91
56
  let _image = null
92
57
 
93
58
  if (icon) {
94
- _image = <Icon name={icon} style={componentStyles.icon}/>
59
+ _image = <Icon name={icon as AppIcon} style={styles.icon} />
95
60
  } else if (image) {
96
- _image = <Image source={image} style={[componentStyles.image]}/>
61
+ _image = <Image source={image} style={styles.image} />
97
62
  }
98
63
 
99
64
  return (
100
- <View style={componentStyles.wrapper}>
65
+ <View style={styles.wrapper}>
101
66
  {React.isValidElement(_image) ? (
102
- <View style={componentStyles.imageWrapper}>
67
+ <View style={styles.imageWrapper}>
103
68
  {_image}
104
69
  </View>
105
70
  ) : null}
106
71
 
107
- {React.isValidElement(emptyText) ? emptyText : <Text text={emptyText} style={componentStyles.title}/> }
108
- {React.isValidElement(description) ? description : <Text text={description} style={componentStyles.description}/> }
72
+ {React.isValidElement(emptyText) ? emptyText : <Text text={emptyText} style={styles.title} />}
73
+ {React.isValidElement(description) ? description : <Text text={description} style={styles.description} />}
109
74
  </View>
110
75
  )
111
76
  }
77
+
78
+ EmptyPlaceholder.styleRegistryName = 'EmptyPlaceholder'
79
+ EmptyPlaceholder.elements = ['wrapper', 'loader', 'title', 'description', 'image', 'icon']
80
+ EmptyPlaceholder.rootElement = 'wrapper'
81
+
82
+ EmptyPlaceholder.withVariantTypes = <S extends AnyRecord>(styles: S) => {
83
+ return EmptyPlaceholder as (props: StyledComponentProps<EmptyPlaceholderProps, typeof styles>) => IJSX
84
+ }
85
+
86
+ EmptyPlaceholder.defaultProps = {} as Partial<EmptyPlaceholderProps>
87
+
88
+ MobileStyleRegistry.registerComponent(EmptyPlaceholder)
@@ -1,4 +1,3 @@
1
- import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
1
  import { ActivityIndicatorComposition } from '../ActivityIndicator'
3
2
 
4
3
  export type EmptyPlaceholderComposition =
@@ -10,7 +9,3 @@ export type EmptyPlaceholderComposition =
10
9
  | 'image'
11
10
  | 'imageWrapper'
12
11
  | 'icon'
13
-
14
- const createEmptyPlaceholderStyle = createDefaultVariantFactory<EmptyPlaceholderComposition>()
15
-
16
- export const EmptyPlaceholderPresets = includePresets((styles) => createEmptyPlaceholderStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,21 @@
1
+ import { AppIcon, StyledProp } from '@codeleap/styles'
2
+ import { ReactElement } from 'react'
3
+ import { ImageProps } from '../Image'
4
+ import { EmptyPlaceholderComposition } from './styles'
5
+
6
+ type RenderEmpty = (props: {
7
+ emptyText: string | ReactElement
8
+ emptyIconName?: AppIcon
9
+ style?: StyledProp<EmptyPlaceholderComposition>
10
+ }) => ReactElement
11
+
12
+ export type EmptyPlaceholderProps = {
13
+ itemName?: string
14
+ title?: ReactElement | string
15
+ description?: ReactElement | string
16
+ image?: ImageProps['source']
17
+ icon?: AppIcon
18
+ loading?: boolean
19
+ style?: StyledProp<EmptyPlaceholderComposition>
20
+ renderEmpty?: RenderEmpty
21
+ }
@@ -1,50 +1,20 @@
1
1
  import React, { forwardRef, useImperativeHandle, useRef } from 'react'
2
- import {
3
- parseFilePathData,
4
- useCodeleapContext,
5
- MobileFile,
6
- AnyRef,
7
- FormTypes,
8
- } from '@codeleap/common'
2
+ import { parseFilePathData, MobileFile } from '@codeleap/common'
9
3
  import { OSAlert } from '../../utils'
10
4
  import ImageCropPicker, { ImageOrVideo, Options } from 'react-native-image-crop-picker'
11
- import DocumentPicker, { DocumentPickerOptions } from 'react-native-document-picker'
12
- export * from './styles'
5
+ import DocumentPicker from 'react-native-document-picker'
6
+ import { FileInputImageSource, FileInputProps, FileInputRef, FileResult } from './types'
13
7
 
14
- export const useSomething = useImperativeHandle
15
-
16
- type FileInputImageSource = 'camera' | 'library' | 'fs'
17
-
18
- type FileResult = FormTypes.AnyFile
19
-
20
- export type FileInputRef = {
21
- openFilePicker: (string?: FileInputImageSource) => Promise<FileResult[]>
22
- }
23
- export type FileInputProps = {
24
- mode: 'hidden' | 'button'
25
- onFileSelect?: (files: FileResult[]) => void
26
- options?: DocumentPickerOptions<any>
27
-
28
- ref?: AnyRef<FileInputRef>
29
-
30
- type?: 'image' | 'anyFile'
31
- alertProps?: Parameters<typeof OSAlert.ask>[0]
32
- pickerOptions?: Partial<Options>
33
- required?: boolean
34
- onOpenCamera?: (resolve: (() => void)) => Promise<void>
35
- onOpenFileSystem?: (resolve: (() => void)) => Promise<void>
36
- onOpenGallery?: (resolve: (() => void)) => Promise<void>
37
- onError?: (error: any) => void
38
- }
8
+ export * from './types'
39
9
 
40
10
  const pickerDefaults = {
41
11
  cropping: true,
42
12
  }
43
13
 
44
14
  function parsePickerData(data: ImageOrVideo): FileResult {
45
-
46
15
  const filePathData = parseFilePathData(data.path)
47
- const d: MobileFile = {
16
+
17
+ const file: MobileFile = {
48
18
  ...data,
49
19
  name: filePathData.name,
50
20
  size: data.size,
@@ -54,32 +24,25 @@ function parsePickerData(data: ImageOrVideo): FileResult {
54
24
  }
55
25
 
56
26
  return {
57
- file: d,
27
+ file,
58
28
  preview: data.path,
59
29
  }
60
30
  }
61
31
 
62
- const _FileInput = forwardRef<
63
- FileInputRef,
64
- FileInputProps
65
- >((fileInputProps, ref) => {
32
+ const _FileInput = forwardRef<FileInputRef, FileInputProps>((fileInputProps, ref) => {
66
33
  const {
67
-
68
34
  onFileSelect,
69
-
70
35
  options,
71
36
  type = 'image',
72
37
  alertProps,
73
-
74
38
  pickerOptions,
75
-
76
39
  onOpenCamera = null,
77
40
  onOpenGallery = null,
78
41
  onOpenFileSystem = null,
79
42
  onError,
80
43
  } = fileInputProps
44
+
81
45
  const resolveWithFile = useRef<(file: FileResult[]) => any>()
82
- const { logger } = useCodeleapContext()
83
46
 
84
47
  const handleResolve = (files: Array<FileResult>) => {
85
48
  if (resolveWithFile.current) {
@@ -105,10 +68,7 @@ const _FileInput = forwardRef<
105
68
  }
106
69
 
107
70
  function handleError(err) {
108
-
109
- logger.warn('File Input Error', err, 'FILE INPUT')
110
71
  onError?.(err)
111
-
112
72
  }
113
73
 
114
74
  const mergedOptions = {
@@ -125,6 +85,7 @@ const _FileInput = forwardRef<
125
85
  }
126
86
  handleResolve?.(imageArray.map(parsePickerData))
127
87
  }
88
+
128
89
  const onPress = (open?: FileInputImageSource, options?: Options) => {
129
90
  if (open == 'fs') {
130
91
  openFileSystem()
@@ -133,6 +94,7 @@ const _FileInput = forwardRef<
133
94
  ImageCropPicker[call]({ ...mergedOptions, ...(options || {}) }).then(handlePickerResolution)
134
95
  }
135
96
  }
97
+
136
98
  const openFilePicker = async (imageSource = null) => {
137
99
  if (type === 'image') {
138
100
  if (imageSource === 'camera') {