@chem-po/react-native 0.0.52 → 0.0.53
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.
- package/package.json +5 -20
- package/src/components/box/Center.tsx +0 -19
- package/src/components/box/CollapseHorizontal.tsx +0 -44
- package/src/components/box/ContentBox.tsx +0 -24
- package/src/components/box/DropShadow.tsx +0 -28
- package/src/components/box/ExpandOnMount.tsx +0 -74
- package/src/components/box/Expandable.tsx +0 -143
- package/src/components/box/FullSizeContainer.tsx +0 -64
- package/src/components/box/index.ts +0 -7
- package/src/components/button/ActionButton.tsx +0 -196
- package/src/components/button/ButtonText.tsx +0 -60
- package/src/components/button/DeleteButton.tsx +0 -288
- package/src/components/button/LoadingButton.tsx +0 -41
- package/src/components/button/Toggle.tsx +0 -109
- package/src/components/button/hooks.ts +0 -66
- package/src/components/button/index.ts +0 -5
- package/src/components/feed/FeedContentPane.tsx +0 -97
- package/src/components/feed/MediaFeed.tsx +0 -199
- package/src/components/feed/MediaFeedBackground.tsx +0 -136
- package/src/components/feed/MediaFeedRefresh.tsx +0 -113
- package/src/components/feed/constants.ts +0 -2
- package/src/components/feed/context.tsx +0 -19
- package/src/components/feed/hooks.ts +0 -279
- package/src/components/feed/index.ts +0 -2
- package/src/components/form/Condition.tsx +0 -27
- package/src/components/form/Field.tsx +0 -44
- package/src/components/form/Form.tsx +0 -452
- package/src/components/form/FormFooter.tsx +0 -164
- package/src/components/form/UploadProgress/index.tsx +0 -50
- package/src/components/form/index.ts +0 -3
- package/src/components/form/input/Editable.tsx +0 -206
- package/src/components/form/input/InputSlider.tsx +0 -71
- package/src/components/form/input/OptionalTag.tsx +0 -43
- package/src/components/form/input/StandaloneInput.tsx +0 -49
- package/src/components/form/input/boolean/index.tsx +0 -53
- package/src/components/form/input/color/index.tsx +0 -145
- package/src/components/form/input/common/InputClearButton.tsx +0 -57
- package/src/components/form/input/date/index.tsx +0 -125
- package/src/components/form/input/datetime/index.tsx +0 -176
- package/src/components/form/input/file/index.tsx +0 -310
- package/src/components/form/input/hooks/index.ts +0 -2
- package/src/components/form/input/hooks/useInputColor.ts +0 -7
- package/src/components/form/input/hooks/useInputImperativeHandle.ts +0 -22
- package/src/components/form/input/hooks/useInputStyles.ts +0 -114
- package/src/components/form/input/index.ts +0 -4
- package/src/components/form/input/input.tsx +0 -218
- package/src/components/form/input/multipleSelect/index.tsx +0 -221
- package/src/components/form/input/number/index.tsx +0 -108
- package/src/components/form/input/select/index.tsx +0 -152
- package/src/components/form/input/socialMedia/index.tsx +0 -235
- package/src/components/form/input/text/AutoResizeTextarea.tsx +0 -41
- package/src/components/form/input/text/index.tsx +0 -99
- package/src/components/form/input/text/textarea.tsx +0 -32
- package/src/components/form/input/text/useWebAutoResize.tsx +0 -73
- package/src/components/form/input/time/index.tsx +0 -125
- package/src/components/form/types.ts +0 -8
- package/src/components/form/view/file.tsx +0 -80
- package/src/components/form/view/index.tsx +0 -125
- package/src/components/form/view/multipleSelect.tsx +0 -85
- package/src/components/form/view/select.tsx +0 -83
- package/src/components/form/view/styles.ts +0 -12
- package/src/components/icons/index.tsx +0 -28
- package/src/components/image/ImageViewModal.tsx +0 -319
- package/src/components/image/index.ts +0 -1
- package/src/components/index.ts +0 -8
- package/src/components/layout/CollapseHorizontal.tsx +0 -92
- package/src/components/loading/CircularProgress.tsx +0 -56
- package/src/components/loading/Loading.tsx +0 -146
- package/src/components/loading/LoadingImage.tsx +0 -163
- package/src/components/loading/LoadingOverlay.tsx +0 -74
- package/src/components/loading/LoadingSwitch.tsx +0 -110
- package/src/components/loading/ProgressBar.tsx +0 -75
- package/src/components/loading/index.ts +0 -6
- package/src/components/text/AnimatedText.tsx +0 -68
- package/src/components/text/Txt.tsx +0 -12
- package/src/components/text/index.ts +0 -1
- package/src/components/theme/colorMode/DarkModeToggle.tsx +0 -47
- package/src/components/theme/colorMode/index.ts +0 -1
- package/src/components/theme/index.ts +0 -1
- package/src/constants/index.ts +0 -1
- package/src/constants/toast.ts +0 -24
- package/src/contexts/fonts.tsx +0 -23
- package/src/contexts/index.ts +0 -1
- package/src/contexts/root.tsx +0 -190
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useFadeIn.ts +0 -48
- package/src/hooks/useFont.ts +0 -25
- package/src/hooks/useRefreshFontScale.ts +0 -39
- package/src/hooks/useThemeState.ts +0 -43
- package/src/index.ts +0 -6
- package/src/store/index.ts +0 -2
- package/src/store/useFontScale.ts +0 -8
- package/src/store/useScreen.ts +0 -25
- package/src/styles/fill.ts +0 -19
- package/src/types/forms.ts +0 -14
- package/src/types/index.ts +0 -1
- package/src/utils/downloadFile.ts +0 -61
- package/src/utils/downloadFileLegacy.ts +0 -66
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { InputSize } from '@chem-po/core'
|
|
2
|
-
import { useBackgroundColor, useTextColor } from '@chem-po/react'
|
|
3
|
-
import { useMemo } from 'react'
|
|
4
|
-
import { StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'
|
|
5
|
-
import { useFont } from '../../../../hooks/useFont'
|
|
6
|
-
|
|
7
|
-
export const inputStyles = StyleSheet.create({
|
|
8
|
-
input: {
|
|
9
|
-
width: '100%',
|
|
10
|
-
fontSize: 16,
|
|
11
|
-
outlineWidth: 0,
|
|
12
|
-
},
|
|
13
|
-
inputXSmall: {
|
|
14
|
-
paddingVertical: 4,
|
|
15
|
-
paddingHorizontal: 6,
|
|
16
|
-
borderRadius: 3,
|
|
17
|
-
},
|
|
18
|
-
inputSmall: {
|
|
19
|
-
padding: 8,
|
|
20
|
-
borderRadius: 4,
|
|
21
|
-
},
|
|
22
|
-
inputMedium: {
|
|
23
|
-
padding: 12,
|
|
24
|
-
borderRadius: 6,
|
|
25
|
-
},
|
|
26
|
-
inputLarge: {
|
|
27
|
-
padding: 14,
|
|
28
|
-
borderRadius: 8,
|
|
29
|
-
},
|
|
30
|
-
buttonContainer: {
|
|
31
|
-
flexDirection: 'row',
|
|
32
|
-
alignItems: 'center',
|
|
33
|
-
},
|
|
34
|
-
buttonContainerSmall: {
|
|
35
|
-
gap: 6,
|
|
36
|
-
},
|
|
37
|
-
buttonContainerMedium: {
|
|
38
|
-
gap: 8,
|
|
39
|
-
},
|
|
40
|
-
buttonContainerLarge: {
|
|
41
|
-
gap: 10,
|
|
42
|
-
},
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const iconSizeMap = {
|
|
46
|
-
sm: 16,
|
|
47
|
-
md: 20,
|
|
48
|
-
lg: 24,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const clearButtonSizeMap = {
|
|
52
|
-
sm: 12,
|
|
53
|
-
md: 14,
|
|
54
|
-
lg: 16,
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const inputSizeMap = {
|
|
58
|
-
sm: inputStyles.inputSmall,
|
|
59
|
-
md: inputStyles.inputMedium,
|
|
60
|
-
lg: inputStyles.inputLarge,
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const editableInputSizeMap = {
|
|
64
|
-
sm: inputStyles.inputXSmall,
|
|
65
|
-
md: inputStyles.inputSmall,
|
|
66
|
-
lg: inputStyles.inputMedium,
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const buttonContainerSizeMap = {
|
|
70
|
-
sm: inputStyles.buttonContainerSmall,
|
|
71
|
-
md: inputStyles.buttonContainerMedium,
|
|
72
|
-
lg: inputStyles.buttonContainerLarge,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface UseInputStyles {
|
|
76
|
-
text: TextStyle
|
|
77
|
-
container: ViewStyle
|
|
78
|
-
size: InputSize
|
|
79
|
-
iconSize: number
|
|
80
|
-
clearButtonSize: number
|
|
81
|
-
buttonContainer: StyleProp<ViewStyle>
|
|
82
|
-
}
|
|
83
|
-
export const useInputStyles = (
|
|
84
|
-
inEditable: boolean | undefined,
|
|
85
|
-
size: InputSize | undefined,
|
|
86
|
-
formSize: InputSize = 'md',
|
|
87
|
-
): UseInputStyles => {
|
|
88
|
-
const formElementBg = useBackgroundColor(150)
|
|
89
|
-
const bg = useMemo(
|
|
90
|
-
() => (inEditable ? 'transparent' : formElementBg),
|
|
91
|
-
[inEditable, formElementBg],
|
|
92
|
-
)
|
|
93
|
-
const textColor = useTextColor()
|
|
94
|
-
const usedSize = size ?? formSize
|
|
95
|
-
const textFont = useFont('body', usedSize)
|
|
96
|
-
return {
|
|
97
|
-
text: {
|
|
98
|
-
...textFont,
|
|
99
|
-
paddingTop: 0,
|
|
100
|
-
paddingBottom: 0,
|
|
101
|
-
color: textColor,
|
|
102
|
-
outlineWidth: 0,
|
|
103
|
-
},
|
|
104
|
-
container: {
|
|
105
|
-
...inputStyles.input,
|
|
106
|
-
...(inEditable ? editableInputSizeMap[usedSize] : inputSizeMap[usedSize]),
|
|
107
|
-
backgroundColor: bg,
|
|
108
|
-
},
|
|
109
|
-
size: usedSize,
|
|
110
|
-
iconSize: iconSizeMap[usedSize],
|
|
111
|
-
clearButtonSize: clearButtonSizeMap[usedSize],
|
|
112
|
-
buttonContainer: [inputStyles.buttonContainer, buttonContainerSizeMap[usedSize]],
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { FieldType, formatField, InputRef, parseField } from '@chem-po/core'
|
|
2
|
-
import { Field, FormatField, TypedField, usePlaceholderColor, useThemeValue } from '@chem-po/react'
|
|
3
|
-
import React, {
|
|
4
|
-
ForwardedRef,
|
|
5
|
-
forwardRef,
|
|
6
|
-
ForwardRefExoticComponent,
|
|
7
|
-
useCallback,
|
|
8
|
-
useEffect,
|
|
9
|
-
useMemo,
|
|
10
|
-
} from 'react'
|
|
11
|
-
import { Animated, StyleSheet, Text, View, ViewStyle } from 'react-native'
|
|
12
|
-
import { AnimatedText } from '../../text/AnimatedText'
|
|
13
|
-
import { FieldProps } from '../types'
|
|
14
|
-
import { BooleanComponent } from './boolean'
|
|
15
|
-
import { ColorComponent } from './color'
|
|
16
|
-
import { DateInput } from './date'
|
|
17
|
-
import { DateTimeInput } from './datetime'
|
|
18
|
-
import { FileComponent } from './file'
|
|
19
|
-
import { useInputStyles } from './hooks/useInputStyles'
|
|
20
|
-
import { MultipleSelectComponent } from './multipleSelect'
|
|
21
|
-
import { CurrencyAmountComponent, NumberComponent } from './number'
|
|
22
|
-
import { SelectComponent } from './select'
|
|
23
|
-
import { SocialMediaComponent } from './socialMedia'
|
|
24
|
-
import { TextComponent } from './text'
|
|
25
|
-
import { TimeInput } from './time'
|
|
26
|
-
|
|
27
|
-
type ComponentType<T extends Field> = ForwardRefExoticComponent<
|
|
28
|
-
FieldProps<T> & React.RefAttributes<InputRef>
|
|
29
|
-
>
|
|
30
|
-
|
|
31
|
-
const Components: { [Key in FieldType]: ComponentType<TypedField<Key>> } = {
|
|
32
|
-
text: TextComponent,
|
|
33
|
-
file: FileComponent,
|
|
34
|
-
boolean: BooleanComponent,
|
|
35
|
-
select: SelectComponent,
|
|
36
|
-
multipleSelect: MultipleSelectComponent,
|
|
37
|
-
currency: CurrencyAmountComponent,
|
|
38
|
-
number: NumberComponent,
|
|
39
|
-
date: DateInput,
|
|
40
|
-
datetime: DateTimeInput,
|
|
41
|
-
time: TimeInput,
|
|
42
|
-
socialMedia: SocialMediaComponent,
|
|
43
|
-
color: ColorComponent,
|
|
44
|
-
}
|
|
45
|
-
const InputBase = <T extends Field>(props: FieldProps<T>, ref: ForwardedRef<InputRef>) => {
|
|
46
|
-
const {
|
|
47
|
-
field,
|
|
48
|
-
meta: { error, active, touched },
|
|
49
|
-
input,
|
|
50
|
-
inEditable,
|
|
51
|
-
formSize,
|
|
52
|
-
style,
|
|
53
|
-
} = props
|
|
54
|
-
|
|
55
|
-
const { value } = input
|
|
56
|
-
|
|
57
|
-
const placeholderColor = usePlaceholderColor()
|
|
58
|
-
const activeColor = useThemeValue('colors.accent.400')
|
|
59
|
-
const errorColor = useThemeValue('colors.error.400')
|
|
60
|
-
const shadowColorAnim = useMemo(() => new Animated.Value(0), [])
|
|
61
|
-
|
|
62
|
-
const displayedError = useMemo(() => {
|
|
63
|
-
if (error && touched) return error
|
|
64
|
-
return null
|
|
65
|
-
}, [error, touched])
|
|
66
|
-
const shadowColor = useMemo(() => {
|
|
67
|
-
if (displayedError) return errorColor
|
|
68
|
-
return activeColor
|
|
69
|
-
}, [displayedError, activeColor, errorColor])
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
Animated.timing(shadowColorAnim, {
|
|
73
|
-
toValue: active || displayedError ? 1 : 0,
|
|
74
|
-
duration: 300,
|
|
75
|
-
useNativeDriver: false,
|
|
76
|
-
}).start()
|
|
77
|
-
}, [active, displayedError, shadowColorAnim])
|
|
78
|
-
|
|
79
|
-
const animatedShadowColor = shadowColorAnim.interpolate({
|
|
80
|
-
inputRange: [0, 1],
|
|
81
|
-
outputRange: [placeholderColor, shadowColor],
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const { _type, label: Label } = field
|
|
85
|
-
const showPlaceholder = useMemo(
|
|
86
|
-
() => _type === 'multipleSelect' || (!!value && _type !== 'file' && _type !== 'boolean'),
|
|
87
|
-
[value, _type],
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
// const bg = useBackgroundColor(150)
|
|
91
|
-
|
|
92
|
-
const animatedStyles = useMemo(() => {
|
|
93
|
-
if (inEditable) return {}
|
|
94
|
-
switch (_type) {
|
|
95
|
-
case 'text':
|
|
96
|
-
case 'number':
|
|
97
|
-
case 'currency':
|
|
98
|
-
case 'select':
|
|
99
|
-
case 'datetime':
|
|
100
|
-
case 'date':
|
|
101
|
-
case 'time':
|
|
102
|
-
return {
|
|
103
|
-
shadowColor: animatedShadowColor,
|
|
104
|
-
shadowOffset: { width: 0, height: 0 },
|
|
105
|
-
shadowOpacity: 1,
|
|
106
|
-
shadowRadius: 4,
|
|
107
|
-
elevation: 5,
|
|
108
|
-
// backgroundColor: bg,
|
|
109
|
-
} as Animated.WithAnimatedValue<ViewStyle>
|
|
110
|
-
default:
|
|
111
|
-
return {}
|
|
112
|
-
}
|
|
113
|
-
}, [_type, animatedShadowColor, inEditable])
|
|
114
|
-
|
|
115
|
-
const Component = useMemo(() => Components[_type] as ComponentType<T>, [_type])
|
|
116
|
-
|
|
117
|
-
const parse = useCallback(
|
|
118
|
-
(raw: any) => {
|
|
119
|
-
const defaultParse = parseField[field._type]
|
|
120
|
-
if (!defaultParse) return raw
|
|
121
|
-
return defaultParse(field, raw)
|
|
122
|
-
},
|
|
123
|
-
[field],
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
const { text } = useInputStyles(inEditable, field.size, formSize)
|
|
127
|
-
|
|
128
|
-
const format = useCallback(
|
|
129
|
-
(raw: any) => {
|
|
130
|
-
const defaultFormat = formatField[field._type] as FormatField<T>
|
|
131
|
-
if (!defaultFormat) return raw
|
|
132
|
-
return defaultFormat(field, raw)
|
|
133
|
-
},
|
|
134
|
-
[field],
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
const formattedValue = useMemo(() => format(value), [value, format])
|
|
138
|
-
const onChange = useCallback(
|
|
139
|
-
(v: any) => {
|
|
140
|
-
input.onChange(parse(v))
|
|
141
|
-
},
|
|
142
|
-
[input, parse],
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<View style={[staticStyles.container, style]}>
|
|
147
|
-
{Label && !inEditable ? (
|
|
148
|
-
typeof Label === 'string' ? (
|
|
149
|
-
<Text style={staticStyles.label}>{Label}</Text>
|
|
150
|
-
) : (
|
|
151
|
-
<Label />
|
|
152
|
-
)
|
|
153
|
-
) : null}
|
|
154
|
-
{inEditable ? null : (
|
|
155
|
-
<AnimatedText
|
|
156
|
-
style={staticStyles.placeholder}
|
|
157
|
-
show={showPlaceholder}
|
|
158
|
-
color={placeholderColor}
|
|
159
|
-
height={16}
|
|
160
|
-
marginBottom={6}>
|
|
161
|
-
{field.placeholder ?? ''}
|
|
162
|
-
</AnimatedText>
|
|
163
|
-
)}
|
|
164
|
-
<Animated.View style={[staticStyles.inputContainer, animatedStyles]}>
|
|
165
|
-
<Component ref={ref} {...props} input={{ ...input, onChange, value: formattedValue }} />
|
|
166
|
-
</Animated.View>
|
|
167
|
-
{/* {!inEditable && ( */}
|
|
168
|
-
<AnimatedText
|
|
169
|
-
style={[staticStyles.errorText, { fontSize: text.fontSize ?? 14 }]}
|
|
170
|
-
show={!!displayedError}
|
|
171
|
-
color={errorColor}
|
|
172
|
-
height={(text.fontSize ?? 14) + 5}
|
|
173
|
-
marginBottom={inEditable ? 10 : 0}>
|
|
174
|
-
{displayedError}
|
|
175
|
-
</AnimatedText>
|
|
176
|
-
{/* )} */}
|
|
177
|
-
{/* {optional && !inEditable ? <OptionalTag field={field} value={value} /> : null} */}
|
|
178
|
-
</View>
|
|
179
|
-
)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const staticStyles = StyleSheet.create({
|
|
183
|
-
container: {
|
|
184
|
-
position: 'relative',
|
|
185
|
-
width: '100%',
|
|
186
|
-
// backgroundColor: 'blue',
|
|
187
|
-
},
|
|
188
|
-
label: {
|
|
189
|
-
color: '#1A202C',
|
|
190
|
-
fontSize: 14,
|
|
191
|
-
paddingHorizontal: 8,
|
|
192
|
-
},
|
|
193
|
-
inputContainer: {
|
|
194
|
-
width: '100%',
|
|
195
|
-
paddingVertical: 1,
|
|
196
|
-
// overflow: 'hidden',
|
|
197
|
-
},
|
|
198
|
-
errorText: {
|
|
199
|
-
paddingTop: 3,
|
|
200
|
-
paddingHorizontal: 8,
|
|
201
|
-
fontWeight: 500,
|
|
202
|
-
// backgroundColor: 'red',
|
|
203
|
-
},
|
|
204
|
-
errorTextEditable: {
|
|
205
|
-
fontSize: 14,
|
|
206
|
-
paddingHorizontal: 6,
|
|
207
|
-
paddingBottom: 8,
|
|
208
|
-
fontWeight: 500,
|
|
209
|
-
// backgroundColor: 'red',
|
|
210
|
-
},
|
|
211
|
-
placeholder: {
|
|
212
|
-
fontSize: 14,
|
|
213
|
-
paddingHorizontal: 4,
|
|
214
|
-
overflow: 'hidden',
|
|
215
|
-
},
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
export const Input = forwardRef<InputRef, FieldProps<Field>>(InputBase)
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { InputRef, RenderSelectOptionProps } from '@chem-po/core'
|
|
2
|
-
import {
|
|
3
|
-
MultipleSelectField,
|
|
4
|
-
useBackgroundColor,
|
|
5
|
-
useBorderColor,
|
|
6
|
-
useColorMode,
|
|
7
|
-
useIconColor,
|
|
8
|
-
usePlaceholderColor,
|
|
9
|
-
useTextColor,
|
|
10
|
-
} from '@chem-po/react'
|
|
11
|
-
import { Ionicons } from '@expo/vector-icons'
|
|
12
|
-
import React, {
|
|
13
|
-
ForwardedRef,
|
|
14
|
-
forwardRef,
|
|
15
|
-
PropsWithChildren,
|
|
16
|
-
useImperativeHandle,
|
|
17
|
-
useMemo,
|
|
18
|
-
useRef,
|
|
19
|
-
} from 'react'
|
|
20
|
-
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
|
|
21
|
-
import { IDropdownRef, MultiSelect } from 'react-native-element-dropdown'
|
|
22
|
-
import { Txt } from '../../../text/Txt'
|
|
23
|
-
import { FieldProps } from '../../types'
|
|
24
|
-
import { InputClearButton } from '../common/InputClearButton'
|
|
25
|
-
import { useInputStyles } from '../hooks/useInputStyles'
|
|
26
|
-
|
|
27
|
-
export const SelectedOptionContainer = ({
|
|
28
|
-
children,
|
|
29
|
-
style,
|
|
30
|
-
}: PropsWithChildren<{ key?: string; style?: StyleProp<ViewStyle> }>) => {
|
|
31
|
-
const borderColor = useBorderColor()
|
|
32
|
-
const bg = useBackgroundColor(100)
|
|
33
|
-
return (
|
|
34
|
-
<View style={[styles.selectedOption, { borderColor, backgroundColor: bg }, style]}>
|
|
35
|
-
{children}
|
|
36
|
-
</View>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const BaseMultipleSelectComponent = <T extends MultipleSelectField>(
|
|
41
|
-
{ field, input, meta, formSize, inEditable }: FieldProps<T>,
|
|
42
|
-
ref: ForwardedRef<InputRef>,
|
|
43
|
-
) => {
|
|
44
|
-
const { placeholder, options, renderOption: RenderOption, searchable, searchPlaceholder } = field
|
|
45
|
-
const { onChange, value, onFocus, onBlur } = input
|
|
46
|
-
const { active } = meta
|
|
47
|
-
|
|
48
|
-
const colorMode = useColorMode()
|
|
49
|
-
const inputRef = useRef<IDropdownRef>(null)
|
|
50
|
-
const { container, iconSize, clearButtonSize, text, buttonContainer, size } = useInputStyles(
|
|
51
|
-
inEditable,
|
|
52
|
-
field.size,
|
|
53
|
-
formSize,
|
|
54
|
-
)
|
|
55
|
-
const iconColor = useIconColor()
|
|
56
|
-
const textColor = useTextColor()
|
|
57
|
-
const placeholderColor = usePlaceholderColor()
|
|
58
|
-
const menuBg = useBackgroundColor(100)
|
|
59
|
-
const inputBg = useBackgroundColor(50)
|
|
60
|
-
const selectedOptionBg = useBackgroundColor(50)
|
|
61
|
-
const borderColor = useBorderColor()
|
|
62
|
-
|
|
63
|
-
useImperativeHandle(ref, () => ({
|
|
64
|
-
focus: () => {
|
|
65
|
-
inputRef.current?.open()
|
|
66
|
-
},
|
|
67
|
-
blur: () => {
|
|
68
|
-
inputRef.current?.close()
|
|
69
|
-
},
|
|
70
|
-
}))
|
|
71
|
-
|
|
72
|
-
const RenderOptionText = (
|
|
73
|
-
props: RenderSelectOptionProps<T['options'][number]['value'], T['options'][number]>,
|
|
74
|
-
) => {
|
|
75
|
-
if (typeof RenderOption === 'function') {
|
|
76
|
-
return RenderOption(props)
|
|
77
|
-
}
|
|
78
|
-
return <Txt style={[styles.defaultOption, text]}>{props.option.label}</Txt>
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const RenderSelectedOptionText = (
|
|
82
|
-
props: RenderSelectOptionProps<T['options'][number]['value'], T['options'][number]>,
|
|
83
|
-
) => {
|
|
84
|
-
if (typeof RenderOption === 'function') {
|
|
85
|
-
return RenderOption(props)
|
|
86
|
-
}
|
|
87
|
-
return (
|
|
88
|
-
<View style={[container, { width: 'auto' }]}>
|
|
89
|
-
<Txt style={[text]}>{props.option.label}</Txt>
|
|
90
|
-
</View>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const selectedOptions = useMemo(() => {
|
|
95
|
-
return options.filter(o => value?.includes(o.value))
|
|
96
|
-
}, [options, value])
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<View style={[styles.wrapper]}>
|
|
100
|
-
<MultiSelect
|
|
101
|
-
ref={inputRef}
|
|
102
|
-
style={container}
|
|
103
|
-
placeholderStyle={[text, { color: value?.length ? textColor : placeholderColor }]}
|
|
104
|
-
containerStyle={{
|
|
105
|
-
backgroundColor: menuBg,
|
|
106
|
-
boxShadow: `0 0 10px #00000066`,
|
|
107
|
-
borderWidth: 0,
|
|
108
|
-
}}
|
|
109
|
-
inputSearchStyle={[styles.inputSearch, text, { backgroundColor: inputBg, borderWidth: 0 }]}
|
|
110
|
-
iconStyle={styles.iconStyle}
|
|
111
|
-
data={options}
|
|
112
|
-
search={searchable}
|
|
113
|
-
searchField={searchable ? 'label' : undefined}
|
|
114
|
-
maxHeight={300}
|
|
115
|
-
labelField="label"
|
|
116
|
-
valueField="value"
|
|
117
|
-
placeholder={
|
|
118
|
-
selectedOptions.length ? selectedOptions.map(v => v.label).join(', ') : placeholder
|
|
119
|
-
}
|
|
120
|
-
searchPlaceholder={searchPlaceholder ?? placeholder}
|
|
121
|
-
value={value ?? []}
|
|
122
|
-
onChange={updated => {
|
|
123
|
-
onChange(updated)
|
|
124
|
-
}}
|
|
125
|
-
onFocus={onFocus}
|
|
126
|
-
onBlur={onBlur}
|
|
127
|
-
itemContainerStyle={{
|
|
128
|
-
backgroundColor: menuBg,
|
|
129
|
-
borderTopWidth: 1,
|
|
130
|
-
borderColor: borderColor,
|
|
131
|
-
}}
|
|
132
|
-
renderItem={(item, selected) => (
|
|
133
|
-
<View
|
|
134
|
-
style={{
|
|
135
|
-
backgroundColor: selected ? selectedOptionBg : menuBg,
|
|
136
|
-
paddingVertical: 8,
|
|
137
|
-
paddingHorizontal: 12,
|
|
138
|
-
flexDirection: 'row',
|
|
139
|
-
alignItems: 'center',
|
|
140
|
-
width: '100%',
|
|
141
|
-
}}>
|
|
142
|
-
<RenderOptionText
|
|
143
|
-
value={item.value}
|
|
144
|
-
option={item}
|
|
145
|
-
colorMode={colorMode}
|
|
146
|
-
isSelected={!!selected}
|
|
147
|
-
size={size}
|
|
148
|
-
/>
|
|
149
|
-
{selected ? <Ionicons name="checkmark" size={iconSize} color={iconColor} /> : null}
|
|
150
|
-
</View>
|
|
151
|
-
)}
|
|
152
|
-
renderSelectedItem={item => (
|
|
153
|
-
<SelectedOptionContainer style={{ marginTop: 10 }}>
|
|
154
|
-
<RenderSelectedOptionText
|
|
155
|
-
value={item.value}
|
|
156
|
-
option={item}
|
|
157
|
-
colorMode={colorMode}
|
|
158
|
-
isSelected
|
|
159
|
-
size={size}
|
|
160
|
-
/>
|
|
161
|
-
<View style={[styles.optionClearContainer, { borderColor }]}>
|
|
162
|
-
<InputClearButton
|
|
163
|
-
size={clearButtonSize}
|
|
164
|
-
onPress={() => {
|
|
165
|
-
onChange(value?.filter(v => v !== item.value))
|
|
166
|
-
}}
|
|
167
|
-
isActive
|
|
168
|
-
/>
|
|
169
|
-
</View>
|
|
170
|
-
</SelectedOptionContainer>
|
|
171
|
-
)}
|
|
172
|
-
renderRightIcon={() => (
|
|
173
|
-
<View style={buttonContainer}>
|
|
174
|
-
<Ionicons
|
|
175
|
-
name={active ? 'chevron-up' : 'chevron-down'}
|
|
176
|
-
size={iconSize}
|
|
177
|
-
color={iconColor}
|
|
178
|
-
/>
|
|
179
|
-
</View>
|
|
180
|
-
)}
|
|
181
|
-
/>
|
|
182
|
-
</View>
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export const MultipleSelectComponent = forwardRef(BaseMultipleSelectComponent)
|
|
187
|
-
|
|
188
|
-
const styles = StyleSheet.create({
|
|
189
|
-
wrapper: {
|
|
190
|
-
width: '100%',
|
|
191
|
-
},
|
|
192
|
-
defaultOption: {
|
|
193
|
-
flex: 1,
|
|
194
|
-
},
|
|
195
|
-
iconStyle: {
|
|
196
|
-
width: 20,
|
|
197
|
-
height: 20,
|
|
198
|
-
},
|
|
199
|
-
inputSearch: {
|
|
200
|
-
paddingVertical: 4,
|
|
201
|
-
minHeight: 0,
|
|
202
|
-
outlineWidth: 0,
|
|
203
|
-
fontSize: 16,
|
|
204
|
-
},
|
|
205
|
-
selectedOption: {
|
|
206
|
-
flexDirection: 'row',
|
|
207
|
-
borderRadius: 4,
|
|
208
|
-
borderWidth: 1,
|
|
209
|
-
alignItems: 'center',
|
|
210
|
-
marginTop: 4,
|
|
211
|
-
marginBottom: 4,
|
|
212
|
-
marginHorizontal: 4,
|
|
213
|
-
},
|
|
214
|
-
optionClearContainer: {
|
|
215
|
-
paddingHorizontal: 8,
|
|
216
|
-
borderLeftWidth: 1,
|
|
217
|
-
borderTopRightRadius: 8,
|
|
218
|
-
borderBottomRightRadius: 8,
|
|
219
|
-
justifyContent: 'center',
|
|
220
|
-
},
|
|
221
|
-
})
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { InputRef } from '@chem-po/core'
|
|
2
|
-
import { CurrencyAmountField, NumberField, usePlaceholderColor, useTextColor } from '@chem-po/react'
|
|
3
|
-
import React, { ForwardedRef, forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
4
|
-
import { StyleSheet, Text, TextInput, View } from 'react-native'
|
|
5
|
-
import { FieldProps } from '../../types'
|
|
6
|
-
import { InputSlider } from '../InputSlider'
|
|
7
|
-
import { useInputImperativeHandle } from '../hooks/useInputImperativeHandle'
|
|
8
|
-
import { useInputStyles } from '../hooks/useInputStyles'
|
|
9
|
-
|
|
10
|
-
export const NumberComponent = forwardRef<InputRef, FieldProps<NumberField> & { prefix?: string }>(
|
|
11
|
-
(
|
|
12
|
-
{
|
|
13
|
-
input: { onChange, value, ...input },
|
|
14
|
-
inputStyle,
|
|
15
|
-
field,
|
|
16
|
-
prefix,
|
|
17
|
-
inEditable,
|
|
18
|
-
style,
|
|
19
|
-
formSize,
|
|
20
|
-
},
|
|
21
|
-
ref,
|
|
22
|
-
) => {
|
|
23
|
-
const { type, defaultValue, placeholder, size } = field
|
|
24
|
-
const color = useTextColor()
|
|
25
|
-
const { container: conatinerStyles, text: inputStyles } = useInputStyles(
|
|
26
|
-
inEditable,
|
|
27
|
-
size,
|
|
28
|
-
formSize,
|
|
29
|
-
)
|
|
30
|
-
const inputRef = useInputImperativeHandle(ref)
|
|
31
|
-
const [endsWith, setEndsWith] = useState('')
|
|
32
|
-
const displayed = typeof value === 'number' && !Number.isNaN(value) ? `${value}${endsWith}` : ''
|
|
33
|
-
|
|
34
|
-
const placeholderColor = usePlaceholderColor()
|
|
35
|
-
|
|
36
|
-
if (type === 'slider') {
|
|
37
|
-
return (
|
|
38
|
-
<InputSlider
|
|
39
|
-
label={placeholder}
|
|
40
|
-
style={style}
|
|
41
|
-
onValueChange={onChange}
|
|
42
|
-
value={value}
|
|
43
|
-
minimumValue={defaultValue}
|
|
44
|
-
/>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<View style={[styles.container, conatinerStyles, style]}>
|
|
50
|
-
{prefix && <Text style={styles.prefix}>{prefix}</Text>}
|
|
51
|
-
<TextInput
|
|
52
|
-
ref={inputRef}
|
|
53
|
-
style={[inputStyles, { color, outlineWidth: 0 }, inputStyle]}
|
|
54
|
-
placeholder={field.placeholder}
|
|
55
|
-
placeholderTextColor={placeholderColor}
|
|
56
|
-
keyboardType="numeric"
|
|
57
|
-
value={displayed}
|
|
58
|
-
onChangeText={text => {
|
|
59
|
-
if (text.endsWith('.')) {
|
|
60
|
-
setEndsWith('.')
|
|
61
|
-
} else if (text.includes('.') && text.endsWith('0')) {
|
|
62
|
-
setEndsWith('0')
|
|
63
|
-
} else {
|
|
64
|
-
setEndsWith('')
|
|
65
|
-
}
|
|
66
|
-
const num = parseFloat(text)
|
|
67
|
-
onChange(!isNaN(num) ? num : undefined)
|
|
68
|
-
}}
|
|
69
|
-
{...input}
|
|
70
|
-
// {...props}
|
|
71
|
-
/>
|
|
72
|
-
</View>
|
|
73
|
-
)
|
|
74
|
-
},
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
const BaseCurrencyAmountComponent = (
|
|
78
|
-
{ field, ...props }: FieldProps<CurrencyAmountField>,
|
|
79
|
-
ref: ForwardedRef<InputRef>,
|
|
80
|
-
) => {
|
|
81
|
-
const inputRef = useRef<TextInput>(null)
|
|
82
|
-
|
|
83
|
-
useImperativeHandle(ref, () => ({
|
|
84
|
-
focus: () => {
|
|
85
|
-
inputRef.current?.focus()
|
|
86
|
-
},
|
|
87
|
-
blur: () => {
|
|
88
|
-
inputRef.current?.blur()
|
|
89
|
-
},
|
|
90
|
-
}))
|
|
91
|
-
return <NumberComponent prefix="$" field={{ ...field, _type: 'number' }} {...props} />
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const CurrencyAmountComponent = forwardRef<InputRef, FieldProps<CurrencyAmountField>>(
|
|
95
|
-
BaseCurrencyAmountComponent as any,
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
const styles = StyleSheet.create({
|
|
99
|
-
container: {
|
|
100
|
-
flexDirection: 'row',
|
|
101
|
-
alignItems: 'center',
|
|
102
|
-
width: '100%',
|
|
103
|
-
},
|
|
104
|
-
prefix: {
|
|
105
|
-
marginRight: 4,
|
|
106
|
-
fontSize: 16,
|
|
107
|
-
},
|
|
108
|
-
})
|