@codeleap/mobile 3.25.0 → 3.25.3

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,37 +1,70 @@
1
- import React from 'react'
2
- import { arePropsEqual, TypeGuards } from '@codeleap/common'
3
- import { Image as NativeImage } from 'react-native'
1
+ import * as React from 'react'
2
+ import {
3
+ ComponentVariants,
4
+ useDefaultComponentStyle,
5
+ arePropsEqual,
6
+ FormTypes,
7
+ TypeGuards,
8
+ getNestedStylesByKey,
9
+ } from '@codeleap/common'
10
+ import {
11
+ Image as NativeImage,
12
+ ImageProps as NativeImageProps,
13
+ ImageStyle,
14
+ StyleProp,
15
+ StyleSheet,
16
+ TextStyle,
17
+ ViewStyle,
18
+ } from 'react-native'
19
+ import {
20
+ ImageComposition,
21
+ ImagePresets,
22
+ } from './styles'
4
23
  import { useImageSpotlight } from '../ImageView/Spotlight'
5
24
  import { Touchable } from '../Touchable'
6
25
  import { isFile, toMultipartFile } from '../../utils'
7
- import { LoadingOverlay } from '../LoadingOverlay'
8
- import FastImage from 'react-native-fast-image'
9
- import { ImageProps } from './types'
10
- import { AnyRecord, useNestedStylesByKey, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
11
- import { MobileStyleRegistry } from '../../Registry'
12
- import { useStylesFor } from '../../hooks'
26
+ import { LoadingOverlay, LoadingOverlayProps } from '../LoadingOverlay'
27
+ import { StylesOf } from '../../types'
28
+ import FastImage, { Source } from 'react-native-fast-image'
13
29
 
14
30
  export * from './styles'
15
- export * from './types'
16
31
 
17
- export const Image = React.memo((props: ImageProps) => {
32
+ export type ImageProps = Omit<NativeImageProps, 'source' | 'style'> & {
33
+ variants?: ComponentVariants<typeof ImagePresets>['variants']
34
+ fast?: boolean
35
+ styles?: StylesOf<ImageComposition>
36
+ style?: StyleProp<ImageStyle | TextStyle | ViewStyle>
37
+ source:
38
+ | Source
39
+ | FormTypes.AnyFile
40
+ resizeMode?: keyof typeof FastImage.resizeMode
41
+ spotlight?: string
42
+ maintainAspectRatio?: boolean
43
+ withLoadingOverlay?: boolean | ((props: LoadingOverlayProps) => JSX.Element)
44
+ }
45
+
46
+ export const ImageComponent = (props:ImageProps) => {
18
47
  const {
48
+ variants,
19
49
  style,
20
- fast,
50
+ styles: componentStyleSheet = {},
51
+ fast = true,
21
52
  spotlight = null,
22
- resizeMode,
53
+ resizeMode = 'contain',
23
54
  source,
24
- withLoadingOverlay,
25
- maintainAspectRatio,
55
+ withLoadingOverlay = false,
56
+ maintainAspectRatio = true,
26
57
  ...imageProps
27
- } = {
28
- ...Image.defaultProps,
29
- ...props,
30
- }
58
+ } = props
31
59
 
60
+ const variantStyles = useDefaultComponentStyle<'u:Image', typeof ImagePresets>('u:Image', {
61
+ variants,
62
+ styles: componentStyleSheet,
63
+ transform: StyleSheet.flatten,
64
+ })
32
65
  const [loading, setLoading] = React.useState(false)
33
66
 
34
- const styles = useStylesFor(Image.styleRegistryName, style)
67
+ const styles = StyleSheet.flatten([variantStyles.wrapper, style])
35
68
 
36
69
  let imSource = source
37
70
 
@@ -40,14 +73,12 @@ export const Image = React.memo((props: ImageProps) => {
40
73
  } else if (TypeGuards.isString(source)) {
41
74
  imSource = { uri: source }
42
75
  }
43
-
44
76
  const spotlightActions = useImageSpotlight(spotlight, props.source)
45
77
  const Wrapper = !!spotlight ? Touchable : ({ children }) => <>{children}</>
46
-
47
78
  const wrapperProps = {
48
79
  onPress: spotlightActions.onImagePressed,
49
80
  debugName: `Press spotlight image ${props.source}`,
50
- style: styles.touchable,
81
+ style: [variantStyles.touchable],
51
82
  android_ripple: null,
52
83
  }
53
84
 
@@ -91,21 +122,23 @@ export const Image = React.memo((props: ImageProps) => {
91
122
  const Loading = TypeGuards.isFunction(withLoadingOverlay) ? withLoadingOverlay : LoadingOverlay
92
123
  const showLoading = !!withLoadingOverlay
93
124
 
94
- const overlayStyle = useNestedStylesByKey('overlay', styles)
125
+ const overlayStyle = React.useMemo(() => getNestedStylesByKey('overlay', variantStyles), [variantStyles])
95
126
 
96
127
  const loadingElement = React.useMemo(() => {
97
128
  return showLoading ? (
98
- <Loading visible={loading} style={overlayStyle} />
129
+ <Loading visible={loading} styles={overlayStyle}/>
130
+
99
131
  ) : null
100
132
  }, [showLoading, loading])
101
133
 
102
134
  if (fast) {
103
135
  return (
104
136
  <Wrapper {...wrapperProps}>
137
+
105
138
  <FastImage
106
- style={[aspectRatioStyle, styles.wrapper]}
139
+ style={[aspectRatioStyle, styles]}
107
140
  // @ts-ignore
108
- tintColor={styles?.wrapper?.tintColor}
141
+ tintColor={styles?.tintColor}
109
142
  // @ts-ignore
110
143
  source={imSource}
111
144
  resizeMode={FastImage.resizeMode[resizeMode || 'contain']}
@@ -116,38 +149,25 @@ export const Image = React.memo((props: ImageProps) => {
116
149
  </Wrapper>
117
150
  )
118
151
  }
119
-
120
- return (
121
- <Wrapper {...wrapperProps}>
122
- <NativeImage
123
- resizeMode={resizeMode}
124
- source={imSource}
125
- {...(imageProps as any)}
126
- {...loadProps.current}
127
- style={[aspectRatioStyle, styles.wrapper]}
128
- />
129
-
130
- {loadingElement}
131
- </Wrapper>
132
- )
133
- }, (prevProps, nextProps) => {
134
- const equal = arePropsEqual(prevProps, nextProps, { check: ['source', 'style', 'resizeMode', 'fast'] })
135
- return equal
136
- }) as StyledComponentWithProps<ImageProps>
137
-
138
- Image.styleRegistryName = 'Image'
139
- Image.elements = ['wrapper', 'touchable', 'overlay']
140
- Image.rootElement = 'wrapper'
141
-
142
- Image.withVariantTypes = <S extends AnyRecord>(styles: S) => {
143
- return Image as (props: StyledComponentProps<ImageProps, typeof styles>) => IJSX
152
+ return <Wrapper {...wrapperProps}>
153
+ <NativeImage
154
+ style={[aspectRatioStyle, styles]}
155
+ resizeMode={resizeMode}
156
+ source={imSource}
157
+ {...(imageProps as any)}
158
+ {...loadProps.current}
159
+ />
160
+ {
161
+ loadingElement
162
+ }
163
+ </Wrapper>
144
164
  }
145
165
 
146
- Image.defaultProps = {
147
- fast: true,
148
- resizeMode: 'contain',
149
- withLoadingOverlay: false,
150
- maintainAspectRatio: true,
166
+ function areEqual(prevProps, nextProps) {
167
+ const check = ['source', 'style', 'variants', 'resizeMode', 'fast']
168
+ const res = arePropsEqual(prevProps, nextProps, { check })
169
+ return res
151
170
  }
152
171
 
153
- MobileStyleRegistry.registerComponent(Image)
172
+ export const Image = React.memo(ImageComponent, areEqual) as typeof ImageComponent
173
+
@@ -1,3 +1,8 @@
1
- import { LoadingOverlayComposition } from '../LoadingOverlay'
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { LoadingOverlayComposition } from '../LoadingOverlay/styles'
2
3
 
3
4
  export type ImageComposition = 'wrapper' | 'touchable' | `overlay${Capitalize<LoadingOverlayComposition>}`
5
+ const createImageStyle = createDefaultVariantFactory<ImageComposition>()
6
+
7
+ export const ImagePresets = includePresets((styles) => createImageStyle(() => ({ wrapper: styles, touchable: styles })))
8
+
@@ -1,5 +1,6 @@
1
1
  import React, { useContext, useState } from 'react'
2
2
  import { deepEqual, onUpdate, ReactState, TypeGuards, usePrevious, useUnmount } from '@codeleap/common'
3
+
3
4
  import uuid from 'react-native-uuid'
4
5
  import { ImageView, ImageViewProps } from './component'
5
6
  import { ImageProps } from '../Image'
@@ -165,7 +166,9 @@ export type SpotlightProps = {
165
166
  } & ImageViewProps
166
167
 
167
168
  const DefaultFooterComponent: SpootlightFooterComponent = ({ imageIndex, imagesLength }) => (
168
- <View><Text text={imageIndex + 1 + '/' + imagesLength} /></View>
169
+ <View variants={['marginBottom:5', 'alignCenter']}>
170
+ <Text text={imageIndex + 1 + '/' + imagesLength} />
171
+ </View>
169
172
  )
170
173
 
171
174
  export const Spotlight = (props: SpotlightProps) => {
@@ -1,4 +1,5 @@
1
- import React from 'react'
1
+ import * as React from 'react'
2
+
2
3
  import { onUpdate, PropsOf } from '@codeleap/common'
3
4
  import _ImageView from 'react-native-image-viewing'
4
5
  import { StatusBar } from 'react-native'
@@ -16,12 +16,11 @@ export const InputBaseDefaultOrder: InputBaseProps['order'] = [
16
16
  'innerWrapper',
17
17
  'error',
18
18
  ]
19
-
20
19
  const KeyPassthrough = (props: React.PropsWithChildren<any>) => {
21
20
  return <>{props.children}</>
22
21
  }
23
22
 
24
- export const InputBase = (props: InputBaseProps) => {
23
+ export const InputBase = React.forwardRef<any, InputBaseProps>((props, ref) => {
25
24
  const {
26
25
  children,
27
26
  error = null,
@@ -29,67 +28,69 @@ export const InputBase = (props: InputBaseProps) => {
29
28
  description = null,
30
29
  leftIcon = null,
31
30
  rightIcon = null,
32
- wrapper: WrapperComponent,
31
+ styles,
32
+ wrapper,
33
33
  debugName,
34
- innerWrapper: InnerWrapperComponent,
34
+ innerWrapper,
35
35
  focused,
36
36
  innerWrapperProps = {},
37
37
  wrapperProps = {},
38
- disabled,
38
+ disabled = false,
39
39
  order = InputBaseDefaultOrder,
40
40
  style,
41
- labelAsRow,
42
- hideErrorMessage,
41
+ labelAsRow = false,
42
+ hideErrorMessage = false,
43
43
  ...otherProps
44
- } = {
45
- ...InputBase.defaultProps,
46
- ...props,
47
- }
44
+ } = props
48
45
 
49
- const styles = useInputBaseStyles(props)
46
+ const WrapperComponent = wrapper || View
47
+ const InnerWrapperComponent = innerWrapper || View
48
+
49
+ const _styles = useInputBaseStyles(props)
50
50
 
51
51
  const _leftIcon = getRenderedComponent<Partial<ActionIconProps>>(leftIcon, ActionIcon, {
52
52
  // @ts-ignore
53
- style: styles.leftIconStyles,
53
+ styles: _styles.leftIconStyles,
54
54
  debugName: `${debugName} left icon`,
55
55
  dismissKeyboard: false,
56
56
  })
57
57
 
58
58
  const _rightIcon = getRenderedComponent<Partial<ActionIconProps>>(rightIcon, ActionIcon, {
59
+
59
60
  // @ts-ignore
60
- style: styles.rightIconStyles,
61
+ styles: _styles.rightIconStyles,
61
62
  debugName: `${debugName} right icon`,
62
63
  dismissKeyboard: false,
63
64
  })
64
65
 
65
- const _label = TypeGuards.isString(label) ? <Text text={label} style={styles.labelStyle} /> : label
66
+ const _label = TypeGuards.isString(label) ? <Text text={label} style={_styles.labelStyle} /> : label
66
67
 
67
- const _error = TypeGuards.isString(error) ? <Text text={error} style={styles.errorStyle} /> : error
68
+ const _error = TypeGuards.isString(error) ? <Text text={error} style={_styles.errorStyle} /> : error
68
69
 
69
- const _description = TypeGuards.isString(description) ? <Text text={description} style={styles.descriptionStyle} /> : description
70
+ const _description = TypeGuards.isString(description) ? <Text text={description} style={_styles.descriptionStyle} /> : description
70
71
 
71
72
  const parts = {
72
- label: labelAsRow ? <View style={styles.labelRowStyle}>
73
+ label: labelAsRow ? <View style={_styles.labelRowStyle}>
73
74
  {_label}
74
75
  {_description}
75
76
  </View> : _label,
76
77
  description: labelAsRow ? null : _description,
77
78
  innerWrapper: <InnerWrapperComponent style={[
78
- styles.innerWrapperStyle,
79
+ _styles.innerWrapperStyle,
79
80
  ]} {...innerWrapperProps}>
80
81
  {_leftIcon}
81
82
  {children}
82
83
  {_rightIcon}
83
84
  </InnerWrapperComponent>,
84
85
  error: hideErrorMessage ? null : (
85
- _error || <Text text={''} style={styles.errorStyle} />
86
+ _error || <Text text={''} style={_styles.errorStyle} />
86
87
  ),
87
88
  }
88
89
 
89
90
  return <WrapperComponent
91
+ style={[_styles.wrapperStyle, style]}
90
92
  {...otherProps}
91
93
  {...wrapperProps}
92
- style={styles.wrapperStyle}
93
94
  >
94
95
  {
95
96
  order.map((key) => <KeyPassthrough key={key}>
@@ -97,16 +98,6 @@ export const InputBase = (props: InputBaseProps) => {
97
98
  </KeyPassthrough>)
98
99
 
99
100
  }
100
- </WrapperComponent>
101
- }
102
101
 
103
- InputBase.elements = ['wrapper', 'innerWrapper', 'label', 'errorMessage', 'description', 'icon', 'leftIcon', 'rightIcon']
104
-
105
- InputBase.defaultProps = {
106
- disabled: false,
107
- labelAsRow: false,
108
- hideErrorMessage: false,
109
- order: InputBaseDefaultOrder,
110
- wrapper: View,
111
- innerWrapper: View,
112
- } as Partial<InputBaseProps>
102
+ </WrapperComponent>
103
+ })
@@ -1,8 +1,7 @@
1
- import { TypeGuards } from "@codeleap/common"
2
- import { ActionIconParts } from "../ActionIcon"
1
+ import { TypeGuards, createDefaultVariantFactory, getRenderedComponent, includePresets, useDefaultComponentStyle, useMemo, useNestedStylesByKey } from "@codeleap/common"
2
+ import { ActionIconComposition, ActionIconParts } from "../ActionIcon"
3
3
  import { InputBaseProps } from "./types"
4
- import { mergeStyles, useCompositionStyles } from '@codeleap/styles'
5
- import { useMemo } from 'react'
4
+ import { StyleSheet } from "react-native"
6
5
 
7
6
  type InputIcons = 'icon' | 'leftIcon' | 'rightIcon'
8
7
 
@@ -25,33 +24,32 @@ export type IconLessInputBaseParts = Exclude<InputBaseParts, InputIconCompositio
25
24
 
26
25
  export type InputBaseComposition = `${InputBaseParts}:${InputBaseStates}` | InputBaseParts
27
26
 
28
- const getIconStyles = (obj, state) => ({
29
- icon: mergeStyles([
30
- obj.icon,
31
- state.focused && obj['icon:focus'],
32
- state.hasError && obj['icon:error'],
33
- state.disabled && obj['icon:disabled']
34
- ]),
35
- 'icon:disabled': mergeStyles([
36
- state.disabled && obj['icon:disabled']
37
- ]),
38
- touchableWrapper: mergeStyles([
39
- obj.touchableWrapper,
40
- state.focused && obj['touchableWrapper:focus'],
41
- state.hasError && obj['touchableWrapper:error'],
42
- state.disabled && obj['touchableWrapper:disabled']
43
- ]),
44
- 'touchableWrapper:disabled': mergeStyles([
45
- state.disabled && obj['touchableWrapper:disabled']
46
- ])
47
- })
48
-
49
- const useIconStyles = (styles, iconStyles, states) => {
50
- return useMemo(() => {
51
- const _iconStyles = getIconStyles(iconStyles, states)
52
-
53
- return mergeStyles([styles, _iconStyles])
54
- }, [states, styles, iconStyles])
27
+ const createTextInputBaseComposition = createDefaultVariantFactory<InputBaseComposition>()
28
+
29
+ export const InputBasePresets = includePresets((styles) => createTextInputBaseComposition(() => ({ wrapper: styles })))
30
+
31
+
32
+ const getIconStyles = (obj, state) => {
33
+ return {
34
+ icon: [
35
+ obj.icon,
36
+ state.focused && obj['icon:focus'],
37
+ state.hasError && obj['icon:error'],
38
+ state.disabled && obj['icon:disabled']
39
+ ],
40
+ 'icon:disabled': [
41
+ state.disabled && obj['icon:disabled']
42
+ ],
43
+ touchableWrapper: [
44
+ obj.touchableWrapper,
45
+ state.focused && obj['touchableWrapper:focus'],
46
+ state.hasError && obj['touchableWrapper:error'],
47
+ state.disabled && obj['touchableWrapper:disabled']
48
+ ],
49
+ 'touchableWrapper:disabled': [
50
+ state.disabled && obj['touchableWrapper:disabled']
51
+ ]
52
+ }
55
53
  }
56
54
 
57
55
  export const useInputBaseStyles = (props: InputBaseProps) => {
@@ -59,65 +57,76 @@ export const useInputBaseStyles = (props: InputBaseProps) => {
59
57
  focused,
60
58
  disabled,
61
59
  error,
62
- style: styles,
60
+ styles
63
61
  } = props
64
62
 
65
63
  const hasError = !TypeGuards.isNil(error)
66
64
 
67
- const compositionStyles = useCompositionStyles(['leftIcon', 'rightIcon', 'icon'], styles)
65
+ const variantStyles = useDefaultComponentStyle<'u:InputBase', typeof InputBasePresets>('u:InputBase', {
66
+ styles,
67
+ transform: StyleSheet.flatten,
68
+ rootElement: 'wrapper'
69
+ })
68
70
 
69
- const generalIconStyles = getIconStyles(compositionStyles?.icon, { hasError, disabled })
71
+ const _leftIconStyles = useNestedStylesByKey<ActionIconComposition>('leftIcon', variantStyles)
72
+ const _rightIconStyles = useNestedStylesByKey<ActionIconComposition>('rightIcon', variantStyles)
73
+ const _generalIconStyles = useNestedStylesByKey<ActionIconComposition>('icon', variantStyles)
70
74
 
71
- const leftIconStyles = useIconStyles(generalIconStyles, compositionStyles?.leftIcon, {
72
- // @ts-expect-error
73
- hasError, disabled: (disabled || props?.leftIcon?.disabled), focused
74
- })
75
+ const generalIconStyles = getIconStyles(_generalIconStyles, { hasError, disabled })
75
76
 
76
- const rightIconStyles = useIconStyles(generalIconStyles, compositionStyles?.rightIcon, {
77
- // @ts-expect-error
78
- hasError, disabled: (disabled || props?.rightIcon?.disabled), focused
79
- })
77
+ const leftIconStyles = [
78
+ generalIconStyles,
79
+ // @ts-ignore
80
+ getIconStyles(_leftIconStyles, { hasError, disabled: disabled || props?.leftIcon?.disabled, focused })
81
+ ]
82
+
83
+ const rightIconStyles = [
84
+ generalIconStyles,
85
+ // @ts-ignore
86
+ getIconStyles(_rightIconStyles, { hasError, disabled: disabled || props?.right?.disabled, focused })
87
+ ]
80
88
 
81
89
  const labelStyle = [
82
- styles.label,
83
- focused && styles['label:focus'],
84
- hasError && styles['label:error'],
85
- disabled && styles['label:disabled'],
90
+ variantStyles.label,
91
+ focused && variantStyles['label:focus'],
92
+ hasError && variantStyles['label:error'],
93
+ disabled && variantStyles['label:disabled'],
94
+
86
95
  ]
87
96
 
88
97
  const errorStyle = [
89
- styles.errorMessage,
90
- focused && styles['errorMessage:focus'],
91
- hasError && styles['errorMessage:error'],
92
- disabled && styles['errorMessage:disabled'],
98
+ variantStyles.errorMessage,
99
+ focused && variantStyles['errorMessage:focus'],
100
+ hasError && variantStyles['errorMessage:error'],
101
+ disabled && variantStyles['errorMessage:disabled'],
93
102
  ]
94
103
 
95
104
  const descriptionStyle = [
96
- styles.description,
97
- focused && styles['description:focus'],
98
- hasError && styles['description:error'],
99
- disabled && styles['description:disabled'],
105
+ variantStyles.description,
106
+ focused && variantStyles['description:focus'],
107
+ hasError && variantStyles['description:error'],
108
+ disabled && variantStyles['description:disabled'],
100
109
  ]
101
110
 
102
111
  const wrapperStyle = [
103
- styles.wrapper,
104
- focused && styles['wrapper:focus'],
105
- error && styles['wrapper:error'],
106
- disabled && styles['wrapper:disabled'],
112
+ variantStyles.wrapper,
113
+ focused && variantStyles['wrapper:focus'],
114
+ error && variantStyles['wrapper:error'],
115
+ disabled && variantStyles['wrapper:disabled'],
107
116
  ]
108
117
 
109
118
  const innerWrapperStyle = [
110
- styles.innerWrapper,
111
- focused && styles['innerWrapper:focus'],
112
- hasError && styles['innerWrapper:error'],
113
- disabled && styles['innerWrapper:disabled'],
119
+ variantStyles.innerWrapper,
120
+ focused && variantStyles['innerWrapper:focus'],
121
+ hasError && variantStyles['innerWrapper:error'],
122
+ disabled && variantStyles['innerWrapper:disabled'],
114
123
  ]
115
124
 
116
125
  const labelRowStyle = [
117
- styles.labelRow,
118
- focused && styles['labelRow:focus'],
119
- hasError && styles['labelRow:error'],
120
- disabled && styles['labelRow:disabled'],
126
+ variantStyles.labelRow,
127
+ focused && variantStyles['labelRow:focus'],
128
+ hasError && variantStyles['labelRow:error'],
129
+ disabled && variantStyles['labelRow:disabled'],
121
130
  ]
122
131
 
123
132
  return {
@@ -1,4 +1,5 @@
1
- import { PropsOf, StylesOf } from '@codeleap/common'
1
+ import { PropsOf } from '@codeleap/common'
2
+ import { StylesOf } from '../../types'
2
3
  import { InputBaseComposition } from './styles'
3
4
  import { ActionIcon } from '../ActionIcon'
4
5
 
@@ -6,7 +7,6 @@ type ActionIconProps = PropsOf<typeof ActionIcon>
6
7
 
7
8
  type OrderedParts = 'label' | 'description' | 'innerWrapper' | 'error'
8
9
  type IconProp = Partial<ActionIconProps> | JSX.Element
9
-
10
10
  export type InputBaseProps = React.PropsWithChildren<{
11
11
  label?: React.ReactNode
12
12
  error?: React.ReactNode
@@ -16,12 +16,13 @@ export type InputBaseProps = React.PropsWithChildren<{
16
16
  wrapperProps?: any
17
17
  innerWrapper?: React.FC<any>
18
18
  innerWrapperProps?: any
19
+ styles?: StylesOf<InputBaseComposition>
19
20
  description?: React.ReactNode
20
21
  debugName: string
21
22
  focused?: boolean
22
23
  disabled?: boolean
23
24
  order?: OrderedParts[]
24
- style?: StylesOf<InputBaseComposition>
25
+ style?: any
25
26
  labelAsRow?: boolean
26
27
  hideErrorMessage?: boolean
27
28
  }>
@@ -8,10 +8,8 @@ type OmitDiff<T1, T2> = {
8
8
 
9
9
  type InputBaseKey = keyof InputBaseProps
10
10
 
11
- type BaseProps = Omit<InputBaseProps, 'style'>
12
-
13
- export function selectInputBaseProps<T extends BaseProps>(props: T): {
14
- inputBaseProps: BaseProps
11
+ export function selectInputBaseProps<T extends InputBaseProps>(props: T): {
12
+ inputBaseProps: InputBaseProps
15
13
  others: OmitDiff<T, T>
16
14
  } {
17
15
  const varList:InputBaseKey[] = [
@@ -21,6 +19,7 @@ export function selectInputBaseProps<T extends BaseProps>(props: T): {
21
19
  'innerWrapper',
22
20
  'leftIcon',
23
21
  'rightIcon',
22
+ // 'styles',
24
23
  'description',
25
24
  'wrapper',
26
25
  'children',
@@ -28,7 +27,6 @@ export function selectInputBaseProps<T extends BaseProps>(props: T): {
28
27
  'wrapperProps',
29
28
  'disabled',
30
29
  'hideErrorMessage',
31
- 'style',
32
30
  ]
33
31
 
34
32
  const copy = { ...props }
@@ -38,7 +36,7 @@ export function selectInputBaseProps<T extends BaseProps>(props: T): {
38
36
  acc[key] = copy[key]
39
37
 
40
38
  return acc
41
- }, {} as BaseProps)
39
+ }, {} as InputBaseProps)
42
40
 
43
41
  return { inputBaseProps: result, others: copy as OmitDiff<T, T> }
44
42
  }
@@ -0,0 +1,38 @@
1
+ import React from 'react'
2
+ import { ComponentVariants, FormTypes, useDefaultComponentStyle } from '@codeleap/common'
3
+ import { StylesOf } from '../../types'
4
+ import { View, ViewProps } from '../View'
5
+ import { InputLabelComposition, InputLabelPresets } from './styles'
6
+ import { Text } from '../Text'
7
+ import { StyleSheet } from 'react-native'
8
+
9
+ export type InputLabelProps = ViewProps & {
10
+ styles?: StylesOf<InputLabelComposition>
11
+ label?: FormTypes.Label
12
+ required?: boolean
13
+ } & ComponentVariants<typeof InputLabelPresets>
14
+
15
+ export * from './styles'
16
+
17
+ export const InputLabel:React.FC<InputLabelProps> = (props) => {
18
+ const { label, required = false, variants = [], styles = {}, style, ...viewProps } = props
19
+ const variantStyles = useDefaultComponentStyle<'u:InputLabel', typeof InputLabelPresets>('u:InputLabel', {
20
+ variants, styles, transform: StyleSheet.flatten,
21
+ })
22
+
23
+ if (!label) return null
24
+
25
+ switch (typeof label) {
26
+ case 'string':
27
+ return <View {...viewProps} style={[variantStyles.wrapper, style]}>
28
+ <Text style={variantStyles.text} text={label} />
29
+ {required && <Text style={variantStyles.asterisk} text={' *'} />}
30
+ </View>
31
+ case 'object':
32
+ return <>
33
+ {label as React.ReactNode}
34
+ </>
35
+ default:
36
+ return null
37
+ }
38
+ }
@@ -0,0 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type InputLabelComposition = 'text' | 'wrapper' | 'asterisk'
4
+
5
+ const createInputLabelStyle = createDefaultVariantFactory<InputLabelComposition>()
6
+
7
+ export const InputLabelPresets = includePresets(style => createInputLabelStyle(() => ({ wrapper: style, text: style })))