-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa5996a
commit f764f06
Showing
37 changed files
with
1,121 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React, { useImperativeHandle, useState } from 'react'; | ||
import { Text } from '..'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { Branding, useBranding } from '../../contexts'; | ||
import { ListPicker } from '../listPickers'; | ||
|
||
interface Props { | ||
name: string; | ||
value?: string; | ||
label?: string; | ||
error?: string; | ||
lists?: string[]; | ||
labelList?: string[]; | ||
onChange?: (value: string) => void; | ||
isColum?: boolean; | ||
isCenter?: boolean; | ||
} | ||
export interface FiledSelectionViewRef { | ||
value: () => string | undefined; | ||
errorCheck: () => boolean | undefined; | ||
} | ||
|
||
export const FiledSelectionView = React.forwardRef< | ||
FiledSelectionViewRef, | ||
Props | ||
>( | ||
( | ||
{ | ||
name, | ||
lists, | ||
labelList, | ||
label, | ||
onChange, | ||
value: defaultValue, | ||
isColum = false, | ||
isCenter = false, | ||
}: Props, | ||
ref: React.Ref<FiledSelectionViewRef> | ||
) => { | ||
const branding = useBranding(); | ||
|
||
const styles = requireNutritionFactStyle(branding); | ||
const [value, setValue] = useState<string | undefined>(defaultValue); | ||
const [error, setError] = useState<string>(); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
value: () => { | ||
return value; | ||
}, | ||
errorCheck: () => { | ||
if (value === undefined || value?.length === 0) { | ||
setError('please enter value'); | ||
} else { | ||
setError(undefined); | ||
} | ||
return value?.length === 0; | ||
}, | ||
}), | ||
[value] | ||
); | ||
|
||
const renderFiled = () => { | ||
return ( | ||
<View style={[styles.formRow, isColum && styles.formColum]}> | ||
<Text | ||
weight="400" | ||
size="_12px" | ||
color="gray500" | ||
style={[styles.label, styles.labelMargin]} | ||
> | ||
{name} | ||
</Text> | ||
<ListPicker | ||
value={value ?? ''} | ||
title={name} | ||
isCenter={isCenter} | ||
onChange={(item) => { | ||
onChange?.(item); | ||
setError(undefined); | ||
setValue(item); | ||
}} | ||
lists={lists ?? []} | ||
label={label} | ||
labelList={labelList} | ||
style={styles.pickerTextInput} | ||
error={error ?? ''} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
return <View>{renderFiled()}</View>; | ||
} | ||
); | ||
|
||
const requireNutritionFactStyle = ({}: Branding) => | ||
StyleSheet.create({ | ||
formRow: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
marginBottom: 10, | ||
}, | ||
formColum: { | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
marginBottom: 10, | ||
}, | ||
label: { | ||
flex: 1, | ||
}, | ||
labelMargin: { | ||
marginTop: 10, | ||
}, | ||
pickerTextInput: { | ||
flexWrap: 'wrap', | ||
textAlign: 'right', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import React, { useImperativeHandle, useState } from 'react'; | ||
import { Text, TextInput } from '..'; | ||
import { | ||
Image, | ||
KeyboardTypeOptions, | ||
StyleSheet, | ||
TouchableOpacity, | ||
View, | ||
} from 'react-native'; | ||
import { Branding, useBranding } from '../../contexts'; | ||
import { scaleHeight } from '../../utils'; | ||
import { ICONS } from '../../assets'; | ||
|
||
interface Props { | ||
name: string; | ||
value?: string; | ||
label?: string; | ||
keyboardType?: KeyboardTypeOptions; | ||
isColum?: boolean; | ||
onDelete?: () => void; | ||
} | ||
|
||
export interface FiledViewRef { | ||
value: () => string | undefined; | ||
errorCheck: () => boolean | undefined; | ||
} | ||
|
||
export const FiledView = React.forwardRef<FiledViewRef, Props>( | ||
( | ||
{ | ||
name, | ||
value: defaultValue, | ||
keyboardType = 'decimal-pad', | ||
label = 'value', | ||
isColum = false, | ||
onDelete, | ||
}: Props, | ||
ref: React.Ref<FiledViewRef> | ||
) => { | ||
const branding = useBranding(); | ||
const [value, setValue] = useState<string | undefined>(defaultValue); | ||
const [error, setError] = useState<string>(); | ||
|
||
const styles = requireNutritionFactStyle(branding); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
value: () => { | ||
return value; | ||
}, | ||
errorCheck: () => { | ||
if (value === undefined || value?.length === 0) { | ||
setError('please enter value'); | ||
} else { | ||
setError(undefined); | ||
} | ||
return value?.length === 0; | ||
}, | ||
}), | ||
[value] | ||
); | ||
|
||
const renderFiled = () => { | ||
return ( | ||
<View style={[!isColum && styles.formRow, isColum && styles.formColum]}> | ||
<Text | ||
weight="400" | ||
size="_12px" | ||
color="gray500" | ||
style={[styles.label, styles.labelMargin]} | ||
> | ||
{name} | ||
</Text> | ||
<TextInput | ||
style={styles.textInput} | ||
onChangeText={(text) => { | ||
setValue(text); | ||
setError(undefined); | ||
}} | ||
value={defaultValue} | ||
containerStyle={styles.containerTextInput} | ||
placeholder={label} | ||
error={error} | ||
enterKeyHint="next" | ||
keyboardType={keyboardType} | ||
/> | ||
{onDelete && ( | ||
<TouchableOpacity onPress={onDelete}> | ||
<Image source={ICONS.delete} style={styles.delete} /> | ||
</TouchableOpacity> | ||
)} | ||
</View> | ||
); | ||
}; | ||
|
||
return <View>{renderFiled()}</View>; | ||
} | ||
); | ||
|
||
const requireNutritionFactStyle = ({ white, gray300 }: Branding) => | ||
StyleSheet.create({ | ||
formRow: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
marginBottom: 10, | ||
}, | ||
formColum: { | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
marginBottom: 10, | ||
}, | ||
label: { | ||
flex: 1, | ||
}, | ||
labelMargin: { | ||
marginTop: 10, | ||
}, | ||
delete: { | ||
height: 24, | ||
width: 24, | ||
marginHorizontal: 6, | ||
}, | ||
textInput: { | ||
textAlign: 'left', | ||
flex: 1, | ||
fontWeight: '400', | ||
fontSize: 14, | ||
backgroundColor: white, | ||
borderColor: gray300, | ||
paddingVertical: scaleHeight(8), | ||
borderRadius: scaleHeight(4), | ||
}, | ||
containerTextInput: { | ||
flex: 1, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './FiledSelectionView'; | ||
export * from './FiledView'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.