Skip to content

Commit

Permalink
add placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
javadbat committed Nov 12, 2023
1 parent 90ae271 commit c12f5bd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#changelog
## [2.3.0] - 2023-11-12
### new features
- add placeholder support when input is empty
## [2.2.0] - 2023-10-20
### new features
- add support for `Date` type value
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ you can set minimum date and maximum date range for your app
<JBDateInput label="تاریخ شروع " value="2020-08-10T08:51:23.176Z" min="2020-08-05T08:51:23.176Z" max="2020-08-15T08:51:23.176Z">
</JBDateInput>
```
## placeholder

you can set placeholder to show it to user when input is empty. to doing so just set `placeholder` attribute in JSX DOM:

```jsx
<JBDateInput placeholder="Enter Date Here">
</JBDateInput>
```
## custom validation

beside of min and max you can also set your own custom validation like any other jb react components family to achive this you must create a array of validations and pass it to validationList props.
Expand Down
29 changes: 6 additions & 23 deletions lib/JBDateInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { useEffect, useRef, useState, useImperativeHandle, useCallback, DOMAttributes } from 'react';
// import PropTypes from 'prop-types';
// import {type} from 'jb-date-input';
import 'jb-date-input';
// eslint-disable-next-line no-duplicate-imports
import { JBDateInputWebComponent, JBDateInputInputTypes, JBDateInputValidationItem, JBDDateInputInboxElementWebComponent,JBDateInputValueObject } from 'jb-date-input';
Expand Down Expand Up @@ -50,6 +48,7 @@ export type JBDateInputProps = {
required?: boolean,
calendarDefaultDateView?:{ year:number, month: number, dateType:JBDateInputInputTypes},
usePersianNumber?: boolean,
placeholder:string | null | undefined,
children?:any,
}

Expand Down Expand Up @@ -125,6 +124,11 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
element.current.value = props.value;
}
}, [props.value]);
useEffect(() => {
if (element.current && props.placeholder !== undefined) {
element.current.placeholder = props.placeholder;
}
}, [props.placeholder]);
useEffect(() => {
if (element.current) {
if(typeof props.style == "string"){
Expand Down Expand Up @@ -168,24 +172,3 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
);
});
JBDateInput.displayName = "JBDateInput";
// JBDateInput.propTypes = {
// label: PropTypes.string,
// name:PropTypes.string,
// className:PropTypes.string,
// min: PropTypes.string,
// max: PropTypes.string,
// format: PropTypes.string,
// onKeyup: PropTypes.func,
// onChange: PropTypes.func,
// onSelect: PropTypes.func,
// valueType: PropTypes.oneOf(['GREGORIAN', 'JALALI', 'TIME_STAMP']),
// inputType: PropTypes.oneOf(['GREGORIAN', 'JALALI']),
// direction: PropTypes.oneOf(['ltr', 'rtl']),
// value: PropTypes.string,
// validationList: PropTypes.array,
// required: PropTypes.bool,
// calendarDefaultDateView: PropTypes.shape({ year: PropTypes.number.isRequired, month: PropTypes.number.isRequired, dateType: PropTypes.oneOf<JBDateInputInputTypes>([JBDateInputInputTypes.gregorian, JBDateInputInputTypes.jalali]).isRequired }),
// // calendarDefaultDateView: PropTypes.object,
// usePersianNumber: PropTypes.bool,
// // children:PropTypes.element
// };
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react component",
"react"
],
"version": "2.2.0",
"version": "2.3.0",
"bugs": "https://github.com/javadbat/jb-date-input-react/issues",
"license": "MIT",
"files": [
Expand All @@ -36,6 +36,6 @@
"url": "https://github.com/javadbat/jb-date-input-react"
},
"dependencies": {
"jb-date-input": ">=3.9.0"
"jb-date-input": ">=3.10.0"
}
}

0 comments on commit c12f5bd

Please sign in to comment.