@@ -55,132 +55,132 @@ export type JBDateInputProps = {
55
55
}
56
56
57
57
export const JBDateInput = React . forwardRef ( ( props : JBDateInputProps , ref ) => {
58
- const element = useRef < JBDateInputWebComponent > ( null ) ;
59
- const [ refChangeCount , refChangeCountSetter ] = useState ( 0 ) ;
60
- const onFormatChangeCallBackQueueRef = useRef < ( ( ) => void ) [ ] > ( [ ] ) ;
61
- useImperativeHandle (
62
- ref ,
63
- ( ) => ( element ? element . current : { } ) ,
64
- [ element ] ,
65
- ) ;
66
- useEffect ( ( ) => {
67
- refChangeCountSetter ( refChangeCount + 1 ) ;
68
- } , [ element . current ] ) ;
69
- const onchange = useCallback ( ( e :JBDateInputEventType < Event > ) => {
70
- if ( props . onChange ) {
71
- props . onChange ( e ) ;
72
- }
73
- } , [ props . onChange ] ) ;
74
- const onKeyup = useCallback ( ( e :JBDateInputEventType < KeyboardEvent > ) => {
75
- if ( props . onKeyup ) {
76
- props . onKeyup ( e ) ;
77
- }
78
- } , [ props . onKeyup ] ) ;
79
- const onSelect = useCallback ( ( e :JBDateInputEventType < CustomEvent > ) => {
80
- if ( props . onSelect ) {
81
- props . onSelect ( e ) ;
82
- }
83
- } , [ props . onSelect ] ) ;
84
- useEvent ( element . current , 'change' , onchange , true ) ;
85
- useEvent ( element . current , 'keyup' , onKeyup , true ) ;
86
- useEvent ( element . current , 'select' , onSelect , true ) ;
87
- useEffect ( ( ) => {
88
- if ( props . format ) {
89
- if ( props . format !== element . current ?. valueFormat ) {
90
- element . current ?. setAttribute ( 'format' , props . format ) ;
91
- }
92
- if ( onFormatChangeCallBackQueueRef . current . length > 0 ) {
93
- onFormatChangeCallBackQueueRef . current . forEach ( ( callBack :( ) => void ) => {
94
- callBack ( ) ;
95
- } ) ;
96
- onFormatChangeCallBackQueueRef . current = [ ] ;
97
- }
58
+ const element = useRef < JBDateInputWebComponent > ( null ) ;
59
+ const [ refChangeCount , refChangeCountSetter ] = useState ( 0 ) ;
60
+ const onFormatChangeCallBackQueueRef = useRef < ( ( ) => void ) [ ] > ( [ ] ) ;
61
+ useImperativeHandle (
62
+ ref ,
63
+ ( ) => ( element ? element . current : { } ) ,
64
+ [ element ] ,
65
+ ) ;
66
+ useEffect ( ( ) => {
67
+ refChangeCountSetter ( refChangeCount + 1 ) ;
68
+ } , [ element . current ] ) ;
69
+ const onchange = useCallback ( ( e :JBDateInputEventType < Event > ) => {
70
+ if ( props . onChange ) {
71
+ props . onChange ( e ) ;
72
+ }
73
+ } , [ props . onChange ] ) ;
74
+ const onKeyup = useCallback ( ( e :JBDateInputEventType < KeyboardEvent > ) => {
75
+ if ( props . onKeyup ) {
76
+ props . onKeyup ( e ) ;
77
+ }
78
+ } , [ props . onKeyup ] ) ;
79
+ const onSelect = useCallback ( ( e :JBDateInputEventType < CustomEvent > ) => {
80
+ if ( props . onSelect ) {
81
+ props . onSelect ( e ) ;
82
+ }
83
+ } , [ props . onSelect ] ) ;
84
+ useEvent ( element . current , 'change' , onchange , true ) ;
85
+ useEvent ( element . current , 'keyup' , onKeyup , true ) ;
86
+ useEvent ( element . current , 'select' , onSelect , true ) ;
87
+ useEffect ( ( ) => {
88
+ if ( props . format ) {
89
+ if ( props . format !== element . current ?. valueFormat ) {
90
+ element . current ?. setAttribute ( 'format' , props . format ) ;
91
+ }
92
+ if ( onFormatChangeCallBackQueueRef . current . length > 0 ) {
93
+ onFormatChangeCallBackQueueRef . current . forEach ( ( callBack :( ) => void ) => {
94
+ callBack ( ) ;
95
+ } ) ;
96
+ onFormatChangeCallBackQueueRef . current = [ ] ;
97
+ }
98
98
99
- }
100
- } , [ props . format ] ) ;
101
- useEffect ( ( ) => {
102
- if ( props . max ) {
103
- if ( props . format && props . format !== element . current ?. valueFormat ) {
104
- onFormatChangeCallBackQueueRef . current . push ( ( ) => {
105
- if ( props . max ) { element . current ?. setMaxDate ( props . max ) ; }
106
- } ) ;
107
- } else {
108
- element . current ?. setMaxDate ( props . max ) ;
109
- }
110
- }
99
+ }
100
+ } , [ props . format ] ) ;
101
+ useEffect ( ( ) => {
102
+ if ( props . max ) {
103
+ if ( props . format && props . format !== element . current ?. valueFormat ) {
104
+ onFormatChangeCallBackQueueRef . current . push ( ( ) => {
105
+ if ( props . max ) { element . current ?. setMaxDate ( props . max ) ; }
106
+ } ) ;
107
+ } else {
108
+ element . current ?. setMaxDate ( props . max ) ;
109
+ }
110
+ }
111
111
112
- } , [ props . max ] ) ;
113
- useEffect ( ( ) => {
114
- if ( props . min ) {
115
- if ( props . format && props . format !== element . current ?. valueFormat ) {
116
- onFormatChangeCallBackQueueRef . current . push ( ( ) => {
117
- props . min && element . current ?. setMinDate ( props . min ) ;
118
- } ) ;
119
- } else {
120
- element . current ?. setMinDate ( props . min ) ;
121
- }
122
- }
123
- } , [ props . min ] ) ;
124
- useEffect ( ( ) => {
125
- if ( element . current && props . value ) {
126
- element . current . value = props . value ;
127
- }
128
- } , [ props . value ] ) ;
129
- useEffect ( ( ) => {
130
- if ( element . current && Array . isArray ( props . jalaliMonthList ) ) {
131
- element . current . setMonthList ( "JALALI" , props . jalaliMonthList ) ;
132
- }
133
- } , [ props . jalaliMonthList ] ) ;
134
- useEffect ( ( ) => {
135
- if ( element . current && Array . isArray ( props . gregorianMonthList ) ) {
136
- element . current . setMonthList ( "GREGORIAN" , props . gregorianMonthList ) ;
137
- }
138
- } , [ props . gregorianMonthList ] ) ;
139
- useEffect ( ( ) => {
140
- if ( element . current && props . placeholder !== undefined ) {
141
- element . current . placeholder = props . placeholder ;
142
- }
143
- } , [ props . placeholder ] ) ;
144
- useEffect ( ( ) => {
145
- if ( element . current ) {
146
- if ( typeof props . style == "string" ) {
147
- element . current . setAttribute ( "style" , props . style ) ;
148
- }
149
- }
150
- } , [ props . style ] ) ;
151
- useEffect ( ( ) => {
152
- if ( element . current && Array . isArray ( props . validationList ) ) {
153
- element . current . validationList = props . validationList ;
154
- }
155
- } , [ props . validationList ] ) ;
156
- useEffect ( ( ) => {
157
- if ( element . current && props . direction ) {
158
- element . current . setAttribute ( 'direction' , props . direction ) ;
159
- }
160
- } , [ props . direction ] ) ;
161
- useEffect ( ( ) => {
162
- if ( props . required ) {
163
- element . current ?. setAttribute ( 'required' , "true" ) ;
164
- } else {
165
- element . current ?. removeAttribute ( 'required' ) ;
166
- }
167
- } , [ props . required ] ) ;
168
- useEffect ( ( ) => {
169
- if ( typeof props . calendarDefaultDateView == "object" && props . calendarDefaultDateView . year && props . calendarDefaultDateView . month ) {
170
- element . current ?. setCalendarDefaultDateView ( props . calendarDefaultDateView . year , props . calendarDefaultDateView . month , props . calendarDefaultDateView . dateType ) ;
171
- }
172
- } , [ props . calendarDefaultDateView ] ) ;
173
- useEffect ( ( ) => {
174
- if ( props . usePersianNumber ) {
175
- element . current ?. setAttribute ( 'use-persian-number' , 'true' ) ;
176
- } else {
177
- element . current ?. removeAttribute ( 'use-persian-number' ) ;
178
- }
179
- } , [ props . usePersianNumber ] ) ;
180
- return (
181
- < jb-date-input class = { props . className ? props . className : "" } name = { props . name } label = { props . label } value-type = { props . valueType ? props . valueType : 'GREGORIAN' } ref = { element } input-type = { props . inputType ? props . inputType : 'JALALI' } >
182
- { props . children }
183
- </ jb-date-input >
184
- ) ;
112
+ } , [ props . max ] ) ;
113
+ useEffect ( ( ) => {
114
+ if ( props . min ) {
115
+ if ( props . format && props . format !== element . current ?. valueFormat ) {
116
+ onFormatChangeCallBackQueueRef . current . push ( ( ) => {
117
+ props . min && element . current ?. setMinDate ( props . min ) ;
118
+ } ) ;
119
+ } else {
120
+ element . current ?. setMinDate ( props . min ) ;
121
+ }
122
+ }
123
+ } , [ props . min ] ) ;
124
+ useEffect ( ( ) => {
125
+ if ( element . current && props . value ) {
126
+ element . current . value = props . value ;
127
+ }
128
+ } , [ props . value ] ) ;
129
+ useEffect ( ( ) => {
130
+ if ( element . current && Array . isArray ( props . jalaliMonthList ) ) {
131
+ element . current . setMonthList ( "JALALI" , props . jalaliMonthList ) ;
132
+ }
133
+ } , [ props . jalaliMonthList ] ) ;
134
+ useEffect ( ( ) => {
135
+ if ( element . current && Array . isArray ( props . gregorianMonthList ) ) {
136
+ element . current . setMonthList ( "GREGORIAN" , props . gregorianMonthList ) ;
137
+ }
138
+ } , [ props . gregorianMonthList ] ) ;
139
+ useEffect ( ( ) => {
140
+ if ( element . current && props . placeholder !== undefined ) {
141
+ element . current . placeholder = props . placeholder ;
142
+ }
143
+ } , [ props . placeholder ] ) ;
144
+ useEffect ( ( ) => {
145
+ if ( element . current ) {
146
+ if ( typeof props . style == "string" ) {
147
+ element . current . setAttribute ( "style" , props . style ) ;
148
+ }
149
+ }
150
+ } , [ props . style ] ) ;
151
+ useEffect ( ( ) => {
152
+ if ( element . current && Array . isArray ( props . validationList ) ) {
153
+ element . current . validationList = props . validationList ;
154
+ }
155
+ } , [ props . validationList ] ) ;
156
+ useEffect ( ( ) => {
157
+ if ( element . current && props . direction ) {
158
+ element . current . setAttribute ( 'direction' , props . direction ) ;
159
+ }
160
+ } , [ props . direction ] ) ;
161
+ useEffect ( ( ) => {
162
+ if ( props . required ) {
163
+ element . current ?. setAttribute ( 'required' , "true" ) ;
164
+ } else {
165
+ element . current ?. removeAttribute ( 'required' ) ;
166
+ }
167
+ } , [ props . required ] ) ;
168
+ useEffect ( ( ) => {
169
+ if ( typeof props . calendarDefaultDateView == "object" && props . calendarDefaultDateView . year && props . calendarDefaultDateView . month ) {
170
+ element . current ?. setCalendarDefaultDateView ( props . calendarDefaultDateView . year , props . calendarDefaultDateView . month , props . calendarDefaultDateView . dateType ) ;
171
+ }
172
+ } , [ props . calendarDefaultDateView ] ) ;
173
+ useEffect ( ( ) => {
174
+ if ( props . usePersianNumber ) {
175
+ element . current ?. setAttribute ( 'use-persian-number' , 'true' ) ;
176
+ } else {
177
+ element . current ?. removeAttribute ( 'use-persian-number' ) ;
178
+ }
179
+ } , [ props . usePersianNumber ] ) ;
180
+ return (
181
+ < jb-date-input class = { props . className ? props . className : "" } name = { props . name } label = { props . label } value-type = { props . valueType ? props . valueType : 'GREGORIAN' } ref = { element } input-type = { props . inputType ? props . inputType : 'JALALI' } >
182
+ { props . children }
183
+ </ jb-date-input >
184
+ ) ;
185
185
} ) ;
186
186
JBDateInput . displayName = "JBDateInput" ;
0 commit comments