kahuna-base-react-components 1.2.4 → 1.2.6
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/components/KSelectDate/KSelectDate.d.ts +1 -0
- package/dist/components/KSelectRange/KSelectRange.d.ts +1 -0
- package/dist/components/KSpan/KSpan.d.ts +2 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
- package/src/components/KSelectDate/KSelectDate.stories.tsx +41 -16
- package/src/components/KSelectDate/KSelectDate.tsx +9 -3
- package/src/components/KSelectRange/KSelectRange.stories.tsx +21 -3
- package/src/components/KSelectRange/KSelectRange.tsx +12 -1
- package/src/components/KSpan/KSpan.stories.tsx +11 -4
- package/src/components/KSpan/KSpan.tsx +24 -8
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { KeyboardEvent } from 'react';
|
|
1
|
+
import React, { CSSProperties, KeyboardEvent } from 'react';
|
|
2
2
|
import { MultiValue } from 'react-select';
|
|
3
3
|
|
|
4
4
|
interface KButtonProps {
|
|
@@ -34,6 +34,7 @@ interface KSpanProps {
|
|
|
34
34
|
lineHeight?: string;
|
|
35
35
|
fontStyle?: string;
|
|
36
36
|
letterSpacing?: string;
|
|
37
|
+
hoverStyle?: CSSProperties;
|
|
37
38
|
textDecoration?: string;
|
|
38
39
|
ellipsis?: boolean;
|
|
39
40
|
}
|
|
@@ -208,6 +209,7 @@ interface KSelectDateProps {
|
|
|
208
209
|
anchorToButton?: boolean;
|
|
209
210
|
position?: "top" | "bottom" | "left" | "right";
|
|
210
211
|
align?: "top" | "bottom" | "left" | "right" | "center";
|
|
212
|
+
hideBackdrop?: boolean;
|
|
211
213
|
}
|
|
212
214
|
declare const KSelectDate: React.FC<KSelectDateProps>;
|
|
213
215
|
|
|
@@ -297,6 +299,7 @@ interface KSelectRangeProps {
|
|
|
297
299
|
minimumDate?: Date;
|
|
298
300
|
maximumDate?: Date;
|
|
299
301
|
popupCalendarBackground?: string;
|
|
302
|
+
hideBackdrop?: boolean;
|
|
300
303
|
}
|
|
301
304
|
type DateRangeType = Date | null | [Date | null, Date | null];
|
|
302
305
|
declare const KSelectRange: React.FC<KSelectRangeProps>;
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import KSelectDate, { KSelectDateProps } from "./KSelectDate"
|
|
|
3
3
|
import { useEffect, useState } from "react"
|
|
4
4
|
//@ts-ignore
|
|
5
5
|
import CalendarNewIcon from "../../assets/calendar-new.svg"
|
|
6
|
+
import KSpan from "../KSpan"
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
title: "ReactComponentLibrary/KSelectDate",
|
|
@@ -13,28 +14,52 @@ export default {
|
|
|
13
14
|
} as Meta<typeof KSelectDate>
|
|
14
15
|
|
|
15
16
|
const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
|
|
16
|
-
|
|
17
17
|
const [selectedDate, setSelectedDate] = useState<Date | undefined>(undefined)
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
// console.log("selectedDate: ", selectedDate)
|
|
20
20
|
}, [selectedDate])
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
<div className=" flex flex-row gap-4 items-center">
|
|
24
|
+
<div className="flex flex-row items-center justify-center w-auto h-40 z-10">
|
|
25
|
+
<KSpan text="Lorem Ipsum is simply dummy text of the printing and typesetting industry." />
|
|
26
|
+
</div>
|
|
27
|
+
<div className="flex flex-col relative">
|
|
28
|
+
<KSelectDate
|
|
29
|
+
{...args}
|
|
30
|
+
value={selectedDate}
|
|
31
|
+
onChange={(date) => {
|
|
32
|
+
// console.log("date: ", date)
|
|
33
|
+
if (date) {
|
|
34
|
+
setSelectedDate(date)
|
|
35
|
+
console.log("updating is completed: ", date)
|
|
36
|
+
// console.log("updating is completed date.toISOString(): ", date?.toISOString())
|
|
37
|
+
} else {
|
|
38
|
+
setSelectedDate(undefined)
|
|
39
|
+
// console.log("Deleting is completed")
|
|
40
|
+
}
|
|
41
|
+
}}
|
|
42
|
+
anchorToButton
|
|
43
|
+
/>
|
|
44
|
+
<KSelectDate
|
|
45
|
+
{...args}
|
|
46
|
+
value={selectedDate}
|
|
47
|
+
onChange={(date) => {
|
|
48
|
+
// console.log("date: ", date)
|
|
49
|
+
if (date) {
|
|
50
|
+
setSelectedDate(date)
|
|
51
|
+
console.log("updating is completed: ", date)
|
|
52
|
+
// console.log("updating is completed date.toISOString(): ", date?.toISOString())
|
|
53
|
+
} else {
|
|
54
|
+
setSelectedDate(undefined)
|
|
55
|
+
// console.log("Deleting is completed")
|
|
56
|
+
}
|
|
57
|
+
}}
|
|
58
|
+
anchorToButton
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
<div></div>
|
|
62
|
+
</div>
|
|
38
63
|
)
|
|
39
64
|
}
|
|
40
65
|
|
|
@@ -34,11 +34,12 @@ export interface KSelectDateProps {
|
|
|
34
34
|
anchorToButton?: boolean // opens the calendar relative to the button's position, does not have any effect if body is not hidden.
|
|
35
35
|
position?: "top" | "bottom" | "left" | "right" // position of the calendar relative to the button's position, has effect as long as anchorButton is true
|
|
36
36
|
align?: "top" | "bottom" | "left" | "right" | "center" // lets to align the calendar, has effect as long as anchorButton is true
|
|
37
|
+
hideBackdrop?: boolean
|
|
37
38
|
}
|
|
38
39
|
interface MonthSelectorType {
|
|
39
40
|
monthName: string
|
|
40
41
|
year: string
|
|
41
|
-
date: Date
|
|
42
|
+
date: Date
|
|
42
43
|
monthIndex: string | number
|
|
43
44
|
}
|
|
44
45
|
interface DaySelectorType {
|
|
@@ -75,6 +76,8 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
|
|
|
75
76
|
const position = props.position || "bottom"
|
|
76
77
|
const align = props.align || "center"
|
|
77
78
|
|
|
79
|
+
const hideBackdrop = props.hideBackdrop || false
|
|
80
|
+
|
|
78
81
|
const formatShortWeekday = (locale: string | undefined, date: Date): string => {
|
|
79
82
|
return date.toLocaleDateString(locale, { weekday: "short" }).charAt(0) // Return only the first letter of the weekday
|
|
80
83
|
}
|
|
@@ -182,7 +185,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
|
|
|
182
185
|
)
|
|
183
186
|
}
|
|
184
187
|
|
|
185
|
-
const monthSelector = (month: string, year: string, date: Date, monthIndex:string | number) => {
|
|
188
|
+
const monthSelector = (month: string, year: string, date: Date, monthIndex: string | number) => {
|
|
186
189
|
const monthText: MonthTextType = lang.common.months_short
|
|
187
190
|
|
|
188
191
|
const text = `${monthText[monthIndex]}, ${year}`
|
|
@@ -309,6 +312,9 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
|
|
|
309
312
|
|
|
310
313
|
return (
|
|
311
314
|
<React.Fragment>
|
|
315
|
+
{openCalendar && !hideBackdrop && (
|
|
316
|
+
<div className="w-[100vw] h-[100vh] fixed left-0 top-0 z-[49] bg-[#0000004d]"/>
|
|
317
|
+
)}
|
|
312
318
|
{openCalendar && (!hideBody || !anchorToButton) && (
|
|
313
319
|
<div className="w-[100vw] h-[100vh] fixed left-0 top-0 flex items-center justify-center z-50">
|
|
314
320
|
<div>{renderPopUpCalendar()}</div>
|
|
@@ -373,7 +379,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
|
|
|
373
379
|
) : (
|
|
374
380
|
<div className="flex relative">
|
|
375
381
|
{openCalendar && anchorToButton && (
|
|
376
|
-
<div className={`absolute ${absolutePositionClassName(position, align)}`}>
|
|
382
|
+
<div className={`absolute ${absolutePositionClassName(position, align)} z-[51]`}>
|
|
377
383
|
<div>{renderPopUpCalendar()}</div>
|
|
378
384
|
</div>
|
|
379
385
|
)}
|
|
@@ -50,7 +50,25 @@ const KSelectRangeWrapper: React.FC<KSelectRangeProps> = (args) => {
|
|
|
50
50
|
// console.log("Deleting is completed")
|
|
51
51
|
}
|
|
52
52
|
}}
|
|
53
|
-
|
|
53
|
+
/>
|
|
54
|
+
<div className="relative z-10">
|
|
55
|
+
<KSelectRange
|
|
56
|
+
{...args}
|
|
57
|
+
value={selectedDate}
|
|
58
|
+
onChange={(date: DateRangeType) => {
|
|
59
|
+
// console.log("date: ", date)
|
|
60
|
+
if (date) {
|
|
61
|
+
setSelectedDate(date)
|
|
62
|
+
console.log("updating is completed: ", date)
|
|
63
|
+
// console.log("updating is completed date.toISOString(): ", date?.toISOString())
|
|
64
|
+
} else {
|
|
65
|
+
setSelectedDate(null)
|
|
66
|
+
// console.log("Deleting is completed")
|
|
67
|
+
}
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
54
72
|
)
|
|
55
73
|
}
|
|
56
74
|
|
|
@@ -63,10 +81,10 @@ KSelectRangePrimary.args = {
|
|
|
63
81
|
backgroundColor: "#F7F7F7",
|
|
64
82
|
hoverBackgroundColor: "#F3F3F3",
|
|
65
83
|
borderRadius: 24,
|
|
66
|
-
anchorToButton:true,
|
|
67
84
|
position: "top",
|
|
68
85
|
align: "center",
|
|
69
|
-
|
|
86
|
+
hideBackdrop: true,
|
|
87
|
+
anchorToButton: true,
|
|
70
88
|
onChange: (value) => {
|
|
71
89
|
if (value) {
|
|
72
90
|
console.log("value is updated using this value:", value)
|
|
@@ -30,6 +30,7 @@ export interface KSelectRangeProps {
|
|
|
30
30
|
minimumDate?: Date
|
|
31
31
|
maximumDate?: Date
|
|
32
32
|
popupCalendarBackground?: string
|
|
33
|
+
hideBackdrop?: boolean
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export type DateRangeType = Date | null | [Date | null, Date | null]
|
|
@@ -47,6 +48,7 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
47
48
|
const anchorToButton = props.anchorToButton || false
|
|
48
49
|
const position = props.position || "bottom"
|
|
49
50
|
const align = props.align || "center"
|
|
51
|
+
const hideBackdrop = props.hideBackdrop || false
|
|
50
52
|
|
|
51
53
|
const [value, setValue] = useState<DateRangeType>(props.value)
|
|
52
54
|
const [range, setRange] = useState<DateRangeType>(props.value)
|
|
@@ -59,6 +61,8 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
59
61
|
approved: -1
|
|
60
62
|
})
|
|
61
63
|
|
|
64
|
+
const [openBackdrop, setOpenBackdrop] = useState<boolean>(false)
|
|
65
|
+
|
|
62
66
|
const convertToMonthYear = (date: Date | null): string => {
|
|
63
67
|
if (!date) return "?"
|
|
64
68
|
|
|
@@ -351,6 +355,7 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
351
355
|
onClick={() => {
|
|
352
356
|
setRange(value)
|
|
353
357
|
setOpenCalendar(false)
|
|
358
|
+
setOpenBackdrop(false)
|
|
354
359
|
const approvedIndex = shorthandIndex.approved
|
|
355
360
|
setShorthandIndex({ ...shorthandIndex, current: approvedIndex })
|
|
356
361
|
if (Array.isArray(value) && value[0] !== null) {
|
|
@@ -368,6 +373,7 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
368
373
|
onClick={() => {
|
|
369
374
|
setValue(range)
|
|
370
375
|
setOpenCalendar(false)
|
|
376
|
+
setOpenBackdrop(false)
|
|
371
377
|
const currentIndex = shorthandIndex.current
|
|
372
378
|
setShorthandIndex({ ...shorthandIndex, approved: currentIndex })
|
|
373
379
|
if (Array.isArray(range) && range[0] !== null) {
|
|
@@ -395,6 +401,9 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
395
401
|
|
|
396
402
|
return (
|
|
397
403
|
<React.Fragment>
|
|
404
|
+
{openBackdrop && !hideBackdrop && (
|
|
405
|
+
<div className="w-[100vw] h-[100vh] fixed left-0 top-0 z-[49] bg-[#0000004d]"/>
|
|
406
|
+
)}
|
|
398
407
|
{openCalendar && !anchorToButton && (
|
|
399
408
|
<div
|
|
400
409
|
className="w-[100vw] h-[100vh] fixed left-0 top-0 flex items-center justify-center z-50"
|
|
@@ -405,7 +414,7 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
405
414
|
)}
|
|
406
415
|
<div className="flex relative">
|
|
407
416
|
{openCalendar && anchorToButton && (
|
|
408
|
-
<div className={`absolute
|
|
417
|
+
<div className={`absolute ${absolutePositionClassName(position, align)} z-[51]`}>
|
|
409
418
|
<div>{renderPopUpCalendar()}</div>
|
|
410
419
|
</div>
|
|
411
420
|
)}
|
|
@@ -422,9 +431,11 @@ const KSelectRange: React.FC<KSelectRangeProps> = (props) => {
|
|
|
422
431
|
onClick={() => {
|
|
423
432
|
if (!openCalendar) {
|
|
424
433
|
setOpenCalendar(true)
|
|
434
|
+
setOpenBackdrop(true)
|
|
425
435
|
} else {
|
|
426
436
|
setRange(value)
|
|
427
437
|
setOpenCalendar(false)
|
|
438
|
+
setOpenBackdrop(false)
|
|
428
439
|
const approvedIndex = shorthandIndex.approved
|
|
429
440
|
setShorthandIndex({ ...shorthandIndex, current: approvedIndex })
|
|
430
441
|
if (Array.isArray(value) && value[0] !== null) {
|
|
@@ -24,13 +24,20 @@ const Template: StoryFn<typeof KSpanWrapper> = (args) => <KSpanWrapper {...args}
|
|
|
24
24
|
|
|
25
25
|
export const KSpanPrimary = Template.bind({})
|
|
26
26
|
KSpanPrimary.args = {
|
|
27
|
-
text: "
|
|
27
|
+
text: "Login",
|
|
28
28
|
fontSize: 14,
|
|
29
|
-
color: "#
|
|
29
|
+
color: "#1F1F1F",
|
|
30
30
|
fontWeight: 400,
|
|
31
31
|
lineHeight: "20px",
|
|
32
32
|
fontStyle: "normal",
|
|
33
33
|
letterSpacing: "-0.084px",
|
|
34
|
-
textDecoration: "
|
|
35
|
-
ellipsis: true
|
|
34
|
+
textDecoration: "none",
|
|
35
|
+
ellipsis: true,
|
|
36
|
+
hoverStyle: {
|
|
37
|
+
textDecoration: "underline",
|
|
38
|
+
cursor: "pointer",
|
|
39
|
+
fontWeight: "500",
|
|
40
|
+
transitionDuration: "0.5s",
|
|
41
|
+
transitionTimingFunction: "linear"
|
|
42
|
+
}
|
|
36
43
|
}
|
|
@@ -9,11 +9,13 @@ export interface KSpanProps {
|
|
|
9
9
|
lineHeight?: string
|
|
10
10
|
fontStyle?: string
|
|
11
11
|
letterSpacing?: string
|
|
12
|
-
|
|
12
|
+
hoverStyle?: CSSProperties
|
|
13
|
+
textDecoration?: string
|
|
13
14
|
ellipsis?: boolean
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
const KSpan: React.FC<KSpanProps> = (props) => {
|
|
18
|
+
const [onHover, setOnHover] = useState(false)
|
|
17
19
|
|
|
18
20
|
const fontSize = props.fontSize || 14
|
|
19
21
|
const color = props.color || "#737373"
|
|
@@ -21,19 +23,33 @@ const KSpan: React.FC<KSpanProps> = (props) => {
|
|
|
21
23
|
const lineHeight = props.lineHeight || "20px"
|
|
22
24
|
const fontStyle = props.fontStyle || "normal"
|
|
23
25
|
const letterSpacing = props.letterSpacing || "-0.084px"
|
|
26
|
+
const hoverStyle = props.hoverStyle || {}
|
|
24
27
|
const textDecoration = props.textDecoration || "none"
|
|
25
28
|
const ellipsis = props.ellipsis || false
|
|
26
29
|
|
|
27
|
-
const ellipsisStyle = {overflow:"hidden", textOverflow:"ellipsis", whiteSpace:"nowrap"}
|
|
30
|
+
const ellipsisStyle = { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }
|
|
31
|
+
|
|
32
|
+
const baseSpanStyle = {
|
|
33
|
+
fontSize,
|
|
34
|
+
color,
|
|
35
|
+
fontWeight,
|
|
36
|
+
lineHeight,
|
|
37
|
+
fontStyle,
|
|
38
|
+
letterSpacing,
|
|
39
|
+
textDecoration,
|
|
40
|
+
...(ellipsis && ellipsisStyle)
|
|
41
|
+
}
|
|
28
42
|
|
|
29
43
|
return (
|
|
30
44
|
<span
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
className={"k-span"}
|
|
46
|
+
onMouseEnter={() => setOnHover(true)}
|
|
47
|
+
onMouseLeave={() => setOnHover(false)}
|
|
48
|
+
style={onHover ? { ...baseSpanStyle, ...hoverStyle } : { ...baseSpanStyle }}
|
|
49
|
+
>
|
|
50
|
+
{props.text}
|
|
51
|
+
</span>
|
|
36
52
|
)
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
export default KSpan
|
|
55
|
+
export default KSpan
|