Skip to content

Commit

Permalink
add date value
Browse files Browse the repository at this point in the history
  • Loading branch information
javadbat committed Oct 20, 2023
1 parent f23d5aa commit bde3af2
Show file tree
Hide file tree
Showing 3 changed files with 36 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.2.0] - 2023-10-20
### new features
- add support for `Date` type value
## [2.1.1] - 2023-10-17
### fixed
- fix value PropType to accept `null` value type
Expand Down
54 changes: 31 additions & 23 deletions lib/JBDateInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState, useImperativeHandle, useCallback, DOMAttributes } from 'react';
import PropTypes from 'prop-types';
// import PropTypes from 'prop-types';
// import {type} from 'jb-date-input';
import 'jb-date-input';
// eslint-disable-next-line no-duplicate-imports
Expand Down Expand Up @@ -33,6 +33,7 @@ export type JBDateInputEventType<T> = T & {
}
export type JBDateInputProps = {
label?: string,
style?:string,
name?:string,
min?: string,
max?: string,
Expand All @@ -44,7 +45,7 @@ export type JBDateInputProps = {
valueType?: 'GREGORIAN'|'JALALI'|'TIME_STAMP',
inputType?: 'GREGORIAN'|'JALALI',
direction?: 'ltr'|'rtl',
value: string | null | undefined,
value: string | Date | null | undefined,
validationList?: JBDateInputValidationItem[],
required?: boolean,
calendarDefaultDateView?:{ year:number, month: number, dateType:JBDateInputInputTypes},
Expand Down Expand Up @@ -124,6 +125,13 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
element.current.value = props.value;
}
}, [props.value]);
useEffect(() => {
if (element.current) {
if(typeof props.style == "string"){
element.current.setAttribute("style",props.style);
}
}
}, [props.style]);
useEffect(() => {
if (element.current && Array.isArray(props.validationList)) {
element.current.validationList = props.validationList;
Expand Down Expand Up @@ -160,24 +168,24 @@ 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
};
// 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.1.1",
"version": "2.2.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.7.13"
"jb-date-input": ">=3.9.0"
}
}

0 comments on commit bde3af2

Please sign in to comment.