kahuna-base-react-components 1.4.3 → 1.4.4

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/types.d.ts CHANGED
@@ -348,6 +348,7 @@ interface KSelectRangeDateProps {
348
348
  hideBackdrop?: boolean;
349
349
  weeklyMode?: boolean;
350
350
  shorthandEndDateOffsetDays?: number;
351
+ weeklyModeStartDay?: number;
351
352
  }
352
353
  type DateRangeType = Date | null | [Date | null, Date | null];
353
354
  declare const KSelectRangeDate: React.FC<KSelectRangeDateProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahuna-base-react-components",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -94,6 +94,7 @@ KSelectRangeWeekly.args = {
94
94
  hideBackdrop: true,
95
95
  anchorToButton: true,
96
96
  weeklyMode: true,
97
+ weeklyModeStartDay: 5,
97
98
 
98
99
  onChange: (value) => {
99
100
  if (value) {
@@ -33,6 +33,7 @@ export interface KSelectRangeDateProps {
33
33
  hideBackdrop?: boolean
34
34
  weeklyMode?: boolean
35
35
  shorthandEndDateOffsetDays?: number
36
+ weeklyModeStartDay?: number // Day the weekly range should start from (0=Sun...6=Sat); defaults to a rolling 7-day range if unset.
36
37
  }
37
38
 
38
39
  export type DateRangeType = Date | null | [Date | null, Date | null]
@@ -125,9 +126,25 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
125
126
 
126
127
  if (props.weeklyMode) {
127
128
  const DAY = 24 * 60 * 60 * 1000
128
-
129
- const endDate = clickedDate
130
- const startDate = new Date(clickedDate.getTime() - 6 * DAY)
129
+ let startDate: Date
130
+ let endDate: Date
131
+
132
+ if (props.weeklyModeStartDay !== undefined) {
133
+ const startDay = props.weeklyModeStartDay
134
+ const dayOfWeek = clickedDate.getDay()
135
+ const daysSinceStart = (dayOfWeek - startDay + 7) % 7
136
+
137
+ startDate = new Date(clickedDate)
138
+ startDate.setDate(clickedDate.getDate() - daysSinceStart)
139
+ startDate.setHours(0, 0, 0, 0)
140
+
141
+ endDate = new Date(startDate)
142
+ endDate.setDate(startDate.getDate() + 6)
143
+ endDate.setHours(0, 0, 0, 0)
144
+ } else {
145
+ endDate = clickedDate
146
+ startDate = new Date(clickedDate.getTime() - 6 * DAY)
147
+ }
131
148
 
132
149
  setRange([startDate, endDate])
133
150
  skipNextOpenRef.current = true
@@ -214,8 +231,29 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
214
231
 
215
232
  if (hoveredDate && props.weeklyMode) {
216
233
  const DAY = 24 * 60 * 60 * 1000
217
- const end = hoveredDate.getTime()
218
- const start = end - 6 * DAY
234
+ let start: number
235
+ let end: number
236
+
237
+ if (props.weeklyModeStartDay !== undefined) {
238
+ const startDay = props.weeklyModeStartDay
239
+ const dayOfWeek = hoveredDate.getDay()
240
+ const daysSinceStart = (dayOfWeek - startDay + 7) % 7
241
+
242
+ const startDate = new Date(hoveredDate)
243
+ startDate.setDate(hoveredDate.getDate() - daysSinceStart)
244
+ startDate.setHours(0, 0, 0, 0)
245
+
246
+ const endDate = new Date(startDate)
247
+ endDate.setDate(startDate.getDate() + 6)
248
+ endDate.setHours(0, 0, 0, 0)
249
+
250
+ start = startDate.getTime()
251
+ end = endDate.getTime()
252
+ } else {
253
+ end = hoveredDate.getTime()
254
+ start = end - 6 * DAY
255
+ }
256
+
219
257
  const t = date.getTime()
220
258
  if (t >= start && t <= end) {
221
259
  return "hovered-range-day"