@chem-po/react-native 0.0.15 → 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.
Files changed (147) hide show
  1. package/lib/commonjs/components/form/Field.js +4 -2
  2. package/lib/commonjs/components/form/Field.js.map +1 -1
  3. package/lib/commonjs/components/form/Form.js +20 -7
  4. package/lib/commonjs/components/form/Form.js.map +1 -1
  5. package/lib/commonjs/components/form/input/Editable.js +24 -7
  6. package/lib/commonjs/components/form/input/Editable.js.map +1 -1
  7. package/lib/commonjs/components/form/input/common/InputClearButton.js +10 -5
  8. package/lib/commonjs/components/form/input/common/InputClearButton.js.map +1 -1
  9. package/lib/commonjs/components/form/input/date/index.js +23 -15
  10. package/lib/commonjs/components/form/input/date/index.js.map +1 -1
  11. package/lib/commonjs/components/form/input/datetime/index.js +22 -18
  12. package/lib/commonjs/components/form/input/datetime/index.js.map +1 -1
  13. package/lib/commonjs/components/form/input/hooks/index.js +4 -4
  14. package/lib/commonjs/components/form/input/hooks/index.js.map +1 -1
  15. package/lib/commonjs/components/form/input/hooks/useInputStyles.js +111 -0
  16. package/lib/commonjs/components/form/input/hooks/useInputStyles.js.map +1 -0
  17. package/lib/commonjs/components/form/input/input.js +49 -11
  18. package/lib/commonjs/components/form/input/input.js.map +1 -1
  19. package/lib/commonjs/components/form/input/multipleSelect/index.js +162 -44
  20. package/lib/commonjs/components/form/input/multipleSelect/index.js.map +1 -1
  21. package/lib/commonjs/components/form/input/number/index.js +10 -5
  22. package/lib/commonjs/components/form/input/number/index.js.map +1 -1
  23. package/lib/commonjs/components/form/input/select/index.js +84 -173
  24. package/lib/commonjs/components/form/input/select/index.js.map +1 -1
  25. package/lib/commonjs/components/form/input/text/index.js +7 -5
  26. package/lib/commonjs/components/form/input/text/index.js.map +1 -1
  27. package/lib/commonjs/components/form/input/text/textarea.js +10 -5
  28. package/lib/commonjs/components/form/input/text/textarea.js.map +1 -1
  29. package/lib/commonjs/components/form/input/time/index.js +22 -13
  30. package/lib/commonjs/components/form/input/time/index.js.map +1 -1
  31. package/lib/commonjs/components/form/view/file.js +18 -4
  32. package/lib/commonjs/components/form/view/file.js.map +1 -1
  33. package/lib/commonjs/components/form/view/index.js +24 -23
  34. package/lib/commonjs/components/form/view/index.js.map +1 -1
  35. package/lib/commonjs/components/form/view/multipleSelect.js +38 -10
  36. package/lib/commonjs/components/form/view/multipleSelect.js.map +1 -1
  37. package/lib/commonjs/components/form/view/select.js +24 -9
  38. package/lib/commonjs/components/form/view/select.js.map +1 -1
  39. package/lib/commonjs/components/form/view/styles.js +21 -0
  40. package/lib/commonjs/components/form/view/styles.js.map +1 -0
  41. package/lib/module/components/form/Field.js +4 -2
  42. package/lib/module/components/form/Field.js.map +1 -1
  43. package/lib/module/components/form/Form.js +20 -7
  44. package/lib/module/components/form/Form.js.map +1 -1
  45. package/lib/module/components/form/input/Editable.js +24 -7
  46. package/lib/module/components/form/input/Editable.js.map +1 -1
  47. package/lib/module/components/form/input/common/InputClearButton.js +11 -6
  48. package/lib/module/components/form/input/common/InputClearButton.js.map +1 -1
  49. package/lib/module/components/form/input/date/index.js +23 -15
  50. package/lib/module/components/form/input/date/index.js.map +1 -1
  51. package/lib/module/components/form/input/datetime/index.js +22 -18
  52. package/lib/module/components/form/input/datetime/index.js.map +1 -1
  53. package/lib/module/components/form/input/hooks/index.js +1 -1
  54. package/lib/module/components/form/input/hooks/index.js.map +1 -1
  55. package/lib/module/components/form/input/hooks/useInputStyles.js +104 -0
  56. package/lib/module/components/form/input/hooks/useInputStyles.js.map +1 -0
  57. package/lib/module/components/form/input/input.js +51 -13
  58. package/lib/module/components/form/input/input.js.map +1 -1
  59. package/lib/module/components/form/input/multipleSelect/index.js +163 -46
  60. package/lib/module/components/form/input/multipleSelect/index.js.map +1 -1
  61. package/lib/module/components/form/input/number/index.js +10 -5
  62. package/lib/module/components/form/input/number/index.js.map +1 -1
  63. package/lib/module/components/form/input/select/index.js +86 -175
  64. package/lib/module/components/form/input/select/index.js.map +1 -1
  65. package/lib/module/components/form/input/text/index.js +7 -5
  66. package/lib/module/components/form/input/text/index.js.map +1 -1
  67. package/lib/module/components/form/input/text/textarea.js +11 -6
  68. package/lib/module/components/form/input/text/textarea.js.map +1 -1
  69. package/lib/module/components/form/input/time/index.js +22 -13
  70. package/lib/module/components/form/input/time/index.js.map +1 -1
  71. package/lib/module/components/form/view/file.js +18 -4
  72. package/lib/module/components/form/view/file.js.map +1 -1
  73. package/lib/module/components/form/view/index.js +25 -24
  74. package/lib/module/components/form/view/index.js.map +1 -1
  75. package/lib/module/components/form/view/multipleSelect.js +38 -10
  76. package/lib/module/components/form/view/multipleSelect.js.map +1 -1
  77. package/lib/module/components/form/view/select.js +23 -9
  78. package/lib/module/components/form/view/select.js.map +1 -1
  79. package/lib/module/components/form/view/styles.js +15 -0
  80. package/lib/module/components/form/view/styles.js.map +1 -0
  81. package/lib/typescript/components/form/Field.d.ts +2 -1
  82. package/lib/typescript/components/form/Field.d.ts.map +1 -1
  83. package/lib/typescript/components/form/Form.d.ts +7 -4
  84. package/lib/typescript/components/form/Form.d.ts.map +1 -1
  85. package/lib/typescript/components/form/input/Editable.d.ts +1 -1
  86. package/lib/typescript/components/form/input/Editable.d.ts.map +1 -1
  87. package/lib/typescript/components/form/input/common/InputClearButton.d.ts +4 -2
  88. package/lib/typescript/components/form/input/common/InputClearButton.d.ts.map +1 -1
  89. package/lib/typescript/components/form/input/date/index.d.ts.map +1 -1
  90. package/lib/typescript/components/form/input/datetime/index.d.ts.map +1 -1
  91. package/lib/typescript/components/form/input/hooks/index.d.ts +1 -1
  92. package/lib/typescript/components/form/input/hooks/index.d.ts.map +1 -1
  93. package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts +61 -0
  94. package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts.map +1 -0
  95. package/lib/typescript/components/form/input/input.d.ts.map +1 -1
  96. package/lib/typescript/components/form/input/multipleSelect/index.d.ts +6 -1
  97. package/lib/typescript/components/form/input/multipleSelect/index.d.ts.map +1 -1
  98. package/lib/typescript/components/form/input/number/index.d.ts.map +1 -1
  99. package/lib/typescript/components/form/input/select/index.d.ts.map +1 -1
  100. package/lib/typescript/components/form/input/text/index.d.ts.map +1 -1
  101. package/lib/typescript/components/form/input/text/textarea.d.ts.map +1 -1
  102. package/lib/typescript/components/form/input/time/index.d.ts.map +1 -1
  103. package/lib/typescript/components/form/view/file.d.ts +3 -1
  104. package/lib/typescript/components/form/view/file.d.ts.map +1 -1
  105. package/lib/typescript/components/form/view/index.d.ts +3 -1
  106. package/lib/typescript/components/form/view/index.d.ts.map +1 -1
  107. package/lib/typescript/components/form/view/multipleSelect.d.ts +5 -3
  108. package/lib/typescript/components/form/view/multipleSelect.d.ts.map +1 -1
  109. package/lib/typescript/components/form/view/select.d.ts +4 -1
  110. package/lib/typescript/components/form/view/select.d.ts.map +1 -1
  111. package/lib/typescript/components/form/view/styles.d.ts +14 -0
  112. package/lib/typescript/components/form/view/styles.d.ts.map +1 -0
  113. package/package.json +5 -4
  114. package/src/components/form/Field.tsx +3 -2
  115. package/src/components/form/Form.tsx +41 -11
  116. package/src/components/form/input/Editable.tsx +23 -6
  117. package/src/components/form/input/common/InputClearButton.tsx +12 -4
  118. package/src/components/form/input/date/index.tsx +23 -12
  119. package/src/components/form/input/datetime/index.tsx +27 -14
  120. package/src/components/form/input/hooks/index.ts +1 -1
  121. package/src/components/form/input/hooks/useInputStyles.ts +124 -0
  122. package/src/components/form/input/input.tsx +57 -25
  123. package/src/components/form/input/multipleSelect/index.tsx +189 -60
  124. package/src/components/form/input/number/index.tsx +5 -4
  125. package/src/components/form/input/select/index.tsx +88 -166
  126. package/src/components/form/input/text/index.tsx +4 -9
  127. package/src/components/form/input/text/textarea.tsx +18 -16
  128. package/src/components/form/input/time/index.tsx +31 -11
  129. package/src/components/form/view/file.tsx +19 -4
  130. package/src/components/form/view/index.tsx +36 -22
  131. package/src/components/form/view/multipleSelect.tsx +42 -15
  132. package/src/components/form/view/select.tsx +28 -11
  133. package/src/components/form/view/styles.ts +15 -0
  134. package/lib/commonjs/components/form/input/hooks/useInputStyle.js +0 -50
  135. package/lib/commonjs/components/form/input/hooks/useInputStyle.js.map +0 -1
  136. package/lib/commonjs/components/form/input/styles.js +0 -17
  137. package/lib/commonjs/components/form/input/styles.js.map +0 -1
  138. package/lib/module/components/form/input/hooks/useInputStyle.js +0 -43
  139. package/lib/module/components/form/input/hooks/useInputStyle.js.map +0 -1
  140. package/lib/module/components/form/input/styles.js +0 -11
  141. package/lib/module/components/form/input/styles.js.map +0 -1
  142. package/lib/typescript/components/form/input/hooks/useInputStyle.d.ts +0 -9
  143. package/lib/typescript/components/form/input/hooks/useInputStyle.d.ts.map +0 -1
  144. package/lib/typescript/components/form/input/styles.d.ts +0 -10
  145. package/lib/typescript/components/form/input/styles.d.ts.map +0 -1
  146. package/src/components/form/input/hooks/useInputStyle.ts +0 -40
  147. 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
- ForwardedRef,
12
- forwardRef,
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 { inputStyles } from '../styles'
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 { placeholder, options, renderOption: RenderOption, getOptionKey, optional } = field
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 selected = useMemo(() => {
37
- if (!value) return undefined
38
- return options.find(o => {
39
- if (getOptionKey) {
40
- const key1 = getOptionKey(o)
41
- const key2 = getOptionKey(value)
42
- return key1 === key2
43
- }
44
- return o === value
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
- onFocus()
51
- // setIsOpen(true)
45
+ inputRef.current?.open()
52
46
  },
53
47
  blur: () => {
54
- onBlur()
55
- // setIsOpen(false)
48
+ inputRef.current?.close()
56
49
  },
57
50
  }))
58
51
 
59
- const handleButtonLayout = () => {
60
- buttonRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
61
- setButtonLayout({ x: pageX, y: pageY, width, height })
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({ ...props, value: props.value ?? '' })
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 typeof option === 'object' ? JSON.stringify(option) : String(option)
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
- <View ref={buttonRef} onLayout={handleButtonLayout} style={styles.container}>
97
- <TouchableOpacity
98
- style={[styles.button, inputStyles.input]}
99
- onPress={() => {
100
- if (active) {
101
- onBlur()
102
- } else {
103
- onFocus()
104
- }
105
- }}>
106
- <View style={styles.buttonTextContainer}>
107
- {selected ? (
108
- <RenderOptionText value={selected} colorMode="light" isSelected={true} />
109
- ) : (
110
- <Text style={[styles.placeholder, { color: placeholderColor }]}>{placeholder}</Text>
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
- <Ionicons
114
- name={active ? 'chevron-up' : 'chevron-down'}
115
- size={20}
116
- color={iconColor}
117
- style={styles.icon}
118
- />
119
- {optional && value ? (
120
- <InputClearButton onPress={() => onChange(null)} isActive={!!value} />
121
- ) : null}
122
- </TouchableOpacity>
123
- </View>
124
- <Modal visible={active} transparent animationType="fade" onRequestClose={() => onBlur()}>
125
- <TouchableOpacity style={styles.modalOverlay} activeOpacity={1} onPress={() => onBlur()}>
126
- <View
127
- style={[
128
- styles.dropdownContainer,
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
- </TouchableOpacity>
160
- </Modal>
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
- container: {
172
- width: '100%',
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
- modalOverlay: {
188
- flex: 1,
189
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
134
+ iconStyle: {
135
+ width: 20,
136
+ height: 20,
190
137
  },
191
- dropdownContainer: {
192
- backgroundColor: 'white',
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 { inputStyles } from '../styles'
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
- <TextInput
26
- ref={inputRef}
27
- style={[styles.textarea, inEditable && styles.inEditable, { color }]}
28
- placeholder={field.placeholder}
29
- placeholderTextColor={placeholderColor}
30
- multiline
31
- maxLength={200}
32
- textAlignVertical="top"
33
- value={value ?? ''}
34
- onChangeText={onChange}
35
- {...inputProps}
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 { inputStyles } from '../styles'
11
+ import { useInputStyles } from '../hooks/useInputStyles'
12
12
 
13
13
  export const TimeInput = forwardRef<InputRef, FieldProps<TimeField>>(
14
- ({ input: { onChange, value, onFocus, onBlur }, field: { placeholder, optional } }, ref) => {
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.input]}
75
+ style={[styles.button, inputStyles]}
61
76
  onPress={() => {
62
77
  setVisible(true)
63
78
  onFocus()
64
79
  }}>
65
- <Text style={[styles.text, { color: inputColor }]}>{formattedValue ?? placeholder}</Text>
66
- <Ionicons name="time" size={20} color={iconColor} style={styles.icon} />
67
- {optional && value ? (
68
- <DateInputClearButton onPress={() => onChange(null)} isActive={!!value} />
69
- ) : null}
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: 150,
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 { formatField } from '@chem-po/core'
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 = formatField[field._type]
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={styles.label}>{placeholder}</Txt>}
52
- <Txt style={value ? styles.value : styles.valueEmpty}>{formatted ?? 'None'}</Txt>
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 <SelectFieldView style={style} field={field} value={value} noLabel={noLabel} />
70
+ return (
71
+ <SelectFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
72
+ )
71
73
  case 'multipleSelect':
72
- return <MultipleSelectFieldView style={style} field={field} value={value} noLabel={noLabel} />
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 <FileFieldView style={style} field={field} value={value} noLabel={noLabel} />
84
+ return (
85
+ <FileFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
86
+ )
75
87
  default:
76
- return <DefaultFieldView style={style} field={field} value={value} noLabel={noLabel} />
88
+ return (
89
+ <DefaultFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
90
+ )
77
91
  }
78
92
  }