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