diff --git a/docs/prop-types.json b/docs/prop-types.json index ecc05836f..5d9d811fb 100644 --- a/docs/prop-types.json +++ b/docs/prop-types.json @@ -2859,6 +2859,27 @@ }, "required": true, "description": "" + }, + "todayLabel": { + "type": { + "name": "string" + }, + "required": true, + "description": "" + }, + "showTodayButton": { + "type": { + "name": "bool" + }, + "required": true, + "description": "" + }, + "onSetToday": { + "type": { + "name": "func" + }, + "required": true, + "description": "" } } } @@ -2999,6 +3020,13 @@ "description": "", "displayName": "ModalWrapper", "methods": [ + { + "name": "handleSetTodayDate", + "docblock": null, + "modifiers": [], + "params": [], + "returns": null + }, { "name": "open", "docblock": null, @@ -3114,6 +3142,28 @@ "computed": false } }, + "todayLabel": { + "type": { + "name": "string" + }, + "required": false, + "description": "\"Today\" label message", + "defaultValue": { + "value": "'Today'", + "computed": false + } + }, + "showTodayButton": { + "type": { + "name": "bool" + }, + "required": false, + "description": "If true today button will be displayed\nNote* that clear button has higher priority", + "defaultValue": { + "value": "false", + "computed": false + } + }, "onOpen": { "type": { "name": "func" @@ -3180,6 +3230,17 @@ "computed": true } }, + "onSetToday": { + "type": { + "name": "func" + }, + "required": false, + "description": "", + "defaultValue": { + "value": "undefined", + "computed": true + } + }, "children": { "type": { "name": "node" diff --git a/docs/src/Examples/Demo/BasicDatePicker.jsx b/docs/src/Examples/Demo/BasicDatePicker.jsx index 700a1b9d0..642f53e32 100644 --- a/docs/src/Examples/Demo/BasicDatePicker.jsx +++ b/docs/src/Examples/Demo/BasicDatePicker.jsx @@ -35,6 +35,18 @@ export default class BasicDatePicker extends PureComponent { animateYearScrolling={false} /> + +
+ +
); } diff --git a/docs/src/Examples/Demo/BasicDateTimePicker.jsx b/docs/src/Examples/Demo/BasicDateTimePicker.jsx index 28a968f00..23600d2c1 100644 --- a/docs/src/Examples/Demo/BasicDateTimePicker.jsx +++ b/docs/src/Examples/Demo/BasicDateTimePicker.jsx @@ -34,6 +34,16 @@ export default class BasicDateTimePicker extends PureComponent { label="24h clock" /> + +
+ +
); } diff --git a/docs/src/Examples/Demo/TimePickerBasic.jsx b/docs/src/Examples/Demo/TimePickerBasic.jsx index 8935c2865..0a502dd71 100644 --- a/docs/src/Examples/Demo/TimePickerBasic.jsx +++ b/docs/src/Examples/Demo/TimePickerBasic.jsx @@ -32,6 +32,16 @@ export default class BasicUsage extends PureComponent { onChange={this.handleDateChange} /> + +
+ +
); } diff --git a/lib/__tests__/_shared/ModalDialog.test.js b/lib/__tests__/_shared/ModalDialog.test.js index 563ca39f4..bf2e679de 100644 --- a/lib/__tests__/_shared/ModalDialog.test.js +++ b/lib/__tests__/_shared/ModalDialog.test.js @@ -1,16 +1,86 @@ import React from 'react'; import { shallow } from '../test-utils'; -import ModalDialog from '../../src/_shared/ModalDialog'; +import { ModalDialog } from '../../src/_shared/ModalDialog'; + +const initialProps = { + onAccept: jest.fn(), + onDismiss: jest.fn(), + onClear: jest.fn(), + okLabel: 'OK', + cancelLabel: 'Cancel', + clearLabel: 'Clear', + clearable: false, + todayLabel: 'Today', + showTodayButton: false, + onSetToday: jest.fn(), + classes: {}, + children: 'Test', +}; describe('ModalDialog', () => { let component; + const props = { ...initialProps }; beforeEach(() => { - component = shallow(); + component = shallow(); }); it('Should renders', () => { // console.log(component.debug()); expect(component).toBeTruthy(); }); + + it('Should render dialog content', () => { + expect(component.find('WithStyles(DialogContent)').props().children).toBe(props.children); + }); + + it('Should render dialog actions with 2 buttons', () => { + expect(component.find('WithStyles(DialogActions)').length).toBe(1); + expect(component.find('WithStyles(Button)').at(0).props().children).toBe('Cancel'); + expect(component.find('WithStyles(Button)').at(1).props().children).toBe('OK'); + }); + + it('Should handle on OK button click', () => { + component.find('WithStyles(Button)').at(1).simulate('click'); + expect(props.onAccept).toHaveBeenCalled(); + }); + + it('Should handle on Cancel button click', () => { + component.find('WithStyles(Button)').at(0).simulate('click'); + expect(props.onDismiss).toHaveBeenCalled(); + }); +}); + +describe('ModalDialog with Clear Button', () => { + let component; + const props = { + ...initialProps, + clearable: true, + }; + + beforeEach(() => { + component = shallow(); + }); + + it('Should handle on Clear button click', () => { + component.find('WithStyles(Button)').at(0).simulate('click'); + expect(props.onClear).toHaveBeenCalled(); + }); +}); + +describe('ModalDialog with Today Button', () => { + let component; + const props = { + ...initialProps, + showTodayButton: true, + }; + + beforeEach(() => { + component = shallow(); + }); + + it('Should handle on Clear button click', () => { + component.find('WithStyles(Button)').at(0).simulate('click'); + expect(props.onSetToday).toHaveBeenCalled(); + }); }); diff --git a/lib/src/DatePicker/DatePickerWrapper.jsx b/lib/src/DatePicker/DatePickerWrapper.jsx index dd3cdb017..a6f05c473 100644 --- a/lib/src/DatePicker/DatePickerWrapper.jsx +++ b/lib/src/DatePicker/DatePickerWrapper.jsx @@ -92,6 +92,7 @@ export class DatePickerWrapper extends PickerBase { onAccept={this.handleAccept} onChange={this.handleTextFieldChange} onDismiss={this.handleDismiss} + onSetToday={this.handleSetTodayDate} labelFunc={labelFunc} minDate={minDate} maxDate={maxDate} diff --git a/lib/src/DateTimePicker/DateTimePickerWrapper.jsx b/lib/src/DateTimePicker/DateTimePickerWrapper.jsx index ec5840e1d..faa676887 100644 --- a/lib/src/DateTimePicker/DateTimePickerWrapper.jsx +++ b/lib/src/DateTimePicker/DateTimePickerWrapper.jsx @@ -116,6 +116,7 @@ export class DateTimePickerWrapper extends PickerBase { onChange={this.handleTextFieldChange} onDismiss={this.handleDismiss} onClear={this.handleClear} + onSetToday={this.handleSetTodayDate} dialogContentClassName={classes.dialogContent} minDate={minDate} maxDate={maxDate} diff --git a/lib/src/TimePicker/TimePickerWrapper.jsx b/lib/src/TimePicker/TimePickerWrapper.jsx index 28a6b84eb..c89c0c713 100644 --- a/lib/src/TimePicker/TimePickerWrapper.jsx +++ b/lib/src/TimePicker/TimePickerWrapper.jsx @@ -50,6 +50,7 @@ export class TimePickerWrapper extends PickerBase { onAccept={this.handleAccept} onChange={this.handleTextFieldChange} onDismiss={this.handleDismiss} + onSetToday={this.handleSetTodayDate} {...other} > ( @@ -55,7 +63,10 @@ const ModalDialog = ({ { clearable && @@ -68,6 +79,16 @@ const ModalDialog = ({ } + { !clearable && showTodayButton && + + } +