@chem-po/react-native 0.0.14 → 0.0.16
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/form/Field.js +4 -2
- package/lib/commonjs/components/form/Field.js.map +1 -1
- package/lib/commonjs/components/form/Form.js +20 -7
- package/lib/commonjs/components/form/Form.js.map +1 -1
- package/lib/commonjs/components/form/input/Editable.js +24 -7
- package/lib/commonjs/components/form/input/Editable.js.map +1 -1
- package/lib/commonjs/components/form/input/common/InputClearButton.js +10 -5
- package/lib/commonjs/components/form/input/common/InputClearButton.js.map +1 -1
- package/lib/commonjs/components/form/input/date/index.js +23 -15
- package/lib/commonjs/components/form/input/date/index.js.map +1 -1
- package/lib/commonjs/components/form/input/datetime/index.js +22 -18
- package/lib/commonjs/components/form/input/datetime/index.js.map +1 -1
- package/lib/commonjs/components/form/input/hooks/index.js +4 -4
- package/lib/commonjs/components/form/input/hooks/index.js.map +1 -1
- package/lib/commonjs/components/form/input/hooks/useInputStyles.js +111 -0
- package/lib/commonjs/components/form/input/hooks/useInputStyles.js.map +1 -0
- package/lib/commonjs/components/form/input/input.js +49 -11
- package/lib/commonjs/components/form/input/input.js.map +1 -1
- package/lib/commonjs/components/form/input/multipleSelect/index.js +162 -44
- package/lib/commonjs/components/form/input/multipleSelect/index.js.map +1 -1
- package/lib/commonjs/components/form/input/number/index.js +10 -5
- package/lib/commonjs/components/form/input/number/index.js.map +1 -1
- package/lib/commonjs/components/form/input/select/index.js +84 -173
- package/lib/commonjs/components/form/input/select/index.js.map +1 -1
- package/lib/commonjs/components/form/input/text/index.js +7 -5
- package/lib/commonjs/components/form/input/text/index.js.map +1 -1
- package/lib/commonjs/components/form/input/text/textarea.js +10 -5
- package/lib/commonjs/components/form/input/text/textarea.js.map +1 -1
- package/lib/commonjs/components/form/input/time/index.js +22 -13
- package/lib/commonjs/components/form/input/time/index.js.map +1 -1
- package/lib/commonjs/components/form/view/file.js +18 -4
- package/lib/commonjs/components/form/view/file.js.map +1 -1
- package/lib/commonjs/components/form/view/index.js +24 -23
- package/lib/commonjs/components/form/view/index.js.map +1 -1
- package/lib/commonjs/components/form/view/multipleSelect.js +38 -10
- package/lib/commonjs/components/form/view/multipleSelect.js.map +1 -1
- package/lib/commonjs/components/form/view/select.js +24 -9
- package/lib/commonjs/components/form/view/select.js.map +1 -1
- package/lib/commonjs/components/form/view/styles.js +21 -0
- package/lib/commonjs/components/form/view/styles.js.map +1 -0
- package/lib/commonjs/contexts/root.js +6 -0
- package/lib/commonjs/contexts/root.js.map +1 -1
- package/lib/module/components/form/Field.js +4 -2
- package/lib/module/components/form/Field.js.map +1 -1
- package/lib/module/components/form/Form.js +20 -7
- package/lib/module/components/form/Form.js.map +1 -1
- package/lib/module/components/form/input/Editable.js +24 -7
- package/lib/module/components/form/input/Editable.js.map +1 -1
- package/lib/module/components/form/input/common/InputClearButton.js +11 -6
- package/lib/module/components/form/input/common/InputClearButton.js.map +1 -1
- package/lib/module/components/form/input/date/index.js +23 -15
- package/lib/module/components/form/input/date/index.js.map +1 -1
- package/lib/module/components/form/input/datetime/index.js +22 -18
- package/lib/module/components/form/input/datetime/index.js.map +1 -1
- package/lib/module/components/form/input/hooks/index.js +1 -1
- package/lib/module/components/form/input/hooks/index.js.map +1 -1
- package/lib/module/components/form/input/hooks/useInputStyles.js +104 -0
- package/lib/module/components/form/input/hooks/useInputStyles.js.map +1 -0
- package/lib/module/components/form/input/input.js +51 -13
- package/lib/module/components/form/input/input.js.map +1 -1
- package/lib/module/components/form/input/multipleSelect/index.js +163 -46
- package/lib/module/components/form/input/multipleSelect/index.js.map +1 -1
- package/lib/module/components/form/input/number/index.js +10 -5
- package/lib/module/components/form/input/number/index.js.map +1 -1
- package/lib/module/components/form/input/select/index.js +86 -175
- package/lib/module/components/form/input/select/index.js.map +1 -1
- package/lib/module/components/form/input/text/index.js +7 -5
- package/lib/module/components/form/input/text/index.js.map +1 -1
- package/lib/module/components/form/input/text/textarea.js +11 -6
- package/lib/module/components/form/input/text/textarea.js.map +1 -1
- package/lib/module/components/form/input/time/index.js +22 -13
- package/lib/module/components/form/input/time/index.js.map +1 -1
- package/lib/module/components/form/view/file.js +18 -4
- package/lib/module/components/form/view/file.js.map +1 -1
- package/lib/module/components/form/view/index.js +25 -24
- package/lib/module/components/form/view/index.js.map +1 -1
- package/lib/module/components/form/view/multipleSelect.js +38 -10
- package/lib/module/components/form/view/multipleSelect.js.map +1 -1
- package/lib/module/components/form/view/select.js +23 -9
- package/lib/module/components/form/view/select.js.map +1 -1
- package/lib/module/components/form/view/styles.js +15 -0
- package/lib/module/components/form/view/styles.js.map +1 -0
- package/lib/module/contexts/root.js +6 -0
- package/lib/module/contexts/root.js.map +1 -1
- package/lib/typescript/components/form/Field.d.ts +2 -1
- package/lib/typescript/components/form/Field.d.ts.map +1 -1
- package/lib/typescript/components/form/Form.d.ts +7 -4
- package/lib/typescript/components/form/Form.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/common/InputClearButton.d.ts +4 -2
- package/lib/typescript/components/form/input/common/InputClearButton.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/hooks/index.d.ts +1 -1
- package/lib/typescript/components/form/input/hooks/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts +61 -0
- package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts.map +1 -0
- package/lib/typescript/components/form/input/input.d.ts.map +1 -1
- package/lib/typescript/components/form/input/multipleSelect/index.d.ts +6 -1
- package/lib/typescript/components/form/input/multipleSelect/index.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/text/index.d.ts.map +1 -1
- package/lib/typescript/components/form/input/text/textarea.d.ts.map +1 -1
- package/lib/typescript/components/form/input/time/index.d.ts.map +1 -1
- package/lib/typescript/components/form/view/file.d.ts +3 -1
- package/lib/typescript/components/form/view/file.d.ts.map +1 -1
- package/lib/typescript/components/form/view/index.d.ts +3 -1
- package/lib/typescript/components/form/view/index.d.ts.map +1 -1
- package/lib/typescript/components/form/view/multipleSelect.d.ts +5 -3
- package/lib/typescript/components/form/view/multipleSelect.d.ts.map +1 -1
- package/lib/typescript/components/form/view/select.d.ts +4 -1
- package/lib/typescript/components/form/view/select.d.ts.map +1 -1
- package/lib/typescript/components/form/view/styles.d.ts +14 -0
- package/lib/typescript/components/form/view/styles.d.ts.map +1 -0
- package/lib/typescript/contexts/root.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/components/form/Field.tsx +3 -2
- package/src/components/form/Form.tsx +41 -11
- package/src/components/form/input/Editable.tsx +23 -6
- package/src/components/form/input/common/InputClearButton.tsx +12 -4
- package/src/components/form/input/date/index.tsx +23 -12
- package/src/components/form/input/datetime/index.tsx +27 -14
- package/src/components/form/input/hooks/index.ts +1 -1
- package/src/components/form/input/hooks/useInputStyles.ts +124 -0
- package/src/components/form/input/input.tsx +57 -25
- package/src/components/form/input/multipleSelect/index.tsx +189 -60
- package/src/components/form/input/number/index.tsx +5 -4
- package/src/components/form/input/select/index.tsx +88 -166
- package/src/components/form/input/text/index.tsx +4 -9
- package/src/components/form/input/text/textarea.tsx +18 -16
- package/src/components/form/input/time/index.tsx +31 -11
- package/src/components/form/view/file.tsx +19 -4
- package/src/components/form/view/index.tsx +36 -22
- package/src/components/form/view/multipleSelect.tsx +42 -15
- package/src/components/form/view/select.tsx +28 -11
- package/src/components/form/view/styles.ts +15 -0
- package/src/contexts/root.tsx +7 -0
- package/lib/commonjs/components/form/input/hooks/useInputStyle.js +0 -50
- package/lib/commonjs/components/form/input/hooks/useInputStyle.js.map +0 -1
- package/lib/commonjs/components/form/input/styles.js +0 -17
- package/lib/commonjs/components/form/input/styles.js.map +0 -1
- package/lib/module/components/form/input/hooks/useInputStyle.js +0 -43
- package/lib/module/components/form/input/hooks/useInputStyle.js.map +0 -1
- package/lib/module/components/form/input/styles.js +0 -11
- package/lib/module/components/form/input/styles.js.map +0 -1
- package/lib/typescript/components/form/input/hooks/useInputStyle.d.ts +0 -9
- package/lib/typescript/components/form/input/hooks/useInputStyle.d.ts.map +0 -1
- package/lib/typescript/components/form/input/styles.d.ts +0 -10
- package/lib/typescript/components/form/input/styles.d.ts.map +0 -1
- package/src/components/form/input/hooks/useInputStyle.ts +0 -40
- package/src/components/form/input/styles.ts +0 -11
|
@@ -7,83 +7,55 @@ import {
|
|
|
7
7
|
usePlaceholderColor,
|
|
8
8
|
} from '@chem-po/react'
|
|
9
9
|
import { Ionicons } from '@expo/vector-icons'
|
|
10
|
-
import React, {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
useImperativeHandle,
|
|
14
|
-
useMemo,
|
|
15
|
-
useRef,
|
|
16
|
-
useState,
|
|
17
|
-
} from 'react'
|
|
18
|
-
import { Modal, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
|
10
|
+
import React, { ForwardedRef, forwardRef, useImperativeHandle, useRef } from 'react'
|
|
11
|
+
import { StyleSheet, View } from 'react-native'
|
|
12
|
+
import { Dropdown, IDropdownRef } from 'react-native-element-dropdown'
|
|
19
13
|
import { Txt } from '../../../text/Txt'
|
|
20
14
|
import { FieldProps } from '../../types'
|
|
21
15
|
import { InputClearButton } from '../common/InputClearButton'
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
type SelectOption<T extends SelectField> = T['options'][number]
|
|
16
|
+
import { useInputStyles } from '../hooks/useInputStyles'
|
|
25
17
|
|
|
26
18
|
const BaseSelectComponent = <T extends SelectField>(
|
|
27
|
-
{ field, input, meta }: FieldProps<T>,
|
|
19
|
+
{ field, input, meta, formSize, inEditable }: FieldProps<T>,
|
|
28
20
|
ref: ForwardedRef<InputRef>,
|
|
29
21
|
) => {
|
|
30
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
placeholder,
|
|
24
|
+
options,
|
|
25
|
+
renderOption: RenderOption,
|
|
26
|
+
optional,
|
|
27
|
+
searchable,
|
|
28
|
+
searchPlaceholder,
|
|
29
|
+
} = field
|
|
31
30
|
const { onChange, value, onFocus, onBlur } = input
|
|
32
31
|
const { active } = meta
|
|
33
|
-
const [buttonLayout, setButtonLayout] = useState({ x: 0, y: 0, width: 0, height: 0 })
|
|
34
|
-
const buttonRef = useRef<View>(null)
|
|
35
32
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
}, [value, options, getOptionKey])
|
|
33
|
+
const inputRef = useRef<IDropdownRef>(null)
|
|
34
|
+
const {
|
|
35
|
+
container: inputStyles,
|
|
36
|
+
iconSize,
|
|
37
|
+
text,
|
|
38
|
+
size,
|
|
39
|
+
clearButtonSize,
|
|
40
|
+
buttonContainer,
|
|
41
|
+
} = useInputStyles(inEditable, field.size, formSize)
|
|
47
42
|
|
|
48
43
|
useImperativeHandle(ref, () => ({
|
|
49
44
|
focus: () => {
|
|
50
|
-
|
|
51
|
-
// setIsOpen(true)
|
|
45
|
+
inputRef.current?.open()
|
|
52
46
|
},
|
|
53
47
|
blur: () => {
|
|
54
|
-
|
|
55
|
-
// setIsOpen(false)
|
|
48
|
+
inputRef.current?.close()
|
|
56
49
|
},
|
|
57
50
|
}))
|
|
58
51
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const RenderOptionText = (props: RenderSelectOptionProps<T['defaultValue']>) => {
|
|
52
|
+
const RenderOptionText = (
|
|
53
|
+
props: RenderSelectOptionProps<T['options'][number]['value'], T['options'][number]>,
|
|
54
|
+
) => {
|
|
66
55
|
if (typeof RenderOption === 'function') {
|
|
67
|
-
return RenderOption(
|
|
68
|
-
}
|
|
69
|
-
if (typeof props.value === 'object') {
|
|
70
|
-
return <Txt>{JSON.stringify(props.value)}</Txt>
|
|
71
|
-
}
|
|
72
|
-
return <Txt>{String(props.value)}</Txt>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const getKey = (option: SelectOption<T>): string => {
|
|
76
|
-
if (getOptionKey) {
|
|
77
|
-
const key = getOptionKey(option)
|
|
78
|
-
return typeof key === 'object' ? JSON.stringify(key) : String(key)
|
|
56
|
+
return RenderOption(props)
|
|
79
57
|
}
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const handleOptionPress = (option: SelectOption<T>) => {
|
|
84
|
-
onChange(option)
|
|
85
|
-
onBlur()
|
|
86
|
-
// setIsOpen(false)
|
|
58
|
+
return <Txt style={styles.defaultOption}>{props.option.label}</Txt>
|
|
87
59
|
}
|
|
88
60
|
|
|
89
61
|
const iconColor = useIconColor()
|
|
@@ -91,73 +63,61 @@ const BaseSelectComponent = <T extends SelectField>(
|
|
|
91
63
|
const menuBg = useBackgroundColor(100)
|
|
92
64
|
const selectedOptionBg = useBackgroundColor(50)
|
|
93
65
|
const borderColor = useBorderColor()
|
|
66
|
+
|
|
94
67
|
return (
|
|
95
68
|
<View style={styles.wrapper}>
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
69
|
+
<Dropdown
|
|
70
|
+
ref={inputRef}
|
|
71
|
+
style={[inputStyles, { borderColor }]}
|
|
72
|
+
placeholderStyle={[text, { color: placeholderColor }]}
|
|
73
|
+
selectedTextStyle={text}
|
|
74
|
+
inputSearchStyle={[styles.inputSearch, text]}
|
|
75
|
+
iconStyle={styles.iconStyle}
|
|
76
|
+
data={options}
|
|
77
|
+
search={searchable}
|
|
78
|
+
searchField={searchable ? 'label' : undefined}
|
|
79
|
+
maxHeight={300}
|
|
80
|
+
labelField="label"
|
|
81
|
+
valueField="value"
|
|
82
|
+
placeholder={placeholder}
|
|
83
|
+
searchPlaceholder={searchPlaceholder ?? placeholder}
|
|
84
|
+
value={value}
|
|
85
|
+
onChange={item => {
|
|
86
|
+
onChange(item.value)
|
|
87
|
+
}}
|
|
88
|
+
activeColor={selectedOptionBg}
|
|
89
|
+
// onFocus={onFocus}
|
|
90
|
+
// onBlur={onBlur}
|
|
91
|
+
renderItem={(item, selected) => (
|
|
92
|
+
<View style={{ backgroundColor: selected ? selectedOptionBg : menuBg }}>
|
|
93
|
+
<RenderOptionText
|
|
94
|
+
value={item.value}
|
|
95
|
+
option={item}
|
|
96
|
+
colorMode="light"
|
|
97
|
+
isSelected={!!selected}
|
|
98
|
+
size={size}
|
|
99
|
+
/>
|
|
112
100
|
</View>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
position: 'absolute',
|
|
131
|
-
top: buttonLayout.y + buttonLayout.height + 4,
|
|
132
|
-
left: buttonLayout.x,
|
|
133
|
-
width: buttonLayout.width,
|
|
134
|
-
backgroundColor: menuBg,
|
|
135
|
-
borderColor,
|
|
136
|
-
},
|
|
137
|
-
]}>
|
|
138
|
-
<ScrollView style={styles.dropdown}>
|
|
139
|
-
{options.map((option: SelectOption<T>) => {
|
|
140
|
-
const key = getKey(option)
|
|
141
|
-
const isSelected = option === selected
|
|
142
|
-
return (
|
|
143
|
-
<TouchableOpacity
|
|
144
|
-
key={key}
|
|
145
|
-
style={[
|
|
146
|
-
styles.option,
|
|
147
|
-
{ borderColor },
|
|
148
|
-
isSelected && { backgroundColor: selectedOptionBg },
|
|
149
|
-
]}
|
|
150
|
-
onPress={() => handleOptionPress(option)}>
|
|
151
|
-
<View>
|
|
152
|
-
<RenderOptionText value={option} colorMode="light" isSelected={isSelected} />
|
|
153
|
-
</View>
|
|
154
|
-
</TouchableOpacity>
|
|
155
|
-
)
|
|
156
|
-
})}
|
|
157
|
-
</ScrollView>
|
|
101
|
+
)}
|
|
102
|
+
renderRightIcon={() => (
|
|
103
|
+
<View style={buttonContainer}>
|
|
104
|
+
<Ionicons
|
|
105
|
+
name={active ? 'chevron-up' : 'chevron-down'}
|
|
106
|
+
size={iconSize}
|
|
107
|
+
color={iconColor}
|
|
108
|
+
/>
|
|
109
|
+
{optional && value ? (
|
|
110
|
+
<InputClearButton
|
|
111
|
+
size={clearButtonSize}
|
|
112
|
+
onPress={() => {
|
|
113
|
+
onChange(null)
|
|
114
|
+
}}
|
|
115
|
+
isActive={!!value}
|
|
116
|
+
/>
|
|
117
|
+
) : null}
|
|
158
118
|
</View>
|
|
159
|
-
|
|
160
|
-
|
|
119
|
+
)}
|
|
120
|
+
/>
|
|
161
121
|
</View>
|
|
162
122
|
)
|
|
163
123
|
}
|
|
@@ -168,54 +128,16 @@ const styles = StyleSheet.create({
|
|
|
168
128
|
wrapper: {
|
|
169
129
|
width: '100%',
|
|
170
130
|
},
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
},
|
|
174
|
-
button: {
|
|
175
|
-
flexDirection: 'row',
|
|
176
|
-
alignItems: 'center',
|
|
177
|
-
justifyContent: 'space-between',
|
|
178
|
-
backgroundColor: 'transparent',
|
|
179
|
-
borderRadius: 4,
|
|
180
|
-
},
|
|
181
|
-
buttonTextContainer: {
|
|
182
|
-
flex: 1,
|
|
183
|
-
},
|
|
184
|
-
buttonText: {
|
|
185
|
-
fontSize: 16,
|
|
131
|
+
defaultOption: {
|
|
132
|
+
padding: 10,
|
|
186
133
|
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
134
|
+
iconStyle: {
|
|
135
|
+
width: 20,
|
|
136
|
+
height: 20,
|
|
190
137
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
borderWidth: 1,
|
|
194
|
-
borderColor: '#ddd',
|
|
195
|
-
borderRadius: 4,
|
|
196
|
-
maxHeight: 200,
|
|
197
|
-
elevation: 3,
|
|
198
|
-
shadowColor: '#000',
|
|
199
|
-
shadowOffset: { width: 0, height: 2 },
|
|
200
|
-
shadowOpacity: 0.1,
|
|
201
|
-
shadowRadius: 2,
|
|
202
|
-
padding: 0,
|
|
203
|
-
},
|
|
204
|
-
dropdown: {
|
|
205
|
-
maxHeight: 200,
|
|
206
|
-
},
|
|
207
|
-
option: {
|
|
208
|
-
paddingVertical: 12,
|
|
209
|
-
paddingHorizontal: 16,
|
|
210
|
-
borderBottomWidth: 1,
|
|
211
|
-
},
|
|
212
|
-
optionText: {
|
|
138
|
+
inputSearch: {
|
|
139
|
+
height: 40,
|
|
213
140
|
fontSize: 16,
|
|
214
|
-
|
|
215
|
-
placeholder: {
|
|
216
|
-
color: '#666',
|
|
217
|
-
},
|
|
218
|
-
icon: {
|
|
219
|
-
marginRight: 10,
|
|
141
|
+
outlineWidth: 0,
|
|
220
142
|
},
|
|
221
143
|
})
|
|
@@ -4,15 +4,16 @@ 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 {
|
|
7
|
+
import { useInputStyles } from '../hooks/useInputStyles'
|
|
8
8
|
import { TextAreaComponent } from './textarea'
|
|
9
9
|
|
|
10
10
|
export const TextComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
11
|
-
({ input, inEditable, meta, field, style }, ref) => {
|
|
11
|
+
({ input, inEditable, meta, field, style, formSize }, ref) => {
|
|
12
12
|
const { placeholder, type } = field
|
|
13
13
|
const [isHidden, setIsHidden] = useState(type === 'password')
|
|
14
14
|
const { value, onChange, ...inputProps } = input
|
|
15
15
|
const inputRef = useRef<TextInput>(null)
|
|
16
|
+
const { container: inputStyles } = useInputStyles(inEditable, field.size, formSize)
|
|
16
17
|
|
|
17
18
|
useImperativeHandle(ref, () => ({
|
|
18
19
|
focus: () => {
|
|
@@ -31,13 +32,7 @@ export const TextComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
|
31
32
|
) : (
|
|
32
33
|
<TextInput
|
|
33
34
|
ref={inputRef}
|
|
34
|
-
style={[
|
|
35
|
-
inputStyles.input,
|
|
36
|
-
// inEditable && styles.inEditable,
|
|
37
|
-
type === 'password' && styles.passwordInput,
|
|
38
|
-
{ color },
|
|
39
|
-
style,
|
|
40
|
-
]}
|
|
35
|
+
style={[inputStyles, { color }, style]}
|
|
41
36
|
secureTextEntry={isHidden}
|
|
42
37
|
placeholderTextColor={placeholderColor}
|
|
43
38
|
placeholder={placeholder}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { InputRef } from '@chem-po/core'
|
|
2
2
|
import { TextField, usePlaceholderColor, useTextColor } from '@chem-po/react'
|
|
3
3
|
import React, { forwardRef, useImperativeHandle, useRef } from 'react'
|
|
4
|
-
import { StyleSheet, TextInput } from 'react-native'
|
|
4
|
+
import { StyleSheet, TextInput, View } from 'react-native'
|
|
5
5
|
import { FieldProps } from '../../types'
|
|
6
|
+
import { useInputStyles } from '../hooks/useInputStyles'
|
|
6
7
|
|
|
7
8
|
export const TextAreaComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
8
|
-
({ input, field, inEditable }, ref) => {
|
|
9
|
+
({ input, field, inEditable, formSize }, ref) => {
|
|
9
10
|
const inputRef = useRef<TextInput>(null)
|
|
11
|
+
const { container: inputStyles } = useInputStyles(inEditable, field.size, formSize)
|
|
10
12
|
const { value, onChange, ...inputProps } = input
|
|
11
13
|
|
|
12
14
|
useImperativeHandle(ref, () => ({
|
|
@@ -22,18 +24,20 @@ export const TextAreaComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
|
22
24
|
const color = useTextColor()
|
|
23
25
|
|
|
24
26
|
return (
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
<View style={inputStyles}>
|
|
28
|
+
<TextInput
|
|
29
|
+
ref={inputRef}
|
|
30
|
+
style={[styles.textarea, inEditable && styles.inEditable, { color }]}
|
|
31
|
+
placeholder={field.placeholder}
|
|
32
|
+
placeholderTextColor={placeholderColor}
|
|
33
|
+
multiline
|
|
34
|
+
maxLength={200}
|
|
35
|
+
textAlignVertical="top"
|
|
36
|
+
value={value ?? ''}
|
|
37
|
+
onChangeText={onChange}
|
|
38
|
+
{...inputProps}
|
|
39
|
+
/>
|
|
40
|
+
</View>
|
|
37
41
|
)
|
|
38
42
|
},
|
|
39
43
|
)
|
|
@@ -44,8 +48,6 @@ const styles = StyleSheet.create({
|
|
|
44
48
|
textarea: {
|
|
45
49
|
width: '100%',
|
|
46
50
|
minHeight: 80,
|
|
47
|
-
paddingHorizontal: 12,
|
|
48
|
-
paddingVertical: 8,
|
|
49
51
|
backgroundColor: 'transparent',
|
|
50
52
|
textAlignVertical: 'top',
|
|
51
53
|
},
|
|
@@ -8,12 +8,27 @@ 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 {
|
|
11
|
+
import { useInputStyles } from '../hooks/useInputStyles'
|
|
12
12
|
|
|
13
13
|
export const TimeInput = forwardRef<InputRef, FieldProps<TimeField>>(
|
|
14
|
-
(
|
|
14
|
+
(
|
|
15
|
+
{
|
|
16
|
+
input: { onChange, value, onFocus, onBlur },
|
|
17
|
+
field: { placeholder, optional, size },
|
|
18
|
+
formSize,
|
|
19
|
+
inEditable,
|
|
20
|
+
},
|
|
21
|
+
ref,
|
|
22
|
+
) => {
|
|
15
23
|
const [visible, setVisible] = useState(false)
|
|
16
24
|
|
|
25
|
+
const {
|
|
26
|
+
container: inputStyles,
|
|
27
|
+
iconSize,
|
|
28
|
+
text,
|
|
29
|
+
clearButtonSize,
|
|
30
|
+
buttonContainer,
|
|
31
|
+
} = useInputStyles(inEditable, size, formSize)
|
|
17
32
|
useImperativeHandle(ref, () => ({
|
|
18
33
|
focus: () => {
|
|
19
34
|
setVisible(true)
|
|
@@ -57,16 +72,24 @@ export const TimeInput = forwardRef<InputRef, FieldProps<TimeField>>(
|
|
|
57
72
|
return (
|
|
58
73
|
<View style={styles.container}>
|
|
59
74
|
<TouchableOpacity
|
|
60
|
-
style={[styles.button, inputStyles
|
|
75
|
+
style={[styles.button, inputStyles]}
|
|
61
76
|
onPress={() => {
|
|
62
77
|
setVisible(true)
|
|
63
78
|
onFocus()
|
|
64
79
|
}}>
|
|
65
|
-
<Text style={[styles.text, { color: inputColor }]}>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
<Text style={[styles.text, text, { color: inputColor }]}>
|
|
81
|
+
{formattedValue ?? placeholder}
|
|
82
|
+
</Text>
|
|
83
|
+
<View style={buttonContainer}>
|
|
84
|
+
<Ionicons name="time" size={iconSize} color={iconColor} />
|
|
85
|
+
{optional && value ? (
|
|
86
|
+
<DateInputClearButton
|
|
87
|
+
size={clearButtonSize}
|
|
88
|
+
onPress={() => onChange(null)}
|
|
89
|
+
isActive={!!value}
|
|
90
|
+
/>
|
|
91
|
+
) : null}
|
|
92
|
+
</View>
|
|
70
93
|
</TouchableOpacity>
|
|
71
94
|
<Portal>
|
|
72
95
|
<TimePickerModal
|
|
@@ -98,7 +121,4 @@ const styles = StyleSheet.create({
|
|
|
98
121
|
fontSize: 16,
|
|
99
122
|
flex: 1,
|
|
100
123
|
},
|
|
101
|
-
icon: {
|
|
102
|
-
marginRight: 10,
|
|
103
|
-
},
|
|
104
124
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageViewOptions } from '@chem-po/core'
|
|
1
|
+
import { ImageViewOptions, InputSize } from '@chem-po/core'
|
|
2
2
|
import { FileField } from '@chem-po/react'
|
|
3
3
|
import React, { useMemo } from 'react'
|
|
4
4
|
import { StyleSheet, Text, View, ViewStyle } from 'react-native'
|
|
@@ -24,24 +24,39 @@ const styles = StyleSheet.create({
|
|
|
24
24
|
},
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
+
const getFileSizeHeight = (size: InputSize) => {
|
|
28
|
+
switch (size) {
|
|
29
|
+
case 'sm':
|
|
30
|
+
return 80
|
|
31
|
+
case 'md':
|
|
32
|
+
return 120
|
|
33
|
+
case 'lg':
|
|
34
|
+
return 150
|
|
35
|
+
default:
|
|
36
|
+
return 120
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
27
40
|
export const FileFieldView = ({
|
|
28
41
|
field,
|
|
29
42
|
value,
|
|
30
43
|
noLabel,
|
|
31
44
|
style,
|
|
45
|
+
size: sizeProp,
|
|
32
46
|
}: {
|
|
33
47
|
field: FileField
|
|
34
48
|
value: any
|
|
35
49
|
noLabel?: boolean
|
|
36
50
|
style?: ViewStyle
|
|
51
|
+
size?: InputSize
|
|
37
52
|
}) => {
|
|
38
|
-
const { imageOptions, placeholder } = field
|
|
53
|
+
const { imageOptions, placeholder, size } = field
|
|
39
54
|
const options = useMemo<ImageViewOptions>(
|
|
40
55
|
() => ({
|
|
41
|
-
height:
|
|
56
|
+
height: getFileSizeHeight(size ?? sizeProp ?? 'md'),
|
|
42
57
|
...imageOptions,
|
|
43
58
|
}),
|
|
44
|
-
[imageOptions],
|
|
59
|
+
[imageOptions, size, sizeProp],
|
|
45
60
|
)
|
|
46
61
|
|
|
47
62
|
return (
|
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Field } from '@chem-po/react'
|
|
1
|
+
import { displayField, InputSize } from '@chem-po/core'
|
|
2
|
+
import { Field, FormatField } from '@chem-po/react'
|
|
3
3
|
import React, { useMemo } from 'react'
|
|
4
4
|
import { StyleSheet, View, ViewStyle } from 'react-native'
|
|
5
5
|
import { Txt } from '../../text'
|
|
6
|
+
import { useInputStyles } from '../input/hooks/useInputStyles'
|
|
6
7
|
import { FileFieldView } from './file'
|
|
7
8
|
import { MultipleSelectFieldView } from './multipleSelect'
|
|
8
9
|
import { SelectFieldView } from './select'
|
|
10
|
+
import { inputViewStyles } from './styles'
|
|
9
11
|
|
|
10
12
|
const styles = StyleSheet.create({
|
|
11
13
|
container: {
|
|
12
14
|
flexDirection: 'row',
|
|
13
15
|
alignItems: 'center',
|
|
14
16
|
},
|
|
15
|
-
label: {
|
|
16
|
-
paddingRight: 8,
|
|
17
|
-
opacity: 0.7,
|
|
18
|
-
fontWeight: '600',
|
|
19
|
-
},
|
|
20
|
-
value: {
|
|
21
|
-
opacity: 1,
|
|
22
|
-
fontSize: 16,
|
|
23
|
-
},
|
|
24
|
-
valueEmpty: {
|
|
25
|
-
opacity: 0.6,
|
|
26
|
-
fontSize: 16,
|
|
27
|
-
},
|
|
28
17
|
})
|
|
29
18
|
|
|
30
19
|
const DefaultFieldView = ({
|
|
@@ -32,24 +21,33 @@ const DefaultFieldView = ({
|
|
|
32
21
|
value,
|
|
33
22
|
noLabel,
|
|
34
23
|
style,
|
|
24
|
+
size: sizeProp,
|
|
35
25
|
}: {
|
|
36
26
|
field: Field
|
|
37
27
|
value: any
|
|
38
28
|
noLabel?: boolean
|
|
39
29
|
style?: ViewStyle
|
|
30
|
+
size?: InputSize
|
|
40
31
|
}) => {
|
|
41
32
|
const { placeholder } = field
|
|
42
33
|
|
|
34
|
+
const { text } = useInputStyles(false, field.size, sizeProp)
|
|
43
35
|
const formatted = useMemo(() => {
|
|
44
|
-
const format =
|
|
36
|
+
const format = displayField[field._type] as FormatField<Field>
|
|
45
37
|
if (!format) return value
|
|
46
38
|
return format(field, value)
|
|
47
39
|
}, [value, field])
|
|
48
40
|
|
|
41
|
+
const hasValue = useMemo(() => {
|
|
42
|
+
return value !== null && value !== undefined && value !== ''
|
|
43
|
+
}, [value])
|
|
44
|
+
|
|
49
45
|
return (
|
|
50
46
|
<View style={[styles.container, style]}>
|
|
51
|
-
{!noLabel && <Txt style={
|
|
52
|
-
<Txt style={
|
|
47
|
+
{!noLabel && <Txt style={[inputViewStyles.label, text]}>{placeholder}</Txt>}
|
|
48
|
+
<Txt style={[hasValue ? inputViewStyles.value : inputViewStyles.valueEmpty, text]}>
|
|
49
|
+
{hasValue ? formatted : 'None'}
|
|
50
|
+
</Txt>
|
|
53
51
|
</View>
|
|
54
52
|
)
|
|
55
53
|
}
|
|
@@ -59,20 +57,36 @@ export const FieldView = ({
|
|
|
59
57
|
value,
|
|
60
58
|
noLabel,
|
|
61
59
|
style,
|
|
60
|
+
size,
|
|
62
61
|
}: {
|
|
63
62
|
field: Field
|
|
64
63
|
value: any
|
|
65
64
|
noLabel?: boolean
|
|
66
65
|
style?: ViewStyle
|
|
66
|
+
size?: InputSize
|
|
67
67
|
}) => {
|
|
68
68
|
switch (field._type) {
|
|
69
69
|
case 'select':
|
|
70
|
-
return
|
|
70
|
+
return (
|
|
71
|
+
<SelectFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
|
|
72
|
+
)
|
|
71
73
|
case 'multipleSelect':
|
|
72
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
<MultipleSelectFieldView
|
|
76
|
+
style={style}
|
|
77
|
+
field={field}
|
|
78
|
+
value={value}
|
|
79
|
+
noLabel={noLabel}
|
|
80
|
+
size={size}
|
|
81
|
+
/>
|
|
82
|
+
)
|
|
73
83
|
case 'file':
|
|
74
|
-
return
|
|
84
|
+
return (
|
|
85
|
+
<FileFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
|
|
86
|
+
)
|
|
75
87
|
default:
|
|
76
|
-
return
|
|
88
|
+
return (
|
|
89
|
+
<DefaultFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
|
|
90
|
+
)
|
|
77
91
|
}
|
|
78
92
|
}
|