kahuna-base-react-components 1.3.3 → 1.3.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/components/KDropdown/KDropdown.d.ts +1 -0
- package/dist/components/KTitleSpan/KTitleSpan.d.ts +2 -0
- 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 +22 -20
- package/package.json +1 -1
- package/src/components/KDropdown/KDropdown.tsx +22 -3
- package/src/components/KSelectRangeDate/KSelectRangeDate.stories.tsx +16 -28
- package/src/components/KSelectRangeDate/KSelectRangeDate.tsx +22 -2
- package/src/components/KSpan/KSpan.stories.tsx +1 -1
- package/src/components/KTitleSpan/KTitleSpan.stories.tsx +14 -4
- package/src/components/KTitleSpan/KTitleSpan.tsx +3 -0
- package/src/components/KTooltip/KTooltip.stories.tsx +2 -6
- package/src/components/KTooltip/KTooltip.tsx +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -41,6 +41,26 @@ interface KSpanProps {
|
|
|
41
41
|
}
|
|
42
42
|
declare const KSpan: React.FC<KSpanProps>;
|
|
43
43
|
|
|
44
|
+
interface KTooltipProps {
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
content: React.ReactNode;
|
|
47
|
+
position?: "top" | "bottom" | "left" | "right";
|
|
48
|
+
align?: "top" | "bottom" | "left" | "right" | "center";
|
|
49
|
+
backgroundColor?: string;
|
|
50
|
+
width?: string;
|
|
51
|
+
height?: string;
|
|
52
|
+
zIndex?: number;
|
|
53
|
+
border?: string;
|
|
54
|
+
borderRadius?: string;
|
|
55
|
+
boxShadow?: string;
|
|
56
|
+
showArrow?: boolean;
|
|
57
|
+
arrowColor?: string;
|
|
58
|
+
padding?: string;
|
|
59
|
+
marginTop?: string;
|
|
60
|
+
marginLeft?: string;
|
|
61
|
+
}
|
|
62
|
+
declare const KTooltip: React.FC<KTooltipProps>;
|
|
63
|
+
|
|
44
64
|
interface KTitleSpanProps {
|
|
45
65
|
text: string;
|
|
46
66
|
fontSize?: number;
|
|
@@ -51,6 +71,7 @@ interface KTitleSpanProps {
|
|
|
51
71
|
letterSpacing?: string;
|
|
52
72
|
bold?: boolean;
|
|
53
73
|
ellipsis?: boolean;
|
|
74
|
+
tooltipProps?: Partial<KTooltipProps>;
|
|
54
75
|
}
|
|
55
76
|
declare const KTitleSpan: React.FC<KTitleSpanProps>;
|
|
56
77
|
|
|
@@ -179,6 +200,7 @@ interface KDropdownProps {
|
|
|
179
200
|
border?: string;
|
|
180
201
|
activeBorder?: string;
|
|
181
202
|
onInputChange?: (text: string) => void;
|
|
203
|
+
sortSelectedFirst?: boolean;
|
|
182
204
|
}
|
|
183
205
|
declare const KDropdown: React.FC<KDropdownProps>;
|
|
184
206
|
|
|
@@ -220,26 +242,6 @@ interface KSelectDateProps {
|
|
|
220
242
|
}
|
|
221
243
|
declare const KSelectDate: React.FC<KSelectDateProps>;
|
|
222
244
|
|
|
223
|
-
interface KTooltipProps {
|
|
224
|
-
children: React.ReactNode;
|
|
225
|
-
content: React.ReactNode;
|
|
226
|
-
position?: "top" | "bottom" | "left" | "right";
|
|
227
|
-
align?: "top" | "bottom" | "left" | "right" | "center";
|
|
228
|
-
backgroundColor?: string;
|
|
229
|
-
width?: string;
|
|
230
|
-
height?: string;
|
|
231
|
-
zIndex?: number;
|
|
232
|
-
border?: string;
|
|
233
|
-
borderRadius?: string;
|
|
234
|
-
boxShadow?: string;
|
|
235
|
-
showArrow?: boolean;
|
|
236
|
-
arrowColor?: string;
|
|
237
|
-
padding?: string;
|
|
238
|
-
marginTop?: string;
|
|
239
|
-
marginLeft?: string;
|
|
240
|
-
}
|
|
241
|
-
declare const KTooltip: React.FC<KTooltipProps>;
|
|
242
|
-
|
|
243
245
|
interface SliderLabelOption {
|
|
244
246
|
label: string;
|
|
245
247
|
value: number;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react"
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react"
|
|
2
2
|
import "../../main.css"
|
|
3
3
|
import Select, { MultiValue } from "react-select"
|
|
4
4
|
// @ts-ignore
|
|
@@ -54,6 +54,8 @@ export interface KDropdownProps {
|
|
|
54
54
|
border?: string
|
|
55
55
|
activeBorder?: string
|
|
56
56
|
onInputChange?: (text: string) => void
|
|
57
|
+
sortSelectedFirst?: boolean
|
|
58
|
+
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
const KDropdown: React.FC<KDropdownProps> = (props) => {
|
|
@@ -61,7 +63,7 @@ const KDropdown: React.FC<KDropdownProps> = (props) => {
|
|
|
61
63
|
const [iconCount, setIconCount] = useState<number>(0)
|
|
62
64
|
const [background, setBackground] = useState("#F5F5F5")
|
|
63
65
|
const [border, setBorder] = useState("none")
|
|
64
|
-
|
|
66
|
+
|
|
65
67
|
useEffect(() => {
|
|
66
68
|
const emptyBackground = props.background || "#F5F5F5"
|
|
67
69
|
const activeBackground = props.activeBackground || "#FFF"
|
|
@@ -77,6 +79,7 @@ const KDropdown: React.FC<KDropdownProps> = (props) => {
|
|
|
77
79
|
setSelectedOption(props.selected)
|
|
78
80
|
}, [props.selected])
|
|
79
81
|
|
|
82
|
+
|
|
80
83
|
const width = props.width || "100%"
|
|
81
84
|
const height = props.height || "auto"
|
|
82
85
|
const borderRadius = props.borderRadius || 10
|
|
@@ -97,6 +100,22 @@ const KDropdown: React.FC<KDropdownProps> = (props) => {
|
|
|
97
100
|
const placeholderColor = props.placeholderColor || "#848484"
|
|
98
101
|
const enableIndicator = props.enableIndicator || false
|
|
99
102
|
const allowContainerShrink = props.allowContainerShrink || false
|
|
103
|
+
|
|
104
|
+
const sortedOptions = useMemo<KSelectOption[]>(() => {
|
|
105
|
+
if (!props.sortSelectedFirst) {
|
|
106
|
+
return props.options
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!selectedOption || !isMulti) {
|
|
110
|
+
return props.options
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const selections = (selectedOption as KSelectOption[]).map((o) => o.value)
|
|
114
|
+
const selectedOnes = props.options.filter((opt) => selections.includes(opt.value))
|
|
115
|
+
const others = props.options.filter((opt) => !selections.includes(opt.value))
|
|
116
|
+
return [...selectedOnes, ...others]
|
|
117
|
+
}, [props.options, selectedOption, isMulti, props.sortSelectedFirst])
|
|
118
|
+
|
|
100
119
|
let closeMenuOnSelect = true
|
|
101
120
|
if (props.closeMenuOnSelect === false) {
|
|
102
121
|
closeMenuOnSelect = false
|
|
@@ -235,7 +254,7 @@ const KDropdown: React.FC<KDropdownProps> = (props) => {
|
|
|
235
254
|
name={props.label || ""}
|
|
236
255
|
closeMenuOnSelect={closeMenuOnSelect}
|
|
237
256
|
placeholder={props.placeholder || ""}
|
|
238
|
-
options={
|
|
257
|
+
options={sortedOptions}
|
|
239
258
|
className={"k-dropdown"}
|
|
240
259
|
onInputChange={(text) => {
|
|
241
260
|
if (props.onInputChange) props.onInputChange(text)
|
|
@@ -30,43 +30,30 @@ const KSelectRangeDateWrapper: React.FC<KSelectRangeDateProps> = (args) => {
|
|
|
30
30
|
new Date() // End date: today
|
|
31
31
|
])
|
|
32
32
|
useEffect(() => {
|
|
33
|
-
|
|
33
|
+
console.log("selectedDate: ", selectedDate)
|
|
34
34
|
}, [selectedDate])
|
|
35
|
+
const MILISECONDS_MONTH = 2678400000
|
|
36
|
+
|
|
35
37
|
|
|
36
38
|
return (
|
|
37
39
|
<div>
|
|
38
40
|
<KSelectRangeDate
|
|
39
41
|
{...args}
|
|
40
42
|
value={selectedDate}
|
|
41
|
-
onChange={(
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// console.log("Deleting is completed")
|
|
43
|
+
onChange={(event: any) => {
|
|
44
|
+
console.log("works")
|
|
45
|
+
if (!event) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
if (event[1] - event[0] > MILISECONDS_MONTH) {
|
|
49
|
+
console.log("not allowed")
|
|
50
|
+
return
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
setSelectedDate(event)
|
|
51
54
|
}}
|
|
52
55
|
/>
|
|
53
|
-
<div className="relative z-10">
|
|
54
|
-
<KSelectRangeDate
|
|
55
|
-
{...args}
|
|
56
|
-
value={selectedDate}
|
|
57
|
-
onChange={(date: DateRangeType) => {
|
|
58
|
-
// console.log("date: ", date)
|
|
59
|
-
if (date) {
|
|
60
|
-
setSelectedDate(date)
|
|
61
|
-
console.log("updating is completed: ", date)
|
|
62
|
-
// console.log("updating is completed date.toISOString(): ", date?.toISOString())
|
|
63
|
-
} else {
|
|
64
|
-
setSelectedDate(null)
|
|
65
|
-
// console.log("Deleting is completed")
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
/>
|
|
69
|
-
</div>
|
|
56
|
+
<div className="relative z-10"></div>
|
|
70
57
|
</div>
|
|
71
58
|
)
|
|
72
59
|
}
|
|
@@ -80,10 +67,11 @@ KSelectRangePrimary.args = {
|
|
|
80
67
|
backgroundColor: "#F7F7F7",
|
|
81
68
|
hoverBackgroundColor: "#F3F3F3",
|
|
82
69
|
borderRadius: 24,
|
|
83
|
-
position: "
|
|
70
|
+
position: "bottom",
|
|
84
71
|
align: "center",
|
|
85
72
|
hideBackdrop: true,
|
|
86
73
|
anchorToButton: true,
|
|
74
|
+
|
|
87
75
|
onChange: (value) => {
|
|
88
76
|
if (value) {
|
|
89
77
|
console.log("value is updated using this value:", value)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react"
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react"
|
|
2
2
|
import Calendar from "react-calendar"
|
|
3
3
|
import "./KSelectRangeDateCustom.css"
|
|
4
4
|
//@ts-ignore
|
|
@@ -52,11 +52,30 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
|
|
|
52
52
|
|
|
53
53
|
const [value, setValue] = useState<DateRangeType>(props.value)
|
|
54
54
|
const [range, setRange] = useState<DateRangeType>(props.value)
|
|
55
|
+
const [openCalendar, setOpenCalendar] = useState<boolean>(false)
|
|
56
|
+
|
|
57
|
+
const skipNextOpenRef = useRef(false)
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setValue(props.value)
|
|
61
|
+
setRange(props.value)
|
|
62
|
+
}, [props.value])
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (openCalendar) {
|
|
66
|
+
if(skipNextOpenRef?.current) {
|
|
67
|
+
skipNextOpenRef.current = false
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setRange(props.value)
|
|
72
|
+
}
|
|
73
|
+
}, [props.value, openCalendar])
|
|
55
74
|
|
|
56
75
|
const [leftCalendarYear, setLeftCalendarYear] = useState<number>(new Date().getFullYear())
|
|
57
76
|
const [leftCalendarMonth, setLeftCalendarMonth] = useState<number>(new Date().getMonth())
|
|
58
77
|
|
|
59
|
-
|
|
78
|
+
|
|
60
79
|
const [shorthandIndex, setShorthandIndex] = useState<{ current: number; approved: number }>({
|
|
61
80
|
current: -1,
|
|
62
81
|
approved: -1
|
|
@@ -107,6 +126,7 @@ const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
|
|
|
107
126
|
const newRange: DateRangeType =
|
|
108
127
|
range[0].getTime() > clickedDate.getTime() ? [clickedDate, range[0]] : [range[0], clickedDate]
|
|
109
128
|
setRange(newRange)
|
|
129
|
+
skipNextOpenRef.current = true
|
|
110
130
|
setOpenCalendar(false)
|
|
111
131
|
setTimeout(() => {
|
|
112
132
|
setOpenCalendar(true)
|
|
@@ -24,7 +24,7 @@ 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: "Burada uzun metin var, overflow olabilir.",
|
|
28
28
|
fontSize: 14,
|
|
29
29
|
color: "#1F1F1F",
|
|
30
30
|
fontWeight: 400,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {Meta, StoryFn} from "@storybook/react";
|
|
2
2
|
import KTitleSpan, { KTitleSpanProps } from "./KTitleSpan";
|
|
3
|
+
import KSpan from "../KSpan";
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
title: "ReactComponentLibrary/KTitleSpan",
|
|
@@ -21,18 +22,27 @@ const KTitleSpanWrapper: React.FC<KTitleSpanProps> = (args) => {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const Template: StoryFn<typeof KTitleSpanWrapper> = (args) => <KTitleSpanWrapper {...args} />;
|
|
24
|
-
|
|
25
|
+
const myText = "Hello how are you, how is it going? "
|
|
25
26
|
export const KTitleSpanPrimary = Template.bind({});
|
|
26
27
|
KTitleSpanPrimary.args = {
|
|
27
|
-
text:
|
|
28
|
+
text: myText,
|
|
28
29
|
fontSize: 48,
|
|
29
30
|
color: "#111",
|
|
30
31
|
lineHeight: "56px",
|
|
31
32
|
fontStyle: "normal",
|
|
32
33
|
letterSpacing: "-0.48px",
|
|
33
34
|
bold: false,
|
|
34
|
-
ellipsis: true
|
|
35
|
-
|
|
35
|
+
ellipsis: true,
|
|
36
|
+
tooltipProps: {
|
|
37
|
+
width: "150px",
|
|
38
|
+
position: "bottom",
|
|
39
|
+
content: (
|
|
40
|
+
<div className="w-full whitespace-normal">
|
|
41
|
+
<KSpan text={myText} color="#111" />
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
36
46
|
|
|
37
47
|
export const KTitleSpanSecondary = Template.bind({});
|
|
38
48
|
KTitleSpanSecondary.args = {
|
|
@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from "react"
|
|
|
2
2
|
import "../../main.css"
|
|
3
3
|
import KTooltip from "../KTooltip"
|
|
4
4
|
import KSpan from "../KSpan"
|
|
5
|
+
import { KTooltipProps } from "../KTooltip/KTooltip"
|
|
5
6
|
|
|
6
7
|
export interface KTitleSpanProps {
|
|
7
8
|
text: string
|
|
@@ -13,6 +14,7 @@ export interface KTitleSpanProps {
|
|
|
13
14
|
letterSpacing?: string
|
|
14
15
|
bold?: boolean
|
|
15
16
|
ellipsis?: boolean
|
|
17
|
+
tooltipProps?: Partial<KTooltipProps>
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
const KTitleSpan: React.FC<KTitleSpanProps> = (props) => {
|
|
@@ -55,6 +57,7 @@ const KTitleSpan: React.FC<KTitleSpanProps> = (props) => {
|
|
|
55
57
|
<KSpan text={props.text} color="#111" />
|
|
56
58
|
</div>
|
|
57
59
|
}
|
|
60
|
+
{...props.tooltipProps}
|
|
58
61
|
>
|
|
59
62
|
<span
|
|
60
63
|
ref={textRef}
|
|
@@ -21,11 +21,7 @@ const Template: StoryFn<KTooltipProps> = (args) => (
|
|
|
21
21
|
|
|
22
22
|
export const KTooltipPrimary = Template.bind({})
|
|
23
23
|
KTooltipPrimary.args = {
|
|
24
|
-
content:
|
|
25
|
-
<div className="bg-red-100 flex justify-center items-center">
|
|
26
|
-
<div className="bg-green-300 font-extrabold ">BURADA</div>
|
|
27
|
-
</div>
|
|
28
|
-
),
|
|
24
|
+
content: "null",
|
|
29
25
|
position: "top",
|
|
30
26
|
align: "right",
|
|
31
27
|
zIndex: 1000,
|
|
@@ -38,7 +34,7 @@ KTooltipPrimary.args = {
|
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
export const KTooltipSecondary = Template.bind({})
|
|
41
|
-
|
|
37
|
+
KTooltipSecondary.args = {
|
|
42
38
|
content: (
|
|
43
39
|
<div className="flex flex-col gap-2 justify-center items-start px-4 py-2">
|
|
44
40
|
<div
|
|
@@ -3,7 +3,7 @@ import "../../main.css"
|
|
|
3
3
|
|
|
4
4
|
export interface KTooltipProps {
|
|
5
5
|
children: React.ReactNode
|
|
6
|
-
content: React.ReactNode
|
|
6
|
+
content: React.ReactNode // if content === null the tooltip will not be visible
|
|
7
7
|
position?: "top" | "bottom" | "left" | "right"
|
|
8
8
|
align?: "top" | "bottom" | "left" | "right" | "center"
|
|
9
9
|
backgroundColor?: string
|
|
@@ -61,7 +61,7 @@ const KTooltip: React.FC<KTooltipProps> = (props) => {
|
|
|
61
61
|
<div className="relative box-border" onMouseEnter={showTooltip} onMouseLeave={hideTooltip}>
|
|
62
62
|
{props.children}
|
|
63
63
|
|
|
64
|
-
<div
|
|
64
|
+
{props.content !== null && <div
|
|
65
65
|
className={`${absolutePositionClassName(position, align)} absolute ${
|
|
66
66
|
isVisible ? "k-tooltip-enter" : "k-tooltip-exit"
|
|
67
67
|
}`}
|
|
@@ -81,7 +81,7 @@ const KTooltip: React.FC<KTooltipProps> = (props) => {
|
|
|
81
81
|
{props.content}
|
|
82
82
|
</div>
|
|
83
83
|
{showArrow && <div className={`arrow-${position}`} style={{ backgroundColor: arrowColor, zIndex: -200 }}></div>}
|
|
84
|
-
</div>
|
|
84
|
+
</div>}
|
|
85
85
|
</div>
|
|
86
86
|
)
|
|
87
87
|
}
|