@codeleap/web 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 (150) hide show
  1. package/package.json +1 -2
  2. package/src/components/ActionIcon/index.tsx +52 -51
  3. package/src/components/ActionIcon/styles.ts +5 -1
  4. package/src/components/ActivityIndicator/index.tsx +55 -34
  5. package/src/components/ActivityIndicator/styles.ts +6 -0
  6. package/src/components/Badge/index.tsx +80 -43
  7. package/src/components/Badge/styles.ts +11 -1
  8. package/src/components/Button/index.tsx +89 -46
  9. package/src/components/Button/styles.ts +5 -0
  10. package/src/components/Checkbox/index.tsx +97 -83
  11. package/src/components/Checkbox/styles.ts +5 -1
  12. package/src/components/Collapse/index.tsx +83 -41
  13. package/src/components/Collapse/styles.ts +6 -3
  14. package/src/components/ColorPicker/index.tsx +48 -95
  15. package/src/components/ColorPicker/styles.ts +11 -11
  16. package/src/components/ColorPicker/types.ts +12 -26
  17. package/src/components/CropPicker/index.tsx +104 -100
  18. package/src/components/CropPicker/styles.ts +7 -0
  19. package/src/components/CropPicker/types.ts +17 -8
  20. package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
  21. package/src/components/CropPicker/utils.ts +51 -0
  22. package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
  23. package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
  24. package/src/components/DatePicker/index.tsx +124 -110
  25. package/src/components/DatePicker/styles.ts +12 -1
  26. package/src/components/DatePicker/types.ts +33 -16
  27. package/src/components/Drawer/index.tsx +125 -133
  28. package/src/components/Drawer/styles.ts +5 -0
  29. package/src/components/Dropzone/index.tsx +63 -87
  30. package/src/components/Dropzone/styles.ts +6 -0
  31. package/src/components/Dropzone/types.ts +37 -29
  32. package/src/components/EmptyPlaceholder/index.tsx +83 -63
  33. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  34. package/src/components/FileInput.tsx +91 -0
  35. package/src/components/Grid/index.tsx +41 -40
  36. package/src/components/Grid/styles.ts +9 -2
  37. package/src/components/Grid/types.ts +12 -10
  38. package/src/components/Icon/index.tsx +47 -45
  39. package/src/components/Icon/styles.ts +8 -0
  40. package/src/components/InputBase/index.tsx +42 -71
  41. package/src/components/InputBase/styles.ts +47 -37
  42. package/src/components/InputBase/types.ts +7 -19
  43. package/src/components/InputBase/utils.ts +23 -3
  44. package/src/components/List/ListLayout.tsx +37 -20
  45. package/src/components/List/PaginationIndicator.tsx +102 -0
  46. package/src/components/List/index.tsx +41 -36
  47. package/src/components/List/styles.ts +11 -5
  48. package/src/components/List/types.ts +20 -30
  49. package/src/components/List/useInfiniteScroll.ts +159 -0
  50. package/src/components/LoadingOverlay/index.tsx +33 -31
  51. package/src/components/LoadingOverlay/styles.ts +8 -3
  52. package/src/components/Modal/index.tsx +160 -98
  53. package/src/components/Modal/styles.ts +5 -0
  54. package/src/components/NumberIncrement/index.tsx +98 -67
  55. package/src/components/NumberIncrement/styles.ts +5 -0
  56. package/src/components/Overlay/index.tsx +35 -37
  57. package/src/components/Overlay/styles.ts +5 -3
  58. package/src/components/Pager/index.tsx +81 -65
  59. package/src/components/Pager/styles.ts +9 -3
  60. package/src/components/Progress/Bar/index.tsx +50 -45
  61. package/src/components/Progress/Bar/styles.tsx +7 -0
  62. package/src/components/Progress/Bar/types.tsx +30 -0
  63. package/src/components/Progress/Circle/index.tsx +48 -45
  64. package/src/components/Progress/Circle/styles.ts +8 -1
  65. package/src/components/Progress/Circle/types.ts +22 -10
  66. package/src/components/RadioInput/index.tsx +124 -78
  67. package/src/components/RadioInput/styles.ts +6 -0
  68. package/src/components/Scroll/index.tsx +32 -0
  69. package/src/components/Scroll/styles.ts +8 -0
  70. package/src/components/SearchInput/index.tsx +10 -10
  71. package/src/components/SectionFilters/index.tsx +36 -47
  72. package/src/components/SectionFilters/styles.ts +5 -1
  73. package/src/components/SectionFilters/types.ts +13 -14
  74. package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
  75. package/src/components/SegmentedControl/index.tsx +89 -111
  76. package/src/components/SegmentedControl/styles.ts +21 -7
  77. package/src/components/Select/index.tsx +58 -92
  78. package/src/components/Select/styles.ts +36 -19
  79. package/src/components/Select/types.ts +13 -17
  80. package/src/components/Slider/index.tsx +93 -85
  81. package/src/components/Slider/styles.ts +6 -13
  82. package/src/components/Switch/index.tsx +74 -63
  83. package/src/components/Switch/styles.ts +6 -1
  84. package/src/components/Tag/index.tsx +44 -39
  85. package/src/components/Tag/styles.ts +9 -1
  86. package/src/components/Tag/types.ts +10 -10
  87. package/src/components/Text/index.tsx +48 -37
  88. package/src/components/Text/styles.ts +8 -0
  89. package/src/components/Text/types.ts +8 -8
  90. package/src/components/TextEditor/index.tsx +28 -49
  91. package/src/components/TextEditor/styles.ts +8 -1
  92. package/src/components/TextEditor/types.ts +6 -11
  93. package/src/components/TextInput/index.tsx +96 -58
  94. package/src/components/TextInput/mask.tsx +50 -2
  95. package/src/components/TextInput/styles.ts +8 -3
  96. package/src/components/Tooltip/index.tsx +84 -61
  97. package/src/components/Tooltip/styles.ts +10 -3
  98. package/src/components/Touchable/index.tsx +86 -43
  99. package/src/components/Touchable/styles.ts +6 -0
  100. package/src/components/View/index.tsx +50 -36
  101. package/src/components/View/styles.ts +6 -0
  102. package/src/components/View/types.ts +15 -14
  103. package/src/components/components.ts +3 -2
  104. package/src/components/defaultStyles.ts +79 -0
  105. package/src/index.ts +0 -1
  106. package/src/lib/hooks/index.ts +0 -5
  107. package/src/lib/hooks/useBreakpointMatch.ts +7 -8
  108. package/src/lib/hooks/useMediaQuery.ts +3 -4
  109. package/src/lib/hooks/usePagination.ts +63 -79
  110. package/src/lib/index.ts +0 -1
  111. package/src/lib/utils/index.ts +0 -1
  112. package/src/lib/utils/test.ts +2 -2
  113. package/src/components/ActionIcon/types.ts +0 -15
  114. package/src/components/ActivityIndicator/types.ts +0 -12
  115. package/src/components/Badge/types.ts +0 -28
  116. package/src/components/Button/types.ts +0 -25
  117. package/src/components/Checkbox/types.ts +0 -15
  118. package/src/components/Collapse/types.ts +0 -11
  119. package/src/components/Drawer/types.ts +0 -23
  120. package/src/components/EmptyPlaceholder/types.ts +0 -32
  121. package/src/components/FileInput/index.tsx +0 -72
  122. package/src/components/FileInput/types.ts +0 -14
  123. package/src/components/Icon/types.ts +0 -15
  124. package/src/components/LoadingOverlay/types.ts +0 -16
  125. package/src/components/Modal/types.ts +0 -55
  126. package/src/components/NumberIncrement/types.ts +0 -29
  127. package/src/components/Overlay/types.ts +0 -13
  128. package/src/components/Pager/types.ts +0 -35
  129. package/src/components/PaginationButtons/index.tsx +0 -173
  130. package/src/components/PaginationButtons/styles.ts +0 -7
  131. package/src/components/PaginationButtons/types.ts +0 -26
  132. package/src/components/PaginationIndicator/index.tsx +0 -69
  133. package/src/components/PaginationIndicator/styles.ts +0 -3
  134. package/src/components/PaginationIndicator/types.ts +0 -18
  135. package/src/components/Progress/Bar/styles.ts +0 -10
  136. package/src/components/Progress/Bar/types.ts +0 -26
  137. package/src/components/RadioInput/types.ts +0 -29
  138. package/src/components/SegmentedControl/types.ts +0 -44
  139. package/src/components/Slider/types.ts +0 -29
  140. package/src/components/Switch/types.ts +0 -13
  141. package/src/components/TextInput/types.ts +0 -85
  142. package/src/components/Tooltip/types.ts +0 -46
  143. package/src/components/Touchable/types.ts +0 -22
  144. package/src/lib/WebStyleRegistry.ts +0 -51
  145. package/src/lib/hooks/useFileInput.ts +0 -15
  146. package/src/lib/hooks/useInfiniteScroll.ts +0 -77
  147. package/src/lib/hooks/useRefresh.ts +0 -87
  148. package/src/lib/hooks/useStylesFor.ts +0 -13
  149. package/src/lib/utils/cache.ts +0 -9
  150. /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
@@ -1,3 +1,5 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
1
3
  import React from 'react'
2
4
  import { TypeGuards, getRenderedComponent } from '@codeleap/common'
3
5
  import { ActionIcon, ActionIconProps } from '../ActionIcon'
@@ -5,103 +7,95 @@ import { View } from '../View'
5
7
  import { useInputBaseStyles } from './styles'
6
8
  import { InputBaseProps } from './types'
7
9
  import { Text } from '../Text'
8
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
9
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
10
10
 
11
11
  export * from './styles'
12
12
  export * from './utils'
13
13
  export * from './types'
14
14
 
15
- export const InputBaseDefaultOrder: InputBaseProps['order'] = [
15
+ export const InputBaseDefaultOrder:InputBaseProps['order'] = [
16
16
  'label',
17
17
  'description',
18
18
  'innerWrapper',
19
19
  'error',
20
20
  ]
21
-
22
21
  const KeyPassthrough = (props: React.PropsWithChildren<any>) => {
23
22
  return <React.Fragment>{props.children}</React.Fragment>
24
23
  }
25
24
 
26
- export const InputBase = (props: InputBaseProps) => {
27
- const allProps = {
28
- ...InputBase.defaultProps,
29
- ...props,
30
- }
31
-
25
+ export const InputBase = React.forwardRef<unknown, InputBaseProps>((props, ref) => {
32
26
  const {
33
27
  children,
34
- error,
28
+ error = null,
35
29
  label,
36
- description,
37
- leftIcon,
38
- rightIcon,
30
+ description = null,
31
+ leftIcon = null,
32
+ rightIcon = null,
33
+ styles,
39
34
  wrapper,
40
35
  debugName,
41
36
  innerWrapper,
42
37
  focused,
43
- innerWrapperProps,
44
- wrapperProps,
45
- disabled,
46
- order,
38
+ innerWrapperProps = {},
39
+ wrapperProps = {},
40
+ disabled = false,
41
+ order = InputBaseDefaultOrder,
47
42
  style,
48
- noError,
49
- labelAsRow,
43
+ noError = false,
44
+ labelAsRow = false,
50
45
  innerWrapperRef,
51
46
  ...otherProps
52
- } = allProps
47
+ } = props
53
48
 
54
49
  const WrapperComponent = wrapper || View
55
50
  const InnerWrapperComponent = innerWrapper || View
56
51
 
57
- const styles = useInputBaseStyles(allProps)
52
+ const _styles = useInputBaseStyles(props)
58
53
 
59
54
  const _leftIcon = getRenderedComponent<Partial<ActionIconProps>>(leftIcon, ActionIcon, {
60
- style: styles.leftIconStyles,
55
+ // @ts-ignore
56
+ styles: _styles.leftIconStyles,
61
57
  disabled,
62
58
  debugName: `${debugName} left icon`,
63
59
  })
64
60
 
65
61
  const _rightIcon = getRenderedComponent<Partial<ActionIconProps>>(rightIcon, ActionIcon, {
66
- style: styles.rightIconStyles,
62
+ // @ts-ignore
63
+ styles: _styles.rightIconStyles,
67
64
  disabled,
68
65
  debugName: `${debugName} right icon`,
69
66
  })
70
67
 
71
- const _label = TypeGuards.isString(label) ? <Text text={label} style={styles.labelStyle} /> : label
68
+ const _label = TypeGuards.isString(label) ? <Text text={label} css={_styles.labelStyle}/> : label
72
69
 
73
- const _error = TypeGuards.isString(error) ? <Text text={error} style={styles.errorStyle} /> : error
70
+ const _error = TypeGuards.isString(error) ? <Text text={error} css={_styles.errorStyle}/> : error
74
71
 
75
- const _description = TypeGuards.isString(description) ? <Text text={description} style={styles.descriptionStyle} /> : description
72
+ const _description = TypeGuards.isString(description) ? <Text text={description} css={_styles.descriptionStyle}/> : description
76
73
 
77
74
  const parts = {
78
- label: labelAsRow ? (
79
- <View style={styles.labelRowStyle}>
80
- {_label}
81
- {_description}
82
- </View>
83
- ) : (
84
- _label
85
- ),
75
+ label: labelAsRow ? <View css={_styles.labelRowStyle}>
76
+ {_label}
77
+ {_description}
78
+ </View> : _label,
86
79
  description: labelAsRow ? null : _description,
87
- innerWrapper:
88
- <InnerWrapperComponent
89
- ref={innerWrapperRef}
90
- style={styles.innerWrapperStyle}
91
- {...innerWrapperProps}
92
- >
93
- {_leftIcon}
94
- {children}
95
- {_rightIcon}
96
- </InnerWrapperComponent>,
97
- error: noError ? null : (_error || <Text children={<React.Fragment> &nbsp; </React.Fragment>} style={styles.errorStyle} />),
80
+ innerWrapper: <InnerWrapperComponent ref={innerWrapperRef} css={[
81
+ _styles.innerWrapperStyle,
82
+ ]} {...innerWrapperProps}>
83
+ {_leftIcon}
84
+ {children}
85
+ {_rightIcon}
86
+ </InnerWrapperComponent>,
87
+ error: noError ? null : (
88
+ _error || <Text children={<React.Fragment>
89
+ &nbsp;
90
+ </React.Fragment>} css={_styles.errorStyle}/>
91
+ ),
98
92
  }
99
93
 
100
94
  return (
101
95
  <WrapperComponent
96
+ css={[_styles.wrapperStyle, style]}
102
97
  {...otherProps}
103
98
  {...wrapperProps}
104
- style={styles.wrapperStyle}
105
99
  >
106
100
  {
107
101
  order.map((key) => (
@@ -112,27 +106,4 @@ export const InputBase = (props: InputBaseProps) => {
112
106
  }
113
107
  </WrapperComponent>
114
108
  )
115
- }
116
-
117
- InputBase.elements = [
118
- 'wrapper',
119
- 'innerWrapper',
120
- 'label',
121
- 'errorMessage',
122
- 'description',
123
- 'labelRow',
124
- 'icon',
125
- 'leftIcon',
126
- 'rightIcon',
127
- ]
128
-
129
- InputBase.defaultProps = {
130
- noError: false,
131
- labelAsRow: false,
132
- disabled: false,
133
- order: InputBaseDefaultOrder,
134
- rightIcon: null,
135
- leftIcon: null,
136
- description: null,
137
- error: null,
138
- } as Partial<InputBaseProps>
109
+ })
@@ -1,6 +1,5 @@
1
- import { TypeGuards } from '@codeleap/common'
2
- import { useCompositionStyles } from '@codeleap/styles'
3
- import { ActionIconParts } from '../ActionIcon'
1
+ import { TypeGuards, createDefaultVariantFactory, includePresets, useDefaultComponentStyle, useNestedStylesByKey } from '@codeleap/common'
2
+ import { ActionIconComposition, ActionIconParts } from '../ActionIcon'
4
3
  import { InputBaseProps } from './types'
5
4
  import { concatStyles, getIconStyles, iconStylesOf } from './utils'
6
5
 
@@ -25,75 +24,86 @@ export type IconLessInputBaseParts = Exclude<InputBaseParts, InputIconCompositio
25
24
 
26
25
  export type InputBaseComposition = `${InputBaseParts}:${InputBaseStates}` | InputBaseParts
27
26
 
27
+ const createTextInputBaseComposition = createDefaultVariantFactory<InputBaseComposition>()
28
+
29
+ export const InputBasePresets = includePresets((styles) => createTextInputBaseComposition(() => ({ wrapper: styles })))
30
+
28
31
  export const useInputBaseStyles = (props: InputBaseProps) => {
29
32
  const {
30
33
  focused,
31
34
  disabled,
32
35
  error,
33
- style: styles,
36
+ styles,
34
37
  } = props
35
38
 
36
39
  const hasError = !TypeGuards.isNil(error)
37
40
 
38
- const compositionStyles = useCompositionStyles(['leftIcon', 'rightIcon', 'icon'], styles)
41
+ const variantStyles = useDefaultComponentStyle<'u:InputBase', typeof InputBasePresets>('u:InputBase', {
42
+ rootElement: 'wrapper',
43
+ styles,
44
+ })
45
+
46
+ const _leftIconStyles = useNestedStylesByKey<ActionIconComposition>('leftIcon', variantStyles)
47
+ const _rightIconStyles = useNestedStylesByKey<ActionIconComposition>('rightIcon', variantStyles)
48
+ const _baseIconStyles = useNestedStylesByKey<ActionIconComposition>('icon', variantStyles)
39
49
 
40
- const baseIconStyles = getIconStyles(compositionStyles.icon, { hasError, disabled, focused })
50
+ const baseIconStyles = getIconStyles(_baseIconStyles, { hasError, disabled, focused })
41
51
 
42
- const leftIconStylesCompose = getIconStyles(compositionStyles.leftIcon, {
43
- hasError,
44
- disabled: disabled || props?.leftIcon?.disabled,
45
- focused,
52
+ const leftIconStylesCompose = getIconStyles(_leftIconStyles, {
53
+ hasError,
54
+ disabled: disabled || props?.leftIcon?.disabled,
55
+ focused
46
56
  })
47
57
 
48
- const rightIconStylesCompose = getIconStyles(compositionStyles.rightIcon, {
49
- hasError,
58
+ const rightIconStylesCompose = getIconStyles(_rightIconStyles, {
59
+ hasError,
50
60
  disabled: disabled || props?.rightIcon?.disabled,
51
- focused,
61
+ focused
52
62
  })
53
63
 
54
64
  const leftIconStyles = iconStylesOf(baseIconStyles, leftIconStylesCompose)
55
65
  const rightIconStyles = iconStylesOf(baseIconStyles, rightIconStylesCompose)
56
66
 
57
67
  const labelStyle = [
58
- styles.label,
59
- focused && styles['label:focus'],
60
- hasError && styles['label:error'],
61
- disabled && styles['label:disabled'],
68
+ variantStyles.label,
69
+ focused && variantStyles['label:focus'],
70
+ hasError && variantStyles['label:error'],
71
+ disabled && variantStyles['label:disabled'],
62
72
  ]
63
73
 
64
74
  const errorStyle = [
65
- styles.errorMessage,
66
- focused && styles['errorMessage:focus'],
67
- hasError && styles['errorMessage:error'],
68
- disabled && styles['errorMessage:disabled'],
75
+ variantStyles.errorMessage,
76
+ focused && variantStyles['errorMessage:focus'],
77
+ hasError && variantStyles['errorMessage:error'],
78
+ disabled && variantStyles['errorMessage:disabled'],
69
79
  ]
70
80
 
71
81
  const descriptionStyle = [
72
- styles.description,
73
- focused && styles['description:focus'],
74
- hasError && styles['description:error'],
75
- disabled && styles['description:disabled'],
82
+ variantStyles.description,
83
+ focused && variantStyles['description:focus'],
84
+ hasError && variantStyles['description:error'],
85
+ disabled && variantStyles['description:disabled'],
76
86
  ]
77
87
 
78
88
  const wrapperStyle = [
79
- styles.wrapper,
80
- focused && styles['wrapper:focus'],
81
- error && styles['wrapper:error'],
82
- disabled && styles['wrapper:disabled'],
89
+ variantStyles.wrapper,
90
+ focused && variantStyles['wrapper:focus'],
91
+ error && variantStyles['wrapper:error'],
92
+ disabled && variantStyles['wrapper:disabled'],
83
93
  ]
84
94
 
85
95
  const innerWrapperStyle = [
86
- concatStyles(Array.isArray(styles.innerWrapper) ? styles.innerWrapper : [styles.innerWrapper]),
87
- focused && styles['innerWrapper:focus'],
88
- hasError && styles['innerWrapper:error'],
89
- disabled && styles['innerWrapper:disabled'],
96
+ concatStyles(variantStyles.innerWrapper),
97
+ focused && variantStyles['innerWrapper:focus'],
98
+ hasError && variantStyles['innerWrapper:error'],
99
+ disabled && variantStyles['innerWrapper:disabled'],
90
100
  ]
91
101
 
92
102
  const labelRowStyle = [
93
- styles.labelRow,
94
- focused && styles['labelRow:focus'],
95
- hasError && styles['labelRow:error'],
96
- disabled && styles['labelRow:disabled'],
103
+ variantStyles.labelRow,
104
+ focused && variantStyles['labelRow:focus'],
105
+ hasError && variantStyles['labelRow:error'],
106
+ disabled && variantStyles['labelRow:disabled'],
97
107
  ]
98
108
 
99
109
  return {
@@ -1,6 +1,9 @@
1
- import { StylesOf } from '@codeleap/common'
1
+ import { PropsOf } from '@codeleap/common'
2
+ import { StylesOf } from '../../types'
2
3
  import { InputBaseComposition } from './styles'
3
- import { ActionIconComposition, ActionIconProps } from '../ActionIcon'
4
+ import { ActionIcon } from '../ActionIcon'
5
+
6
+ type ActionIconProps = PropsOf<typeof ActionIcon>
4
7
 
5
8
  type OrderedParts = 'label' | 'description' | 'innerWrapper' | 'error'
6
9
 
@@ -13,29 +16,14 @@ export type InputBaseProps = React.PropsWithChildren<{
13
16
  wrapperProps?: any
14
17
  innerWrapper?: React.FC<any>
15
18
  innerWrapperProps?: any
16
- style?: StylesOf<InputBaseComposition>
19
+ styles?: StylesOf<InputBaseComposition>
17
20
  description?: React.ReactNode
18
21
  debugName: string
19
22
  focused?: boolean
20
23
  disabled?: boolean
21
24
  order?: OrderedParts[]
25
+ style?: any
22
26
  labelAsRow?: boolean
23
27
  noError?: boolean
24
28
  innerWrapperRef?: React.MutableRefObject<HTMLDivElement | null>
25
29
  }>
26
-
27
- export type OmitDiff<T1, T2> = {
28
- [K in Exclude<keyof T1, keyof T2>]: T1[K]
29
- } & {
30
- [K in keyof T2]: T2[K]
31
- }
32
-
33
- export type InputBaseKey = keyof InputBaseProps
34
-
35
- export type IconStyles = StylesOf<ActionIconComposition>
36
-
37
- export type IconState = {
38
- focused: boolean
39
- hasError: boolean
40
- disabled: boolean
41
- }
@@ -1,15 +1,27 @@
1
- import { IconState, IconStyles, InputBaseKey, InputBaseProps, OmitDiff } from './types'
1
+ import { StylesOf } from '@codeleap/common'
2
+ import { ActionIconComposition } from '../ActionIcon'
3
+ import { InputBaseProps } from './types'
2
4
 
3
- export function selectInputBaseProps<T extends Omit<InputBaseProps, 'style'>>(props: T): {
5
+ type OmitDiff<T1, T2> = {
6
+ [K in Exclude<keyof T1, keyof T2>]: T1[K]
7
+ } & {
8
+ [K in keyof T2]: T2[K]
9
+ }
10
+
11
+ type InputBaseKey = keyof InputBaseProps
12
+
13
+ export function selectInputBaseProps<T extends InputBaseProps>(props: T): {
4
14
  inputBaseProps: InputBaseProps
5
15
  others: OmitDiff<T, T>
6
16
  } {
7
17
  const varList:InputBaseKey[] = [
8
18
  'label',
19
+
9
20
  'error',
10
21
  'innerWrapper',
11
22
  'leftIcon',
12
23
  'rightIcon',
24
+ // 'styles',
13
25
  'description',
14
26
  'wrapper',
15
27
  'children',
@@ -30,6 +42,14 @@ export function selectInputBaseProps<T extends Omit<InputBaseProps, 'style'>>(pr
30
42
  return { inputBaseProps: result, others: copy as OmitDiff<T, T> }
31
43
  }
32
44
 
45
+ type IconStyles = StylesOf<ActionIconComposition>
46
+
47
+ type IconState = {
48
+ focused: boolean
49
+ hasError: boolean
50
+ disabled: boolean
51
+ }
52
+
33
53
  export const getIconStyles = (obj: IconStyles, state: IconState) => ({
34
54
  icon: {
35
55
  ...obj.icon,
@@ -80,5 +100,5 @@ export const iconStylesOf = (baseStyles: IconStyles, styles: IconStyles) => ({
80
100
  'touchableWrapper:disabled': {
81
101
  ...baseStyles['touchableWrapper:disabled'],
82
102
  ...styles['touchableWrapper:disabled'],
83
- },
103
+ }
84
104
  })
@@ -1,16 +1,26 @@
1
1
  import React from 'react'
2
+ import { StylesOf, TypeGuards } from '@codeleap/common'
3
+ import { ListComposition, ListParts } from './styles'
4
+ import { ListProps } from './types'
2
5
  import { View } from '../View'
3
- import { ListLayoutProps, ListRefreshControlComponent } from './types'
4
- import { mergeStyles } from '@codeleap/styles'
6
+ import { UseInfiniteScrollReturn } from './useInfiniteScroll'
5
7
  import { ActivityIndicator } from '../ActivityIndicator'
6
- import { ListParts } from './styles'
7
- import { TypeGuards } from '@codeleap/common'
8
8
  import { motion } from 'framer-motion'
9
9
 
10
+ export type ListLayoutProps = Omit<ListProps, 'renderItem'> & UseInfiniteScrollReturn['layoutProps'] & {
11
+ variantStyles: StylesOf<ListComposition>
12
+ children?: React.ReactNode
13
+ showFooter?: boolean
14
+ }
15
+
16
+ type ListRefreshControlComponent = Partial<ListLayoutProps> & {
17
+ variantStyles: StylesOf<ListComposition>
18
+ }
19
+
10
20
  const DefaultRefreshIndicator = (props: ListRefreshControlComponent) => {
11
21
  const {
12
22
  refreshing,
13
- styles,
23
+ variantStyles,
14
24
  refreshPosition,
15
25
  refreshControlProps,
16
26
  debugName,
@@ -20,19 +30,19 @@ const DefaultRefreshIndicator = (props: ListRefreshControlComponent) => {
20
30
 
21
31
  return (
22
32
  <motion.div
33
+ css={[variantStyles?.refreshControl]}
23
34
  initial={false}
24
35
  animate={{
25
36
  opacity: refreshing ? 1 : 0,
26
- top: refreshing ? refreshPosition : 0,
37
+ top: refreshing ? refreshPosition : 0
27
38
  }}
28
39
  {...refreshControlProps}
29
- style={styles?.refreshControl}
30
40
  >
31
41
  <ActivityIndicator
32
42
  debugName={debugName + 'refresh-indicator'}
33
43
  size={refreshSize}
44
+ style={variantStyles.refreshControlIndicator}
34
45
  {...refreshControlIndicatorProps}
35
- style={styles.refreshControlIndicator}
36
46
  />
37
47
  </motion.div>
38
48
  )
@@ -45,10 +55,11 @@ export const ListLayout = (props: ListLayoutProps) => {
45
55
  ListHeaderComponent,
46
56
  refresh,
47
57
  ListRefreshControlComponent = DefaultRefreshIndicator,
48
- styles,
58
+ variantStyles,
49
59
  isEmpty,
50
60
  isLoading,
51
61
  placeholder = {},
62
+ style,
52
63
  children,
53
64
  debugName,
54
65
  isFetching,
@@ -58,27 +69,33 @@ export const ListLayout = (props: ListLayoutProps) => {
58
69
  showFooter = true,
59
70
  } = props
60
71
 
61
- const getKeyStyle = (key: ListParts) => mergeStyles([
62
- styles[key],
63
- isLoading ? styles[`${key}:loading`] : null,
64
- isEmpty ? styles[`${key}:empty`] : null,
65
- ])
66
-
67
- const showIndicator = (isFetching || isFetchingNextPage) && !TypeGuards.isNil(ListLoadingIndicatorComponent)
72
+ const getKeyStyle = React.useCallback((key: ListParts) => ([
73
+ variantStyles[key],
74
+ isLoading && variantStyles[`${key}:loading`],
75
+ isEmpty && variantStyles[`${key}:empty`],
76
+ ]), [isLoading, isEmpty])
68
77
 
69
78
  return (
70
- <View style={getKeyStyle('wrapper')} ref={scrollableRef}>
79
+ // @ts-ignore
80
+ <View css={[getKeyStyle('wrapper'), style]} ref={scrollableRef}>
71
81
  {!!ListHeaderComponent ? <ListHeaderComponent /> : null}
72
82
 
73
83
  {isEmpty ? <ListEmptyComponent debugName={debugName} {...placeholder} /> : null}
74
84
 
75
- <View style={[getKeyStyle('innerWrapper'), isEmpty && { display: 'none' }]}>
76
- {(!ListRefreshControlComponent || !refresh) ? null : <ListRefreshControlComponent {...props} styles={styles} />}
85
+ <View css={[getKeyStyle('innerWrapper'), isEmpty && { display: 'none' }]}>
86
+ {(!ListRefreshControlComponent || !refresh) ? null : (
87
+ <ListRefreshControlComponent
88
+ {...props}
89
+ variantStyles={variantStyles}
90
+ />
91
+ )}
77
92
 
78
93
  {children}
79
94
  </View>
80
95
 
81
- {showIndicator ? <ListLoadingIndicatorComponent /> : null}
96
+ {((isFetching || isFetchingNextPage) && !TypeGuards.isNil(ListLoadingIndicatorComponent))
97
+ ? <ListLoadingIndicatorComponent />
98
+ : null}
82
99
 
83
100
  {(!!ListFooterComponent && showFooter) ? <ListFooterComponent {...props} /> : null}
84
101
  </View>
@@ -0,0 +1,102 @@
1
+ import React from 'react'
2
+ import {
3
+ assignTextStyle,
4
+ ComponentVariants,
5
+ createDefaultVariantFactory,
6
+ getNestedStylesByKey,
7
+ includePresets,
8
+ StylesOf,
9
+ TypeGuards,
10
+ useDefaultComponentStyle,
11
+ } from '@codeleap/common'
12
+ import { ActivityIndicator, ActivityIndicatorComposition, ActivityIndicatorProps } from '../ActivityIndicator'
13
+ import { Text, TextProps } from '../Text'
14
+ import { View } from '../View'
15
+ import { ComponentCommonProps } from '../../types'
16
+
17
+ export type PaginationIndicatorComposition = 'text' | `loader${Capitalize<ActivityIndicatorComposition>}` | 'wrapper'
18
+
19
+ const createPaginationIndicatorStyle = createDefaultVariantFactory<PaginationIndicatorComposition>()
20
+
21
+ const presets = includePresets((style) => createPaginationIndicatorStyle(() => ({ loaderWrapper: style, text: style })))
22
+
23
+ export const PaginationIndicatorStyles = {
24
+ ...presets,
25
+ default: createPaginationIndicatorStyle((theme) => {
26
+ return {
27
+ wrapper: {
28
+ ...theme.presets.fullWidth,
29
+ ...theme.presets.center,
30
+ },
31
+ loaderWrapper: {
32
+ ...theme.presets.center,
33
+ ...theme.spacing.marginVertical(3),
34
+ },
35
+ text: {
36
+ ...assignTextStyle('h4')(theme).text,
37
+ ...theme.presets.textCenter,
38
+ ...theme.spacing.marginVertical(3),
39
+ ...theme.presets.fullWidth,
40
+ },
41
+ }
42
+ }),
43
+ }
44
+
45
+ export type PaginationIndicatorProps = {
46
+ isFetching?: boolean
47
+ noMoreItemsText: React.ReactChild
48
+ hasMore?: boolean
49
+ activityIndicator?: JSX.Element
50
+ styles?: StylesOf<PaginationIndicatorComposition>
51
+ style?: React.CSSProperties
52
+ indicatorProps?: Partial<ActivityIndicatorProps>
53
+ textProps?: Partial<TextProps<'p'>>
54
+ } & ComponentVariants<typeof PaginationIndicatorStyles> & ComponentCommonProps
55
+
56
+ const defaultProps: Partial<PaginationIndicatorProps> = {}
57
+
58
+ export const PaginationIndicator = (props: PaginationIndicatorProps) => {
59
+ const allProps = {
60
+ ...PaginationIndicator.defaultProps,
61
+ ...props,
62
+ }
63
+
64
+ const {
65
+ hasMore,
66
+ isFetching,
67
+ noMoreItemsText,
68
+ style,
69
+ activityIndicator,
70
+ styles = {},
71
+ responsiveVariants = {},
72
+ variants = [],
73
+ indicatorProps = {},
74
+ debugName,
75
+ } = allProps
76
+
77
+ const variantStyles = useDefaultComponentStyle<
78
+ 'u:PaginationIndicator',
79
+ typeof PaginationIndicatorStyles
80
+ >('u:PaginationIndicator', {
81
+ variants,
82
+ responsiveVariants,
83
+ styles,
84
+ })
85
+
86
+ const loaderStyles = getNestedStylesByKey('loader', variantStyles)
87
+
88
+ if (isFetching) {
89
+ return activityIndicator || <View css={[variantStyles.wrapper, style]}><ActivityIndicator debugName={debugName} {...indicatorProps} styles={loaderStyles}/></View>
90
+ }
91
+
92
+ if (!hasMore) {
93
+ if (TypeGuards.isString(noMoreItemsText) || TypeGuards.isNumber(noMoreItemsText)) {
94
+ return <Text debugName={debugName} css={[variantStyles.text, style]} text={noMoreItemsText.toString()}/>
95
+ }
96
+ return noMoreItemsText
97
+ }
98
+
99
+ return null
100
+ }
101
+
102
+ PaginationIndicator.defaultProps = defaultProps