@chem-po/react-native 0.0.9 → 0.0.11
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/lib/commonjs/components/box/Expandable.js +10 -10
- package/lib/commonjs/components/box/Expandable.js.map +1 -1
- package/lib/commonjs/components/box/FullSizeContainer.js +4 -4
- package/lib/commonjs/components/box/FullSizeContainer.js.map +1 -1
- package/lib/commonjs/components/button/DeleteButton.js +1 -1
- package/lib/commonjs/components/button/DeleteButton.js.map +1 -1
- package/lib/commonjs/components/form/Form.js +12 -10
- package/lib/commonjs/components/form/Form.js.map +1 -1
- package/lib/commonjs/components/form/FormFooter.js +2 -2
- package/lib/commonjs/components/form/FormFooter.js.map +1 -1
- package/lib/commonjs/components/form/input/Editable.js +76 -19
- package/lib/commonjs/components/form/input/Editable.js.map +1 -1
- package/lib/commonjs/components/form/input/date/index.js +3 -5
- package/lib/commonjs/components/form/input/date/index.js.map +1 -1
- package/lib/commonjs/components/form/input/datetime/index.js +3 -5
- package/lib/commonjs/components/form/input/datetime/index.js.map +1 -1
- package/lib/commonjs/components/form/input/file/index.js +2 -1
- package/lib/commonjs/components/form/input/file/index.js.map +1 -1
- package/lib/commonjs/components/form/input/input.js +6 -5
- package/lib/commonjs/components/form/input/input.js.map +1 -1
- package/lib/commonjs/components/form/input/multipleSelect/index.js +6 -2
- package/lib/commonjs/components/form/input/multipleSelect/index.js.map +1 -1
- package/lib/commonjs/components/form/input/number/index.js +4 -17
- package/lib/commonjs/components/form/input/number/index.js.map +1 -1
- package/lib/commonjs/components/form/input/select/index.js +22 -14
- package/lib/commonjs/components/form/input/select/index.js.map +1 -1
- package/lib/commonjs/components/form/input/styles.js +17 -0
- package/lib/commonjs/components/form/input/styles.js.map +1 -0
- package/lib/commonjs/components/form/input/text/index.js +12 -14
- package/lib/commonjs/components/form/input/text/index.js.map +1 -1
- package/lib/commonjs/components/form/input/time/index.js +3 -5
- package/lib/commonjs/components/form/input/time/index.js.map +1 -1
- package/lib/commonjs/components/form/view/index.js +8 -5
- package/lib/commonjs/components/form/view/index.js.map +1 -1
- package/lib/commonjs/components/form/view/multipleSelect.js +11 -6
- package/lib/commonjs/components/form/view/multipleSelect.js.map +1 -1
- package/lib/commonjs/components/form/view/select.js +10 -4
- package/lib/commonjs/components/form/view/select.js.map +1 -1
- package/lib/commonjs/components/loading/Loading.js +24 -4
- package/lib/commonjs/components/loading/Loading.js.map +1 -1
- package/lib/module/components/box/Expandable.js +10 -10
- package/lib/module/components/box/Expandable.js.map +1 -1
- package/lib/module/components/box/FullSizeContainer.js +4 -4
- package/lib/module/components/box/FullSizeContainer.js.map +1 -1
- package/lib/module/components/button/DeleteButton.js +1 -1
- package/lib/module/components/button/DeleteButton.js.map +1 -1
- package/lib/module/components/form/Form.js +13 -11
- package/lib/module/components/form/Form.js.map +1 -1
- package/lib/module/components/form/FormFooter.js +2 -2
- package/lib/module/components/form/FormFooter.js.map +1 -1
- package/lib/module/components/form/input/Editable.js +78 -21
- package/lib/module/components/form/input/Editable.js.map +1 -1
- package/lib/module/components/form/input/date/index.js +3 -5
- package/lib/module/components/form/input/date/index.js.map +1 -1
- package/lib/module/components/form/input/datetime/index.js +3 -5
- package/lib/module/components/form/input/datetime/index.js.map +1 -1
- package/lib/module/components/form/input/file/index.js +2 -1
- package/lib/module/components/form/input/file/index.js.map +1 -1
- package/lib/module/components/form/input/input.js +6 -5
- package/lib/module/components/form/input/input.js.map +1 -1
- package/lib/module/components/form/input/multipleSelect/index.js +6 -2
- package/lib/module/components/form/input/multipleSelect/index.js.map +1 -1
- package/lib/module/components/form/input/number/index.js +4 -17
- package/lib/module/components/form/input/number/index.js.map +1 -1
- package/lib/module/components/form/input/select/index.js +22 -14
- package/lib/module/components/form/input/select/index.js.map +1 -1
- package/lib/module/components/form/input/styles.js +11 -0
- package/lib/module/components/form/input/styles.js.map +1 -0
- package/lib/module/components/form/input/text/index.js +12 -14
- package/lib/module/components/form/input/text/index.js.map +1 -1
- package/lib/module/components/form/input/time/index.js +3 -5
- package/lib/module/components/form/input/time/index.js.map +1 -1
- package/lib/module/components/form/view/index.js +9 -6
- package/lib/module/components/form/view/index.js.map +1 -1
- package/lib/module/components/form/view/multipleSelect.js +12 -7
- package/lib/module/components/form/view/multipleSelect.js.map +1 -1
- package/lib/module/components/form/view/select.js +12 -6
- package/lib/module/components/form/view/select.js.map +1 -1
- package/lib/module/components/loading/Loading.js +26 -6
- package/lib/module/components/loading/Loading.js.map +1 -1
- package/lib/typescript/components/box/Expandable.d.ts +1 -1
- package/lib/typescript/components/box/Expandable.d.ts.map +1 -1
- package/lib/typescript/components/box/FullSizeContainer.d.ts +1 -1
- package/lib/typescript/components/box/FullSizeContainer.d.ts.map +1 -1
- package/lib/typescript/components/form/Form.d.ts +1 -1
- package/lib/typescript/components/form/Form.d.ts.map +1 -1
- package/lib/typescript/components/form/FormFooter.d.ts +1 -1
- package/lib/typescript/components/form/FormFooter.d.ts.map +1 -1
- package/lib/typescript/components/form/input/Editable.d.ts +1 -1
- package/lib/typescript/components/form/input/Editable.d.ts.map +1 -1
- package/lib/typescript/components/form/input/date/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/datetime/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/file/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/hooks/useInputImperativeHandle.d.ts +1 -1
- package/lib/typescript/components/form/input/hooks/useInputImperativeHandle.d.ts.map +1 -1
- package/lib/typescript/components/form/input/input.d.ts.map +1 -1
- package/lib/typescript/components/form/input/number/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/select/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/styles.d.ts +10 -0
- package/lib/typescript/components/form/input/styles.d.ts.map +1 -0
- package/lib/typescript/components/form/input/text/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/time/index.d.ts.map +1 -1
- package/lib/typescript/components/form/view/index.d.ts.map +1 -1
- package/lib/typescript/components/form/view/multipleSelect.d.ts +1 -1
- package/lib/typescript/components/form/view/multipleSelect.d.ts.map +1 -1
- package/lib/typescript/components/form/view/select.d.ts.map +1 -1
- package/lib/typescript/components/loading/Loading.d.ts +1 -1
- package/lib/typescript/components/loading/Loading.d.ts.map +1 -1
- package/package.json +24 -41
- package/src/components/box/Expandable.tsx +6 -6
- package/src/components/box/FullSizeContainer.tsx +2 -2
- package/src/components/button/DeleteButton.tsx +1 -1
- package/src/components/form/Form.tsx +13 -7
- package/src/components/form/FormFooter.tsx +3 -3
- package/src/components/form/input/Editable.tsx +108 -38
- package/src/components/form/input/date/index.tsx +2 -4
- package/src/components/form/input/datetime/index.tsx +2 -4
- package/src/components/form/input/file/index.tsx +3 -1
- package/src/components/form/input/input.tsx +20 -11
- package/src/components/form/input/multipleSelect/index.tsx +2 -2
- package/src/components/form/input/number/index.tsx +3 -12
- package/src/components/form/input/select/index.tsx +14 -15
- package/src/components/form/input/styles.ts +11 -0
- package/src/components/form/input/text/index.tsx +10 -14
- package/src/components/form/input/time/index.tsx +2 -4
- package/src/components/form/view/index.tsx +6 -5
- package/src/components/form/view/multipleSelect.tsx +8 -6
- package/src/components/form/view/select.tsx +13 -6
- package/src/components/loading/Loading.tsx +35 -5
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
EditableProps,
|
|
3
|
+
Field,
|
|
4
|
+
useColorModeValue,
|
|
5
|
+
useEditable,
|
|
6
|
+
useIconColor,
|
|
7
|
+
useThemeValue,
|
|
8
|
+
} from '@chem-po/react'
|
|
3
9
|
import { Ionicons } from '@expo/vector-icons'
|
|
4
|
-
import React, { useEffect, useMemo } from 'react'
|
|
10
|
+
import React, { useCallback, useEffect, useMemo } from 'react'
|
|
5
11
|
import { StyleSheet, TouchableOpacity, View, ViewStyle } from 'react-native'
|
|
6
12
|
import { LoadingOverlay } from '../../loading/Loading'
|
|
7
13
|
import { UploadProgress } from '../UploadProgress'
|
|
@@ -16,6 +22,7 @@ export const Editable = <T extends Field>({
|
|
|
16
22
|
style,
|
|
17
23
|
onEditClose,
|
|
18
24
|
onEditOpen,
|
|
25
|
+
containerStyle,
|
|
19
26
|
}: EditableProps<ViewStyle, T>) => {
|
|
20
27
|
const {
|
|
21
28
|
formattedValue,
|
|
@@ -41,7 +48,38 @@ export const Editable = <T extends Field>({
|
|
|
41
48
|
onEditClose,
|
|
42
49
|
})
|
|
43
50
|
|
|
44
|
-
const alwaysEditing = useMemo(() =>
|
|
51
|
+
const alwaysEditing = useMemo(() => {
|
|
52
|
+
switch (field._type) {
|
|
53
|
+
case 'file':
|
|
54
|
+
case 'boolean':
|
|
55
|
+
return true
|
|
56
|
+
default:
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
}, [field])
|
|
60
|
+
|
|
61
|
+
const shouldSubmitOnChange = useMemo(() => {
|
|
62
|
+
if (alwaysEditing) return true
|
|
63
|
+
switch (field._type) {
|
|
64
|
+
case 'select':
|
|
65
|
+
case 'date':
|
|
66
|
+
case 'time':
|
|
67
|
+
case 'datetime':
|
|
68
|
+
return true
|
|
69
|
+
default:
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
}, [field, alwaysEditing])
|
|
73
|
+
|
|
74
|
+
const noCloseButton = useMemo(() => {
|
|
75
|
+
if (alwaysEditing) return true
|
|
76
|
+
switch (field._type) {
|
|
77
|
+
case 'select':
|
|
78
|
+
return true
|
|
79
|
+
default:
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
}, [field, alwaysEditing])
|
|
45
83
|
|
|
46
84
|
useEffect(() => {
|
|
47
85
|
if (isEditing) {
|
|
@@ -49,7 +87,31 @@ export const Editable = <T extends Field>({
|
|
|
49
87
|
}
|
|
50
88
|
}, [isEditing, inputRef])
|
|
51
89
|
|
|
90
|
+
const iconColor = useIconColor()
|
|
91
|
+
|
|
52
92
|
const editingBorderColor = useColorModeValue('#00000055', '#ffffff55')
|
|
93
|
+
const submitColor = useThemeValue('colors.accent.200')
|
|
94
|
+
|
|
95
|
+
const handleBlur = useCallback(() => {
|
|
96
|
+
switch (field._type) {
|
|
97
|
+
case 'select':
|
|
98
|
+
case 'date':
|
|
99
|
+
case 'time':
|
|
100
|
+
case 'datetime':
|
|
101
|
+
handleEditClose()
|
|
102
|
+
break
|
|
103
|
+
default:
|
|
104
|
+
break
|
|
105
|
+
}
|
|
106
|
+
}, [field, handleEditClose])
|
|
107
|
+
|
|
108
|
+
const editableField = useMemo(
|
|
109
|
+
() => ({
|
|
110
|
+
...field,
|
|
111
|
+
optional: false,
|
|
112
|
+
}),
|
|
113
|
+
[field],
|
|
114
|
+
)
|
|
53
115
|
|
|
54
116
|
return (
|
|
55
117
|
<View
|
|
@@ -58,7 +120,7 @@ export const Editable = <T extends Field>({
|
|
|
58
120
|
{
|
|
59
121
|
borderColor: editHovered && !isEditing ? editingBorderColor : 'transparent',
|
|
60
122
|
},
|
|
61
|
-
|
|
123
|
+
containerStyle,
|
|
62
124
|
]}>
|
|
63
125
|
<View style={styles.contentContainer}>
|
|
64
126
|
<View
|
|
@@ -74,53 +136,55 @@ export const Editable = <T extends Field>({
|
|
|
74
136
|
ref={inputRef}
|
|
75
137
|
value={formattedValue}
|
|
76
138
|
inEditable
|
|
77
|
-
field={
|
|
78
|
-
style={
|
|
79
|
-
onChange={
|
|
139
|
+
field={editableField}
|
|
140
|
+
style={style}
|
|
141
|
+
onChange={shouldSubmitOnChange ? v => submitValue(parse(v)) : v => setValue(parse(v))}
|
|
142
|
+
onBlur={handleBlur}
|
|
80
143
|
/>
|
|
81
144
|
) : (
|
|
82
|
-
<FieldView style={style} field={field} value={value} />
|
|
145
|
+
<FieldView noLabel style={style} field={field} value={value} />
|
|
83
146
|
)}
|
|
84
147
|
</View>
|
|
85
148
|
|
|
86
149
|
{!alwaysEditing && (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
150
|
+
<View style={styles.buttonsContainer}>
|
|
151
|
+
{noCloseButton && isEditing ? null : (
|
|
152
|
+
<TouchableOpacity
|
|
153
|
+
style={styles.editButton}
|
|
154
|
+
onPress={() => {
|
|
155
|
+
if (isEditing) {
|
|
156
|
+
setValue(value)
|
|
157
|
+
handleEditClose()
|
|
158
|
+
} else {
|
|
159
|
+
handleEditOpen()
|
|
160
|
+
}
|
|
161
|
+
}}
|
|
162
|
+
onPressIn={() => setEditHovered(true)}
|
|
163
|
+
onPressOut={() => setEditHovered(false)}>
|
|
164
|
+
<Ionicons
|
|
165
|
+
name={isEditing ? 'close' : 'create-outline'}
|
|
166
|
+
size={20}
|
|
167
|
+
color={iconColor}
|
|
168
|
+
/>
|
|
169
|
+
</TouchableOpacity>
|
|
170
|
+
)}
|
|
107
171
|
<View
|
|
108
172
|
style={[
|
|
109
173
|
styles.submitButtonContainer,
|
|
110
174
|
{
|
|
111
|
-
width: isEditing ?
|
|
175
|
+
width: isEditing ? 26 : 0,
|
|
112
176
|
opacity: isEditing ? 1 : 0,
|
|
113
177
|
},
|
|
114
178
|
]}>
|
|
115
179
|
<TouchableOpacity
|
|
116
|
-
style={[styles.submitButton, { backgroundColor:
|
|
180
|
+
style={[styles.submitButton, { backgroundColor: submitColor }]}
|
|
117
181
|
onPress={() => {
|
|
118
182
|
submit()
|
|
119
183
|
}}>
|
|
120
184
|
<Ionicons name="checkmark" size={20} color="#fff" />
|
|
121
185
|
</TouchableOpacity>
|
|
122
186
|
</View>
|
|
123
|
-
|
|
187
|
+
</View>
|
|
124
188
|
)}
|
|
125
189
|
<LoadingOverlay isLoading={isLoading} />
|
|
126
190
|
</View>
|
|
@@ -136,6 +200,12 @@ const styles = StyleSheet.create({
|
|
|
136
200
|
borderStyle: 'dashed',
|
|
137
201
|
width: '100%',
|
|
138
202
|
},
|
|
203
|
+
buttonsContainer: {
|
|
204
|
+
flexDirection: 'row',
|
|
205
|
+
alignItems: 'center',
|
|
206
|
+
gap: 4,
|
|
207
|
+
marginLeft: 5,
|
|
208
|
+
},
|
|
139
209
|
contentContainer: {
|
|
140
210
|
flexDirection: 'row',
|
|
141
211
|
alignItems: 'center',
|
|
@@ -149,19 +219,19 @@ const styles = StyleSheet.create({
|
|
|
149
219
|
borderWidth: 1,
|
|
150
220
|
borderStyle: 'dashed',
|
|
151
221
|
},
|
|
152
|
-
input: {
|
|
153
|
-
padding: 0,
|
|
154
|
-
},
|
|
155
222
|
editButton: {
|
|
156
223
|
padding: 4,
|
|
157
|
-
marginLeft: 4,
|
|
158
224
|
},
|
|
159
225
|
submitButtonContainer: {
|
|
160
|
-
justifyContent: '
|
|
226
|
+
justifyContent: 'center',
|
|
227
|
+
alignItems: 'center',
|
|
161
228
|
overflow: 'hidden',
|
|
162
229
|
},
|
|
163
230
|
submitButton: {
|
|
164
|
-
|
|
231
|
+
width: 24,
|
|
232
|
+
height: 24,
|
|
165
233
|
borderRadius: 4,
|
|
234
|
+
alignItems: 'center',
|
|
235
|
+
justifyContent: 'center',
|
|
166
236
|
},
|
|
167
237
|
})
|
|
@@ -8,6 +8,7 @@ import { DatePickerModal } from 'react-native-paper-dates'
|
|
|
8
8
|
import { FieldProps } from '../../types'
|
|
9
9
|
import { DateInputClearButton } from '../common/InputClearButton'
|
|
10
10
|
import { useInputColor } from '../hooks/useInputColor'
|
|
11
|
+
import { inputStyles } from '../styles'
|
|
11
12
|
|
|
12
13
|
// const parseDate = (date?: Date) =>
|
|
13
14
|
// date
|
|
@@ -48,7 +49,7 @@ export const DateInput = forwardRef<InputRef, FieldProps<DateField>>(
|
|
|
48
49
|
|
|
49
50
|
return (
|
|
50
51
|
<View style={styles.container}>
|
|
51
|
-
<TouchableOpacity style={styles.button} onPress={showDialog}>
|
|
52
|
+
<TouchableOpacity style={[styles.button, inputStyles.input]} onPress={showDialog}>
|
|
52
53
|
<Text style={[styles.text, { color: inputColor }]}>
|
|
53
54
|
{value ? getDateString(value, 'short') : placeholder}
|
|
54
55
|
</Text>
|
|
@@ -89,9 +90,6 @@ const styles = StyleSheet.create({
|
|
|
89
90
|
alignItems: 'center',
|
|
90
91
|
justifyContent: 'space-between',
|
|
91
92
|
width: '100%',
|
|
92
|
-
height: 40,
|
|
93
|
-
paddingHorizontal: 12,
|
|
94
|
-
paddingVertical: 8,
|
|
95
93
|
},
|
|
96
94
|
text: {
|
|
97
95
|
fontSize: 16,
|
|
@@ -8,6 +8,7 @@ import { DatePickerModal, TimePickerModal } from 'react-native-paper-dates'
|
|
|
8
8
|
import { FieldProps } from '../../types'
|
|
9
9
|
import { DateInputClearButton } from '../common/InputClearButton'
|
|
10
10
|
import { useInputColor } from '../hooks/useInputColor'
|
|
11
|
+
import { inputStyles } from '../styles'
|
|
11
12
|
|
|
12
13
|
export const DateTimeInput = forwardRef<InputRef, FieldProps<DateTimeField>>(
|
|
13
14
|
({ input: { value, onBlur, onChange, onFocus }, field, meta: { active } }, ref) => {
|
|
@@ -76,7 +77,7 @@ export const DateTimeInput = forwardRef<InputRef, FieldProps<DateTimeField>>(
|
|
|
76
77
|
return (
|
|
77
78
|
<View style={styles.container}>
|
|
78
79
|
<TouchableOpacity
|
|
79
|
-
style={styles.button}
|
|
80
|
+
style={[styles.button, inputStyles.input]}
|
|
80
81
|
onPress={() => {
|
|
81
82
|
setShowDatePicker(true)
|
|
82
83
|
onFocus()
|
|
@@ -129,9 +130,6 @@ const styles = StyleSheet.create({
|
|
|
129
130
|
alignItems: 'center',
|
|
130
131
|
justifyContent: 'space-between',
|
|
131
132
|
width: '100%',
|
|
132
|
-
height: 40,
|
|
133
|
-
paddingHorizontal: 12,
|
|
134
|
-
paddingVertical: 8,
|
|
135
133
|
},
|
|
136
134
|
text: {
|
|
137
135
|
fontSize: 16,
|
|
@@ -14,8 +14,10 @@ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
|
|
14
14
|
import { LoadingImage } from '../../../loading/LoadingImage'
|
|
15
15
|
import { FieldProps } from '../../types'
|
|
16
16
|
|
|
17
|
+
const fallbackAccept =
|
|
18
|
+
'image/jpg,image/jpeg,image/png,image/svg,image/gif,application/pdf,audio/mp3,audio/wav,audio/x-wav,audio/webm,audio/ogg'
|
|
17
19
|
const generateAccept = (field: FileField) => {
|
|
18
|
-
if (!field.accept) return
|
|
20
|
+
if (!field.accept) return fallbackAccept
|
|
19
21
|
const accept: string[] = []
|
|
20
22
|
if (field.accept.includes('image')) {
|
|
21
23
|
accept.push('image/jpg', 'image/jpeg', 'image/png', 'image/svg', 'image/gif')
|
|
@@ -52,6 +52,7 @@ const InputBase = <T extends Field>(props: FieldProps<T>, ref: ForwardedRef<Inpu
|
|
|
52
52
|
meta: { error, active, touched },
|
|
53
53
|
input,
|
|
54
54
|
inEditable,
|
|
55
|
+
style,
|
|
55
56
|
} = props
|
|
56
57
|
|
|
57
58
|
const { value } = input
|
|
@@ -84,7 +85,7 @@ const InputBase = <T extends Field>(props: FieldProps<T>, ref: ForwardedRef<Inpu
|
|
|
84
85
|
outputRange: [placeholderColor, shadowColor],
|
|
85
86
|
})
|
|
86
87
|
|
|
87
|
-
const { _type, label } = field
|
|
88
|
+
const { _type, label: Label } = field
|
|
88
89
|
const showPlaceholder = useMemo(
|
|
89
90
|
() => _type === 'multipleSelect' || (!!value && _type !== 'file' && _type !== 'boolean'),
|
|
90
91
|
[value, _type],
|
|
@@ -118,16 +119,24 @@ const InputBase = <T extends Field>(props: FieldProps<T>, ref: ForwardedRef<Inpu
|
|
|
118
119
|
const Component = useMemo(() => Components[_type] as ComponentType<T>, [_type])
|
|
119
120
|
|
|
120
121
|
return (
|
|
121
|
-
<View style={[staticStyles.container]}>
|
|
122
|
-
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
<View style={[staticStyles.container, style]}>
|
|
123
|
+
{Label && !inEditable ? (
|
|
124
|
+
typeof Label === 'string' ? (
|
|
125
|
+
<Text style={staticStyles.label}>{Label}</Text>
|
|
126
|
+
) : (
|
|
127
|
+
<Label />
|
|
128
|
+
)
|
|
129
|
+
) : null}
|
|
130
|
+
{inEditable ? null : (
|
|
131
|
+
<AnimatedText
|
|
132
|
+
style={staticStyles.placeholder}
|
|
133
|
+
show={showPlaceholder}
|
|
134
|
+
color={placeholderColor}
|
|
135
|
+
height={16}
|
|
136
|
+
marginBottom={6}>
|
|
137
|
+
{field.placeholder ?? ''}
|
|
138
|
+
</AnimatedText>
|
|
139
|
+
)}
|
|
131
140
|
<Animated.View style={[staticStyles.inputContainer, animatedStyles]}>
|
|
132
141
|
<Component ref={ref} {...props} />
|
|
133
142
|
</Animated.View>
|
|
@@ -6,7 +6,7 @@ import { FieldProps } from '../../types'
|
|
|
6
6
|
|
|
7
7
|
export const MultipleSelectComponent = forwardRef<InputRef, FieldProps<MultipleSelectField>>(
|
|
8
8
|
({ field, input, inEditable }, ref) => {
|
|
9
|
-
const { options, renderOption, getOptionKey } = field
|
|
9
|
+
const { options, renderOption: RenderOption, getOptionKey } = field
|
|
10
10
|
const { onChange, value, onFocus, onBlur } = input
|
|
11
11
|
const colorMode = useColorMode()
|
|
12
12
|
|
|
@@ -34,7 +34,7 @@ export const MultipleSelectComponent = forwardRef<InputRef, FieldProps<MultipleS
|
|
|
34
34
|
key={getOptionKey ? getOptionKey(o) : o}
|
|
35
35
|
style={[styles.option, value?.includes(o) && styles.selectedOption]}
|
|
36
36
|
onPress={() => handleOptionPress(o)}>
|
|
37
|
-
{
|
|
37
|
+
<RenderOption value={o} colorMode={colorMode} isSelected={!!value?.includes(o)} />
|
|
38
38
|
</TouchableOpacity>
|
|
39
39
|
))}
|
|
40
40
|
</View>
|
|
@@ -5,13 +5,12 @@ import { StyleSheet, Text, TextInput, View } from 'react-native'
|
|
|
5
5
|
import { FieldProps } from '../../types'
|
|
6
6
|
import { InputSlider } from '../InputSlider'
|
|
7
7
|
import { useInputImperativeHandle } from '../hooks/useInputImperativeHandle'
|
|
8
|
-
import {
|
|
8
|
+
import { inputStyles } from '../styles'
|
|
9
9
|
|
|
10
10
|
export const NumberComponent = forwardRef<InputRef, FieldProps<NumberField> & { prefix?: string }>(
|
|
11
|
-
({ input: { onChange, value, ...input }, field,
|
|
11
|
+
({ input: { onChange, value, ...input }, field, prefix, inEditable: _, style }, ref) => {
|
|
12
12
|
const { type, defaultValue, placeholder } = field
|
|
13
13
|
const color = useTextColor()
|
|
14
|
-
const { style } = useInputStyle(size)
|
|
15
14
|
const inputRef = useInputImperativeHandle(ref)
|
|
16
15
|
const [endsWith, setEndsWith] = useState('')
|
|
17
16
|
const displayed = typeof value === 'number' && !Number.isNaN(value) ? `${value}${endsWith}` : ''
|
|
@@ -34,8 +33,7 @@ export const NumberComponent = forwardRef<InputRef, FieldProps<NumberField> & {
|
|
|
34
33
|
{prefix && <Text style={styles.prefix}>{prefix}</Text>}
|
|
35
34
|
<TextInput
|
|
36
35
|
ref={inputRef}
|
|
37
|
-
style={[
|
|
38
|
-
// style={styles.input}
|
|
36
|
+
style={[inputStyles.input, { color }, style]}
|
|
39
37
|
placeholder={field.placeholder}
|
|
40
38
|
placeholderTextColor={placeholderColor}
|
|
41
39
|
keyboardType="numeric"
|
|
@@ -86,13 +84,6 @@ const styles = StyleSheet.create({
|
|
|
86
84
|
alignItems: 'center',
|
|
87
85
|
width: '100%',
|
|
88
86
|
},
|
|
89
|
-
input: {
|
|
90
|
-
flex: 1,
|
|
91
|
-
height: 40,
|
|
92
|
-
paddingHorizontal: 12,
|
|
93
|
-
paddingVertical: 8,
|
|
94
|
-
backgroundColor: 'transparent',
|
|
95
|
-
},
|
|
96
87
|
prefix: {
|
|
97
88
|
marginRight: 4,
|
|
98
89
|
fontSize: 16,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputRef } from '@chem-po/core'
|
|
1
|
+
import { InputRef, RenderSelectOptionProps } from '@chem-po/core'
|
|
2
2
|
import {
|
|
3
3
|
SelectField,
|
|
4
4
|
useBackgroundColor,
|
|
@@ -19,6 +19,7 @@ import { Modal, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'rea
|
|
|
19
19
|
import { Txt } from '../../../text/Txt'
|
|
20
20
|
import { FieldProps } from '../../types'
|
|
21
21
|
import { InputClearButton } from '../common/InputClearButton'
|
|
22
|
+
import { inputStyles } from '../styles'
|
|
22
23
|
|
|
23
24
|
type SelectOption<T extends SelectField> = T['options'][number]
|
|
24
25
|
|
|
@@ -26,7 +27,7 @@ const BaseSelectComponent = <T extends SelectField>(
|
|
|
26
27
|
{ field, input, meta }: FieldProps<T>,
|
|
27
28
|
ref: ForwardedRef<InputRef>,
|
|
28
29
|
) => {
|
|
29
|
-
const { placeholder, options, renderOption, getOptionKey, optional } = field
|
|
30
|
+
const { placeholder, options, renderOption: RenderOption, getOptionKey, optional } = field
|
|
30
31
|
const { onChange, value, onFocus, onBlur } = input
|
|
31
32
|
const { active } = meta
|
|
32
33
|
const [buttonLayout, setButtonLayout] = useState({ x: 0, y: 0, width: 0, height: 0 })
|
|
@@ -61,14 +62,14 @@ const BaseSelectComponent = <T extends SelectField>(
|
|
|
61
62
|
})
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
const
|
|
65
|
-
if (typeof
|
|
66
|
-
return
|
|
65
|
+
const RenderOptionText = (props: RenderSelectOptionProps<T['defaultValue']>) => {
|
|
66
|
+
if (typeof RenderOption === 'function') {
|
|
67
|
+
return RenderOption({ ...props, value: props.value ?? '' })
|
|
67
68
|
}
|
|
68
|
-
if (typeof
|
|
69
|
-
return <Txt>{JSON.stringify(
|
|
69
|
+
if (typeof props.value === 'object') {
|
|
70
|
+
return <Txt>{JSON.stringify(props.value)}</Txt>
|
|
70
71
|
}
|
|
71
|
-
return <Txt>{String(
|
|
72
|
+
return <Txt>{String(props.value)}</Txt>
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
const getKey = (option: SelectOption<T>): string => {
|
|
@@ -94,7 +95,7 @@ const BaseSelectComponent = <T extends SelectField>(
|
|
|
94
95
|
<View style={styles.wrapper}>
|
|
95
96
|
<View ref={buttonRef} onLayout={handleButtonLayout} style={styles.container}>
|
|
96
97
|
<TouchableOpacity
|
|
97
|
-
style={[styles.button]}
|
|
98
|
+
style={[styles.button, inputStyles.input]}
|
|
98
99
|
onPress={() => {
|
|
99
100
|
if (active) {
|
|
100
101
|
onBlur()
|
|
@@ -104,7 +105,7 @@ const BaseSelectComponent = <T extends SelectField>(
|
|
|
104
105
|
}}>
|
|
105
106
|
<View style={styles.buttonTextContainer}>
|
|
106
107
|
{selected ? (
|
|
107
|
-
|
|
108
|
+
<RenderOptionText value={selected} colorMode="light" isSelected={true} />
|
|
108
109
|
) : (
|
|
109
110
|
<Text style={[styles.placeholder, { color: placeholderColor }]}>{placeholder}</Text>
|
|
110
111
|
)}
|
|
@@ -147,7 +148,9 @@ const BaseSelectComponent = <T extends SelectField>(
|
|
|
147
148
|
isSelected && { backgroundColor: selectedOptionBg },
|
|
148
149
|
]}
|
|
149
150
|
onPress={() => handleOptionPress(option)}>
|
|
150
|
-
<View>
|
|
151
|
+
<View>
|
|
152
|
+
<RenderOptionText value={option} colorMode="light" isSelected={isSelected} />
|
|
153
|
+
</View>
|
|
151
154
|
</TouchableOpacity>
|
|
152
155
|
)
|
|
153
156
|
})}
|
|
@@ -172,10 +175,6 @@ const styles = StyleSheet.create({
|
|
|
172
175
|
flexDirection: 'row',
|
|
173
176
|
alignItems: 'center',
|
|
174
177
|
justifyContent: 'space-between',
|
|
175
|
-
width: '100%',
|
|
176
|
-
height: 40,
|
|
177
|
-
paddingHorizontal: 12,
|
|
178
|
-
paddingVertical: 8,
|
|
179
178
|
backgroundColor: 'transparent',
|
|
180
179
|
borderRadius: 4,
|
|
181
180
|
},
|
|
@@ -4,10 +4,11 @@ import { Ionicons } from '@expo/vector-icons'
|
|
|
4
4
|
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
5
5
|
import { StyleSheet, TextInput, TouchableOpacity, View } from 'react-native'
|
|
6
6
|
import { FieldProps } from '../../types'
|
|
7
|
+
import { inputStyles } from '../styles'
|
|
7
8
|
import { TextAreaComponent } from './textarea'
|
|
8
9
|
|
|
9
10
|
export const TextComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
10
|
-
({ input, inEditable, meta, field }, ref) => {
|
|
11
|
+
({ input, inEditable, meta, field, style }, ref) => {
|
|
11
12
|
const { placeholder, type } = field
|
|
12
13
|
const [isHidden, setIsHidden] = useState(type === 'password')
|
|
13
14
|
const { value, onChange, ...inputProps } = input
|
|
@@ -31,10 +32,11 @@ export const TextComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
|
31
32
|
<TextInput
|
|
32
33
|
ref={inputRef}
|
|
33
34
|
style={[
|
|
34
|
-
|
|
35
|
-
inEditable && styles.inEditable,
|
|
35
|
+
inputStyles.input,
|
|
36
|
+
// inEditable && styles.inEditable,
|
|
36
37
|
type === 'password' && styles.passwordInput,
|
|
37
38
|
{ color },
|
|
39
|
+
style,
|
|
38
40
|
]}
|
|
39
41
|
secureTextEntry={isHidden}
|
|
40
42
|
placeholderTextColor={placeholderColor}
|
|
@@ -61,17 +63,11 @@ export const TextComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
|
61
63
|
TextComponent.displayName = 'TextComponent'
|
|
62
64
|
|
|
63
65
|
const styles = StyleSheet.create({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
inEditable: {
|
|
71
|
-
paddingHorizontal: 0,
|
|
72
|
-
paddingVertical: 0,
|
|
73
|
-
height: 'auto',
|
|
74
|
-
},
|
|
66
|
+
// inEditable: {
|
|
67
|
+
// paddingHorizontal: 0,
|
|
68
|
+
// paddingVertical: 0,
|
|
69
|
+
// height: 'auto',
|
|
70
|
+
// },
|
|
75
71
|
passwordInput: {
|
|
76
72
|
paddingRight: 40,
|
|
77
73
|
},
|
|
@@ -8,6 +8,7 @@ import { TimePickerModal } from 'react-native-paper-dates'
|
|
|
8
8
|
import { FieldProps } from '../../types'
|
|
9
9
|
import { DateInputClearButton } from '../common/InputClearButton'
|
|
10
10
|
import { useInputColor } from '../hooks/useInputColor'
|
|
11
|
+
import { inputStyles } from '../styles'
|
|
11
12
|
|
|
12
13
|
export const TimeInput = forwardRef<InputRef, FieldProps<TimeField>>(
|
|
13
14
|
({ input: { onChange, value, onFocus, onBlur }, field: { placeholder, optional } }, ref) => {
|
|
@@ -56,7 +57,7 @@ export const TimeInput = forwardRef<InputRef, FieldProps<TimeField>>(
|
|
|
56
57
|
return (
|
|
57
58
|
<View style={styles.container}>
|
|
58
59
|
<TouchableOpacity
|
|
59
|
-
style={styles.button}
|
|
60
|
+
style={[styles.button, inputStyles.input]}
|
|
60
61
|
onPress={() => {
|
|
61
62
|
setVisible(true)
|
|
62
63
|
onFocus()
|
|
@@ -92,9 +93,6 @@ const styles = StyleSheet.create({
|
|
|
92
93
|
alignItems: 'center',
|
|
93
94
|
justifyContent: 'space-between',
|
|
94
95
|
width: '100%',
|
|
95
|
-
height: 40,
|
|
96
|
-
paddingHorizontal: 12,
|
|
97
|
-
paddingVertical: 8,
|
|
98
96
|
},
|
|
99
97
|
text: {
|
|
100
98
|
fontSize: 16,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { formatField } from '@chem-po/core'
|
|
2
2
|
import { Field } from '@chem-po/react'
|
|
3
3
|
import React, { useMemo } from 'react'
|
|
4
|
-
import { StyleSheet,
|
|
4
|
+
import { StyleSheet, View, ViewStyle } from 'react-native'
|
|
5
|
+
import { Txt } from '../../text'
|
|
5
6
|
import { FileFieldView } from './file'
|
|
6
7
|
import { MultipleSelectFieldView } from './multipleSelect'
|
|
7
8
|
import { SelectFieldView } from './select'
|
|
@@ -18,9 +19,11 @@ const styles = StyleSheet.create({
|
|
|
18
19
|
},
|
|
19
20
|
value: {
|
|
20
21
|
opacity: 1,
|
|
22
|
+
fontSize: 16,
|
|
21
23
|
},
|
|
22
24
|
valueEmpty: {
|
|
23
25
|
opacity: 0.6,
|
|
26
|
+
fontSize: 16,
|
|
24
27
|
},
|
|
25
28
|
})
|
|
26
29
|
|
|
@@ -45,10 +48,8 @@ const DefaultFieldView = ({
|
|
|
45
48
|
|
|
46
49
|
return (
|
|
47
50
|
<View style={[styles.container, style]}>
|
|
48
|
-
{!noLabel && <
|
|
49
|
-
<
|
|
50
|
-
{formatted ?? 'None'}
|
|
51
|
-
</Text>
|
|
51
|
+
{!noLabel && <Txt style={styles.label}>{placeholder}</Txt>}
|
|
52
|
+
<Txt style={value ? styles.value : styles.valueEmpty}>{formatted ?? 'None'}</Txt>
|
|
52
53
|
</View>
|
|
53
54
|
)
|
|
54
55
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MultipleSelectField } from '@chem-po/react'
|
|
2
|
-
import React, { StyleSheet, Text,
|
|
1
|
+
import { MultipleSelectField, useColorMode } from '@chem-po/react'
|
|
2
|
+
import React, { StyleSheet, Text, View, ViewStyle } from 'react-native'
|
|
3
3
|
|
|
4
4
|
const styles = StyleSheet.create({
|
|
5
5
|
container: {
|
|
@@ -32,16 +32,18 @@ export const MultipleSelectFieldView = ({
|
|
|
32
32
|
noLabel?: boolean
|
|
33
33
|
style?: ViewStyle
|
|
34
34
|
}) => {
|
|
35
|
-
const { placeholder, renderOption
|
|
36
|
-
const
|
|
35
|
+
const { placeholder, renderOption: RenderOption } = field
|
|
36
|
+
const colorMode = useColorMode()
|
|
37
37
|
|
|
38
38
|
return (
|
|
39
39
|
<View style={[styles.container, style]}>
|
|
40
40
|
{!noLabel && <Text style={styles.label}>{placeholder}</Text>}
|
|
41
41
|
{value ? (
|
|
42
42
|
value.map((v: any) => (
|
|
43
|
-
<View
|
|
44
|
-
{
|
|
43
|
+
<View
|
|
44
|
+
// key={getOptionKey ? getOptionKey(v) : v}
|
|
45
|
+
style={styles.optionContainer}>
|
|
46
|
+
<RenderOption value={v} colorMode={colorMode} isSelected={true} />
|
|
45
47
|
</View>
|
|
46
48
|
))
|
|
47
49
|
) : (
|