kahuna-base-react-components 1.3.9 → 1.4.0

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
@@ -345,6 +345,7 @@ interface KSelectRangeDateProps {
345
345
  maximumDate?: Date;
346
346
  popupCalendarBackground?: string;
347
347
  hideBackdrop?: boolean;
348
+ weeklyMode?: boolean;
348
349
  }
349
350
  type DateRangeType = Date | null | [Date | null, Date | null];
350
351
  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.3.9",
3
+ "version": "1.4.0",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -288,6 +288,7 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
288
288
  }
289
289
  nextLabel={null}
290
290
  formatShortWeekday={formatShortWeekday}
291
+ formatMonthYear={formatMonthYear}
291
292
  selectRange
292
293
  maxDetail="year"
293
294
  minDetail="year"
@@ -81,6 +81,28 @@ KSelectRangePrimary.args = {
81
81
  }
82
82
  }
83
83
 
84
+ export const KSelectRangeWeekly = Template.bind({})
85
+ KSelectRangeWeekly.args = {
86
+ width: "48px",
87
+ height: "48px",
88
+ backgroundColor: "#F7F7F7",
89
+ hoverBackgroundColor: "#F3F3F3",
90
+ borderRadius: 24,
91
+ position: "bottom",
92
+ align: "center",
93
+ hideBackdrop: true,
94
+ anchorToButton: true,
95
+ weeklyMode: true,
96
+
97
+ onChange: (value) => {
98
+ if (value) {
99
+ console.log("value is updated using this value:", value)
100
+ } else {
101
+ console.log("value is deleted, because it is: ", value)
102
+ }
103
+ }
104
+ }
105
+
84
106
  export const KSelectRangeDateMinimumDate = Template.bind({})
85
107
  KSelectRangeDateMinimumDate.args = {
86
108
  width: "48px",
@@ -31,6 +31,7 @@ export interface KSelectRangeDateProps {
31
31
  maximumDate?: Date
32
32
  popupCalendarBackground?: string
33
33
  hideBackdrop?: boolean
34
+ weeklyMode?: boolean
34
35
  }
35
36
 
36
37
  export type DateRangeType = Date | null | [Date | null, Date | null]
@@ -63,19 +64,18 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
63
64
 
64
65
  useEffect(() => {
65
66
  if (openCalendar) {
66
- if(skipNextOpenRef?.current) {
67
+ if (skipNextOpenRef?.current) {
67
68
  skipNextOpenRef.current = false
68
69
  return
69
70
  }
70
71
 
71
72
  setRange(props.value)
72
- }
73
+ }
73
74
  }, [props.value, openCalendar])
74
75
 
75
76
  const [leftCalendarYear, setLeftCalendarYear] = useState<number>(new Date().getFullYear())
76
77
  const [leftCalendarMonth, setLeftCalendarMonth] = useState<number>(new Date().getMonth())
77
78
 
78
-
79
79
  const [shorthandIndex, setShorthandIndex] = useState<{ current: number; approved: number }>({
80
80
  current: -1,
81
81
  approved: -1
@@ -107,19 +107,35 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
107
107
 
108
108
  const shorthandDateSelection = (range: number) => {
109
109
  const theDate = new Date()
110
- // if isMonth is false, then it is year
111
110
  const year = theDate.getFullYear()
112
111
  const month = theDate.getMonth()
113
112
  const day = theDate.getDate()
114
113
 
115
114
  const endDate = new Date(year, month, day)
116
- const startDate = new Date(year, month, day - range)
115
+ const startDate = new Date(year, month, day - (range - 1))
117
116
  setRange([startDate, endDate])
118
117
  }
119
118
 
120
119
  const onClickDayEvent = (clickedDate: Date) => {
121
120
  if (!Array.isArray(range)) return
122
121
 
122
+ if (props.weeklyMode) {
123
+ const DAY = 24 * 60 * 60 * 1000
124
+
125
+ const endDate = clickedDate
126
+ const startDate = new Date(clickedDate.getTime() - 6 * DAY)
127
+
128
+ setRange([startDate, endDate])
129
+ skipNextOpenRef.current = true
130
+ setOpenCalendar(false)
131
+ setTimeout(() => {
132
+ setOpenCalendar(true)
133
+ }, 100)
134
+
135
+ setShorthandIndex((prev) => ({ ...prev, current: -1 }))
136
+ return
137
+ }
138
+
123
139
  if (range[0] === null && range[1] === null) {
124
140
  setRange([clickedDate, null])
125
141
  } else if (range[0] !== null && range[1] === null) {
@@ -139,11 +155,14 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
139
155
 
140
156
  const tileClassName = ({ date, view }: { date: Date; view: string }) => {
141
157
  if (view === "month") {
142
-
143
- if (Array.isArray(range) && range[0] && !range[1] && hoveredDate &&
144
- ((date.getTime() > hoveredDate.getTime() && date.getTime() < range[0].getTime()) ||
145
- date.getTime() < hoveredDate.getTime() && date.getTime() > range[0].getTime()) ) {
146
-
158
+ if (
159
+ Array.isArray(range) &&
160
+ range[0] &&
161
+ !range[1] &&
162
+ hoveredDate &&
163
+ ((date.getTime() > hoveredDate.getTime() && date.getTime() < range[0].getTime()) ||
164
+ (date.getTime() < hoveredDate.getTime() && date.getTime() > range[0].getTime()))
165
+ ) {
147
166
  return "hovered-range-day"
148
167
  }
149
168
 
@@ -159,15 +178,23 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
159
178
  range[1]?.getDate() === date.getDate()
160
179
  ) {
161
180
  return "active-day-first-day active-day-last-day"
162
- } else if (range[0]?.getFullYear() === date.getFullYear() && range[0]?.getMonth() === date.getMonth() && range[0]?.getDate() === date.getDate()) {
181
+ } else if (
182
+ range[0]?.getFullYear() === date.getFullYear() &&
183
+ range[0]?.getMonth() === date.getMonth() &&
184
+ range[0]?.getDate() === date.getDate()
185
+ ) {
163
186
  return "active-day-first-day"
164
- } else if (range[1]?.getFullYear() === date.getFullYear() && range[1]?.getMonth() === date.getMonth() && range[1]?.getDate() === date.getDate()) {
187
+ } else if (
188
+ range[1]?.getFullYear() === date.getFullYear() &&
189
+ range[1]?.getMonth() === date.getMonth() &&
190
+ range[1]?.getDate() === date.getDate()
191
+ ) {
165
192
  return "active-day-last-day"
166
193
  } else if (range[0]?.getTime() < date.getTime() && date.getTime() < range[1]?.getTime()) {
167
194
  const weekStartsOn = 1
168
195
  const col = (date.getDay() - weekStartsOn + 7) % 7
169
196
  const dayOfMonth = date.getDate()
170
- const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth()+1, 0).getDate()
197
+ const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate()
171
198
  if (col === 6) {
172
199
  return "active-day-range-day-left"
173
200
  } else if (col === 5) {
@@ -181,6 +208,16 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
181
208
  }
182
209
  }
183
210
 
211
+ if (hoveredDate && props.weeklyMode) {
212
+ const DAY = 24 * 60 * 60 * 1000
213
+ const end = hoveredDate.getTime()
214
+ const start = end - 6 * DAY
215
+ const t = date.getTime()
216
+ if (t >= start && t <= end) {
217
+ return "hovered-range-day"
218
+ }
219
+ }
220
+
184
221
  return null
185
222
  }
186
223
  }
@@ -192,10 +229,12 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
192
229
  <div className="absolute left-0 top-0 h-full w-full flex items-center justify-center tile-content-external-div">
193
230
  {Array.isArray(range) &&
194
231
  range[1] !== null &&
195
- ((range[0]?.getFullYear() === date.getFullYear() && range[0]?.getMonth() === date.getMonth() && range[0]?.getDate() === date.getDate()) ||
196
- (range[1]?.getFullYear() === date.getFullYear() && range[1]?.getMonth() === date.getMonth() && range[1]?.getDate() === date.getDate())) && (
197
- <abbr>{day}</abbr>
198
- )}
232
+ ((range[0]?.getFullYear() === date.getFullYear() &&
233
+ range[0]?.getMonth() === date.getMonth() &&
234
+ range[0]?.getDate() === date.getDate()) ||
235
+ (range[1]?.getFullYear() === date.getFullYear() &&
236
+ range[1]?.getMonth() === date.getMonth() &&
237
+ range[1]?.getDate() === date.getDate())) && <abbr>{day}</abbr>}
199
238
  </div>
200
239
  )
201
240
  }
@@ -220,108 +259,114 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
220
259
  const renderPopUpCalendar = () => {
221
260
  return (
222
261
  <div className="flex flex-row">
262
+ {!props.weeklyMode && (
263
+ <div
264
+ className="w-[160px] bg-[#FFF] flex flex-col items-center gap-2 justify-start px-2.5 pt-5 pb-4 border-r-0"
265
+ style={{
266
+ border: "1px solid #F3F3F3",
267
+ borderRightWidth: "0px",
268
+ borderTopLeftRadius: "16px",
269
+ borderBottomLeftRadius: "16px"
270
+ }}
271
+ >
272
+ <KButton
273
+ onClick={() => {
274
+ shorthandDateSelection(2)
275
+ setShorthandIndex({ ...shorthandIndex, current: 0 })
276
+ }}
277
+ width="140px"
278
+ background={shorthandIndex.current === 0 ? "#F7F7F7" : "#FFF"}
279
+ textColor={shorthandIndex.current === 0 ? "#000" : "#999"}
280
+ text={lang.button_text.yesterday}
281
+ borderRadius={8}
282
+ shadowDisabled
283
+ hoverBackground="#F0F0F0"
284
+ height="40px"
285
+ />
286
+ <KButton
287
+ onClick={() => {
288
+ shorthandDateSelection(3)
289
+ setShorthandIndex({ ...shorthandIndex, current: 1 })
290
+ }}
291
+ width="140px"
292
+ background={shorthandIndex.current === 1 ? "#F7F7F7" : "#FFF"}
293
+ textColor={shorthandIndex.current === 1 ? "#000" : "#999"}
294
+ text={lang.button_text.last_three_days}
295
+ borderRadius={8}
296
+ shadowDisabled
297
+ hoverBackground="#F0F0F0"
298
+ height="40px"
299
+ />
300
+ <KButton
301
+ onClick={() => {
302
+ shorthandDateSelection(7)
303
+ setShorthandIndex({ ...shorthandIndex, current: 2 })
304
+ }}
305
+ width="140px"
306
+ background={shorthandIndex.current === 2 ? "#F7F7F7" : "#FFF"}
307
+ textColor={shorthandIndex.current === 2 ? "#000" : "#999"}
308
+ text={lang.button_text.last_week}
309
+ borderRadius={8}
310
+ shadowDisabled
311
+ hoverBackground="#F0F0F0"
312
+ height="40px"
313
+ />
314
+ <KButton
315
+ onClick={() => {
316
+ shorthandDateSelection(14)
317
+ setShorthandIndex({ ...shorthandIndex, current: 3 })
318
+ }}
319
+ width="140px"
320
+ background={shorthandIndex.current === 3 ? "#F7F7F7" : "#FFF"}
321
+ textColor={shorthandIndex.current === 3 ? "#000" : "#999"}
322
+ text={lang.button_text.last_two_weeks}
323
+ borderRadius={8}
324
+ shadowDisabled
325
+ hoverBackground="#F0F0F0"
326
+ height="40px"
327
+ />
328
+ <KButton
329
+ onClick={() => {
330
+ shorthandDateSelection(31)
331
+ setShorthandIndex({ ...shorthandIndex, current: 4 })
332
+ }}
333
+ width="140px"
334
+ background={shorthandIndex.current === 4 ? "#F7F7F7" : "#FFF"}
335
+ textColor={shorthandIndex.current === 4 ? "#000" : "#999"}
336
+ text={lang.button_text.last_month}
337
+ borderRadius={8}
338
+ shadowDisabled
339
+ hoverBackground="#F0F0F0"
340
+ height="40px"
341
+ />
342
+ </div>
343
+ )}
223
344
  <div
224
- className="w-[160px] bg-[#FFF] flex flex-col items-center gap-2 justify-start px-2.5 pt-5 pb-4 border-r-0"
345
+ className="flex flex-col gap-0"
225
346
  style={{
226
- border: "1px solid #F3F3F3",
227
- borderRightWidth: "0px",
228
- borderTopLeftRadius: "16px",
229
- borderBottomLeftRadius: "16px"
347
+ borderTopLeftRadius: 20
230
348
  }}
231
349
  >
232
- <KButton
233
- onClick={() => {
234
- shorthandDateSelection(2)
235
- setShorthandIndex({ ...shorthandIndex, current: 0 })
236
- }}
237
- width="140px"
238
- background={shorthandIndex.current === 0 ? "#F7F7F7" : "#FFF"}
239
- textColor={shorthandIndex.current === 0 ? "#000" : "#999"}
240
- text={lang.button_text.yesterday}
241
- borderRadius={8}
242
- shadowDisabled
243
- hoverBackground="#F0F0F0"
244
- height="40px"
245
- />
246
- <KButton
247
- onClick={() => {
248
- shorthandDateSelection(3)
249
- setShorthandIndex({ ...shorthandIndex, current: 1 })
250
- }}
251
- width="140px"
252
- background={shorthandIndex.current === 1 ? "#F7F7F7" : "#FFF"}
253
- textColor={shorthandIndex.current === 1 ? "#000" : "#999"}
254
- text={lang.button_text.last_three_days}
255
- borderRadius={8}
256
- shadowDisabled
257
- hoverBackground="#F0F0F0"
258
- height="40px"
259
- />
260
- <KButton
261
- onClick={() => {
262
- shorthandDateSelection(7)
263
- setShorthandIndex({ ...shorthandIndex, current: 2 })
264
- }}
265
- width="140px"
266
- background={shorthandIndex.current === 2 ? "#F7F7F7" : "#FFF"}
267
- textColor={shorthandIndex.current === 2 ? "#000" : "#999"}
268
- text={lang.button_text.last_week}
269
- borderRadius={8}
270
- shadowDisabled
271
- hoverBackground="#F0F0F0"
272
- height="40px"
273
- />
274
- <KButton
275
- onClick={() => {
276
- shorthandDateSelection(14)
277
- setShorthandIndex({ ...shorthandIndex, current: 3 })
350
+ <div
351
+ className="flex flex-row"
352
+ onMouseOver={(e) => {
353
+ const tile = (e.target as HTMLElement).closest(".react-calendar__tile")
354
+ if (!tile) return
355
+ const abbr = tile.querySelector("abbr[aria-label]") as HTMLElement | null
356
+ if (!abbr) return
357
+ const label = abbr.getAttribute("aria-label")!
358
+ const date = new Date(label)
359
+ setHoveredDate(date)
278
360
  }}
279
- width="140px"
280
- background={shorthandIndex.current === 3 ? "#F7F7F7" : "#FFF"}
281
- textColor={shorthandIndex.current === 3 ? "#000" : "#999"}
282
- text={lang.button_text.last_two_weeks}
283
- borderRadius={8}
284
- shadowDisabled
285
- hoverBackground="#F0F0F0"
286
- height="40px"
287
- />
288
- <KButton
289
- onClick={() => {
290
- shorthandDateSelection(31)
291
- setShorthandIndex({ ...shorthandIndex, current: 4 })
361
+ onMouseOut={(e) => {
362
+ const leftTile = (e.target as HTMLElement).closest(".react-calendar__tile")
363
+ if (leftTile) {
364
+ setHoveredDate(null)
365
+ }
292
366
  }}
293
- width="140px"
294
- background={shorthandIndex.current === 4 ? "#F7F7F7" : "#FFF"}
295
- textColor={shorthandIndex.current === 4 ? "#000" : "#999"}
296
- text={lang.button_text.last_month}
297
- borderRadius={8}
298
- shadowDisabled
299
- hoverBackground="#F0F0F0"
300
- height="40px"
301
- />
302
- </div>
303
- <div className="flex flex-col gap-0">
304
- <div className="flex flex-row"
305
- onMouseOver={e => {
306
- const tile = (e.target as HTMLElement).closest(".react-calendar__tile")
307
- if (!tile) return
308
- const abbr = tile.querySelector("abbr[aria-label]") as HTMLElement | null;
309
- if (!abbr) return
310
- const label = abbr.getAttribute("aria-label")!
311
- const date = new Date(label)
312
- setHoveredDate(date)
313
- }
314
- }
315
- onMouseOut={e => {
316
-
317
- const leftTile = (e.target as HTMLElement).closest(".react-calendar__tile")
318
- if (leftTile) {
319
- setHoveredDate(null)
320
- }
321
- }
322
- }>
367
+ >
323
368
  <Calendar
324
- className="kselect-range-date left-calendar"
369
+ className={`kselect-range-date left-calendar ${props.weeklyMode ? "weekly-mode" : ""}`}
325
370
  allowPartialRange
326
371
  tileClassName={tileClassName}
327
372
  tileContent={tileContent}
@@ -345,6 +390,7 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
345
390
  }
346
391
  nextLabel={null}
347
392
  formatShortWeekday={formatShortWeekday}
393
+ formatMonthYear={formatMonthYear}
348
394
  selectRange
349
395
  maxDetail="month"
350
396
  minDetail="month"
@@ -360,8 +406,6 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
360
406
  activeStartDate={new Date(leftCalendarYear, leftCalendarMonth + 1, 1)}
361
407
  allowPartialRange
362
408
  onChange={(dates) => {}}
363
- maxDetail="month"
364
- minDetail="month"
365
409
  onClickDay={(clickedDate) => {
366
410
  onClickDayEvent(clickedDate)
367
411
  }}
@@ -380,6 +424,8 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
380
424
  formatShortWeekday={formatShortWeekday}
381
425
  formatMonthYear={formatMonthYear}
382
426
  selectRange
427
+ maxDetail="month"
428
+ minDetail="month"
383
429
  minDate={props.minimumDate || undefined}
384
430
  maxDate={props.maximumDate || undefined}
385
431
  />
@@ -388,7 +434,7 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
388
434
  className="h-19 w-full bg-[#FFF] flex flex-row gap-4 py-4 px-5 justify-between items-center border-[1px] border-[#F3F3F3] border-t-0 rounded-b-[10px]"
389
435
  style={{
390
436
  borderBottomRightRadius: "16px",
391
- borderBottomLeftRadius: "0px"
437
+ borderBottomLeftRadius: props.weeklyMode ? "16px" : "0px"
392
438
  }}
393
439
  >
394
440
  <div className="flex items-center gap-1">
@@ -2,7 +2,10 @@
2
2
  border-top-right-radius: 0 !important;
3
3
  border-right: none !important;
4
4
  }
5
-
5
+ .left-calendar.weekly-mode {
6
+ border-top-left-radius: 16px !important;
7
+ border-right: none !important;
8
+ }
6
9
  .react-calendar.kselect-range-date {
7
10
  width: 350px;
8
11
  max-width: 100%;