Skip to content

Commit f35a7d9

Browse files
authored
Merge pull request #120 from data-driven-forms/update-date-time-picker
Update date time picker
2 parents d603c34 + 8bcb881 commit f35a7d9

File tree

10 files changed

+619
-251
lines changed

10 files changed

+619
-251
lines changed

packages/pf3-component-mapper/demo/demo-schemas/sandbox.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const output = {
3434
condition: {
3535
when: 'text_box_1',
3636
is: true,
37-
}
37+
},
3838
},
3939
{
4040
name: 'text_box_1111',
@@ -149,20 +149,20 @@ const output = {
149149
label: 'Check Box',
150150
title: 'Check Box',
151151
component: components.CHECKBOX,
152-
"options": [
152+
'options': [
153153
{
154-
"label": "Dog",
155-
"value": "1"
154+
'label': 'Dog',
155+
value: '1',
156156
},
157157
{
158-
"label": "Cats",
159-
"value": "2"
158+
'label': 'Cats',
159+
'value': '2',
160160
},
161161
{
162-
"label": "Hamsters",
163-
"value": "3"
164-
}
165-
]
162+
'label': 'Hamsters',
163+
'value': '3',
164+
},
165+
],
166166
},
167167
{
168168
name: 'check_box_2',
@@ -401,8 +401,15 @@ const output = {
401401
{
402402
name: 'date_control_1',
403403
label: 'Datepicker',
404-
title: 'Datepicker',
404+
title: 'Datepicker with disabled days',
405405
component: components.DATE_PICKER,
406+
isClearable: true,
407+
disabledDays: [
408+
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 5),
409+
{
410+
before: new Date(),
411+
},
412+
],
406413
},
407414
{
408415
name: 'date_control_2',

packages/pf3-component-mapper/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
]
7979
},
8080
"dependencies": {
81-
"react-day-picker": "^7.2.4",
81+
"react-day-picker": "^7.3.2",
8282
"react-select": "^2.1.2"
8383
},
8484
"resolutions": {

packages/pf3-component-mapper/src/form-fields/date-time-picker/date-time-picker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class DateTimePicker extends React.Component {
9393
),
9494
}), () => this.props.onChange(this.state.selectedDay))
9595

96+
clearValue = () => this.setState({ selectedDay: undefined })
97+
9698
render() {
9799
const { isOpen, selectedDay, selectingYear, selectingMonth } = this.state;
98100
const {
@@ -103,6 +105,7 @@ export class DateTimePicker extends React.Component {
103105
showTodayButton,
104106
isDisabled,
105107
disabledDays,
108+
isClearable,
106109
} = this.props;
107110
return (
108111
<div style={{ position: 'relative' }} ref={ this.wrapperRef } >
@@ -113,6 +116,8 @@ export class DateTimePicker extends React.Component {
113116
variant={ variant }
114117
locale={ locale }
115118
isDisabled={ isDisabled }
119+
isClearable={ isClearable }
120+
clearValue={ this.clearValue }
116121
/>
117122
<Overlay
118123
show={ isOpen }
@@ -156,6 +161,7 @@ DateTimePicker.propTypes = {
156161
value: PropTypes.instanceOf(Date),
157162
closeOnDaySelect: PropTypes.bool,
158163
onChange: PropTypes.func.isRequired,
164+
isClearable: PropTypes.bool,
159165
};
160166

161167
DateTimePicker.defaultProps = {
@@ -167,5 +173,6 @@ DateTimePicker.defaultProps = {
167173
closeOnDaySelect: false,
168174
isDisabled: false,
169175
disabledDays: [{}],
176+
isClearable: false,
170177
};
171178

packages/pf3-component-mapper/src/form-fields/date-time-picker/picker-input.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FormControl, Icon, Form } from 'patternfly-react';
44
import MomentLocaleUtils from 'react-day-picker/moment';
55
import './date-picker-styles.scss';
66

7-
const PickerInput = ({ variant, selectedDay, locale, handleOverlayToggle, isDisabled, ...props }) =>(
7+
const PickerInput = ({ variant, selectedDay, locale, handleOverlayToggle, isDisabled, isClearable, clearValue, ...props }) =>(
88
<Form.InputGroup style={{ cursor: isDisabled ? 'not-allowed' : 'pointer' }} disabled={ isDisabled }>
99
<FormControl
1010
readOnly={ true }
@@ -20,6 +20,11 @@ const PickerInput = ({ variant, selectedDay, locale, handleOverlayToggle, isDisa
2020
className="picker-input"
2121
disabled={ isDisabled }
2222
/>
23+
{ isClearable && selectedDay && (
24+
<Form.InputGroup.Addon disabled={ isDisabled } onClick={ clearValue }>
25+
<Icon name="times" />
26+
</Form.InputGroup.Addon>
27+
) }
2328
<Form.InputGroup.Addon disabled={ isDisabled } onClick={ () => handleOverlayToggle(true) }>
2429
<Icon name={ variant === 'time' ? 'time' : 'calendar' } />
2530
</Form.InputGroup.Addon>
@@ -32,6 +37,8 @@ PickerInput.propTypes = {
3237
locale: PropTypes.string,
3338
handleOverlayToggle: PropTypes.func.isRequired,
3439
isDisabled: PropTypes.bool,
40+
isClearable: PropTypes.bool,
41+
clearValue: PropTypes.func.isRequired,
3542
};
3643

3744
export default PickerInput;

packages/pf4-component-mapper/src/tests/__snapshots__/form-fields.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ exports[`FormFields should render Switch correctly 1`] = `
856856
<input
857857
aria-label=""
858858
aria-labelledby="someIdKey-on"
859-
checked={false}
860859
className="pf-c-switch__input"
860+
defaultChecked={false}
861861
disabled={false}
862862
id="someIdKey"
863863
name="Name of the field"
@@ -1995,8 +1995,8 @@ exports[`FormFields should render disabled Switch correctly 1`] = `
19951995
<input
19961996
aria-label=""
19971997
aria-labelledby="someIdKey-on"
1998-
checked={false}
19991998
className="pf-c-switch__input"
1999+
defaultChecked={false}
20002000
disabled={true}
20012001
id="someIdKey"
20022002
name="Name of the field"
@@ -2162,8 +2162,8 @@ exports[`FormFields should render disabled Switch correctly 2`] = `
21622162
<input
21632163
aria-label=""
21642164
aria-labelledby="someIdKey-on"
2165-
checked={false}
21662165
className="pf-c-switch__input"
2166+
defaultChecked={false}
21672167
disabled={true}
21682168
id="someIdKey"
21692169
name="Name of the field"

packages/pf4-component-mapper/src/tests/__snapshots__/tabs.test.js.snap

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Tabs component should render tabs correctly 1`] = `
4-
<Tabs
4+
<Component
55
activeKey={0}
6-
className=""
7-
isFilled={false}
8-
isSecondary={false}
9-
leftScrollAriaLabel="Scroll left"
106
onSelect={[Function]}
11-
rightScrollAriaLabel="Scroll right"
12-
variant="div"
137
>
148
<ForwardRef
159
eventKey={0}
@@ -37,5 +31,5 @@ exports[`Tabs component should render tabs correctly 1`] = `
3731
</div>
3832
</div>
3933
</ForwardRef>
40-
</Tabs>
34+
</Component>
4135
`;

packages/pf4-component-mapper/src/tests/wizard/__snapshots__/step-buttons.test.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ exports[`<WizardSTepButtons should add custom className to toolbar 1`] = `
88
handleSubmit={[MockFunction]}
99
submitLabel="Submit"
1010
/>
11-
<Button
11+
<Component
1212
onClick={[MockFunction]}
1313
type="button"
1414
variant="secondary"
1515
>
1616
Back
17-
</Button>
18-
<Button
17+
</Component>
18+
<Component
1919
onClick={[MockFunction]}
2020
type="button"
2121
variant="link"
2222
>
2323
Cancel
24-
</Button>
24+
</Component>
2525
</footer>
2626
`;
2727

@@ -33,19 +33,19 @@ exports[`<WizardSTepButtons should render correctly 1`] = `
3333
handleSubmit={[MockFunction]}
3434
submitLabel="Submit"
3535
/>
36-
<Button
36+
<Component
3737
onClick={[MockFunction]}
3838
type="button"
3939
variant="secondary"
4040
>
4141
Back
42-
</Button>
43-
<Button
42+
</Component>
43+
<Component
4444
onClick={[MockFunction]}
4545
type="button"
4646
variant="link"
4747
>
4848
Cancel
49-
</Button>
49+
</Component>
5050
</footer>
5151
`;

0 commit comments

Comments
 (0)