Skip to content

Commit 78de73c

Browse files
committed
fix(pf3): added clearable option and updated docs.
1 parent d603c34 commit 78de73c

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
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/react-renderer-demo/src/common/examples-definitions.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const baseExamples = [{
159159
title: 'Clearable',
160160
}, {
161161
name: 'simpleValue',
162-
title: 'Simple value'
162+
title: 'Simple value',
163163
}],
164164
},
165165
{
@@ -200,8 +200,25 @@ export const baseExamples = [{
200200
title: 'Label',
201201
component: 'input',
202202
value: 'Date Picker',
203-
},
204-
],
203+
}, {
204+
title: 'Variant',
205+
name: 'variant',
206+
options: [ 'date-time', 'date' ],
207+
}, {
208+
name: 'showTodayButton',
209+
title: 'Show today button',
210+
}, {
211+
name: 'todayButtonLabel',
212+
component: 'input',
213+
value: 'Today',
214+
title: 'Today button label',
215+
}, {
216+
name: 'closeOnDaySelect',
217+
title: 'Close on day select',
218+
}, {
219+
name: 'isClearable',
220+
title: 'Clearable',
221+
}],
205222
},
206223
{
207224
component: componentTypes.TIME_PICKER,

packages/react-renderer-demo/src/docs-components/component-api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,18 @@ All those components provides a shared group of props:
8787

8888
#### Datepicker
8989

90+
This component is using [react-day-picker](https://react-day-picker.js.org/docs/) as a base component.
91+
9092
|Prop|Type|Description|
9193
|----|:--:|----------:|
9294
|placeholder|node/string|A placeholder|
95+
|variant|['date-time', 'date']|variant of date picker|,
96+
|locale|string|Defines date picker locale. See react-day-picker [docs](https://react-day-picker.js.org/docs/localization#moment) for more info |
97+
|todayButtonLabel|string|Label for today button|
98+
|showTodayButton|bool|show/hide today button|
99+
|isDisabled|bool|disable component|
100+
|disabledDays|array|Mark specific days or a range of days as disabled. [More info](https://react-day-picker.js.org/examples/disabled)|
101+
|closeOnDaySelect|bool|Close the calendar popover after selecting date.|
93102

94103
<ExampleLink to='date-picker' />
95104

0 commit comments

Comments
 (0)