Skip to content

Commit

Permalink
Allow DatePicker buttons to be overriden
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaidar authored and Simon Bartlett committed Apr 15, 2019
1 parent 292abac commit 0ef82b0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/DatePicker/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,15 @@ class Calendar extends Component {
const weekTitleDayStyle = prepareStyles(styles.weekTitleDay);

const {
cancelClassName,
cancelLabel,
cancelStyle,
DateTimeFormat,
firstDayOfWeek,
locale,
okClassName,
okLabel,
okStyle,
onClickCancel, // eslint-disable-line no-unused-vars
onClickOk, // eslint-disable-line no-unused-vars
utils,
Expand Down Expand Up @@ -387,8 +391,12 @@ class Calendar extends Component {
{okLabel &&
<CalendarActionButtons
autoOk={this.props.autoOk}
cancelClassName={cancelClassName}
cancelLabel={cancelLabel}
cancelStyle={cancelStyle}
okClassName={okClassName}
okLabel={okLabel}
okStyle={okStyle}
onClickCancel={onClickCancel}
onClickOk={onClickOk}
/>
Expand Down
21 changes: 18 additions & 3 deletions src/DatePicker/CalendarActionButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ class CalendarActionButton extends Component {
onClickOk: PropTypes.func,
};

static defaultProps = {
okStyle: {},
cancelStyle: {},
};

render() {
const {cancelLabel, okLabel} = this.props;
const {
cancelClassName,
cancelLabel,
cancelStyle,
okClassName,
okLabel,
okStyle,
wordings
} = this.props;

const styles = {
root: {
Expand All @@ -35,18 +48,20 @@ class CalendarActionButton extends Component {
return (
<div style={styles.root} >
<FlatButton
className={cancelClassName}
label={cancelLabel}
onClick={this.props.onClickCancel}
primary={true}
style={styles.flatButtons}
style={{...styles.flatButtons, ...cancelStyle}}
/>
{!this.props.autoOk &&
<FlatButton
className={okClassName}
disabled={this.refs.calendar !== undefined && this.refs.calendar.isSelectedDateDisabled()}
label={okLabel}
onClick={this.props.onClickOk}
primary={true}
style={styles.flatButtons}
style={{...styles.flatButtons, ...okStyle}}
/>
}
</div>
Expand Down
24 changes: 24 additions & 0 deletions src/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ class DatePicker extends Component {
* If true, automatically accept and close the picker on select a date.
*/
autoOk: PropTypes.bool,
/**
* The css class name of the 'Cancel' button.
*/
cancelClassName: PropTypes.string,
/**
* Override the default text of the 'Cancel' button.
*/
cancelLabel: PropTypes.node,
/**
* Override the inline-styles of the 'Cancel' button.
*/
cancelStyle: PropTypes.object,
/**
* The css class name of the root element.
*/
Expand Down Expand Up @@ -89,10 +97,18 @@ class DatePicker extends Component {
* Tells the component to display the picker in portrait or landscape mode.
*/
mode: PropTypes.oneOf(['portrait', 'landscape']),
/**
* The css class name of the 'OK' button
*/
okClassName: PropTypes.string,
/**
* Override the default text of the 'OK' button.
*/
okLabel: PropTypes.node,
/**
* Override the inline-styles of the 'OK' button.
*/
okStyle: PropTypes.object,
/**
* Callback function that is fired when the date value changes.
*
Expand Down Expand Up @@ -277,7 +293,9 @@ class DatePicker extends Component {
const {
DateTimeFormat,
autoOk,
cancelClassName,
cancelLabel,
cancelStyle,
className,
container,
defaultDate, // eslint-disable-line no-unused-vars
Expand All @@ -289,7 +307,9 @@ class DatePicker extends Component {
maxDate,
minDate,
mode,
okClassName,
okLabel,
okStyle,
onDismiss,
onFocus, // eslint-disable-line no-unused-vars
onShow,
Expand Down Expand Up @@ -319,7 +339,9 @@ class DatePicker extends Component {
<DatePickerDialog
DateTimeFormat={DateTimeFormat}
autoOk={autoOk}
cancelClassName={cancelClassName}
cancelLabel={cancelLabel}
cancelStyle={cancelStyle}
container={container}
containerStyle={dialogContainerStyle}
disableYearSelection={disableYearSelection}
Expand All @@ -329,7 +351,9 @@ class DatePicker extends Component {
maxDate={maxDate}
minDate={minDate}
mode={mode}
okClassName={okClassName}
okLabel={okLabel}
okStyle={okStyle}
onAccept={this.handleAccept}
onShow={onShow}
onDismiss={onDismiss}
Expand Down
9 changes: 9 additions & 0 deletions src/DatePicker/DatePickerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class DatePickerDialog extends Component {
const {
DateTimeFormat,
autoOk,
cancelClassName,
cancelLabel,
cancelStyle,
container,
containerStyle,
disableYearSelection,
Expand All @@ -118,7 +120,9 @@ class DatePickerDialog extends Component {
maxDate,
minDate,
mode,
okClassName,
okLabel,
okStyle,
onAccept, // eslint-disable-line no-unused-vars
onDismiss, // eslint-disable-line no-unused-vars
onShow, // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -166,7 +170,10 @@ class DatePickerDialog extends Component {
<Calendar
autoOk={autoOk}
DateTimeFormat={DateTimeFormat}
cancelClassName={cancelClassName}
cancelLabel={cancelLabel}
cancelStyle={cancelStyle}
DateTimeFormat={DateTimeFormat}
disableYearSelection={disableYearSelection}
firstDayOfWeek={firstDayOfWeek}
initialDate={initialDate}
Expand All @@ -179,7 +186,9 @@ class DatePickerDialog extends Component {
ref="calendar"
onClickCancel={this.handleClickCancel}
onClickOk={this.handleClickOk}
okClassName={okClassName}
okLabel={okLabel}
okStyle={okStyle}
openToYearSelection={openToYearSelection}
shouldDisableDate={shouldDisableDate}
hideCalendarDate={hideCalendarDate}
Expand Down

0 comments on commit 0ef82b0

Please sign in to comment.