forstok-ui-lib 5.2.44 → 5.2.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +1 -1
- package/dist/index.d.ts +18 -15
- package/dist/index.js +167 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -194
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -10
- package/src/components/date/index.tsx +69 -0
- package/src/components/icon/styles.ts +8 -0
- package/src/components/index.ts +1 -2
- package/src/assets/images/icons/warning copy.svg +0 -5
- package/src/components/date/daterange.css +0 -229
- package/src/components/date/daterange.tsx +0 -284
- package/src/components/date/typed.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forstok-ui-lib",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.46",
|
|
4
4
|
"description": "Forstok UI Components Library",
|
|
5
5
|
"path": "dist",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"@svgr/rollup": "^8.1.0",
|
|
38
38
|
"@types/html-to-text": "^9.0.4",
|
|
39
39
|
"@types/react": "^19.0.2",
|
|
40
|
-
"@types/react-
|
|
40
|
+
"@types/react-datepicker": "^6.2.0",
|
|
41
41
|
"@types/react-dom": "^19.0.2",
|
|
42
42
|
"html-to-text": "^9.0.5",
|
|
43
43
|
"moment-range": "^4.0.2",
|
|
44
44
|
"npm-force-resolutions": "^0.0.10",
|
|
45
45
|
"react": "^19.0.0",
|
|
46
46
|
"react-content-loader": "^7.0.2",
|
|
47
|
-
"react-
|
|
47
|
+
"react-datepicker": "^8.0.0",
|
|
48
48
|
"react-dom": "^19.0.0",
|
|
49
49
|
"react-router-dom": "^7.1.1",
|
|
50
50
|
"react-select": "^5.10.0",
|
|
@@ -58,11 +58,5 @@
|
|
|
58
58
|
"typescript-plugin-styled-components": "^3.0.0",
|
|
59
59
|
"use-state-with-callback": "^3.0.2"
|
|
60
60
|
},
|
|
61
|
-
"overrides": {
|
|
62
|
-
"react-daterange-picker": {
|
|
63
|
-
"moment-range": "^4.0.2",
|
|
64
|
-
"react": "^19.0.0",
|
|
65
|
-
"react-dom": "^19.0.0"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
61
|
+
"overrides": {}
|
|
68
62
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { forwardRef, useState, useEffect } from 'react';
|
|
2
|
+
import DatePicker from 'react-datepicker';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
5
|
+
import './styles.css';
|
|
6
|
+
import { DateContainer, DateIndicatorContainer } from './styles';
|
|
7
|
+
import type { TState } from '../../typeds/base.typed'
|
|
8
|
+
|
|
9
|
+
type TDate = {
|
|
10
|
+
dateFormat?: string
|
|
11
|
+
name: string
|
|
12
|
+
evChange?: (name: string, value: Date | null) => void
|
|
13
|
+
isField?: boolean
|
|
14
|
+
evChangeCustom? : (key: string, value: any) => void
|
|
15
|
+
saveFormat?: string
|
|
16
|
+
showFormat?: string
|
|
17
|
+
isForceUpdate?: boolean
|
|
18
|
+
value?: Date
|
|
19
|
+
isError?: boolean
|
|
20
|
+
allowEmpty?: boolean
|
|
21
|
+
setForceUpdate?: TState<boolean>
|
|
22
|
+
showTimeInput?: boolean
|
|
23
|
+
'data-qa-id'?: string
|
|
24
|
+
'data-tip'?: string
|
|
25
|
+
'data-place'?: string
|
|
26
|
+
'data-type'?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DateComponent = forwardRef(({ dateFormat='MMM dd, yyyy', name, evChange, isField, saveFormat, showFormat, evChangeCustom, value, isForceUpdate, setForceUpdate, isError=false, showTimeInput=false, allowEmpty=false, ...props }:TDate, ref) => {
|
|
30
|
+
const [ _date , setDate ] = useState<Date | null>(value ? value : (allowEmpty ? null : new Date()));
|
|
31
|
+
|
|
32
|
+
const handleChange = (value: Date | null) => {
|
|
33
|
+
setDate(value);
|
|
34
|
+
evChange && evChange(name, value);
|
|
35
|
+
(isField && evChangeCustom) && evChangeCustom(name, value ? moment(value).format(saveFormat) : value);;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (isForceUpdate) {
|
|
40
|
+
const newValue = value ? value : (allowEmpty ? null : new Date());
|
|
41
|
+
setDate(newValue);
|
|
42
|
+
setForceUpdate && setForceUpdate(false);
|
|
43
|
+
}
|
|
44
|
+
}, [isForceUpdate, setForceUpdate, value, allowEmpty])
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<DateContainer $isError={isError} {...props['data-qa-id'] && { 'data-qa-id': props['data-qa-id'] }}>
|
|
48
|
+
<DatePicker
|
|
49
|
+
selected={_date}
|
|
50
|
+
name={name}
|
|
51
|
+
portalId='popup-portal'
|
|
52
|
+
dateFormat={dateFormat}
|
|
53
|
+
onChange={handleChange}
|
|
54
|
+
showTimeInput={showTimeInput}
|
|
55
|
+
onKeyDown={(e) => e.preventDefault()}
|
|
56
|
+
ref={ref as any}
|
|
57
|
+
/>
|
|
58
|
+
{
|
|
59
|
+
(allowEmpty && _date) ? (
|
|
60
|
+
<DateIndicatorContainer onClick={() => handleChange(null)} title='clear'>
|
|
61
|
+
<svg height="20" width="20" viewBox="0 0 20 20" aria-hidden="true" focusable="false"><path d="M14.348 14.849c-0.469 0.469-1.229 0.469-1.697 0l-2.651-3.030-2.651 3.029c-0.469 0.469-1.229 0.469-1.697 0-0.469-0.469-0.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-0.469-0.469-0.469-1.228 0-1.697s1.228-0.469 1.697 0l2.652 3.031 2.651-3.031c0.469-0.469 1.228-0.469 1.697 0s0.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c0.469 0.469 0.469 1.229 0 1.698z"></path></svg>
|
|
62
|
+
</DateIndicatorContainer>
|
|
63
|
+
) : null
|
|
64
|
+
}
|
|
65
|
+
</DateContainer>
|
|
66
|
+
)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
export default DateComponent
|
|
@@ -26,6 +26,7 @@ import IconArrowLeft from '../../assets/images/icons/arrow-left.svg'
|
|
|
26
26
|
import IconArrowLeftDouble from '../../assets/images/icons/arrow-left-double.svg'
|
|
27
27
|
import IconArrowRight from '../../assets/images/icons/arrow-right.svg'
|
|
28
28
|
import IconArrowRightDouble from '../../assets/images/icons/arrow-right-double.svg'
|
|
29
|
+
import IconCalendar from '../../assets/images/icons/calendar.svg'
|
|
29
30
|
|
|
30
31
|
const getIconContainerStyled = ({ $mode, $name, $width, onClick }:{ $mode?: string, $name: string, $width?: string | number, onClick?: (e: MouseEvent<HTMLElement>) => void }) => {
|
|
31
32
|
let style = ``;
|
|
@@ -212,6 +213,13 @@ const getIconContainerStyled = ({ $mode, $name, $width, onClick }:{ $mode?: stri
|
|
|
212
213
|
}
|
|
213
214
|
`
|
|
214
215
|
break
|
|
216
|
+
case 'calendar':
|
|
217
|
+
style += `
|
|
218
|
+
&:before {
|
|
219
|
+
content: url(${IconCalendar});
|
|
220
|
+
}
|
|
221
|
+
`
|
|
222
|
+
break
|
|
215
223
|
default:
|
|
216
224
|
break;
|
|
217
225
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -20,14 +20,13 @@ export { default as UploadComponent } from './upload';
|
|
|
20
20
|
export { default as UploadDragDropComponent } from './upload/drag_drop';
|
|
21
21
|
export { default as TextAreaComponent } from './textarea';
|
|
22
22
|
export { default as TextAreaRefComponent } from './textarea/ref';
|
|
23
|
-
export { default as
|
|
23
|
+
export { default as DateComponent } from './date';
|
|
24
24
|
export { default as DateTimeComponent } from './datetime';
|
|
25
25
|
|
|
26
26
|
export * from './dropdown/typed';
|
|
27
27
|
export * from './message/typed';
|
|
28
28
|
export * from './popup/typed';
|
|
29
29
|
export * from './select/typed';
|
|
30
|
-
export * from './date/typed';
|
|
31
30
|
|
|
32
31
|
export * from './form/styles';
|
|
33
32
|
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<svg width="auto" height="auto" viewBox="0 0 56 56" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<rect x="4" y="4" width="48" height="48" rx="24" fill="#FEE4E2"/>
|
|
3
|
-
<rect x="4" y="4" width="48" height="48" rx="24" stroke="#FEF3F2" stroke-width="8"/>
|
|
4
|
-
<path d="M28 24V28M28 32H28.01M38 28C38 33.5228 33.5228 38 28 38C22.4772 38 18 33.5228 18 28C18 22.4772 22.4772 18 28 18C33.5228 18 38 22.4772 38 28Z" stroke="#D92D20" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
-
</svg>
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
.DateRangePicker {
|
|
2
|
-
display: inline-block;
|
|
3
|
-
margin-bottom: 10px;
|
|
4
|
-
padding: 0;
|
|
5
|
-
position: relative;
|
|
6
|
-
-webkit-user-select: none;
|
|
7
|
-
-moz-user-select: none;
|
|
8
|
-
-ms-user-select: none;
|
|
9
|
-
user-select: none; }
|
|
10
|
-
.DateRangePicker__Legend {
|
|
11
|
-
color: #52575e;
|
|
12
|
-
font-size: 14px;
|
|
13
|
-
line-height: 16px;
|
|
14
|
-
list-style-type: none;
|
|
15
|
-
margin: 20px 0;
|
|
16
|
-
padding: 0; }
|
|
17
|
-
.DateRangePicker__LegendItem {
|
|
18
|
-
display: inline-block;
|
|
19
|
-
margin: 0 20px; }
|
|
20
|
-
.DateRangePicker__LegendItemColor {
|
|
21
|
-
border-radius: 50%;
|
|
22
|
-
display: inline-block;
|
|
23
|
-
height: 14px;
|
|
24
|
-
margin-right: 6px;
|
|
25
|
-
vertical-align: text-bottom;
|
|
26
|
-
width: 14px;
|
|
27
|
-
border: 1px solid rgba(0, 0, 0, 0.25); }
|
|
28
|
-
.DateRangePicker__LegendItemColor--selection {
|
|
29
|
-
background-color: #ed5434; }
|
|
30
|
-
.DateRangePicker__PaginationArrow {
|
|
31
|
-
border: 0;
|
|
32
|
-
cursor: pointer;
|
|
33
|
-
display: block;
|
|
34
|
-
height: 35px;
|
|
35
|
-
outline: none;
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
padding: 0;
|
|
38
|
-
position: absolute;
|
|
39
|
-
text-align: center;
|
|
40
|
-
top: 0;
|
|
41
|
-
white-space: nowrap;
|
|
42
|
-
width: 35px;
|
|
43
|
-
z-index: 1; }
|
|
44
|
-
.DateRangePicker__PaginationArrow--previous {
|
|
45
|
-
left: 20px; }
|
|
46
|
-
.DateRangePicker__PaginationArrow--next {
|
|
47
|
-
right: 20px; }
|
|
48
|
-
.DateRangePicker__PaginationArrow:hover {
|
|
49
|
-
background-color: #ccc; }
|
|
50
|
-
.DateRangePicker__PaginationArrowIcon {
|
|
51
|
-
border-bottom: 8px solid transparent;
|
|
52
|
-
border-top: 8px solid transparent;
|
|
53
|
-
height: 0;
|
|
54
|
-
position: absolute;
|
|
55
|
-
top: 10px;
|
|
56
|
-
width: 0; }
|
|
57
|
-
.DateRangePicker__PaginationArrowIcon--is-disabled {
|
|
58
|
-
opacity: .25; }
|
|
59
|
-
.DateRangePicker__PaginationArrowIcon--previous {
|
|
60
|
-
border-left: 8px solid transparent;
|
|
61
|
-
border-right: 8px solid #aaa;
|
|
62
|
-
right: 11px; }
|
|
63
|
-
.DateRangePicker__PaginationArrowIcon--next {
|
|
64
|
-
border-left: 8px solid #aaa;
|
|
65
|
-
border-right: 8px solid transparent;
|
|
66
|
-
left: 11px; }
|
|
67
|
-
.DateRangePicker__Month {
|
|
68
|
-
color: #333;
|
|
69
|
-
display: inline-block;
|
|
70
|
-
margin: 0 20px;
|
|
71
|
-
position: relative;
|
|
72
|
-
-webkit-user-select: none;
|
|
73
|
-
-moz-user-select: none;
|
|
74
|
-
-ms-user-select: none;
|
|
75
|
-
user-select: none;
|
|
76
|
-
width: 275px; }
|
|
77
|
-
.DateRangePicker__MonthHeader {
|
|
78
|
-
color: #000;
|
|
79
|
-
font-size: 14px;
|
|
80
|
-
font-weight: bold;
|
|
81
|
-
height: 35px;
|
|
82
|
-
line-height: 35px;
|
|
83
|
-
position: relative;
|
|
84
|
-
text-align: center; }
|
|
85
|
-
.DateRangePicker__MonthHeaderLabel {
|
|
86
|
-
display: inline-block;
|
|
87
|
-
position: relative; }
|
|
88
|
-
.DateRangePicker__MonthHeaderSelect {
|
|
89
|
-
background: #e4e4e4;
|
|
90
|
-
border: 0;
|
|
91
|
-
cursor: pointer;
|
|
92
|
-
display: inline-block;
|
|
93
|
-
height: 100%;
|
|
94
|
-
left: 0;
|
|
95
|
-
margin: 0;
|
|
96
|
-
opacity: 0;
|
|
97
|
-
position: absolute;
|
|
98
|
-
top: 0;
|
|
99
|
-
width: 100%;
|
|
100
|
-
z-index: 5; }
|
|
101
|
-
.DateRangePicker__MonthDates {
|
|
102
|
-
border-bottom: 1px solid #f4f5f6;
|
|
103
|
-
border-collapse: separate;
|
|
104
|
-
border-spacing: 0 1px;
|
|
105
|
-
margin: 0;
|
|
106
|
-
width: 100%; }
|
|
107
|
-
.DateRangePicker__WeekdayHeading, .DateRangePicker__Date {
|
|
108
|
-
font-size: 12px;
|
|
109
|
-
line-height: 1;
|
|
110
|
-
padding: 10px 0;
|
|
111
|
-
text-align: center;
|
|
112
|
-
width: 14.285714285714286%; }
|
|
113
|
-
.DateRangePicker__WeekdayHeading {
|
|
114
|
-
border-bottom: 1px solid #f4f5f6;
|
|
115
|
-
color: #000;
|
|
116
|
-
font-weight: bold; }
|
|
117
|
-
.DateRangePicker__WeekdayHeading abbr[title] {
|
|
118
|
-
border-bottom-width: 0;
|
|
119
|
-
color: #000;
|
|
120
|
-
cursor: pointer;
|
|
121
|
-
font-size: inherit;
|
|
122
|
-
text-decoration: none; }
|
|
123
|
-
.DateRangePicker__Date {
|
|
124
|
-
border: 0 solid #f4f5f6;
|
|
125
|
-
border-right-width: 1px;
|
|
126
|
-
cursor: pointer;
|
|
127
|
-
overflow: hidden;
|
|
128
|
-
position: relative; }
|
|
129
|
-
.DateRangePicker__Date:first-child {
|
|
130
|
-
border-left-width: 1px; }
|
|
131
|
-
.DateRangePicker__Date--weekend {
|
|
132
|
-
background-color: #f6f7f9; }
|
|
133
|
-
.DateRangePicker__Date--otherMonth {
|
|
134
|
-
opacity: .25; }
|
|
135
|
-
.DateRangePicker__Date--is-disabled {
|
|
136
|
-
color: #cdcdd1;
|
|
137
|
-
cursor: default; }
|
|
138
|
-
.DateRangePicker__Date--is-selected {
|
|
139
|
-
color: #fff; }
|
|
140
|
-
.DateRangePicker__Date--is-highlighted {
|
|
141
|
-
color: #333; }
|
|
142
|
-
.DateRangePicker__CalendarDatePeriod {
|
|
143
|
-
bottom: 0;
|
|
144
|
-
position: absolute;
|
|
145
|
-
top: 0; }
|
|
146
|
-
.DateRangePicker__CalendarDatePeriod--am {
|
|
147
|
-
left: 0;
|
|
148
|
-
right: 50%; }
|
|
149
|
-
.DateRangePicker__CalendarDatePeriod--pm {
|
|
150
|
-
left: 50%;
|
|
151
|
-
right: 0; }
|
|
152
|
-
.DateRangePicker__CalendarSelection {
|
|
153
|
-
background-color: #ed5434;
|
|
154
|
-
border: 1px solid #eb401d;
|
|
155
|
-
bottom: 5px;
|
|
156
|
-
left: 0;
|
|
157
|
-
position: absolute;
|
|
158
|
-
right: 0;
|
|
159
|
-
top: 5px; }
|
|
160
|
-
.DateRangePicker__CalendarSelection--inOtherMonth {
|
|
161
|
-
opacity: .5; }
|
|
162
|
-
.DateRangePicker__CalendarSelection--start {
|
|
163
|
-
border-bottom-left-radius: 5px;
|
|
164
|
-
border-right-width: 0;
|
|
165
|
-
border-top-left-radius: 5px;
|
|
166
|
-
left: 5px; }
|
|
167
|
-
.DateRangePicker__CalendarSelection--end {
|
|
168
|
-
border-bottom-right-radius: 5px;
|
|
169
|
-
border-left-width: 0;
|
|
170
|
-
border-top-right-radius: 5px;
|
|
171
|
-
right: 5px; }
|
|
172
|
-
.DateRangePicker__CalendarSelection--segment {
|
|
173
|
-
border-left-width: 0;
|
|
174
|
-
border-right-width: 0; }
|
|
175
|
-
.DateRangePicker__CalendarSelection--single {
|
|
176
|
-
border-radius: 5px;
|
|
177
|
-
left: 5px;
|
|
178
|
-
right: 5px; }
|
|
179
|
-
.DateRangePicker__CalendarSelection--is-pending {
|
|
180
|
-
background-color: rgba(237, 84, 52, 0.75);
|
|
181
|
-
border-width: 0; }
|
|
182
|
-
.DateRangePicker__CalendarHighlight {
|
|
183
|
-
background-color: rgba(255, 255, 255, 0.25);
|
|
184
|
-
border: 1px solid rgba(0, 0, 0, 0.25);
|
|
185
|
-
bottom: 5px;
|
|
186
|
-
left: 0;
|
|
187
|
-
position: absolute;
|
|
188
|
-
right: 0;
|
|
189
|
-
top: 5px; }
|
|
190
|
-
.DateRangePicker__CalendarHighlight--inOtherMonth {
|
|
191
|
-
opacity: .5; }
|
|
192
|
-
.DateRangePicker__CalendarHighlight--start {
|
|
193
|
-
border-bottom-left-radius: 5px;
|
|
194
|
-
border-right-width: 0;
|
|
195
|
-
border-top-left-radius: 5px;
|
|
196
|
-
left: 5px; }
|
|
197
|
-
.DateRangePicker__CalendarHighlight--end {
|
|
198
|
-
border-bottom-right-radius: 5px;
|
|
199
|
-
border-left-width: 0;
|
|
200
|
-
border-top-right-radius: 5px;
|
|
201
|
-
right: 5px; }
|
|
202
|
-
.DateRangePicker__CalendarHighlight--segment {
|
|
203
|
-
border-left-width: 0;
|
|
204
|
-
border-right-width: 0; }
|
|
205
|
-
.DateRangePicker__CalendarHighlight--single {
|
|
206
|
-
background-color: #fff;
|
|
207
|
-
border: 1px solid #eb401d;
|
|
208
|
-
border-radius: 5px;
|
|
209
|
-
left: 5px;
|
|
210
|
-
right: 5px; }
|
|
211
|
-
.DateRangePicker__HalfDateStates {
|
|
212
|
-
bottom: -50px;
|
|
213
|
-
left: -50px;
|
|
214
|
-
position: absolute;
|
|
215
|
-
right: -50px;
|
|
216
|
-
top: -50px;
|
|
217
|
-
transform: rotate(30deg); }
|
|
218
|
-
.DateRangePicker__FullDateStates {
|
|
219
|
-
bottom: 0;
|
|
220
|
-
left: 0;
|
|
221
|
-
position: absolute;
|
|
222
|
-
right: 0;
|
|
223
|
-
top: 0; }
|
|
224
|
-
.DateRangePicker__DateLabel {
|
|
225
|
-
display: block;
|
|
226
|
-
position: relative;
|
|
227
|
-
text-align: center;
|
|
228
|
-
width: 100%;
|
|
229
|
-
z-index: 1; }
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState, useRef } from 'react';
|
|
2
|
-
import DateRangePicker from 'react-daterange-picker';
|
|
3
|
-
import moment from 'moment';
|
|
4
|
-
import { extendMoment } from 'moment-range';
|
|
5
|
-
import { configDateRange } from '../../maps/common';
|
|
6
|
-
import IconComponent from '../icon';
|
|
7
|
-
import ButtonComponent from '../button';
|
|
8
|
-
import CheckboxComponent from '../checkbox';
|
|
9
|
-
import ReactPortalComponent from '../portal';
|
|
10
|
-
import TextComponent from '../text';
|
|
11
|
-
import { dateRangeDays, dateRangeStatus } from '../../assets/javascripts/helper';
|
|
12
|
-
import './daterange.css';
|
|
13
|
-
import './styles.css';
|
|
14
|
-
import { DateRangeContainer, DateRangeControl, DateRangeLabelContainer, DateRangeLabel, DateRangeIndicatorsContainer, DateRangeIndicatorsArrowIconSvg, DateRangeMenuContainer, DateRangeMenu, DateRangeSelection, SelectionDate, DateRangeAside, DateRangePortalContainer, DateRangeIconContainer } from './styles';
|
|
15
|
-
import type { TMouseEvent, TState } from '../../typeds';
|
|
16
|
-
import type { TModerateDateFunction } from './typed';
|
|
17
|
-
|
|
18
|
-
type TDateRange = {
|
|
19
|
-
mode: string
|
|
20
|
-
placeholder?: string
|
|
21
|
-
startDate?: string | null
|
|
22
|
-
endDate?: string | null
|
|
23
|
-
rangeDate?: string
|
|
24
|
-
minDate?: string
|
|
25
|
-
evModDate: TModerateDateFunction
|
|
26
|
-
portalId?: string
|
|
27
|
-
isForceUpdate?: boolean
|
|
28
|
-
setForceUpdate?: TState<boolean>
|
|
29
|
-
isCheckType?: boolean
|
|
30
|
-
size?: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const DateRangeComponent = ({ mode='default', placeholder, startDate, endDate, rangeDate, minDate, evModDate, portalId, isForceUpdate, setForceUpdate, isCheckType, size }: TDateRange) => {
|
|
34
|
-
const _placeholder = placeholder || configDateRange.placeholder;
|
|
35
|
-
const _rangeDate = rangeDate || configDateRange.rangeDate;
|
|
36
|
-
const _startDate = startDate || configDateRange.startDate;
|
|
37
|
-
const _endDate = endDate || configDateRange.endDate;
|
|
38
|
-
const _minDate = minDate || configDateRange.minDate;
|
|
39
|
-
|
|
40
|
-
const [isOpen, setOpen] = useState<boolean>(false) ;
|
|
41
|
-
const [offsetLeft, setOffsetLeft] = useState<number>(0);
|
|
42
|
-
const [isLoadOffsetLeft, setLoadOffsetLeft] = useState<boolean>(false);
|
|
43
|
-
const [startDateSelected, setStartDateSelected] = useState<string>(_startDate);
|
|
44
|
-
const [endDateSelected, setEndDateSelected] = useState<string>(_endDate);
|
|
45
|
-
const [rangeDateSelected, setRangeDateSelected] = useState<string>(_rangeDate);
|
|
46
|
-
|
|
47
|
-
const daterangeContainerRef = useRef<HTMLElement | null>(null);
|
|
48
|
-
const buttonRef = useRef<HTMLDivElement | null>(null);
|
|
49
|
-
const newMoment = extendMoment(moment as any);
|
|
50
|
-
|
|
51
|
-
const callback = () => {
|
|
52
|
-
setOpen(false);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (offsetLeft && mode === 'filter' && isLoadOffsetLeft) {
|
|
57
|
-
const _offsetLeft = daterangeContainerRef.current && daterangeContainerRef.current ? daterangeContainerRef.current.getBoundingClientRect().x : 0;
|
|
58
|
-
setOffsetLeft(_offsetLeft);
|
|
59
|
-
setLoadOffsetLeft(true);
|
|
60
|
-
}
|
|
61
|
-
if (isForceUpdate) {
|
|
62
|
-
_startDate && setStartDateSelected(_startDate);
|
|
63
|
-
_endDate && setEndDateSelected(_endDate);
|
|
64
|
-
_rangeDate && setRangeDateSelected(_rangeDate);
|
|
65
|
-
setForceUpdate && setForceUpdate(false);
|
|
66
|
-
}
|
|
67
|
-
},[offsetLeft, isLoadOffsetLeft, mode, isForceUpdate, setForceUpdate, _startDate, _endDate, _rangeDate])
|
|
68
|
-
|
|
69
|
-
const evResetFilter = () => {
|
|
70
|
-
setStartDateSelected(_startDate || '');
|
|
71
|
-
setEndDateSelected(_endDate || '');
|
|
72
|
-
setRangeDateSelected(_rangeDate || '');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const evToogleDateRangePicker: TMouseEvent = e => {
|
|
76
|
-
const refEl = (buttonRef && buttonRef.current) ? buttonRef.current : null;
|
|
77
|
-
const buttonEl = refEl && (e.target as HTMLDivElement).closest(`.${refEl.classList[0]}`) as HTMLDivElement;
|
|
78
|
-
if (!buttonEl) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const containerEl = buttonEl.closest('._refContainer') as HTMLElement;
|
|
82
|
-
const isCurOpen = containerEl.classList.contains('is-shown');
|
|
83
|
-
const offsetPos = containerEl.getBoundingClientRect();
|
|
84
|
-
if (!isCurOpen) {
|
|
85
|
-
const containerRef = document.getElementsByClassName('_refContainer is-shown') as HTMLCollectionOf<HTMLElement>;
|
|
86
|
-
if (containerRef.length) {
|
|
87
|
-
for (var i = 0; i < containerRef.length; i++) {
|
|
88
|
-
containerRef[i].classList.remove('is-shown');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
setTimeout(() => {
|
|
92
|
-
if (portalId) {
|
|
93
|
-
const portalContainerRef = document.getElementsByClassName('._refDateRangePickerPortal is-shown') as HTMLCollectionOf<HTMLElement>;
|
|
94
|
-
if (portalContainerRef.length) {
|
|
95
|
-
for (var i = 0; i < portalContainerRef.length; i++) {
|
|
96
|
-
portalContainerRef[i].classList.remove('is-shown');
|
|
97
|
-
portalContainerRef[i].style.left = '0';
|
|
98
|
-
portalContainerRef[i].style.top = '0';
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
},10)
|
|
103
|
-
}
|
|
104
|
-
setOpen(!isCurOpen);
|
|
105
|
-
if (!isCurOpen) {
|
|
106
|
-
evResetFilter();
|
|
107
|
-
containerEl && containerEl.classList.add('is-shown');
|
|
108
|
-
setTimeout(() => {
|
|
109
|
-
if (portalId) {
|
|
110
|
-
const portalContainerRef = document.querySelector('._refDateRangePickerPortal') as HTMLDivElement;
|
|
111
|
-
if (portalContainerRef) {
|
|
112
|
-
if (offsetPos) {
|
|
113
|
-
portalContainerRef.style.left = offsetPos.left + 'px';
|
|
114
|
-
portalContainerRef.style.top = (offsetPos.top + offsetPos.height) + 'px';
|
|
115
|
-
}
|
|
116
|
-
portalContainerRef.classList.add('is-shown');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}, 10)
|
|
120
|
-
} else {
|
|
121
|
-
containerEl && containerEl.classList.remove('is-shown');
|
|
122
|
-
setTimeout(() => {
|
|
123
|
-
if (portalId) {
|
|
124
|
-
const portalContainerRef = document.querySelector('._refDateRangePickerPortal') as HTMLDivElement;
|
|
125
|
-
if (portalContainerRef) {
|
|
126
|
-
portalContainerRef.classList.remove('is-shown');
|
|
127
|
-
portalContainerRef.style.left = '0';
|
|
128
|
-
portalContainerRef.style.top = '0';
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}, 10)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const handleSelect = (value: any) => {
|
|
136
|
-
const startDate: string = value.start.format('YYYY-MM-DD');
|
|
137
|
-
const endDate: string = value.end.format('YYYY-MM-DD');
|
|
138
|
-
setStartDateSelected(startDate);
|
|
139
|
-
setEndDateSelected(endDate);
|
|
140
|
-
setRangeDateSelected('custom');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const evApplyDateRange = () => {
|
|
144
|
-
let _start_date = '';
|
|
145
|
-
let _end_date = '';
|
|
146
|
-
if (startDateSelected && endDateSelected) {
|
|
147
|
-
_start_date = startDateSelected;
|
|
148
|
-
_end_date = endDateSelected;
|
|
149
|
-
} else if (_rangeDate) {
|
|
150
|
-
_start_date = newMoment().clone().subtract(dateRangeDays(_rangeDate), 'days').format('YYYY-MM-DD');
|
|
151
|
-
_end_date = newMoment().clone().format('YYYY-MM-DD');
|
|
152
|
-
} else if (_startDate && _endDate ) {
|
|
153
|
-
_start_date = _startDate;
|
|
154
|
-
_end_date = _endDate;
|
|
155
|
-
}
|
|
156
|
-
evModDate(_start_date, _end_date, 'custom', callback);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const evCancelDateRange = () => {
|
|
160
|
-
setOpen(false);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const setRange: TMouseEvent = e => {
|
|
164
|
-
const type = (e.target as HTMLDivElement).dataset.type || '';
|
|
165
|
-
let startDate: string = '';
|
|
166
|
-
let endDate: string = newMoment().clone().format('YYYY-MM-DD');
|
|
167
|
-
switch (type) {
|
|
168
|
-
case 'today':
|
|
169
|
-
startDate= newMoment().clone().format('YYYY-MM-DD');
|
|
170
|
-
break;
|
|
171
|
-
case 'lastweek':
|
|
172
|
-
startDate= newMoment().clone().subtract(6, 'days').format('YYYY-MM-DD');
|
|
173
|
-
break;
|
|
174
|
-
case 'lastsecondweek':
|
|
175
|
-
startDate= newMoment().clone().subtract(13, 'days').format('YYYY-MM-DD');
|
|
176
|
-
break;
|
|
177
|
-
case 'lastmonth':
|
|
178
|
-
startDate= newMoment().clone().subtract(29, 'days').format('YYYY-MM-DD');
|
|
179
|
-
break;
|
|
180
|
-
case 'lastquart':
|
|
181
|
-
startDate= newMoment().clone().subtract(89, 'days').format('YYYY-MM-DD');
|
|
182
|
-
break;
|
|
183
|
-
case 'custom':
|
|
184
|
-
startDate = '';
|
|
185
|
-
endDate= '';
|
|
186
|
-
break
|
|
187
|
-
default:
|
|
188
|
-
startDate = '';
|
|
189
|
-
endDate= '';
|
|
190
|
-
break
|
|
191
|
-
}
|
|
192
|
-
setStartDateSelected(startDate);
|
|
193
|
-
setEndDateSelected(endDate);
|
|
194
|
-
setRangeDateSelected(type);
|
|
195
|
-
evModDate(startDate, endDate, type, callback);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const startDateMoment: moment.Moment = newMoment(_startDate, 'YYYY-MM-DD');
|
|
199
|
-
const endDateMoment: moment.Moment = newMoment(_endDate, 'YYYY-MM-DD');
|
|
200
|
-
const _minDateMoment: string = newMoment(_minDate, 'YYYY-MM-DD').format('YYYY-MM-DD');
|
|
201
|
-
const startDateSelectedMoment: moment.Moment = newMoment(startDateSelected, 'YYYY-MM-DD').startOf('day');
|
|
202
|
-
const endDateSelectedMoment: moment.Moment = newMoment(endDateSelected, 'YYYY-MM-DD').endOf('day');
|
|
203
|
-
const minDateMoment: Date | null = _minDate ? new Date(_minDateMoment) : null;
|
|
204
|
-
const openClass = isOpen ? 'is-shown' : ''
|
|
205
|
-
|
|
206
|
-
let value;
|
|
207
|
-
if (startDateSelected && endDateSelected) {
|
|
208
|
-
value = newMoment.range(startDateSelectedMoment, endDateSelectedMoment);
|
|
209
|
-
} else if (_startDate && _endDate) {
|
|
210
|
-
value = newMoment.range(newMoment(_startDate, 'YYYY-MM-DD').startOf('day'), newMoment(_endDate, 'YYYY-MM-DD').endOf('day'));
|
|
211
|
-
} else if (_rangeDate) {
|
|
212
|
-
value = newMoment.range(newMoment().clone().subtract(dateRangeDays(_rangeDate), 'days').startOf('day'), newMoment().clone().endOf('day'));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const dateRangeEl = (
|
|
216
|
-
<DateRangeMenuContainer $mode={mode} style={{ 'left': '-'+offsetLeft+'px' }}>
|
|
217
|
-
<DateRangeMenu>
|
|
218
|
-
<DateRangeSelection>
|
|
219
|
-
<SelectionDate data-type='today' $activated={rangeDateSelected === 'today'} onClick={setRange} data-qa-id='daterange-picker-today'>Today</SelectionDate>
|
|
220
|
-
<SelectionDate data-type='lastweek' $activated={rangeDateSelected === 'lastweek'} onClick={setRange} data-qa-id='daterange-picker-7d'>Last 7 days</SelectionDate>
|
|
221
|
-
<SelectionDate data-type='lastsecondweek' $activated={rangeDateSelected === 'lastsecondweek'} onClick={setRange} data-qa-id='daterange-picker-14d'>Last 14 days</SelectionDate>
|
|
222
|
-
<SelectionDate data-type='lastmonth' $activated={rangeDateSelected === 'lastmonth'} onClick={setRange} data-qa-id='daterange-picker-30d'>Last 30 days</SelectionDate>
|
|
223
|
-
<SelectionDate data-type='lastquart' $activated={rangeDateSelected === 'lastquart'} onClick={setRange} data-qa-id='daterange-picker-90d'>Last 90 days</SelectionDate>
|
|
224
|
-
<SelectionDate data-type='custom' $activated={rangeDateSelected === 'custom'} data-qa-id='daterange-picker-custom'>Custom Range</SelectionDate>
|
|
225
|
-
</DateRangeSelection>
|
|
226
|
-
<DateRangePicker
|
|
227
|
-
bemNamespace='DateRangePicker'
|
|
228
|
-
numberOfCalendars={2}
|
|
229
|
-
onSelect={handleSelect}
|
|
230
|
-
selectionType='range'
|
|
231
|
-
maximumDate={new Date()}
|
|
232
|
-
value={value}
|
|
233
|
-
initialMonth={newMoment().add(-1, 'month').month()}
|
|
234
|
-
initialYear={newMoment().add(0, 'year').year()}
|
|
235
|
-
singleDateRange={true}
|
|
236
|
-
{...minDateMoment && { minimumDate: minDateMoment }}
|
|
237
|
-
/>
|
|
238
|
-
</DateRangeMenu>
|
|
239
|
-
<DateRangeAside>
|
|
240
|
-
<TextComponent>{startDateSelected && endDateSelected ? startDateSelectedMoment.format('LL') +' - '+ endDateSelectedMoment.format('LL') : ' '}</TextComponent>
|
|
241
|
-
<div>
|
|
242
|
-
<ButtonComponent $mode='white' $size='small' onClick={evCancelDateRange} data-qa-id='daterange-picker-cancel'>Cancel</ButtonComponent>
|
|
243
|
-
<ButtonComponent $mode='red' $size='small' onClick={evApplyDateRange} data-qa-id='daterange-picker-apply'>Apply</ButtonComponent>
|
|
244
|
-
</div>
|
|
245
|
-
</DateRangeAside>
|
|
246
|
-
</DateRangeMenuContainer>
|
|
247
|
-
)
|
|
248
|
-
|
|
249
|
-
return (
|
|
250
|
-
<DateRangeContainer className={'_refContainer '+ openClass} $mode={mode} ref={daterangeContainerRef} data-qa-id='daterange-picker'>
|
|
251
|
-
<DateRangeControl ref={buttonRef} onClick={evToogleDateRangePicker} $mode={mode} $size={size}>
|
|
252
|
-
{
|
|
253
|
-
mode === 'filterorder' || mode === 'filterordertofulfill' || mode === 'filterdashboard' ? (
|
|
254
|
-
<ButtonComponent $iconLeft='calendar' $mode='nude' $isIndicatorArrow={true} isIndicatorArrowColor='#494949'>{ (_startDate && _endDate && _rangeDate === 'custom') ? (startDateMoment.format('MMM D, YYYY') + ' - ' +endDateMoment.format('MMM D, YYYY')) : (_rangeDate ? dateRangeStatus(_rangeDate) : _placeholder) }</ButtonComponent>
|
|
255
|
-
) : (
|
|
256
|
-
<>
|
|
257
|
-
{ mode === 'filter' ? <CheckboxComponent name='checkbox-date' id='checkbox-date' className='_refCheckboxContainer' defaultChecked={isCheckType} disabled={true} /> : null }
|
|
258
|
-
{
|
|
259
|
-
mode === 'popuppayment' ? (
|
|
260
|
-
<DateRangeIconContainer>
|
|
261
|
-
<IconComponent $name='calendar' $width='14px' />
|
|
262
|
-
</DateRangeIconContainer>
|
|
263
|
-
) : null
|
|
264
|
-
}
|
|
265
|
-
<DateRangeLabelContainer>
|
|
266
|
-
<DateRangeLabel $size={size}>
|
|
267
|
-
{ (_startDate && _endDate && _rangeDate === 'custom') ? (startDateMoment.format('LL') + ' - ' +endDateMoment.format('LL')) : (_rangeDate ? dateRangeStatus(_rangeDate) : _placeholder) }
|
|
268
|
-
</DateRangeLabel>
|
|
269
|
-
</DateRangeLabelContainer>
|
|
270
|
-
<DateRangeIndicatorsContainer>
|
|
271
|
-
<DateRangeIndicatorsArrowIconSvg height='20' width='20' viewBox='0 0 20 20' aria-hidden='true' focusable='false'>
|
|
272
|
-
<path d='M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z'></path>
|
|
273
|
-
</DateRangeIndicatorsArrowIconSvg>
|
|
274
|
-
</DateRangeIndicatorsContainer>
|
|
275
|
-
</>
|
|
276
|
-
)
|
|
277
|
-
}
|
|
278
|
-
</DateRangeControl>
|
|
279
|
-
{ isOpen && ( portalId ? <ReactPortalComponent><DateRangePortalContainer className='_refDateRangePickerPortal'>{dateRangeEl}</DateRangePortalContainer></ReactPortalComponent> : dateRangeEl ) }
|
|
280
|
-
</DateRangeContainer>
|
|
281
|
-
)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export default DateRangeComponent
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type TModerateDateFunction = (startDateObj: string, endDateObj: string, rangeDateObj: string, callback: () => void) => void;
|