1.1.5 • Published 1 year ago
rn-components_dtc v1.1.5
React-Native-Component_DTC
This lib support some of component basic for project. (build for DTC's projects)
Installation
Step 1: Before use this lib, you need config native "react-native-vector-icons" following this link: https://github.com/oblador/react-native-vector-icons
Step 2: To install lib this project run
npm i rn-components_dtc
Step 3:
cd ios & pod install
If you are having trouble with iOS, try to reinstall the dependencies by running:
1. cd ios
2. bundle install
3. bundle exec pod install
Usage/Examples
const App = () => {
useEffect(() => {
console.log(RNModuleTemplateModule)
})
const isDarkMode = useColorScheme() === 'dark'
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
}
const [isVisible, setisVisible] = useState<boolean>(false)
const [checked, setChecked] = useState<boolean>(false)
const Test = () => {
return <Text>test right custom children</Text>
}
const data = [
{
key: 1,
text: 'Option A',
},
{
key: 2,
text: 'Option B',
},
{
key: 3,
text: 'Option C',
},
]
const onRadioButtonPress = (itemIdx: any) => {
console.log('Clicked', itemIdx)
}
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
backgroundColor={backgroundStyle.backgroundColor}
/>
<ScrollView
contentInsetAdjustmentBehavior='automatic'
style={backgroundStyle}
>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}
>
<View
style={{
flex: 1,
marginTop: 30,
marginHorizontal: 16,
}}
>
<Button
text='test'
onPressBtn={() => {}}
btnStyle={{ marginVertical: 10, padding: 10 }}
/>
<TextInputComponent
containerViewInputStyle={{ marginBottom: 10 }}
textInputStyle={{ borderWidth: 2 }}
errorText='loi roi kia lam lai di'
/>
<ImageCpn
typeVectorIcon='AntDesign'
iconName='plus'
sizeIcon={50}
colorIcon='red'
imgStyle={{ marginBottom: 10, borderWidth: 1, borderRadius: 6 }}
onPressItem={() => {
console.log('pressed item')
}}
/>
<View
style={{ borderWidth: 2, borderColor: 'gray', borderRadius: 6 }}
>
<CollapseView
title={'Tùy chọn tìm kiếm'}
titleStyle={{ color: 'blue' }}
icon={
<Icons.AntDesign
name='infocirlceo'
size={20}
color={'black'}
/>
}
customViewChildStyle={{
borderTopWidth: 1,
borderColor: 'gray',
}}
customContainerStyle={{
borderTopWidth: 1,
}}
>
<Text>test</Text>
<Text>test1</Text>
</CollapseView>
</View>
<ImageCpn typeVectorIcon='AntDesign' iconName='minus' />
<CollapseViewV2 />
<RadioComponent
titleLeft={'Test radio button'}
customStyleContainer={{ marginTop: 10 }}
value={null}
onChangeSwitch={(bool) => {
console.log('changed status')
}}
/>
</View>
<Button
text='Open modal'
onPressBtn={() => {
setisVisible(!isVisible)
}}
btnStyle={{ margin: 10, padding: 10 }}
/>
<Checkbox
leftText='left'
checked={checked}
onChecked={setChecked}
childrenRight={<Test />}
/>
<MultiRadioButton
isSwapTextToLeft={false}
values={data}
onPress={onRadioButtonPress}
/>
</View>
<ModalComponent
isVisible={isVisible}
isShowButtonAccpet
hasCancelButton
titlePopup={'Test modal'}
onPressBtnAccept={() => setisVisible(false)}
customStyleBtnAccept={{ backgroundColor: 'pink' }}
/>
</ScrollView>
</SafeAreaView>
)
}
export default App
Components
I. Button
Props | Description |
---|---|
text | Text in button |
activeOpacity | Opacity when user click button (from 0 to 1) |
disabled | Disable button |
children | Instead of Text <React.ReactNode> |
textStyle | Text Style <StyleProp> |
btnStyle | Style of button <StyleProp> |
onPressBtn | on Press button |
numberOfLines | number of line of Text in button |
adjustsFontSizeToFit | adjust font size |
allowFontScaling | auto scale font |
II. TextInput
Props | Description |
---|---|
value | value input text |
placeholder | place holder text ( default is '...Nhập giá trị' ) |
placeholderStyle | Style for place holder <StyleProp> |
onChangeText | On change value of Text <(value: string) => void> |
onFocus | When user focus on input <(e: NativeSyntheticEvent) => void> |
onBlur | Callback that is called when the text input is blurred <(e: NativeSyntheticEvent) => void> |
onEndEditting | When user end edit text input <(e: NativeSyntheticEvent) => void> |
childrenLeft | When want to custom left children React Node of input text <React.ReactNode> |
childrenLeftStyle | Container Style of children left <StyleProp> |
childrenRight | When want to custom right children React Node of input text <React.ReactNode> |
childrenRightStyle | Container Style of children right <StyleProp> |
textInputStyle | Container Style of textinput <StyleProp> |
containerViewInputStyle | Container Style of all children <StyleProp> |
errorText | Show error text at bottom of text input |
errorTextStyle | Error Text Style <StyleProp> |
editable | Text input can edit ( default is true) |
III. ImageCpn
Props | Description |
---|---|
imageUrl | Static url of image |
image | Url of image with format require('...') type |
imgStyle | Style for image |
iconName | Name of vector icon, match with typeVectorIcon |
typeVectorIcon | Type of vector icons ( AntDesign, Feather, Entypo, EvilIcons, Ionicons, FontAwesome,... ) |
colorIcon | Color of Icon |
sizeIcon | Size of icon |
resizeMode | Resize mode of image ( contain, center, cover, stretch, repeat ) |
onPressItem | On press image or icon |
IV. Modal Component
Props | Description |
---|---|
isVisible | The visible prop determines whether your modal is visible. |
setModalVisible | Function like onRequestClose modal |
onPressBtnAccept | On press accept button to do some thing |
image | Image like avatar of modal |
titlePopup | Title of modal |
subTitlePopup | Subtitle of modal |
titleBtnAccept | Title of button accept |
titleBtnCancel | Title of button cancel |
hasCheckBox | Boolean check box in modal |
isChecked | Status of checkbox |
setCheckedCheckbox | Function change status checkbox |
titleWithCheckBox | Title of checkbox with horizontal |
hasCancelButton | Boolean check cancel button |
customStyleBtnAccept | Style container of button accept |
customStyleBtnCancel | Style container of button cancel |
isDisableBtnAccept | Disable button accept |
colorCheckbox | Color of check box, default is blue |
sizeCheckbox | Size of check box, default is 16 |
isShowButtonAccpet | Boolean check has button accept or not, default is true |
V. Radio Component
Props | Description |
---|---|
value | Value of radio button ( can be boolean value or any value following each projects ). |
titleLeft | Title of Radio button component |
onChangeSwitch | Function change status of Radio button |
customStyleContainer | Custom Style container of radio button |
customStyleTextLeft | Custom text style |
trackColorFalse | Color when radio button is off |
trackColorTrue | Color when radio button is on |
thumbColor | Color of thumb |
VI. Collapse View
Props | Description |
---|---|
disabled | Disable collapse view, default is false |
title | Title of collapse view |
titleStyle | Style for title |
children | Custom Children ( Contents ) when view expanded |
icon | Icon at head ( left ) of title |
colorsIcon | Array color type 'red', 'blue'. When collapse is red, expand is blue |
sizeIcon | Size of icon |
customViewChildStyle | Custom container style of children |
hasCount | Boolean check count ( count is on the right of title) |
count | Count |
isShowRightContent | Boolean check right content or no. (on the right of title with flex - end ) |
txtFollowingCount | Text following on the count ( describe for count like Times, Searchs, ... ) |
isShowButton | Boolean check button with dependency must has isShowRightContent . ( like minus icon or plus icon when user collapse or expand view ) |
txtBtn | Text button if right content is Text, dependency is isShowRightContent |
customBtnRightStyle | Custom Style for right content |
onPressBtn | Action of button right content |
customContainerStyle | Custom container style for collapse view |
openDefault | Boolean check default is collapse or expand |
isSwapChild | Swap children will be show on top or button of collapse |
isSpecialChild | Boolean check custom children special has or no |
titleSpecial | Title of special child |
subTitleSpecial | Subtitle of special child |
valueSpecial | Value Special |
hasHeader | Boolean check has header special or not ( when use expand view ) |
titleHeaderSpecial | Title for header special |
styleTitleHeaderSpecial | Style for title header special |
colorIconClose | Color of icon close ( when use expand view ) |
colorActiveCollapse | Color when view was expand, Exp: default color is white, when view expand, color change to different color |
colorTextActiveCollapse | Color of text when collapse or expand ( like colorActiveCollapse ) |
Note: Devs's DTC following design on Figma "Test firm search APP".
VII. Collapse View V2 (Collapse view text )
Props | Description |
---|---|
lineDefault | Line show default after use collapse view |
textData | Data type Text |
textMore | Text show more |
textCollapse | Text collapse |
icons | Array of icon replace for textMore and textCollapse . Exp: <Icons.AntDesign name='caretdown' color={'black'} size={14} />, <Icons.AntDesign name='caretup' color={'black'} size={14} />, |