@chem-po/react-native 0.0.52 → 0.0.53
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/package.json +5 -20
- package/src/components/box/Center.tsx +0 -19
- package/src/components/box/CollapseHorizontal.tsx +0 -44
- package/src/components/box/ContentBox.tsx +0 -24
- package/src/components/box/DropShadow.tsx +0 -28
- package/src/components/box/ExpandOnMount.tsx +0 -74
- package/src/components/box/Expandable.tsx +0 -143
- package/src/components/box/FullSizeContainer.tsx +0 -64
- package/src/components/box/index.ts +0 -7
- package/src/components/button/ActionButton.tsx +0 -196
- package/src/components/button/ButtonText.tsx +0 -60
- package/src/components/button/DeleteButton.tsx +0 -288
- package/src/components/button/LoadingButton.tsx +0 -41
- package/src/components/button/Toggle.tsx +0 -109
- package/src/components/button/hooks.ts +0 -66
- package/src/components/button/index.ts +0 -5
- package/src/components/feed/FeedContentPane.tsx +0 -97
- package/src/components/feed/MediaFeed.tsx +0 -199
- package/src/components/feed/MediaFeedBackground.tsx +0 -136
- package/src/components/feed/MediaFeedRefresh.tsx +0 -113
- package/src/components/feed/constants.ts +0 -2
- package/src/components/feed/context.tsx +0 -19
- package/src/components/feed/hooks.ts +0 -279
- package/src/components/feed/index.ts +0 -2
- package/src/components/form/Condition.tsx +0 -27
- package/src/components/form/Field.tsx +0 -44
- package/src/components/form/Form.tsx +0 -452
- package/src/components/form/FormFooter.tsx +0 -164
- package/src/components/form/UploadProgress/index.tsx +0 -50
- package/src/components/form/index.ts +0 -3
- package/src/components/form/input/Editable.tsx +0 -206
- package/src/components/form/input/InputSlider.tsx +0 -71
- package/src/components/form/input/OptionalTag.tsx +0 -43
- package/src/components/form/input/StandaloneInput.tsx +0 -49
- package/src/components/form/input/boolean/index.tsx +0 -53
- package/src/components/form/input/color/index.tsx +0 -145
- package/src/components/form/input/common/InputClearButton.tsx +0 -57
- package/src/components/form/input/date/index.tsx +0 -125
- package/src/components/form/input/datetime/index.tsx +0 -176
- package/src/components/form/input/file/index.tsx +0 -310
- package/src/components/form/input/hooks/index.ts +0 -2
- package/src/components/form/input/hooks/useInputColor.ts +0 -7
- package/src/components/form/input/hooks/useInputImperativeHandle.ts +0 -22
- package/src/components/form/input/hooks/useInputStyles.ts +0 -114
- package/src/components/form/input/index.ts +0 -4
- package/src/components/form/input/input.tsx +0 -218
- package/src/components/form/input/multipleSelect/index.tsx +0 -221
- package/src/components/form/input/number/index.tsx +0 -108
- package/src/components/form/input/select/index.tsx +0 -152
- package/src/components/form/input/socialMedia/index.tsx +0 -235
- package/src/components/form/input/text/AutoResizeTextarea.tsx +0 -41
- package/src/components/form/input/text/index.tsx +0 -99
- package/src/components/form/input/text/textarea.tsx +0 -32
- package/src/components/form/input/text/useWebAutoResize.tsx +0 -73
- package/src/components/form/input/time/index.tsx +0 -125
- package/src/components/form/types.ts +0 -8
- package/src/components/form/view/file.tsx +0 -80
- package/src/components/form/view/index.tsx +0 -125
- package/src/components/form/view/multipleSelect.tsx +0 -85
- package/src/components/form/view/select.tsx +0 -83
- package/src/components/form/view/styles.ts +0 -12
- package/src/components/icons/index.tsx +0 -28
- package/src/components/image/ImageViewModal.tsx +0 -319
- package/src/components/image/index.ts +0 -1
- package/src/components/index.ts +0 -8
- package/src/components/layout/CollapseHorizontal.tsx +0 -92
- package/src/components/loading/CircularProgress.tsx +0 -56
- package/src/components/loading/Loading.tsx +0 -146
- package/src/components/loading/LoadingImage.tsx +0 -163
- package/src/components/loading/LoadingOverlay.tsx +0 -74
- package/src/components/loading/LoadingSwitch.tsx +0 -110
- package/src/components/loading/ProgressBar.tsx +0 -75
- package/src/components/loading/index.ts +0 -6
- package/src/components/text/AnimatedText.tsx +0 -68
- package/src/components/text/Txt.tsx +0 -12
- package/src/components/text/index.ts +0 -1
- package/src/components/theme/colorMode/DarkModeToggle.tsx +0 -47
- package/src/components/theme/colorMode/index.ts +0 -1
- package/src/components/theme/index.ts +0 -1
- package/src/constants/index.ts +0 -1
- package/src/constants/toast.ts +0 -24
- package/src/contexts/fonts.tsx +0 -23
- package/src/contexts/index.ts +0 -1
- package/src/contexts/root.tsx +0 -190
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useFadeIn.ts +0 -48
- package/src/hooks/useFont.ts +0 -25
- package/src/hooks/useRefreshFontScale.ts +0 -39
- package/src/hooks/useThemeState.ts +0 -43
- package/src/index.ts +0 -6
- package/src/store/index.ts +0 -2
- package/src/store/useFontScale.ts +0 -8
- package/src/store/useScreen.ts +0 -25
- package/src/styles/fill.ts +0 -19
- package/src/types/forms.ts +0 -14
- package/src/types/index.ts +0 -1
- package/src/utils/downloadFile.ts +0 -61
- package/src/utils/downloadFileLegacy.ts +0 -66
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { InputRef, RenderSelectOptionProps } from '@chem-po/core'
|
|
2
|
-
import {
|
|
3
|
-
SelectField,
|
|
4
|
-
useBackgroundColor,
|
|
5
|
-
useColorMode,
|
|
6
|
-
useIconColor,
|
|
7
|
-
usePlaceholderColor,
|
|
8
|
-
} from '@chem-po/react'
|
|
9
|
-
import { Ionicons } from '@expo/vector-icons'
|
|
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'
|
|
13
|
-
import { Txt } from '../../../text/Txt'
|
|
14
|
-
import { FieldProps } from '../../types'
|
|
15
|
-
import { InputClearButton } from '../common/InputClearButton'
|
|
16
|
-
import { useInputStyles } from '../hooks/useInputStyles'
|
|
17
|
-
|
|
18
|
-
const BaseSelectComponent = <T extends SelectField>(
|
|
19
|
-
{ field, input, meta, formSize, inEditable }: FieldProps<T>,
|
|
20
|
-
ref: ForwardedRef<InputRef>,
|
|
21
|
-
) => {
|
|
22
|
-
const {
|
|
23
|
-
placeholder,
|
|
24
|
-
options,
|
|
25
|
-
renderOption: RenderOption,
|
|
26
|
-
optional,
|
|
27
|
-
searchable,
|
|
28
|
-
searchPlaceholder,
|
|
29
|
-
} = field
|
|
30
|
-
const { onChange, value, onFocus, onBlur } = input
|
|
31
|
-
const { active } = meta
|
|
32
|
-
const colorMode = useColorMode()
|
|
33
|
-
|
|
34
|
-
const inputRef = useRef<IDropdownRef>(null)
|
|
35
|
-
const { container, iconSize, text, size, clearButtonSize, buttonContainer } = useInputStyles(
|
|
36
|
-
inEditable,
|
|
37
|
-
field.size,
|
|
38
|
-
formSize,
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
useImperativeHandle(ref, () => ({
|
|
42
|
-
focus: () => {
|
|
43
|
-
inputRef.current?.open()
|
|
44
|
-
},
|
|
45
|
-
blur: () => {
|
|
46
|
-
inputRef.current?.close()
|
|
47
|
-
},
|
|
48
|
-
}))
|
|
49
|
-
|
|
50
|
-
const RenderOptionText = (
|
|
51
|
-
props: RenderSelectOptionProps<T['options'][number]['value'], T['options'][number]>,
|
|
52
|
-
) => {
|
|
53
|
-
if (typeof RenderOption === 'function') {
|
|
54
|
-
return RenderOption(props)
|
|
55
|
-
}
|
|
56
|
-
return <Txt style={styles.defaultOption}>{props.option.label}</Txt>
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const iconColor = useIconColor()
|
|
60
|
-
const placeholderColor = usePlaceholderColor()
|
|
61
|
-
const menuBg = useBackgroundColor(100)
|
|
62
|
-
const selectedOptionBg = useBackgroundColor(50)
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<View style={styles.wrapper}>
|
|
66
|
-
<Dropdown
|
|
67
|
-
ref={inputRef}
|
|
68
|
-
style={container}
|
|
69
|
-
placeholderStyle={[text, { color: placeholderColor }]}
|
|
70
|
-
containerStyle={{
|
|
71
|
-
backgroundColor: menuBg,
|
|
72
|
-
borderWidth: 0,
|
|
73
|
-
borderColor: 'transparent',
|
|
74
|
-
boxShadow: `0 0 10px #00000066`,
|
|
75
|
-
}}
|
|
76
|
-
selectedTextStyle={text}
|
|
77
|
-
inputSearchStyle={[
|
|
78
|
-
styles.inputSearch,
|
|
79
|
-
text,
|
|
80
|
-
{ backgroundColor: selectedOptionBg, borderColor: 'transparent' },
|
|
81
|
-
]}
|
|
82
|
-
iconStyle={styles.iconStyle}
|
|
83
|
-
data={options}
|
|
84
|
-
search={searchable}
|
|
85
|
-
searchField={searchable ? 'label' : undefined}
|
|
86
|
-
maxHeight={300}
|
|
87
|
-
labelField="label"
|
|
88
|
-
valueField="value"
|
|
89
|
-
placeholder={placeholder}
|
|
90
|
-
searchPlaceholder={searchPlaceholder ?? placeholder}
|
|
91
|
-
value={value}
|
|
92
|
-
onFocus={onFocus}
|
|
93
|
-
onBlur={onBlur}
|
|
94
|
-
onChange={item => {
|
|
95
|
-
onChange(item.value)
|
|
96
|
-
}}
|
|
97
|
-
activeColor={selectedOptionBg}
|
|
98
|
-
// onFocus={onFocus}
|
|
99
|
-
// onBlur={onBlur}
|
|
100
|
-
renderItem={(item, selected) => (
|
|
101
|
-
<View style={{ backgroundColor: selected ? selectedOptionBg : menuBg }}>
|
|
102
|
-
<RenderOptionText
|
|
103
|
-
value={item.value}
|
|
104
|
-
option={item}
|
|
105
|
-
colorMode={colorMode}
|
|
106
|
-
isSelected={!!selected}
|
|
107
|
-
size={size}
|
|
108
|
-
/>
|
|
109
|
-
</View>
|
|
110
|
-
)}
|
|
111
|
-
renderRightIcon={() => (
|
|
112
|
-
<View style={buttonContainer}>
|
|
113
|
-
<Ionicons
|
|
114
|
-
name={active ? 'chevron-up' : 'chevron-down'}
|
|
115
|
-
size={iconSize}
|
|
116
|
-
color={iconColor}
|
|
117
|
-
/>
|
|
118
|
-
{optional && value ? (
|
|
119
|
-
<InputClearButton
|
|
120
|
-
size={clearButtonSize}
|
|
121
|
-
onPress={() => {
|
|
122
|
-
onChange(null)
|
|
123
|
-
}}
|
|
124
|
-
isActive
|
|
125
|
-
/>
|
|
126
|
-
) : null}
|
|
127
|
-
</View>
|
|
128
|
-
)}
|
|
129
|
-
/>
|
|
130
|
-
</View>
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export const SelectComponent = forwardRef(BaseSelectComponent)
|
|
135
|
-
|
|
136
|
-
const styles = StyleSheet.create({
|
|
137
|
-
wrapper: {
|
|
138
|
-
width: '100%',
|
|
139
|
-
},
|
|
140
|
-
defaultOption: {
|
|
141
|
-
padding: 10,
|
|
142
|
-
},
|
|
143
|
-
iconStyle: {
|
|
144
|
-
width: 20,
|
|
145
|
-
height: 20,
|
|
146
|
-
},
|
|
147
|
-
inputSearch: {
|
|
148
|
-
height: 40,
|
|
149
|
-
fontSize: 16,
|
|
150
|
-
outlineWidth: 0,
|
|
151
|
-
},
|
|
152
|
-
})
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { getHandle, InputRef, SocialMediaSites } from '@chem-po/core'
|
|
2
|
-
import { SocialMediaField } from '@chem-po/react'
|
|
3
|
-
import React, {
|
|
4
|
-
FC,
|
|
5
|
-
ForwardedRef,
|
|
6
|
-
forwardRef,
|
|
7
|
-
useCallback,
|
|
8
|
-
useImperativeHandle,
|
|
9
|
-
useMemo,
|
|
10
|
-
useState,
|
|
11
|
-
} from 'react'
|
|
12
|
-
import { Modal, StyleSheet, Text, TextInput, View } from 'react-native'
|
|
13
|
-
import { Pressable } from 'react-native-gesture-handler'
|
|
14
|
-
import { FieldProps } from '../../types'
|
|
15
|
-
const siteToIcon: Record<SocialMediaSites, string> = {
|
|
16
|
-
facebook: 'facebook',
|
|
17
|
-
instagram: 'instagram',
|
|
18
|
-
twitter: 'twitter',
|
|
19
|
-
youtube: 'youtube',
|
|
20
|
-
soundcloud: 'soundcloud',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const SocialMediaSiteInput: FC<{
|
|
24
|
-
site: SocialMediaSites
|
|
25
|
-
value?: string
|
|
26
|
-
onChange: (v?: string) => void
|
|
27
|
-
isModalVisible: boolean
|
|
28
|
-
onModalClose: () => void
|
|
29
|
-
}> = ({ site, value, onChange, isModalVisible, onModalClose }) => {
|
|
30
|
-
const { handle, error } = useMemo(() => {
|
|
31
|
-
try {
|
|
32
|
-
const h = getHandle(site, value)
|
|
33
|
-
return { handle: h }
|
|
34
|
-
} catch (e: any) {
|
|
35
|
-
return { error: e?.message ?? 'Error parsing handle' }
|
|
36
|
-
}
|
|
37
|
-
}, [value, site])
|
|
38
|
-
|
|
39
|
-
const displayedText = useMemo(
|
|
40
|
-
() => (handle ? `${site.toUpperCase()}: ${handle}` : site.toUpperCase()),
|
|
41
|
-
[site, handle],
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<>
|
|
46
|
-
<Pressable
|
|
47
|
-
style={[styles.iconButton, !handle && styles.iconButtonInactive]}
|
|
48
|
-
onPress={() => onModalClose()}>
|
|
49
|
-
<Text style={styles.iconText}>{siteToIcon[site]}</Text>
|
|
50
|
-
</Pressable>
|
|
51
|
-
|
|
52
|
-
<Modal
|
|
53
|
-
visible={isModalVisible}
|
|
54
|
-
transparent={true}
|
|
55
|
-
animationType="slide"
|
|
56
|
-
onRequestClose={onModalClose}>
|
|
57
|
-
<View style={styles.modalContainer}>
|
|
58
|
-
<View style={styles.modalContent}>
|
|
59
|
-
<Text style={styles.modalTitle}>{displayedText}</Text>
|
|
60
|
-
{error && <Text style={styles.errorText}>{error}</Text>}
|
|
61
|
-
<TextInput
|
|
62
|
-
style={styles.modalInput}
|
|
63
|
-
onChangeText={onChange}
|
|
64
|
-
placeholder="Handle or URL"
|
|
65
|
-
value={value}
|
|
66
|
-
autoCapitalize="none"
|
|
67
|
-
autoCorrect={false}
|
|
68
|
-
/>
|
|
69
|
-
<Pressable style={styles.closeButton} onPress={onModalClose}>
|
|
70
|
-
<Text style={styles.closeButtonText}>Close</Text>
|
|
71
|
-
</Pressable>
|
|
72
|
-
</View>
|
|
73
|
-
</View>
|
|
74
|
-
</Modal>
|
|
75
|
-
</>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const SocialMediaComponent = forwardRef<InputRef, FieldProps<SocialMediaField>>(
|
|
80
|
-
(props: FieldProps<SocialMediaField>, ref: ForwardedRef<InputRef>) => {
|
|
81
|
-
const {
|
|
82
|
-
input: { value, onChange },
|
|
83
|
-
field: { sites },
|
|
84
|
-
} = props
|
|
85
|
-
|
|
86
|
-
const [selectedSite, setSelectedSite] = useState<SocialMediaSites | null>(null)
|
|
87
|
-
|
|
88
|
-
const handleChange = useCallback(
|
|
89
|
-
(site: SocialMediaSites, v?: string) => {
|
|
90
|
-
const { [site]: _curr, ...rest } = value ?? {}
|
|
91
|
-
if (!v && Object.keys(rest).length === 0) {
|
|
92
|
-
onChange({ target: { value: undefined } })
|
|
93
|
-
}
|
|
94
|
-
if (!v) onChange(rest)
|
|
95
|
-
onChange({ ...rest, [site]: v })
|
|
96
|
-
},
|
|
97
|
-
[onChange, value],
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
useImperativeHandle(ref, () => ({
|
|
101
|
-
blur: () => {},
|
|
102
|
-
focus: () => {},
|
|
103
|
-
}))
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<View style={styles.container}>
|
|
107
|
-
<Text style={styles.title}>Links</Text>
|
|
108
|
-
<View style={styles.iconsContainer}>
|
|
109
|
-
{(!sites || sites.facebook) && (
|
|
110
|
-
<SocialMediaSiteInput
|
|
111
|
-
onChange={v => handleChange('facebook', v)}
|
|
112
|
-
site="facebook"
|
|
113
|
-
value={value?.facebook}
|
|
114
|
-
isModalVisible={selectedSite === 'facebook'}
|
|
115
|
-
onModalClose={() => setSelectedSite(null)}
|
|
116
|
-
/>
|
|
117
|
-
)}
|
|
118
|
-
{(!sites || sites.instagram) && (
|
|
119
|
-
<SocialMediaSiteInput
|
|
120
|
-
onChange={v => handleChange('instagram', v)}
|
|
121
|
-
site="instagram"
|
|
122
|
-
value={value?.instagram}
|
|
123
|
-
isModalVisible={selectedSite === 'instagram'}
|
|
124
|
-
onModalClose={() => setSelectedSite(null)}
|
|
125
|
-
/>
|
|
126
|
-
)}
|
|
127
|
-
{(!sites || sites.twitter) && (
|
|
128
|
-
<SocialMediaSiteInput
|
|
129
|
-
onChange={v => handleChange('twitter', v)}
|
|
130
|
-
site="twitter"
|
|
131
|
-
value={value?.twitter}
|
|
132
|
-
isModalVisible={selectedSite === 'twitter'}
|
|
133
|
-
onModalClose={() => setSelectedSite(null)}
|
|
134
|
-
/>
|
|
135
|
-
)}
|
|
136
|
-
{(!sites || sites.youtube) && (
|
|
137
|
-
<SocialMediaSiteInput
|
|
138
|
-
onChange={v => handleChange('youtube', v)}
|
|
139
|
-
site="youtube"
|
|
140
|
-
value={value?.youtube}
|
|
141
|
-
isModalVisible={selectedSite === 'youtube'}
|
|
142
|
-
onModalClose={() => setSelectedSite(null)}
|
|
143
|
-
/>
|
|
144
|
-
)}
|
|
145
|
-
{(!sites || sites.soundcloud) && (
|
|
146
|
-
<SocialMediaSiteInput
|
|
147
|
-
onChange={v => handleChange('soundcloud', v)}
|
|
148
|
-
site="soundcloud"
|
|
149
|
-
value={value?.soundcloud}
|
|
150
|
-
isModalVisible={selectedSite === 'soundcloud'}
|
|
151
|
-
onModalClose={() => setSelectedSite(null)}
|
|
152
|
-
/>
|
|
153
|
-
)}
|
|
154
|
-
</View>
|
|
155
|
-
</View>
|
|
156
|
-
)
|
|
157
|
-
},
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
const styles = StyleSheet.create({
|
|
161
|
-
container: {
|
|
162
|
-
flex: 1,
|
|
163
|
-
padding: 8,
|
|
164
|
-
},
|
|
165
|
-
title: {
|
|
166
|
-
fontSize: 16,
|
|
167
|
-
fontWeight: 'bold',
|
|
168
|
-
marginBottom: 8,
|
|
169
|
-
color: '#1A202C',
|
|
170
|
-
},
|
|
171
|
-
iconsContainer: {
|
|
172
|
-
flexDirection: 'row',
|
|
173
|
-
flexWrap: 'wrap',
|
|
174
|
-
gap: 8,
|
|
175
|
-
},
|
|
176
|
-
iconButton: {
|
|
177
|
-
width: 34,
|
|
178
|
-
height: 34,
|
|
179
|
-
borderRadius: 17,
|
|
180
|
-
backgroundColor: '#EDF2F7',
|
|
181
|
-
justifyContent: 'center',
|
|
182
|
-
alignItems: 'center',
|
|
183
|
-
},
|
|
184
|
-
iconButtonInactive: {
|
|
185
|
-
opacity: 0.6,
|
|
186
|
-
},
|
|
187
|
-
iconText: {
|
|
188
|
-
fontSize: 12,
|
|
189
|
-
color: '#1A202C',
|
|
190
|
-
},
|
|
191
|
-
modalContainer: {
|
|
192
|
-
flex: 1,
|
|
193
|
-
justifyContent: 'center',
|
|
194
|
-
alignItems: 'center',
|
|
195
|
-
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
196
|
-
},
|
|
197
|
-
modalContent: {
|
|
198
|
-
backgroundColor: 'white',
|
|
199
|
-
borderRadius: 8,
|
|
200
|
-
padding: 16,
|
|
201
|
-
width: '80%',
|
|
202
|
-
maxWidth: 300,
|
|
203
|
-
},
|
|
204
|
-
modalTitle: {
|
|
205
|
-
fontSize: 16,
|
|
206
|
-
fontWeight: 'bold',
|
|
207
|
-
marginBottom: 8,
|
|
208
|
-
color: '#1A202C',
|
|
209
|
-
},
|
|
210
|
-
errorText: {
|
|
211
|
-
color: '#E53E3E',
|
|
212
|
-
fontSize: 14,
|
|
213
|
-
marginBottom: 8,
|
|
214
|
-
padding: 4,
|
|
215
|
-
backgroundColor: '#FFF5F5',
|
|
216
|
-
},
|
|
217
|
-
modalInput: {
|
|
218
|
-
borderWidth: 1,
|
|
219
|
-
borderColor: '#E2E8F0',
|
|
220
|
-
borderRadius: 4,
|
|
221
|
-
padding: 8,
|
|
222
|
-
marginBottom: 16,
|
|
223
|
-
fontSize: 16,
|
|
224
|
-
},
|
|
225
|
-
closeButton: {
|
|
226
|
-
backgroundColor: '#EDF2F7',
|
|
227
|
-
padding: 8,
|
|
228
|
-
borderRadius: 4,
|
|
229
|
-
alignItems: 'center',
|
|
230
|
-
},
|
|
231
|
-
closeButtonText: {
|
|
232
|
-
color: '#1A202C',
|
|
233
|
-
fontSize: 16,
|
|
234
|
-
},
|
|
235
|
-
})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from 'react'
|
|
2
|
-
import { StyleSheet, TextInput, TextInputProps } from 'react-native'
|
|
3
|
-
|
|
4
|
-
import { useIconColor, useTextColor } from '@chem-po/react'
|
|
5
|
-
|
|
6
|
-
import React from 'react'
|
|
7
|
-
import { useWebAutoResize } from './useWebAutoResize'
|
|
8
|
-
|
|
9
|
-
export const AutoResizeTextarea = forwardRef<TextInput, TextInputProps>(
|
|
10
|
-
({ style, value, onChangeText, ...props }, ref) => {
|
|
11
|
-
const textColor = useTextColor()
|
|
12
|
-
|
|
13
|
-
const { handleChange, height } = useWebAutoResize(onChangeText, style)
|
|
14
|
-
|
|
15
|
-
const iconColor = useIconColor()
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<TextInput
|
|
19
|
-
ref={ref}
|
|
20
|
-
cursorColor={iconColor}
|
|
21
|
-
multiline
|
|
22
|
-
style={[styles.textarea, { color: textColor, height }, style]}
|
|
23
|
-
value={value}
|
|
24
|
-
onChangeText={handleChange}
|
|
25
|
-
{...props}
|
|
26
|
-
/>
|
|
27
|
-
)
|
|
28
|
-
},
|
|
29
|
-
)
|
|
30
|
-
const styles = StyleSheet.create({
|
|
31
|
-
textarea: {
|
|
32
|
-
width: '100%',
|
|
33
|
-
backgroundColor: 'transparent',
|
|
34
|
-
textAlignVertical: 'top',
|
|
35
|
-
outlineWidth: 0,
|
|
36
|
-
},
|
|
37
|
-
inEditable: {
|
|
38
|
-
paddingHorizontal: 0,
|
|
39
|
-
paddingVertical: 0,
|
|
40
|
-
},
|
|
41
|
-
})
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { InputRef } from '@chem-po/core'
|
|
2
|
-
import { TextField, usePlaceholderColor, useTextColor } from '@chem-po/react'
|
|
3
|
-
import { Ionicons } from '@expo/vector-icons'
|
|
4
|
-
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
5
|
-
import { StyleSheet, TextInput, View } from 'react-native'
|
|
6
|
-
import { Pressable } from 'react-native-gesture-handler'
|
|
7
|
-
import { FieldProps } from '../../types'
|
|
8
|
-
import { useInputStyles } from '../hooks/useInputStyles'
|
|
9
|
-
import { TextAreaComponent } from './textarea'
|
|
10
|
-
|
|
11
|
-
export const TextComponent = forwardRef<InputRef, FieldProps<TextField>>(
|
|
12
|
-
({ input, inEditable, meta, field, style, formSize, inputStyle }, ref) => {
|
|
13
|
-
const { placeholder, type } = field
|
|
14
|
-
const [isHidden, setIsHidden] = useState(type === 'password')
|
|
15
|
-
const { value, onChange, ...inputProps } = input
|
|
16
|
-
const inputRef = useRef<TextInput>(null)
|
|
17
|
-
const { container: conatinerStyles, text: inputStyles } = useInputStyles(
|
|
18
|
-
inEditable,
|
|
19
|
-
field.size,
|
|
20
|
-
formSize,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
useImperativeHandle(ref, () => ({
|
|
24
|
-
focus: () => {
|
|
25
|
-
inputRef.current?.focus()
|
|
26
|
-
},
|
|
27
|
-
blur: () => {
|
|
28
|
-
inputRef.current?.clear()
|
|
29
|
-
},
|
|
30
|
-
}))
|
|
31
|
-
|
|
32
|
-
const placeholderColor = usePlaceholderColor()
|
|
33
|
-
const color = useTextColor()
|
|
34
|
-
|
|
35
|
-
if (type === 'textarea') {
|
|
36
|
-
return (
|
|
37
|
-
<TextAreaComponent
|
|
38
|
-
ref={inputRef}
|
|
39
|
-
formSize={formSize}
|
|
40
|
-
inputStyle={inputStyle}
|
|
41
|
-
inEditable={inEditable}
|
|
42
|
-
field={field}
|
|
43
|
-
style={style}
|
|
44
|
-
input={input}
|
|
45
|
-
meta={meta}
|
|
46
|
-
/>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const body = (
|
|
51
|
-
<TextInput
|
|
52
|
-
ref={inputRef}
|
|
53
|
-
style={[inputStyles, { color }, inputStyle]}
|
|
54
|
-
secureTextEntry={isHidden}
|
|
55
|
-
selectTextOnFocus={inEditable}
|
|
56
|
-
placeholderTextColor={placeholderColor}
|
|
57
|
-
placeholder={placeholder}
|
|
58
|
-
value={value ?? ''}
|
|
59
|
-
onChangeText={onChange}
|
|
60
|
-
{...inputProps}
|
|
61
|
-
/>
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
return type === 'password' ? (
|
|
65
|
-
<View style={[conatinerStyles, styles.passwordContainer, style]}>
|
|
66
|
-
{body}
|
|
67
|
-
<Pressable style={styles.eyeIcon} onPress={() => setIsHidden(!isHidden)}>
|
|
68
|
-
<Ionicons name={isHidden ? 'eye' : 'eye-off'} size={20} color="#666" />
|
|
69
|
-
</Pressable>
|
|
70
|
-
</View>
|
|
71
|
-
) : (
|
|
72
|
-
<View style={[conatinerStyles, style]}>{body}</View>
|
|
73
|
-
)
|
|
74
|
-
},
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
TextComponent.displayName = 'TextComponent'
|
|
78
|
-
|
|
79
|
-
const styles = StyleSheet.create({
|
|
80
|
-
// inEditable: {
|
|
81
|
-
// paddingHorizontal: 0,
|
|
82
|
-
// paddingVertical: 0,
|
|
83
|
-
// height: 'auto',
|
|
84
|
-
// },
|
|
85
|
-
passwordInput: {
|
|
86
|
-
paddingRight: 40,
|
|
87
|
-
},
|
|
88
|
-
passwordContainer: {
|
|
89
|
-
width: '100%',
|
|
90
|
-
flexDirection: 'row',
|
|
91
|
-
alignItems: 'center',
|
|
92
|
-
position: 'relative',
|
|
93
|
-
},
|
|
94
|
-
eyeIcon: {
|
|
95
|
-
position: 'absolute',
|
|
96
|
-
right: 12,
|
|
97
|
-
padding: 4,
|
|
98
|
-
},
|
|
99
|
-
})
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { TextField, usePlaceholderColor, useTextColor } from '@chem-po/react'
|
|
2
|
-
import React, { forwardRef } from 'react'
|
|
3
|
-
import { TextInput, View } from 'react-native'
|
|
4
|
-
import { FieldProps } from '../../types'
|
|
5
|
-
import { useInputStyles } from '../hooks/useInputStyles'
|
|
6
|
-
import { AutoResizeTextarea } from './AutoResizeTextarea'
|
|
7
|
-
|
|
8
|
-
export const TextAreaComponent = forwardRef<TextInput, FieldProps<TextField>>(
|
|
9
|
-
({ input, field, inEditable, formSize, inputStyle, style }, ref) => {
|
|
10
|
-
const { text, container } = useInputStyles(inEditable, field.size, formSize)
|
|
11
|
-
const { value, onChange, ...inputProps } = input
|
|
12
|
-
const placeholderColor = usePlaceholderColor()
|
|
13
|
-
const color = useTextColor()
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<View style={[container, style]}>
|
|
17
|
-
<AutoResizeTextarea
|
|
18
|
-
ref={ref}
|
|
19
|
-
style={[{ color, ...text, paddingBottom: inEditable ? 0 : 4 }, inputStyle]}
|
|
20
|
-
placeholder={field.placeholder}
|
|
21
|
-
placeholderTextColor={placeholderColor}
|
|
22
|
-
multiline
|
|
23
|
-
value={value ?? ''}
|
|
24
|
-
onChangeText={onChange}
|
|
25
|
-
{...inputProps}
|
|
26
|
-
/>
|
|
27
|
-
</View>
|
|
28
|
-
)
|
|
29
|
-
},
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
TextAreaComponent.displayName = 'TextAreaComponent'
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
-
import { Platform, StyleProp, StyleSheet, TextStyle } from 'react-native'
|
|
3
|
-
|
|
4
|
-
// creates a span element with the text and style and returns the height
|
|
5
|
-
const getWebTextHeight = (text: string, spanRef: React.RefObject<HTMLSpanElement | null>) => {
|
|
6
|
-
if (!spanRef.current) return null
|
|
7
|
-
const span = spanRef.current
|
|
8
|
-
span.innerText = `${text}\n`
|
|
9
|
-
document.body.appendChild(span)
|
|
10
|
-
const height = span.offsetHeight
|
|
11
|
-
document.body.removeChild(span)
|
|
12
|
-
return height
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const updateSpanStyle = (span: HTMLSpanElement, style: TextStyle | undefined) => {
|
|
16
|
-
span.style.whiteSpace = 'pre-wrap'
|
|
17
|
-
if (style?.fontFamily) {
|
|
18
|
-
span.style.fontFamily = style.fontFamily
|
|
19
|
-
}
|
|
20
|
-
if (style?.fontSize) {
|
|
21
|
-
span.style.fontSize = style.fontSize.toString() + 'px'
|
|
22
|
-
}
|
|
23
|
-
if (style?.fontWeight) {
|
|
24
|
-
span.style.fontWeight = style.fontWeight.toString()
|
|
25
|
-
}
|
|
26
|
-
if (style?.lineHeight) {
|
|
27
|
-
span.style.lineHeight = style.lineHeight.toString()
|
|
28
|
-
}
|
|
29
|
-
if (style?.letterSpacing) {
|
|
30
|
-
span.style.letterSpacing = style.letterSpacing.toString()
|
|
31
|
-
}
|
|
32
|
-
if (style?.textAlign) {
|
|
33
|
-
span.style.textAlign = style.textAlign
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const useWebAutoResize = (
|
|
38
|
-
onChangeText: ((e: string) => void) | undefined,
|
|
39
|
-
style: StyleProp<TextStyle> | undefined,
|
|
40
|
-
) => {
|
|
41
|
-
const flattenedStyle = useMemo(() => StyleSheet.flatten(style), [style])
|
|
42
|
-
const fontSize = useMemo(() => flattenedStyle.fontSize ?? 16, [flattenedStyle.fontSize])
|
|
43
|
-
const [height, setHeight] = useState<number | 'auto'>(
|
|
44
|
-
Platform.OS === 'web' ? fontSize + 10 : 'auto',
|
|
45
|
-
)
|
|
46
|
-
const spanRef = useRef<HTMLSpanElement>(
|
|
47
|
-
Platform.OS === 'web' ? document.createElement('span') : null,
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (Platform.OS === 'web' && spanRef.current) {
|
|
52
|
-
updateSpanStyle(spanRef.current, flattenedStyle)
|
|
53
|
-
}
|
|
54
|
-
}, [flattenedStyle])
|
|
55
|
-
const handleChange = useMemo(
|
|
56
|
-
() =>
|
|
57
|
-
Platform.OS === 'web'
|
|
58
|
-
? (e: string) => {
|
|
59
|
-
if (spanRef.current) {
|
|
60
|
-
const height = getWebTextHeight(e, spanRef)
|
|
61
|
-
setHeight((height ?? fontSize) + 8)
|
|
62
|
-
if (onChangeText) onChangeText(e)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
: onChangeText,
|
|
66
|
-
[onChangeText, fontSize],
|
|
67
|
-
)
|
|
68
|
-
return {
|
|
69
|
-
handleChange,
|
|
70
|
-
height,
|
|
71
|
-
setHeight,
|
|
72
|
-
}
|
|
73
|
-
}
|