Skip to content

Infra/custom datetime picker input #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions demo/src/screens/componentScreens/DateTimePickerScreen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
import React, {Component} from 'react';
import {DateTimePicker, View, Text} from 'react-native-ui-lib'; // eslint-disable-line
import {ScrollView} from 'react-native';
import {DateTimePicker, Text, TouchableOpacity, Colors} from 'react-native-ui-lib'; // eslint-disable-line

export default class DateTimePickerScreen extends Component {

getCustomInputValue = value => {
if (!value) {
return 'Default';
}
return value.includes(new Date().getFullYear() + 1) ? 'Next Year' : value;
};

renderCustomInput = (props, toggle) => {
const {value} = props;
return (
<TouchableOpacity
flex
row
spread
onPress={() => {
toggle(true);
}}
>
<Text>Valid from</Text>
<Text absR color={Colors.primary} text80BO>{this.getCustomInputValue(value)}</Text>
</TouchableOpacity>
);
};

render() {
return (
<View flex padding-s5>
<ScrollView style={{padding: 14}}>
<Text text40>Date Time Picker</Text>
<DateTimePicker
containerStyle={{marginVertical: 20}}
Expand Down Expand Up @@ -37,7 +63,18 @@ export default class DateTimePickerScreen extends Component {
placeholder={'Select time'}
value={new Date('2015-03-25T12:00:00-06:30')}
/>
</View>
<Text text60R marginT-40>
Custom Input
</Text>
<DateTimePicker
containerStyle={{marginVertical: 20}}
title={'Date'}
placeholder={'Select a date'}
renderExpandableInput={this.renderCustomInput}
dateFormat={'MMM D, YYYY'}
// value={new Date('2015-03-25T12:00:00-06:30')}
/>
</ScrollView>
);
}
}
6 changes: 5 additions & 1 deletion src/components/dateTimePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ class DateTimePicker extends Component {
/**
* style to apply to the iOS dialog header
*/
headerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number])
headerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
/**
* Render custom input
*/
renderInput: PropTypes.elementType
};

static defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/textField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export default class TextField extends BaseInput {
const {renderExpandableInput, testID} = this.getThemeProps();

if (_.isFunction(renderExpandableInput)) {
return renderExpandableInput(this.getThemeProps());
return renderExpandableInput(this.getThemeProps(), this.toggleExpandableModal);
}

return (
Expand Down