@chem-po/react-native 0.0.42 → 0.0.44

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 (55) hide show
  1. package/lib/commonjs/components/form/input/Editable.js +12 -14
  2. package/lib/commonjs/components/form/input/Editable.js.map +1 -1
  3. package/lib/commonjs/components/form/input/file/index.js +3 -2
  4. package/lib/commonjs/components/form/input/file/index.js.map +1 -1
  5. package/lib/commonjs/components/form/input/multipleSelect/index.js +7 -11
  6. package/lib/commonjs/components/form/input/multipleSelect/index.js.map +1 -1
  7. package/lib/commonjs/components/form/input/select/index.js +3 -6
  8. package/lib/commonjs/components/form/input/select/index.js.map +1 -1
  9. package/lib/commonjs/components/form/view/file.js +4 -2
  10. package/lib/commonjs/components/form/view/file.js.map +1 -1
  11. package/lib/commonjs/components/form/view/index.js +9 -3
  12. package/lib/commonjs/components/form/view/index.js.map +1 -1
  13. package/lib/commonjs/components/form/view/multipleSelect.js +7 -9
  14. package/lib/commonjs/components/form/view/multipleSelect.js.map +1 -1
  15. package/lib/commonjs/components/form/view/select.js +14 -11
  16. package/lib/commonjs/components/form/view/select.js.map +1 -1
  17. package/lib/module/components/form/input/Editable.js +12 -14
  18. package/lib/module/components/form/input/Editable.js.map +1 -1
  19. package/lib/module/components/form/input/file/index.js +3 -2
  20. package/lib/module/components/form/input/file/index.js.map +1 -1
  21. package/lib/module/components/form/input/multipleSelect/index.js +8 -12
  22. package/lib/module/components/form/input/multipleSelect/index.js.map +1 -1
  23. package/lib/module/components/form/input/select/index.js +4 -7
  24. package/lib/module/components/form/input/select/index.js.map +1 -1
  25. package/lib/module/components/form/view/file.js +4 -2
  26. package/lib/module/components/form/view/file.js.map +1 -1
  27. package/lib/module/components/form/view/index.js +9 -3
  28. package/lib/module/components/form/view/index.js.map +1 -1
  29. package/lib/module/components/form/view/multipleSelect.js +7 -9
  30. package/lib/module/components/form/view/multipleSelect.js.map +1 -1
  31. package/lib/module/components/form/view/select.js +13 -10
  32. package/lib/module/components/form/view/select.js.map +1 -1
  33. package/lib/typescript/components/form/input/Editable.d.ts +1 -1
  34. package/lib/typescript/components/form/input/Editable.d.ts.map +1 -1
  35. package/lib/typescript/components/form/input/file/index.d.ts +3 -2
  36. package/lib/typescript/components/form/input/file/index.d.ts.map +1 -1
  37. package/lib/typescript/components/form/input/multipleSelect/index.d.ts.map +1 -1
  38. package/lib/typescript/components/form/input/select/index.d.ts.map +1 -1
  39. package/lib/typescript/components/form/view/file.d.ts +3 -2
  40. package/lib/typescript/components/form/view/file.d.ts.map +1 -1
  41. package/lib/typescript/components/form/view/index.d.ts +3 -2
  42. package/lib/typescript/components/form/view/index.d.ts.map +1 -1
  43. package/lib/typescript/components/form/view/multipleSelect.d.ts +6 -3
  44. package/lib/typescript/components/form/view/multipleSelect.d.ts.map +1 -1
  45. package/lib/typescript/components/form/view/select.d.ts +10 -6
  46. package/lib/typescript/components/form/view/select.d.ts.map +1 -1
  47. package/package.json +3 -3
  48. package/src/components/form/input/Editable.tsx +28 -25
  49. package/src/components/form/input/file/index.tsx +4 -2
  50. package/src/components/form/input/multipleSelect/index.tsx +5 -6
  51. package/src/components/form/input/select/index.tsx +7 -12
  52. package/src/components/form/view/file.tsx +5 -3
  53. package/src/components/form/view/index.tsx +17 -3
  54. package/src/components/form/view/multipleSelect.tsx +13 -11
  55. package/src/components/form/view/select.tsx +24 -16
@@ -1,7 +1,7 @@
1
1
  import { displayField, InputSize } from '@chem-po/core'
2
2
  import { Field, FormatField, usePlaceholderColor } from '@chem-po/react'
3
3
  import React, { useMemo } from 'react'
4
- import { StyleSheet, View, ViewStyle } from 'react-native'
4
+ import { StyleProp, StyleSheet, TextStyle, View, ViewStyle } from 'react-native'
5
5
  import { Txt } from '../../text'
6
6
  import { useInputStyles } from '../input/hooks/useInputStyles'
7
7
  import { FileFieldView } from './file'
@@ -23,11 +23,13 @@ const DefaultFieldView = ({
23
23
  style,
24
24
  size: sizeProp,
25
25
  inEditable,
26
+ textStyle,
26
27
  }: {
27
28
  field: Field
28
29
  value: any
29
30
  noLabel?: boolean
30
31
  style?: ViewStyle
32
+ textStyle?: StyleProp<TextStyle>
31
33
  size?: InputSize
32
34
  inEditable?: boolean
33
35
  }) => {
@@ -48,7 +50,7 @@ const DefaultFieldView = ({
48
50
  return (
49
51
  <View style={[styles.container, containerStyles, { backgroundColor: 'transparent' }, style]}>
50
52
  {!noLabel && <Txt style={[inputViewStyles.label, text]}>{placeholder}</Txt>}
51
- <Txt style={[text, { color: hasValue ? undefined : placeholderColor }]}>
53
+ <Txt style={[text, { color: hasValue ? text.color : placeholderColor }, textStyle]}>
52
54
  {hasValue ? formatted : 'None'}
53
55
  </Txt>
54
56
  </View>
@@ -60,6 +62,7 @@ export const FieldView = ({
60
62
  value,
61
63
  noLabel,
62
64
  style,
65
+ textStyle,
63
66
  size,
64
67
  inEditable,
65
68
  }: {
@@ -67,6 +70,7 @@ export const FieldView = ({
67
70
  value?: any
68
71
  noLabel?: boolean
69
72
  style?: ViewStyle
73
+ textStyle?: StyleProp<TextStyle>
70
74
  size?: InputSize
71
75
  inEditable?: boolean
72
76
  }) => {
@@ -75,6 +79,7 @@ export const FieldView = ({
75
79
  return (
76
80
  <SelectFieldView
77
81
  style={style}
82
+ textStyle={textStyle}
78
83
  field={field}
79
84
  value={value}
80
85
  noLabel={noLabel}
@@ -88,13 +93,21 @@ export const FieldView = ({
88
93
  style={style}
89
94
  field={field}
90
95
  value={value}
96
+ textStyle={textStyle}
91
97
  noLabel={noLabel}
92
98
  size={size}
93
99
  />
94
100
  )
95
101
  case 'file':
96
102
  return (
97
- <FileFieldView style={style} field={field} value={value} noLabel={noLabel} size={size} />
103
+ <FileFieldView
104
+ textStyle={textStyle}
105
+ style={style}
106
+ field={field}
107
+ value={value}
108
+ noLabel={noLabel}
109
+ size={size}
110
+ />
98
111
  )
99
112
  default:
100
113
  return (
@@ -102,6 +115,7 @@ export const FieldView = ({
102
115
  style={style}
103
116
  field={field}
104
117
  value={value}
118
+ textStyle={textStyle}
105
119
  noLabel={noLabel}
106
120
  size={size}
107
121
  inEditable={inEditable}
@@ -1,7 +1,7 @@
1
- import { InputSize } from '@chem-po/core'
1
+ import { BaseSelectOption, InputSize } from '@chem-po/core'
2
2
  import { MultipleSelectField, useColorMode, usePlaceholderColor } from '@chem-po/react'
3
3
  import { useMemo } from 'react'
4
- import React, { StyleSheet, Text, View, ViewStyle } from 'react-native'
4
+ import React, { StyleProp, StyleSheet, Text, TextStyle, View, ViewStyle } from 'react-native'
5
5
  import { Txt } from '../../text/Txt'
6
6
  import { useInputStyles } from '../input/hooks/useInputStyles'
7
7
  import { SelectedOptionContainer } from '../input/multipleSelect'
@@ -31,16 +31,23 @@ const styles = StyleSheet.create({
31
31
  },
32
32
  })
33
33
 
34
- export const MultipleSelectFieldView = <F extends MultipleSelectField>({
34
+ type NativeMultipleSelectField<
35
+ Value extends any[] = string[],
36
+ Option extends BaseSelectOption<Value[number]> = BaseSelectOption<Value[number]>,
37
+ > = MultipleSelectField<Value, Option>
38
+
39
+ export const MultipleSelectFieldView = <F extends NativeMultipleSelectField>({
35
40
  field,
36
41
  value,
37
42
  noLabel,
38
43
  size: sizeProp,
39
44
  style,
45
+ textStyle,
40
46
  }: {
41
47
  field: F
42
48
  value?: F['defaultValue']
43
49
  noLabel?: boolean
50
+ textStyle?: StyleProp<TextStyle>
44
51
  size?: InputSize
45
52
  style?: ViewStyle
46
53
  }) => {
@@ -49,12 +56,6 @@ export const MultipleSelectFieldView = <F extends MultipleSelectField>({
49
56
  const colorMode = useColorMode()
50
57
  const { size, text, container } = useInputStyles(true, field.size, sizeProp)
51
58
  const placeholderColor = usePlaceholderColor()
52
- const selectedOptionStyle = useMemo<ViewStyle>(() => {
53
- return {
54
- paddingHorizontal: container.paddingHorizontal,
55
- paddingVertical: container.paddingVertical,
56
- }
57
- }, [container])
58
59
  const RenderOption = useMemo(() => customRender ?? DefaultRenderOption, [customRender])
59
60
  return (
60
61
  <View style={[styles.container, style]}>
@@ -62,10 +63,11 @@ export const MultipleSelectFieldView = <F extends MultipleSelectField>({
62
63
  {value?.length ? (
63
64
  <View style={styles.optionsContainer}>
64
65
  {selectedOptions.map(o => (
65
- <SelectedOptionContainer key={o.value} style={selectedOptionStyle}>
66
+ <SelectedOptionContainer key={o.value} style={[container, { width: 'auto' }]}>
66
67
  <RenderOption
67
68
  option={o}
68
69
  value={o.value}
70
+ textStyle={[text, textStyle]}
69
71
  colorMode={colorMode}
70
72
  isSelected
71
73
  size={size}
@@ -75,7 +77,7 @@ export const MultipleSelectFieldView = <F extends MultipleSelectField>({
75
77
  </View>
76
78
  ) : (
77
79
  <View style={container}>
78
- <Txt style={[text, { color: placeholderColor }]}>None</Txt>
80
+ <Txt style={[text, { color: placeholderColor }, textStyle]}>None</Txt>
79
81
  </View>
80
82
  )}
81
83
  </View>
@@ -1,7 +1,7 @@
1
- import { BaseSelectOption, InputSize, RenderSelectOptionProps } from '@chem-po/core'
1
+ import { InputSize, RenderSelectOptionProps } from '@chem-po/core'
2
2
  import { SelectField, useColorMode, usePlaceholderColor } from '@chem-po/react'
3
- import React from 'react'
4
- import { StyleSheet, Text, View, ViewStyle } from 'react-native'
3
+ import React, { useMemo } from 'react'
4
+ import { StyleProp, StyleSheet, Text, TextStyle, View, ViewStyle } from 'react-native'
5
5
  import { Txt } from '../../text'
6
6
  import { useInputStyles } from '../input/hooks/useInputStyles'
7
7
  import { inputViewStyles } from './styles'
@@ -18,31 +18,35 @@ const styles = StyleSheet.create({
18
18
  },
19
19
  })
20
20
 
21
- export const DefaultRenderOption = <
22
- Value = string,
23
- Option extends BaseSelectOption<Value> = BaseSelectOption<Value>,
24
- >({
21
+ export const DefaultRenderOption = ({
25
22
  option,
26
- }: RenderSelectOptionProps<Value, Option>) => {
23
+ containerStyle,
24
+ textStyle,
25
+ }: RenderSelectOptionProps & {
26
+ containerStyle?: StyleProp<ViewStyle>
27
+ textStyle?: StyleProp<TextStyle>
28
+ }) => {
27
29
  return (
28
- <View style={{ padding: 6 }}>
29
- <Txt style={inputViewStyles.value}>{option.label}</Txt>
30
+ <View style={containerStyle}>
31
+ <Txt style={[inputViewStyles.value, textStyle]}>{option.label}</Txt>
30
32
  </View>
31
33
  )
32
34
  }
33
35
 
34
- export const SelectFieldView = ({
36
+ export const SelectFieldView = <F extends SelectField>({
35
37
  field,
36
38
  value,
37
39
  noLabel,
38
40
  style,
39
41
  size: sizeProp,
40
42
  inEditable,
43
+ textStyle,
41
44
  }: {
42
- field: SelectField
43
- value: any
45
+ field: F
46
+ value: F['defaultValue']
44
47
  noLabel?: boolean
45
48
  style?: ViewStyle
49
+ textStyle?: StyleProp<TextStyle>
46
50
  size?: InputSize
47
51
  inEditable?: boolean
48
52
  }) => {
@@ -51,23 +55,27 @@ export const SelectFieldView = ({
51
55
  const placeholderColor = usePlaceholderColor()
52
56
  const { size, text, container } = useInputStyles(inEditable, field.size, sizeProp)
53
57
  const selectedOption = field.options.find(o => o.value === value)
54
- const RenderOption = customRender ?? DefaultRenderOption
58
+ const RenderOption = useMemo(() => customRender ?? DefaultRenderOption, [customRender])
55
59
  return (
56
60
  <View style={[styles.container, style]}>
57
61
  {!noLabel && (
58
- <Text style={[styles.label, text, { color: placeholderColor }]}>{placeholder}</Text>
62
+ <Text style={[styles.label, text, { color: placeholderColor }, textStyle]}>
63
+ {placeholder}
64
+ </Text>
59
65
  )}
60
66
  {selectedOption ? (
61
67
  <RenderOption
62
68
  value={selectedOption.value}
63
69
  option={selectedOption}
70
+ containerStyle={container}
71
+ textStyle={[text, textStyle]}
64
72
  colorMode={colorMode}
65
73
  isSelected={true}
66
74
  size={size}
67
75
  />
68
76
  ) : (
69
77
  <View style={container}>
70
- <Txt style={[text, { color: placeholderColor }]}>None</Txt>
78
+ <Txt style={[text, { color: placeholderColor }, textStyle]}>None</Txt>
71
79
  </View>
72
80
  )}
73
81
  </View>