kahuna-base-react-components 1.4.3 → 1.4.5

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
@@ -250,6 +250,9 @@ interface KSelectDateProps {
250
250
  isTileDisabled?: TileDisabledFunc;
251
251
  applyUndefinedValue?: boolean;
252
252
  buttonText?: string;
253
+ open?: boolean;
254
+ setOpen?: (open: boolean) => void;
255
+ onCancel?: () => void;
253
256
  }
254
257
  declare const KSelectDate: React.FC<KSelectDateProps>;
255
258
 
@@ -348,6 +351,7 @@ interface KSelectRangeDateProps {
348
351
  hideBackdrop?: boolean;
349
352
  weeklyMode?: boolean;
350
353
  shorthandEndDateOffsetDays?: number;
354
+ weeklyModeStartDay?: number;
351
355
  }
352
356
  type DateRangeType = Date | null | [Date | null, Date | null];
353
357
  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.5",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -15,9 +15,15 @@ export default {
15
15
 
16
16
  const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
17
17
  const [selectedDate, setSelectedDate] = useState<Date | undefined>(undefined)
18
+ const [open, setOpen] = useState<boolean>(false)
18
19
  useEffect(() => {
19
20
  // console.log("selectedDate: ", selectedDate)
20
21
  }, [selectedDate])
22
+
23
+ useEffect(() => {
24
+ console.log("open: ", open)
25
+ }, [open])
26
+
21
27
  const periods = [
22
28
  { value: "202401", label: "202401" },
23
29
  { value: "202402", label: "202402" },
@@ -59,7 +65,12 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
59
65
  />
60
66
  <KSelectDate
61
67
  {...args}
68
+ key={selectedDate?.toString()}
62
69
  value={selectedDate}
70
+ open={open}
71
+ setOpen={setOpen}
72
+ hideBody
73
+ hideBackdrop
63
74
  onChange={(date) => {
64
75
  // console.log("date: ", date)
65
76
  if (date) {
@@ -71,10 +82,15 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
71
82
  // console.log("Deleting is completed")
72
83
  }
73
84
  }}
85
+ onCancel={() => {
86
+ console.log("close:::")
87
+ }}
74
88
  anchorToButton
75
89
  />
76
90
  </div>
77
- <div></div>
91
+ <div className="cursor-pointer" onClick={() => {
92
+ setOpen(true)
93
+ }}>Deneme Butonu</div>
78
94
  </div>
79
95
  )
80
96
  }
@@ -36,6 +36,9 @@ export interface KSelectDateProps {
36
36
  isTileDisabled?: TileDisabledFunc
37
37
  applyUndefinedValue?: boolean // if this prop's value is false, makes the Apply button disabled when chosen date is undefined
38
38
  buttonText?: string
39
+ open?: boolean // Use open and setOpen props together. Opens the calendar without requiring a click on the calendar icon.
40
+ setOpen?: (open: boolean) => void // Use open and setOpen props together.
41
+ onCancel?: () => void
39
42
  }
40
43
  interface MonthSelectorType {
41
44
  monthName: string
@@ -70,6 +73,13 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
70
73
  const [weekDays, setWeekDays] = useState<DaySelectorType[]>([])
71
74
  const [openCalendar, setOpenCalendar] = useState<boolean>(false)
72
75
 
76
+ useEffect(() => {
77
+ if (props.open) {
78
+ setOpenCalendar(true) // Used only to open the calendar. The Cancel and Apply buttons handle closing it.
79
+ setCalendarDate(value)
80
+ }
81
+ }, [props.open])
82
+
73
83
  const onlyMonthSelection = props.onlyMonthSelection || false
74
84
  const hideBody = props.hideBody || false
75
85
 
@@ -170,6 +180,8 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
170
180
  textColor="#111"
171
181
  onClick={() => {
172
182
  setOpenCalendar(false)
183
+ if (props.setOpen) props.setOpen(false)
184
+ if (props.onCancel) props.onCancel()
173
185
  }}
174
186
  />
175
187
  <KButton
@@ -182,6 +194,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
182
194
  onClick={() => {
183
195
  setValue(calendarDate)
184
196
  setOpenCalendar(false)
197
+ if (props.setOpen) props.setOpen(false)
185
198
  }}
186
199
  />
187
200
  </div>
@@ -400,6 +413,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
400
413
  onClick={() => {
401
414
  if (openCalendar) {
402
415
  setOpenCalendar(false)
416
+ if (props.setOpen) props.setOpen(false)
403
417
  } else {
404
418
  setOpenCalendar(true)
405
419
  setCalendarDate(value)
@@ -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"