kahuna-base-react-components 1.2.8 → 1.2.10

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
@@ -1,5 +1,6 @@
1
1
  import React, { CSSProperties, KeyboardEvent } from 'react';
2
2
  import { MultiValue } from 'react-select';
3
+ import { TileDisabledFunc } from 'react-calendar';
3
4
 
4
5
  interface KButtonProps {
5
6
  onClick: () => void;
@@ -212,13 +213,17 @@ interface KSelectDateProps {
212
213
  position?: "top" | "bottom" | "left" | "right";
213
214
  align?: "top" | "bottom" | "left" | "right" | "center";
214
215
  hideBackdrop?: boolean;
216
+ isTileDisabled?: TileDisabledFunc;
217
+ applyUndefinedValue?: boolean;
218
+ buttonText?: string;
215
219
  }
216
220
  declare const KSelectDate: React.FC<KSelectDateProps>;
217
221
 
218
222
  interface KTooltipProps {
219
223
  children: React.ReactNode;
220
224
  content: React.ReactNode;
221
- position?: string;
225
+ position?: "top" | "bottom" | "left" | "right";
226
+ align?: "top" | "bottom" | "left" | "right" | "center";
222
227
  backgroundColor?: string;
223
228
  width?: string;
224
229
  height?: string;
@@ -229,6 +234,8 @@ interface KTooltipProps {
229
234
  showArrow?: boolean;
230
235
  arrowColor?: string;
231
236
  padding?: string;
237
+ marginTop?: string;
238
+ marginLeft?: string;
232
239
  }
233
240
  declare const KTooltip: React.FC<KTooltipProps>;
234
241
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahuna-base-react-components",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -79,6 +79,7 @@ KDropdownSingle.args = {
79
79
  placeholder: "Select single...",
80
80
  isClearable: true,
81
81
  isEllipsis: true,
82
+ selected: {label: "1", value: 1},
82
83
  allowContainerShrink: true,
83
84
  hideChosenOptionIcon: true,
84
85
  onBlur: (value: any) => {
@@ -73,6 +73,7 @@ const KDropdown: React.FC<KDropdownProps> = (props) => {
73
73
 
74
74
  setBackground(background)
75
75
  setBorder(border)
76
+ setSelectedOption(props.selected)
76
77
  }, [props.selected])
77
78
 
78
79
  const width = props.width || "100%"
@@ -242,6 +243,7 @@ const KDropdown: React.FC<KDropdownProps> = (props) => {
242
243
  }}
243
244
  filterOption={customFilterOption}
244
245
  isClearable={isClearable}
246
+ value={selectedOption}
245
247
  hideSelectedOptions={!isMulti ? false : showOnlyIconsInMulti ? false : true}
246
248
  styles={{
247
249
  control: (baseStyles, state) => ({
@@ -18,6 +18,20 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
18
18
  useEffect(() => {
19
19
  // console.log("selectedDate: ", selectedDate)
20
20
  }, [selectedDate])
21
+ const periods = [
22
+ { value: "202401", label: "202401" },
23
+ { value: "202402", label: "202402" },
24
+ { value: "202403", label: "202403" },
25
+ { value: "202404", label: "202404" },
26
+ { value: "202405", label: "202405"}]
27
+ const isTileDisabled = ({ date }: { date: Date }) => {
28
+ const year = date.getFullYear()
29
+ const month = (date.getMonth() + 1).toString().padStart(2, "0")
30
+ const formattedDate = `${year}${month}` // Format as YYYYMM
31
+ const includedPeriods = periods.map((period) => String(period.value))
32
+
33
+ return !includedPeriods.includes(formattedDate) // Disable if not in the array
34
+ }
21
35
 
22
36
  return (
23
37
  <div className=" flex flex-row gap-4 items-center">
@@ -28,6 +42,7 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
28
42
  <KSelectDate
29
43
  {...args}
30
44
  value={selectedDate}
45
+ isTileDisabled={isTileDisabled}
31
46
  onChange={(date) => {
32
47
  // console.log("date: ", date)
33
48
  if (date) {
@@ -40,6 +55,7 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
40
55
  }
41
56
  }}
42
57
  anchorToButton
58
+
43
59
  />
44
60
  <KSelectDate
45
61
  {...args}
@@ -87,5 +103,6 @@ KSelectDateHoverText.args = {
87
103
  boxShadow: "none",
88
104
  borderRadius: 22,
89
105
  icon: CalendarNewIcon,
90
- hideBody: true
106
+ hideBody: true,
107
+ onlyMonthSelection: true
91
108
  }
@@ -1,5 +1,5 @@
1
- import React, { CSSProperties, useEffect, useState } from "react"
2
- import Calendar from "react-calendar"
1
+ import React, { useEffect, useState } from "react"
2
+ import Calendar, { TileDisabledFunc } from "react-calendar"
3
3
  import "./CalendarCustom.css"
4
4
  //@ts-ignore
5
5
  import LeftIcon from "../../assets/chevron-left.svg"
@@ -8,8 +8,6 @@ import SeparatorIcon from "../../assets/separator.svg"
8
8
  //@ts-ignore
9
9
  import CalendarIcon from "../../assets/calendar.svg"
10
10
  //@ts-ignore
11
- import CalendarNewIcon from "../../assets/calendar-new.svg"
12
- //@ts-ignore
13
11
  import RightIcon from "../../assets/chevron-right.svg"
14
12
  import "../../main.css"
15
13
  import KButton from "../KButton"
@@ -35,6 +33,9 @@ export interface KSelectDateProps {
35
33
  position?: "top" | "bottom" | "left" | "right" // position of the calendar relative to the button's position, has effect as long as anchorButton is true
36
34
  align?: "top" | "bottom" | "left" | "right" | "center" // lets to align the calendar, has effect as long as anchorButton is true
37
35
  hideBackdrop?: boolean
36
+ isTileDisabled?: TileDisabledFunc
37
+ applyUndefinedValue?: boolean // if this prop's value is false, makes the Apply button disabled when chosen date is undefined
38
+ buttonText?: string
38
39
  }
39
40
  interface MonthSelectorType {
40
41
  monthName: string
@@ -77,6 +78,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
77
78
  const align = props.align || "center"
78
79
 
79
80
  const hideBackdrop = props.hideBackdrop || false
81
+ const applyUndefinedValue = props.applyUndefinedValue !== undefined ? props.applyUndefinedValue : true
80
82
 
81
83
  const formatShortWeekday = (locale: string | undefined, date: Date): string => {
82
84
  return date.toLocaleDateString(locale, { weekday: "short" }).charAt(0) // Return only the first letter of the weekday
@@ -157,6 +159,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
157
159
  formatShortWeekday={formatShortWeekday}
158
160
  formatMonthYear={formatMonthYear}
159
161
  minDate={props.minimumDate || undefined}
162
+ {...(props.isTileDisabled && { tileDisabled: props.isTileDisabled })}
160
163
  />
161
164
  <div className="h-19 w-[350px] bg-[#FFF] flex flex-row gap-4 py-4 justify-center border-[1px] border-[#E7E7E7] border-t-0 rounded-b-[10px]">
162
165
  <KButton
@@ -174,6 +177,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
174
177
  height="44px"
175
178
  width="160px"
176
179
  background="#000"
180
+ disabled={!applyUndefinedValue && !calendarDate}
177
181
  textColor="#FFF"
178
182
  onClick={() => {
179
183
  setValue(calendarDate)
@@ -313,7 +317,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
313
317
  return (
314
318
  <React.Fragment>
315
319
  {openCalendar && !hideBackdrop && (
316
- <div className="w-[100vw] h-[100vh] fixed left-0 top-0 z-[49] bg-[#0000004d]"/>
320
+ <div className="w-[100vw] h-[100vh] fixed left-0 top-0 z-[49] bg-[#0000004d]" />
317
321
  )}
318
322
  {openCalendar && (!hideBody || !anchorToButton) && (
319
323
  <div className="w-[100vw] h-[100vh] fixed left-0 top-0 flex items-center justify-center z-50">
@@ -391,7 +395,8 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
391
395
  }}
392
396
  >
393
397
  <KButton
394
- icon={icon}
398
+ {...(props.buttonText ? { leftIcon: icon } : { icon })}
399
+ {...(props.buttonText && { text: props.buttonText })}
395
400
  onClick={() => {
396
401
  if (openCalendar) {
397
402
  setOpenCalendar(false)
@@ -27,6 +27,7 @@ KTooltipPrimary.args = {
27
27
  </div>
28
28
  ),
29
29
  position: "top",
30
+ align: "right",
30
31
  zIndex: 1000,
31
32
  arrowColor: "green",
32
33
  showArrow: true,
@@ -4,7 +4,8 @@ import "../../main.css"
4
4
  export interface KTooltipProps {
5
5
  children: React.ReactNode
6
6
  content: React.ReactNode
7
- position?: string
7
+ position?: "top" | "bottom" | "left" | "right"
8
+ align?: "top" | "bottom" | "left" | "right" | "center"
8
9
  backgroundColor?: string
9
10
  width?: string
10
11
  height?: string
@@ -15,6 +16,8 @@ export interface KTooltipProps {
15
16
  showArrow?: boolean
16
17
  arrowColor?: string
17
18
  padding?: string
19
+ marginTop?: string // position and align is used to position the tooltip. for additional changes in vertical positioning use this prop
20
+ marginLeft?: string // position and align is used to position the tooltip. for minor changes in horizontal positioning use this prop
18
21
  }
19
22
 
20
23
  const KTooltip: React.FC<KTooltipProps> = (props) => {
@@ -24,6 +27,7 @@ const KTooltip: React.FC<KTooltipProps> = (props) => {
24
27
  const hideTooltip = () => setIsVisible(false)
25
28
 
26
29
  const position = props.position || "top"
30
+ const align = props.align || "center"
27
31
  const width = props.width || "auto"
28
32
  const height = props.height || "auto"
29
33
  const background = props.backgroundColor || "#FFF"
@@ -41,17 +45,35 @@ const KTooltip: React.FC<KTooltipProps> = (props) => {
41
45
  const padding = props.padding || "5px"
42
46
 
43
47
  const baseStyles = { width, height, background, zIndex, border, borderRadius, boxShadow }
48
+
49
+ const absolutePositionClassName = (position: string, align: string) => {
50
+ const finalPosition = position
51
+ let finalAlign = align
52
+ if (finalPosition === "top" || finalPosition === "bottom") {
53
+ finalAlign = align === "top" || align === "bottom" ? "center" : align
54
+ } else if (finalPosition === "left" || finalPosition === "right") {
55
+ finalAlign = align === "left" || align === "right" ? "center" : align
56
+ }
57
+ return `k-tooltip-position-${finalPosition}-${finalAlign}`
58
+ }
59
+
44
60
  return (
45
61
  <div className="relative box-border" onMouseEnter={showTooltip} onMouseLeave={hideTooltip}>
46
62
  {props.children}
47
63
 
48
64
  <div
49
- className={`k-tooltip-${position} absolute ${isVisible ? "k-tooltip-enter" : "k-tooltip-exit"}`}
50
- style={baseStyles}
65
+ className={`${absolutePositionClassName(position, align)} absolute ${
66
+ isVisible ? "k-tooltip-enter" : "k-tooltip-exit"
67
+ }`}
68
+ style={{
69
+ ...baseStyles,
70
+ ...(props.marginTop && { marginTop: `${props.marginTop}` }),
71
+ ...(props.marginLeft && { marginLeft: `${props.marginLeft}` })
72
+ }}
51
73
  >
52
74
  <div
53
75
  style={{
54
- padding: padding,
76
+ padding,
55
77
  borderRadius,
56
78
  background
57
79
  }}
package/src/main.css CHANGED
@@ -124,35 +124,6 @@
124
124
  background-size: auto;
125
125
  background-position: center;
126
126
  }
127
-
128
- .k-tooltip-top {
129
- bottom: 100%;
130
- left: 50%;
131
- transform: translateX(-50%);
132
- margin-bottom: 10px;
133
- }
134
-
135
- .k-tooltip-right {
136
- top: 50%;
137
- left: 100%;
138
- transform: translateY(-50%);
139
- margin-left: 10px;
140
- }
141
-
142
- .k-tooltip-bottom {
143
- top: 100%;
144
- left: 50%;
145
- transform: translateX(-50%);
146
- margin-top: 10px;
147
- }
148
-
149
- .k-tooltip-left {
150
- top: 50%;
151
- right: 100%;
152
- transform: translateY(-50%);
153
- margin-right: 10px;
154
- }
155
-
156
127
  .k-tooltip-enter {
157
128
  opacity: 1;
158
129
  visibility: visible;
@@ -254,3 +225,71 @@
254
225
  background: #F7F7F7 !important;
255
226
  border: none !important;
256
227
  }
228
+ .k-tooltip-position-bottom-center {
229
+ top: 100%;
230
+ margin-top: 10px;
231
+ left:50%;
232
+ transform: translateX(-50%);
233
+ }
234
+ .k-tooltip-position-bottom-left {
235
+ top: 100%;
236
+ margin-top: 10px;
237
+ left:0%;
238
+ transform: translateX(-100%);
239
+ }
240
+ .k-tooltip-position-bottom-right {
241
+ top: 100%;
242
+ margin-top: 10px;
243
+ left:100%;
244
+ }
245
+ .k-tooltip-position-top-center {
246
+ bottom: 100%;
247
+ margin-bottom: 10px;
248
+ left:50%;
249
+ transform: translateX(-50%);
250
+ }
251
+ .k-tooltip-position-top-left {
252
+ bottom: 100%;
253
+ margin-bottom: 10px;
254
+ left:0%;
255
+ transform: translateX(-100%);
256
+ }
257
+ .k-tooltip-position-top-right {
258
+ bottom: 100%;
259
+ margin-bottom: 10px;
260
+ left:100%;
261
+ }
262
+ .k-tooltip-position-left-center {
263
+ top: 50%;
264
+ right: 100%;
265
+ transform: translateY(-50%);
266
+ margin-right: 10px;
267
+ }
268
+ .k-tooltip-position-left-top {
269
+ top: 0%;
270
+ right: 100%;
271
+ transform: translateY(-100%);
272
+ margin-right: 10px;
273
+ }
274
+ .k-tooltip-position-left-bottom {
275
+ top: 100%;
276
+ right: 100%;
277
+ margin-right: 10px;
278
+ }
279
+ .k-tooltip-position-right-center {
280
+ top: 50%;
281
+ left: 100%;
282
+ transform: translateY(-50%);
283
+ margin-left: 10px;
284
+ }
285
+ .k-tooltip-position-right-top {
286
+ top: 0%;
287
+ left: 100%;
288
+ transform: translateY(-100%);
289
+ margin-left: 10px;
290
+ }
291
+ .k-tooltip-position-right-bottom {
292
+ top: 100%;
293
+ left: 100%;
294
+ margin-left: 10px;
295
+ }