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