Skip to content

Commit

Permalink
docs(DatePickerInput): add missing prop types (#5396)
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod authored Feb 20, 2020
1 parent 196a800 commit 2ed888f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/DatePicker/DatePicker-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const datePickerOnChangeActions = decorateAction([
]);

const patterns = {
'Short (d{1,2}/d{4})': 'd{1,2}/d{4}',
'Regular (d{1,2}/d{1,2}/d{4})': 'd{1,2}/d{1,2}/d{4}',
'Short (d{1,2}/d{4})': '\\d{1,2}/\\d{4}',
'Regular (d{1,2}/d{1,2}/d{4})': '\\d{1,2}/\\d{1,2}/\\d{4}',
};

const props = {
Expand Down
42 changes: 42 additions & 0 deletions packages/react/src/components/DatePickerInput/DatePickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,48 @@ export default class DatePickerInput extends Component {
* control
*/
labelText: PropTypes.node.isRequired,

/**
* Provide a regular expression that the input value must match
*/
pattern: (props, propName, componentName) => {
if (props[propName] === undefined) {
return;
}
try {
new RegExp(props[propName]);
} catch (e) {
return new Error(
`Invalid value of prop '${propName}' supplied to '${componentName}', it should be a valid regular expression`
);
}
},

/**
* Specify the type of the <input>
*/
type: PropTypes.string,

/**
* Specify whether or not the input should be disabled
*/
disabled: PropTypes.bool,

/**
* Specify whether or not the input should be invalid
*/
invalid: PropTypes.bool,

/**
* Provide a function to be called when the input field is clicked
*/
onClick: PropTypes.func,

/**
* Specify an `onChange` handler that is called whenever a change in the
* input field has occurred
*/
onChange: PropTypes.func,
};

static defaultProps = {
Expand Down

0 comments on commit 2ed888f

Please sign in to comment.