@chem-po/react-native 0.0.15 → 0.0.17

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 (171) hide show
  1. package/lib/commonjs/components/button/DeleteButton.js +1 -1
  2. package/lib/commonjs/components/button/DeleteButton.js.map +1 -1
  3. package/lib/commonjs/components/button/LoadingButton.js +2 -1
  4. package/lib/commonjs/components/button/LoadingButton.js.map +1 -1
  5. package/lib/commonjs/components/feed/MediaFeed.js +1 -1
  6. package/lib/commonjs/components/feed/MediaFeed.js.map +1 -1
  7. package/lib/commonjs/components/form/Field.js +4 -2
  8. package/lib/commonjs/components/form/Field.js.map +1 -1
  9. package/lib/commonjs/components/form/Form.js +20 -7
  10. package/lib/commonjs/components/form/Form.js.map +1 -1
  11. package/lib/commonjs/components/form/input/Editable.js +24 -7
  12. package/lib/commonjs/components/form/input/Editable.js.map +1 -1
  13. package/lib/commonjs/components/form/input/common/InputClearButton.js +10 -5
  14. package/lib/commonjs/components/form/input/common/InputClearButton.js.map +1 -1
  15. package/lib/commonjs/components/form/input/date/index.js +23 -15
  16. package/lib/commonjs/components/form/input/date/index.js.map +1 -1
  17. package/lib/commonjs/components/form/input/datetime/index.js +22 -18
  18. package/lib/commonjs/components/form/input/datetime/index.js.map +1 -1
  19. package/lib/commonjs/components/form/input/hooks/index.js +4 -4
  20. package/lib/commonjs/components/form/input/hooks/index.js.map +1 -1
  21. package/lib/commonjs/components/form/input/hooks/useInputStyles.js +111 -0
  22. package/lib/commonjs/components/form/input/hooks/useInputStyles.js.map +1 -0
  23. package/lib/commonjs/components/form/input/input.js +46 -11
  24. package/lib/commonjs/components/form/input/input.js.map +1 -1
  25. package/lib/commonjs/components/form/input/multipleSelect/index.js +162 -44
  26. package/lib/commonjs/components/form/input/multipleSelect/index.js.map +1 -1
  27. package/lib/commonjs/components/form/input/number/index.js +10 -5
  28. package/lib/commonjs/components/form/input/number/index.js.map +1 -1
  29. package/lib/commonjs/components/form/input/select/index.js +86 -173
  30. package/lib/commonjs/components/form/input/select/index.js.map +1 -1
  31. package/lib/commonjs/components/form/input/text/index.js +7 -5
  32. package/lib/commonjs/components/form/input/text/index.js.map +1 -1
  33. package/lib/commonjs/components/form/input/text/textarea.js +10 -5
  34. package/lib/commonjs/components/form/input/text/textarea.js.map +1 -1
  35. package/lib/commonjs/components/form/input/time/index.js +22 -13
  36. package/lib/commonjs/components/form/input/time/index.js.map +1 -1
  37. package/lib/commonjs/components/form/view/file.js +18 -4
  38. package/lib/commonjs/components/form/view/file.js.map +1 -1
  39. package/lib/commonjs/components/form/view/index.js +24 -23
  40. package/lib/commonjs/components/form/view/index.js.map +1 -1
  41. package/lib/commonjs/components/form/view/multipleSelect.js +38 -10
  42. package/lib/commonjs/components/form/view/multipleSelect.js.map +1 -1
  43. package/lib/commonjs/components/form/view/select.js +24 -9
  44. package/lib/commonjs/components/form/view/select.js.map +1 -1
  45. package/lib/commonjs/components/form/view/styles.js +21 -0
  46. package/lib/commonjs/components/form/view/styles.js.map +1 -0
  47. package/lib/commonjs/contexts/root.js +0 -6
  48. package/lib/commonjs/contexts/root.js.map +1 -1
  49. package/lib/module/components/button/DeleteButton.js +1 -1
  50. package/lib/module/components/button/DeleteButton.js.map +1 -1
  51. package/lib/module/components/button/LoadingButton.js +2 -1
  52. package/lib/module/components/button/LoadingButton.js.map +1 -1
  53. package/lib/module/components/feed/MediaFeed.js +1 -1
  54. package/lib/module/components/feed/MediaFeed.js.map +1 -1
  55. package/lib/module/components/form/Field.js +4 -2
  56. package/lib/module/components/form/Field.js.map +1 -1
  57. package/lib/module/components/form/Form.js +20 -7
  58. package/lib/module/components/form/Form.js.map +1 -1
  59. package/lib/module/components/form/input/Editable.js +24 -7
  60. package/lib/module/components/form/input/Editable.js.map +1 -1
  61. package/lib/module/components/form/input/common/InputClearButton.js +11 -6
  62. package/lib/module/components/form/input/common/InputClearButton.js.map +1 -1
  63. package/lib/module/components/form/input/date/index.js +23 -15
  64. package/lib/module/components/form/input/date/index.js.map +1 -1
  65. package/lib/module/components/form/input/datetime/index.js +22 -18
  66. package/lib/module/components/form/input/datetime/index.js.map +1 -1
  67. package/lib/module/components/form/input/hooks/index.js +1 -1
  68. package/lib/module/components/form/input/hooks/index.js.map +1 -1
  69. package/lib/module/components/form/input/hooks/useInputStyles.js +104 -0
  70. package/lib/module/components/form/input/hooks/useInputStyles.js.map +1 -0
  71. package/lib/module/components/form/input/input.js +48 -13
  72. package/lib/module/components/form/input/input.js.map +1 -1
  73. package/lib/module/components/form/input/multipleSelect/index.js +163 -46
  74. package/lib/module/components/form/input/multipleSelect/index.js.map +1 -1
  75. package/lib/module/components/form/input/number/index.js +10 -5
  76. package/lib/module/components/form/input/number/index.js.map +1 -1
  77. package/lib/module/components/form/input/select/index.js +88 -175
  78. package/lib/module/components/form/input/select/index.js.map +1 -1
  79. package/lib/module/components/form/input/text/index.js +7 -5
  80. package/lib/module/components/form/input/text/index.js.map +1 -1
  81. package/lib/module/components/form/input/text/textarea.js +11 -6
  82. package/lib/module/components/form/input/text/textarea.js.map +1 -1
  83. package/lib/module/components/form/input/time/index.js +22 -13
  84. package/lib/module/components/form/input/time/index.js.map +1 -1
  85. package/lib/module/components/form/view/file.js +18 -4
  86. package/lib/module/components/form/view/file.js.map +1 -1
  87. package/lib/module/components/form/view/index.js +25 -24
  88. package/lib/module/components/form/view/index.js.map +1 -1
  89. package/lib/module/components/form/view/multipleSelect.js +38 -10
  90. package/lib/module/components/form/view/multipleSelect.js.map +1 -1
  91. package/lib/module/components/form/view/select.js +23 -9
  92. package/lib/module/components/form/view/select.js.map +1 -1
  93. package/lib/module/components/form/view/styles.js +15 -0
  94. package/lib/module/components/form/view/styles.js.map +1 -0
  95. package/lib/module/contexts/root.js +0 -6
  96. package/lib/module/contexts/root.js.map +1 -1
  97. package/lib/typescript/components/button/LoadingButton.d.ts +1 -0
  98. package/lib/typescript/components/button/LoadingButton.d.ts.map +1 -1
  99. package/lib/typescript/components/form/Field.d.ts +2 -1
  100. package/lib/typescript/components/form/Field.d.ts.map +1 -1
  101. package/lib/typescript/components/form/Form.d.ts +7 -4
  102. package/lib/typescript/components/form/Form.d.ts.map +1 -1
  103. package/lib/typescript/components/form/input/Editable.d.ts +1 -1
  104. package/lib/typescript/components/form/input/Editable.d.ts.map +1 -1
  105. package/lib/typescript/components/form/input/common/InputClearButton.d.ts +4 -2
  106. package/lib/typescript/components/form/input/common/InputClearButton.d.ts.map +1 -1
  107. package/lib/typescript/components/form/input/date/index.d.ts.map +1 -1
  108. package/lib/typescript/components/form/input/datetime/index.d.ts.map +1 -1
  109. package/lib/typescript/components/form/input/hooks/index.d.ts +1 -1
  110. package/lib/typescript/components/form/input/hooks/index.d.ts.map +1 -1
  111. package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts +61 -0
  112. package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts.map +1 -0
  113. package/lib/typescript/components/form/input/input.d.ts.map +1 -1
  114. package/lib/typescript/components/form/input/multipleSelect/index.d.ts +6 -1
  115. package/lib/typescript/components/form/input/multipleSelect/index.d.ts.map +1 -1
  116. package/lib/typescript/components/form/input/number/index.d.ts.map +1 -1
  117. package/lib/typescript/components/form/input/select/index.d.ts.map +1 -1
  118. package/lib/typescript/components/form/input/text/index.d.ts.map +1 -1
  119. package/lib/typescript/components/form/input/text/textarea.d.ts.map +1 -1
  120. package/lib/typescript/components/form/input/time/index.d.ts.map +1 -1
  121. package/lib/typescript/components/form/view/file.d.ts +3 -1
  122. package/lib/typescript/components/form/view/file.d.ts.map +1 -1
  123. package/lib/typescript/components/form/view/index.d.ts +3 -1
  124. package/lib/typescript/components/form/view/index.d.ts.map +1 -1
  125. package/lib/typescript/components/form/view/multipleSelect.d.ts +5 -3
  126. package/lib/typescript/components/form/view/multipleSelect.d.ts.map +1 -1
  127. package/lib/typescript/components/form/view/select.d.ts +4 -1
  128. package/lib/typescript/components/form/view/select.d.ts.map +1 -1
  129. package/lib/typescript/components/form/view/styles.d.ts +14 -0
  130. package/lib/typescript/components/form/view/styles.d.ts.map +1 -0
  131. package/lib/typescript/contexts/root.d.ts +2 -2
  132. package/lib/typescript/contexts/root.d.ts.map +1 -1
  133. package/package.json +16 -27
  134. package/src/components/button/DeleteButton.tsx +1 -1
  135. package/src/components/button/LoadingButton.tsx +4 -1
  136. package/src/components/feed/MediaFeed.tsx +1 -1
  137. package/src/components/form/Field.tsx +3 -2
  138. package/src/components/form/Form.tsx +41 -11
  139. package/src/components/form/input/Editable.tsx +23 -6
  140. package/src/components/form/input/common/InputClearButton.tsx +12 -4
  141. package/src/components/form/input/date/index.tsx +23 -12
  142. package/src/components/form/input/datetime/index.tsx +27 -14
  143. package/src/components/form/input/hooks/index.ts +1 -1
  144. package/src/components/form/input/hooks/useInputStyles.ts +124 -0
  145. package/src/components/form/input/input.tsx +54 -25
  146. package/src/components/form/input/multipleSelect/index.tsx +189 -60
  147. package/src/components/form/input/number/index.tsx +5 -4
  148. package/src/components/form/input/select/index.tsx +90 -166
  149. package/src/components/form/input/text/index.tsx +4 -9
  150. package/src/components/form/input/text/textarea.tsx +18 -16
  151. package/src/components/form/input/time/index.tsx +31 -11
  152. package/src/components/form/view/file.tsx +19 -4
  153. package/src/components/form/view/index.tsx +36 -22
  154. package/src/components/form/view/multipleSelect.tsx +42 -15
  155. package/src/components/form/view/select.tsx +28 -11
  156. package/src/components/form/view/styles.ts +15 -0
  157. package/src/contexts/root.tsx +6 -13
  158. package/lib/commonjs/components/form/input/hooks/useInputStyle.js +0 -50
  159. package/lib/commonjs/components/form/input/hooks/useInputStyle.js.map +0 -1
  160. package/lib/commonjs/components/form/input/styles.js +0 -17
  161. package/lib/commonjs/components/form/input/styles.js.map +0 -1
  162. package/lib/module/components/form/input/hooks/useInputStyle.js +0 -43
  163. package/lib/module/components/form/input/hooks/useInputStyle.js.map +0 -1
  164. package/lib/module/components/form/input/styles.js +0 -11
  165. package/lib/module/components/form/input/styles.js.map +0 -1
  166. package/lib/typescript/components/form/input/hooks/useInputStyle.d.ts +0 -9
  167. package/lib/typescript/components/form/input/hooks/useInputStyle.d.ts.map +0 -1
  168. package/lib/typescript/components/form/input/styles.d.ts +0 -10
  169. package/lib/typescript/components/form/input/styles.d.ts.map +0 -1
  170. package/src/components/form/input/hooks/useInputStyle.ts +0 -40
  171. package/src/components/form/input/styles.ts +0 -11
@@ -5,12 +5,13 @@ 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 { inputStyles } from '../styles'
8
+ import { useInputStyles } from '../hooks/useInputStyles'
9
9
 
10
10
  export const NumberComponent = forwardRef<InputRef, FieldProps<NumberField> & { prefix?: string }>(
11
- ({ input: { onChange, value, ...input }, field, prefix, inEditable: _, style }, ref) => {
12
- const { type, defaultValue, placeholder } = field
11
+ ({ input: { onChange, value, ...input }, field, prefix, inEditable, style, formSize }, ref) => {
12
+ const { type, defaultValue, placeholder, size } = field
13
13
  const color = useTextColor()
14
+ const { container: inputStyles } = useInputStyles(inEditable, size, formSize)
14
15
  const inputRef = useInputImperativeHandle(ref)
15
16
  const [endsWith, setEndsWith] = useState('')
16
17
  const displayed = typeof value === 'number' && !Number.isNaN(value) ? `${value}${endsWith}` : ''
@@ -33,7 +34,7 @@ export const NumberComponent = forwardRef<InputRef, FieldProps<NumberField> & {
33
34
  {prefix && <Text style={styles.prefix}>{prefix}</Text>}
34
35
  <TextInput
35
36
  ref={inputRef}
36
- style={[inputStyles.input, { color }, style]}
37
+ style={[inputStyles, { color }, style]}
37
38
  placeholder={field.placeholder}
38
39
  placeholderTextColor={placeholderColor}
39
40
  keyboardType="numeric"
@@ -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,63 @@ 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
+ onFocus={onFocus}
86
+ onBlur={onBlur}
87
+ onChange={item => {
88
+ onChange(item.value)
89
+ }}
90
+ activeColor={selectedOptionBg}
91
+ // onFocus={onFocus}
92
+ // onBlur={onBlur}
93
+ renderItem={(item, selected) => (
94
+ <View style={{ backgroundColor: selected ? selectedOptionBg : menuBg }}>
95
+ <RenderOptionText
96
+ value={item.value}
97
+ option={item}
98
+ colorMode="light"
99
+ isSelected={!!selected}
100
+ size={size}
101
+ />
112
102
  </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>
103
+ )}
104
+ renderRightIcon={() => (
105
+ <View style={buttonContainer}>
106
+ <Ionicons
107
+ name={active ? 'chevron-up' : 'chevron-down'}
108
+ size={iconSize}
109
+ color={iconColor}
110
+ />
111
+ {optional && value ? (
112
+ <InputClearButton
113
+ size={clearButtonSize}
114
+ onPress={() => {
115
+ onChange(null)
116
+ }}
117
+ isActive={!!value}
118
+ />
119
+ ) : null}
158
120
  </View>
159
- </TouchableOpacity>
160
- </Modal>
121
+ )}
122
+ />
161
123
  </View>
162
124
  )
163
125
  }
@@ -168,54 +130,16 @@ const styles = StyleSheet.create({
168
130
  wrapper: {
169
131
  width: '100%',
170
132
  },
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,
133
+ defaultOption: {
134
+ padding: 10,
186
135
  },
187
- modalOverlay: {
188
- flex: 1,
189
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
136
+ iconStyle: {
137
+ width: 20,
138
+ height: 20,
190
139
  },
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: {
140
+ inputSearch: {
141
+ height: 40,
213
142
  fontSize: 16,
214
- },
215
- placeholder: {
216
- color: '#666',
217
- },
218
- icon: {
219
- marginRight: 10,
143
+ outlineWidth: 0,
220
144
  },
221
145
  })
@@ -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
  }