kahuna-base-react-components 1.2.12 → 1.3.1
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/KSelectRangeDate/KSelectRangeDate.d.ts +26 -0
- package/dist/components/KSelectRangeDate/index.d.ts +1 -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/languages/index.d.ts +10 -0
- package/package.json +1 -1
- package/src/components/KSelectRangeDate/KSelectRangeDate.stories.tsx +118 -0
- package/src/components/KSelectRangeDate/KSelectRangeDate.tsx +462 -0
- package/src/components/KSelectRangeDate/KSelectRangeDateCustom.css +351 -0
- package/src/components/KSelectRangeDate/index.ts +1 -0
- package/src/languages/en.json +5 -0
- package/src/languages/tr.json +5 -0
|
@@ -20,6 +20,11 @@ export declare const getLanguageJson: () => {
|
|
|
20
20
|
range: string;
|
|
21
21
|
};
|
|
22
22
|
button_text: {
|
|
23
|
+
yesterday: string;
|
|
24
|
+
last_three_days: string;
|
|
25
|
+
last_week: string;
|
|
26
|
+
last_two_week: string;
|
|
27
|
+
last_month: string;
|
|
23
28
|
last_three_months: string;
|
|
24
29
|
last_six_months: string;
|
|
25
30
|
last_twelve_months: string;
|
|
@@ -51,6 +56,11 @@ export declare const lang: {
|
|
|
51
56
|
range: string;
|
|
52
57
|
};
|
|
53
58
|
button_text: {
|
|
59
|
+
yesterday: string;
|
|
60
|
+
last_three_days: string;
|
|
61
|
+
last_week: string;
|
|
62
|
+
last_two_week: string;
|
|
63
|
+
last_month: string;
|
|
54
64
|
last_three_months: string;
|
|
55
65
|
last_six_months: string;
|
|
56
66
|
last_twelve_months: string;
|
package/package.json
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Meta, StoryFn } from "@storybook/react"
|
|
2
|
+
import KSelectRangeDate, { KSelectRangeDateProps, DateRangeType } from "./KSelectRangeDate"
|
|
3
|
+
import { useEffect, useState } from "react"
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import AppleIcon from "../../assets/platforms/apple-music.svg"
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import MetaIcon from "../../assets/platforms/Meta.svg"
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import TiktokIcon from "../../assets/platforms/tiktok.svg"
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import SpotifyIcon from "../../assets/platforms/Spotify.svg"
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import YoutubeIcon from "../../assets/platforms/youtube.svg"
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import NcmIcon from "../../assets/platforms/ncm.svg"
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import CaretDownIcon from "../../assets/platforms/caret-down.svg"
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
title: "ReactComponentLibrary/KSelectRangeDate",
|
|
21
|
+
component: KSelectRangeDate,
|
|
22
|
+
parameters: {
|
|
23
|
+
layout: "centered"
|
|
24
|
+
}
|
|
25
|
+
} as Meta<typeof KSelectRangeDate>
|
|
26
|
+
|
|
27
|
+
const KSelectRangeDateWrapper: React.FC<KSelectRangeDateProps> = (args) => {
|
|
28
|
+
const [selectedDate, setSelectedDate] = useState<DateRangeType>([
|
|
29
|
+
new Date(new Date().setDate(new Date().getDate() - 7)), // Start date: 3 months ago
|
|
30
|
+
new Date() // End date: today
|
|
31
|
+
])
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
// console.log("selectedDate: ", selectedDate)
|
|
34
|
+
}, [selectedDate])
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div>
|
|
38
|
+
<KSelectRangeDate
|
|
39
|
+
{...args}
|
|
40
|
+
value={selectedDate}
|
|
41
|
+
onChange={(date: DateRangeType) => {
|
|
42
|
+
// console.log("date: ", date)
|
|
43
|
+
if (date) {
|
|
44
|
+
setSelectedDate(date)
|
|
45
|
+
console.log("updating is completed: ", date)
|
|
46
|
+
// console.log("updating is completed date.toISOString(): ", date?.toISOString())
|
|
47
|
+
} else {
|
|
48
|
+
setSelectedDate(null)
|
|
49
|
+
// console.log("Deleting is completed")
|
|
50
|
+
}
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
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>
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const Template: StoryFn<typeof KSelectRangeDateWrapper> = (args) => <KSelectRangeDateWrapper {...args} />
|
|
75
|
+
|
|
76
|
+
export const KSelectRangePrimary = Template.bind({})
|
|
77
|
+
KSelectRangePrimary.args = {
|
|
78
|
+
width: "48px",
|
|
79
|
+
height: "48px",
|
|
80
|
+
backgroundColor: "#F7F7F7",
|
|
81
|
+
hoverBackgroundColor: "#F3F3F3",
|
|
82
|
+
borderRadius: 24,
|
|
83
|
+
position: "top",
|
|
84
|
+
align: "center",
|
|
85
|
+
hideBackdrop: true,
|
|
86
|
+
anchorToButton: true,
|
|
87
|
+
onChange: (value) => {
|
|
88
|
+
if (value) {
|
|
89
|
+
console.log("value is updated using this value:", value)
|
|
90
|
+
} else {
|
|
91
|
+
console.log("value is deleted, because it is: ", value)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const KSelectRangeDateMinimumDate = Template.bind({})
|
|
97
|
+
KSelectRangeDateMinimumDate.args = {
|
|
98
|
+
width: "48px",
|
|
99
|
+
height: "48px",
|
|
100
|
+
backgroundColor: "#F7F7F7",
|
|
101
|
+
hoverBackgroundColor: "#F3F3F3",
|
|
102
|
+
borderRadius: 24,
|
|
103
|
+
anchorToButton: true,
|
|
104
|
+
position: "top",
|
|
105
|
+
align: "center",
|
|
106
|
+
minimumDate: new Date(new Date().getTime() + 14 * 24 * 60 * 60 * 1000),
|
|
107
|
+
|
|
108
|
+
onChange: (value) => {
|
|
109
|
+
if (value) {
|
|
110
|
+
console.log("value is updated using this value:", value)
|
|
111
|
+
} else {
|
|
112
|
+
console.log("value is deleted, because it is: ", value)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const KSelectRangeHoverText = Template.bind({})
|
|
118
|
+
KSelectRangeHoverText.args = {}
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
import React, { CSSProperties, useEffect, useRef, useState } from "react"
|
|
2
|
+
import Calendar from "react-calendar"
|
|
3
|
+
import "./KSelectRangeDateCustom.css"
|
|
4
|
+
//@ts-ignore
|
|
5
|
+
import LeftIcon from "../../assets/chevron-left.svg"
|
|
6
|
+
//@ts-ignore
|
|
7
|
+
import CalendarNewIcon from "../../assets/calendar-new.svg"
|
|
8
|
+
//@ts-ignore
|
|
9
|
+
import RightIcon from "../../assets/chevron-right.svg"
|
|
10
|
+
import "../../main.css"
|
|
11
|
+
import KButton from "../KButton"
|
|
12
|
+
import KSpan from "../KSpan"
|
|
13
|
+
import { lang } from "../../languages"
|
|
14
|
+
|
|
15
|
+
export interface KSelectRangeDateProps {
|
|
16
|
+
value: DateRangeType
|
|
17
|
+
onChange: (date: DateRangeType) => void
|
|
18
|
+
width?: string
|
|
19
|
+
height?: string
|
|
20
|
+
border?: string
|
|
21
|
+
backgroundColor?: string
|
|
22
|
+
boxShadow?: string
|
|
23
|
+
icon?: string
|
|
24
|
+
padding?: string
|
|
25
|
+
hoverBackgroundColor?: string
|
|
26
|
+
borderRadius?: number
|
|
27
|
+
anchorToButton?: boolean // opens the calendar relative to the button's position
|
|
28
|
+
position?: "top" | "bottom" | "left" | "right" // position of the calendar relative to the button's position, has effect as long as anchorButton is true
|
|
29
|
+
align?: "top" | "bottom" | "left" | "right" | "center" // lets to align the calendar, has effect as long as anchorButton is true
|
|
30
|
+
minimumDate?: Date
|
|
31
|
+
maximumDate?: Date
|
|
32
|
+
popupCalendarBackground?: string
|
|
33
|
+
hideBackdrop?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type DateRangeType = Date | null | [Date | null, Date | null]
|
|
37
|
+
|
|
38
|
+
const KSelectRangeDate: React.FC<KSelectRangeDateProps> = (props) => {
|
|
39
|
+
const width = props.width || "36px"
|
|
40
|
+
const height = props.height || "36px"
|
|
41
|
+
const padding = props.padding || "8px"
|
|
42
|
+
const icon = props.icon || CalendarNewIcon
|
|
43
|
+
const boxShadow = props.boxShadow || "0 0 0 1px rgba(17, 17, 17, 0.04), 0 1px 1px 0 rgba(17, 17, 17, 0.04)"
|
|
44
|
+
const backgroundColor = props.backgroundColor || "#FFF"
|
|
45
|
+
const hoverBackgroundColor = props.hoverBackgroundColor || backgroundColor
|
|
46
|
+
const borderRadius = props.borderRadius || 10
|
|
47
|
+
const border = props.border || "none"
|
|
48
|
+
const anchorToButton = props.anchorToButton || false
|
|
49
|
+
const position = props.position || "bottom"
|
|
50
|
+
const align = props.align || "center"
|
|
51
|
+
const hideBackdrop = props.hideBackdrop || false
|
|
52
|
+
|
|
53
|
+
const [value, setValue] = useState<DateRangeType>(props.value)
|
|
54
|
+
const [range, setRange] = useState<DateRangeType>(props.value)
|
|
55
|
+
|
|
56
|
+
const [leftCalendarYear, setLeftCalendarYear] = useState<number>(new Date().getFullYear())
|
|
57
|
+
const [leftCalendarMonth, setLeftCalendarMonth] = useState<number>(new Date().getMonth())
|
|
58
|
+
|
|
59
|
+
const [openCalendar, setOpenCalendar] = useState<boolean>(false)
|
|
60
|
+
const [shorthandIndex, setShorthandIndex] = useState<{ current: number; approved: number }>({
|
|
61
|
+
current: -1,
|
|
62
|
+
approved: -1
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const [openBackdrop, setOpenBackdrop] = useState<boolean>(false)
|
|
66
|
+
|
|
67
|
+
const convertToDayMonthYear = (date: Date | null): string => {
|
|
68
|
+
if (!date) return "?"
|
|
69
|
+
|
|
70
|
+
const year = date.getFullYear()
|
|
71
|
+
const month = date.getMonth()
|
|
72
|
+
const day = date.getDate()
|
|
73
|
+
|
|
74
|
+
const monthNames: { [key: string]: string } = lang.common.months_short
|
|
75
|
+
return `${day} ${monthNames[month.toString()]} ${year}`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const formatShortWeekday = (locale: string | undefined, date: Date): string => {
|
|
79
|
+
return date.toLocaleDateString(locale, { weekday: "short" }).charAt(0) // Return only the first letter of the weekday
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const formatMonthYear = (locale: string | undefined, date: Date): string => {
|
|
83
|
+
const formattedDate = date.toLocaleDateString(locale, { month: "short", year: "numeric" })
|
|
84
|
+
const [month, year] = formattedDate.split(" ")
|
|
85
|
+
const capitalizedMonth = month.charAt(0).toUpperCase() + month.slice(1).toLowerCase()
|
|
86
|
+
return `${capitalizedMonth}, ${year}`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const shorthandDateSelection = (range: number) => {
|
|
90
|
+
const theDate = new Date()
|
|
91
|
+
// if isMonth is false, then it is year
|
|
92
|
+
const year = theDate.getFullYear()
|
|
93
|
+
const month = theDate.getMonth()
|
|
94
|
+
const day = theDate.getDate()
|
|
95
|
+
|
|
96
|
+
const endDate = new Date(year, month, day)
|
|
97
|
+
const startDate = new Date(year, month, day - range)
|
|
98
|
+
setRange([startDate, endDate])
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const onClickDayEvent = (clickedDate: Date) => {
|
|
102
|
+
if (!Array.isArray(range)) return
|
|
103
|
+
|
|
104
|
+
if (range[0] === null && range[1] === null) {
|
|
105
|
+
setRange([clickedDate, null])
|
|
106
|
+
} else if (range[0] !== null && range[1] === null) {
|
|
107
|
+
const newRange: DateRangeType =
|
|
108
|
+
range[0].getTime() > clickedDate.getTime() ? [clickedDate, range[0]] : [range[0], clickedDate]
|
|
109
|
+
setRange(newRange)
|
|
110
|
+
setOpenCalendar(false)
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
setOpenCalendar(true)
|
|
113
|
+
}, 100)
|
|
114
|
+
} else if (range[0] !== null && range[1] !== null) {
|
|
115
|
+
setRange([clickedDate, null])
|
|
116
|
+
}
|
|
117
|
+
setShorthandIndex({ ...shorthandIndex, current: -1 })
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const tileClassName = ({ date, view }: { date: Date; view: string }) => {
|
|
121
|
+
if (view === "year") {
|
|
122
|
+
// Apply active class for current month
|
|
123
|
+
if (!(Array.isArray(range) && range[0] && range[1])) return
|
|
124
|
+
|
|
125
|
+
if (
|
|
126
|
+
range[0]?.getFullYear() === date.getFullYear() &&
|
|
127
|
+
range[0]?.getMonth() === date.getMonth() &&
|
|
128
|
+
range[1]?.getFullYear() === date.getFullYear() &&
|
|
129
|
+
range[1]?.getMonth() === date.getMonth()
|
|
130
|
+
) {
|
|
131
|
+
return "active-month-first-month active-month-last-month"
|
|
132
|
+
} else if (range[0]?.getFullYear() === date.getFullYear() && range[0]?.getMonth() === date.getMonth()) {
|
|
133
|
+
return "active-month-first-month"
|
|
134
|
+
} else if (range[1]?.getFullYear() === date.getFullYear() && range[1]?.getMonth() === date.getMonth()) {
|
|
135
|
+
return "active-month-last-month"
|
|
136
|
+
} else if (range[0]?.getTime() < date.getTime() && date.getTime() < range[1]?.getTime()) {
|
|
137
|
+
if (date.getMonth() % 3 === 0) {
|
|
138
|
+
return "active-month-range-month-left"
|
|
139
|
+
} else if (date.getMonth() % 3 === 1) {
|
|
140
|
+
return "active-month-range-month-middle"
|
|
141
|
+
} else {
|
|
142
|
+
return "active-month-range-month-right"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const tileContent = ({ date, view }: { date: Date; view: string }) => {
|
|
151
|
+
if (view === "year") {
|
|
152
|
+
const month = date.toLocaleString(lang.locale, { month: "long" })
|
|
153
|
+
return (
|
|
154
|
+
<div className="absolute left-0 top-0 h-full w-full flex items-center justify-center tile-content-external-div">
|
|
155
|
+
{Array.isArray(range) &&
|
|
156
|
+
range[1] !== null &&
|
|
157
|
+
((range[0]?.getFullYear() === date.getFullYear() && range[0]?.getMonth() === date.getMonth()) ||
|
|
158
|
+
(range[1]?.getFullYear() === date.getFullYear() && range[1]?.getMonth() === date.getMonth())) && (
|
|
159
|
+
<abbr>{month}</abbr>
|
|
160
|
+
)}
|
|
161
|
+
</div>
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
return null
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
props.onChange(value)
|
|
169
|
+
}, [value])
|
|
170
|
+
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
if (Array.isArray(range)) {
|
|
173
|
+
if (range[0] !== null && range[1] !== null) {
|
|
174
|
+
setLeftCalendarYear(range[0].getFullYear())
|
|
175
|
+
setLeftCalendarMonth(range[0].getMonth())
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}, [range])
|
|
179
|
+
|
|
180
|
+
const renderPopUpCalendar = () => {
|
|
181
|
+
return (
|
|
182
|
+
<div className="flex flex-row">
|
|
183
|
+
<div
|
|
184
|
+
className="w-[160px] bg-[#FFF] flex flex-col items-center gap-2 justify-start px-2.5 pt-5 pb-4 border-r-0"
|
|
185
|
+
style={{
|
|
186
|
+
border: "1px solid #F3F3F3",
|
|
187
|
+
borderRightWidth: "0px",
|
|
188
|
+
borderTopLeftRadius: "0px",
|
|
189
|
+
borderBottomLeftRadius: "16px"
|
|
190
|
+
}}
|
|
191
|
+
>
|
|
192
|
+
<KButton
|
|
193
|
+
onClick={() => {
|
|
194
|
+
shorthandDateSelection(2)
|
|
195
|
+
setShorthandIndex({ ...shorthandIndex, current: 0 })
|
|
196
|
+
}}
|
|
197
|
+
width="140px"
|
|
198
|
+
background={shorthandIndex.current === 0 ? "#F7F7F7" : "#FFF"}
|
|
199
|
+
textColor={shorthandIndex.current === 0 ? "#000" : "#999"}
|
|
200
|
+
text={lang.button_text.yesterday}
|
|
201
|
+
borderRadius={8}
|
|
202
|
+
shadowDisabled
|
|
203
|
+
hoverBackground="#F0F0F0"
|
|
204
|
+
height="40px"
|
|
205
|
+
/>
|
|
206
|
+
<KButton
|
|
207
|
+
onClick={() => {
|
|
208
|
+
shorthandDateSelection(3)
|
|
209
|
+
setShorthandIndex({ ...shorthandIndex, current: 1 })
|
|
210
|
+
}}
|
|
211
|
+
width="140px"
|
|
212
|
+
background={shorthandIndex.current === 1 ? "#F7F7F7" : "#FFF"}
|
|
213
|
+
textColor={shorthandIndex.current === 1 ? "#000" : "#999"}
|
|
214
|
+
text={lang.button_text.last_three_days}
|
|
215
|
+
borderRadius={8}
|
|
216
|
+
shadowDisabled
|
|
217
|
+
hoverBackground="#F0F0F0"
|
|
218
|
+
height="40px"
|
|
219
|
+
/>
|
|
220
|
+
<KButton
|
|
221
|
+
onClick={() => {
|
|
222
|
+
shorthandDateSelection(7)
|
|
223
|
+
setShorthandIndex({ ...shorthandIndex, current: 2 })
|
|
224
|
+
}}
|
|
225
|
+
width="140px"
|
|
226
|
+
background={shorthandIndex.current === 2 ? "#F7F7F7" : "#FFF"}
|
|
227
|
+
textColor={shorthandIndex.current === 2 ? "#000" : "#999"}
|
|
228
|
+
text={lang.button_text.last_week}
|
|
229
|
+
borderRadius={8}
|
|
230
|
+
shadowDisabled
|
|
231
|
+
hoverBackground="#F0F0F0"
|
|
232
|
+
height="40px"
|
|
233
|
+
/>
|
|
234
|
+
<KButton
|
|
235
|
+
onClick={() => {
|
|
236
|
+
shorthandDateSelection(14)
|
|
237
|
+
setShorthandIndex({ ...shorthandIndex, current: 3 })
|
|
238
|
+
}}
|
|
239
|
+
width="140px"
|
|
240
|
+
background={shorthandIndex.current === 3 ? "#F7F7F7" : "#FFF"}
|
|
241
|
+
textColor={shorthandIndex.current === 3 ? "#000" : "#999"}
|
|
242
|
+
text={lang.button_text.last_two_week}
|
|
243
|
+
borderRadius={8}
|
|
244
|
+
shadowDisabled
|
|
245
|
+
hoverBackground="#F0F0F0"
|
|
246
|
+
height="40px"
|
|
247
|
+
/>
|
|
248
|
+
<KButton
|
|
249
|
+
onClick={() => {
|
|
250
|
+
shorthandDateSelection(31)
|
|
251
|
+
setShorthandIndex({ ...shorthandIndex, current: 4 })
|
|
252
|
+
}}
|
|
253
|
+
width="140px"
|
|
254
|
+
background={shorthandIndex.current === 4 ? "#F7F7F7" : "#FFF"}
|
|
255
|
+
textColor={shorthandIndex.current === 4 ? "#000" : "#999"}
|
|
256
|
+
text={lang.button_text.last_month}
|
|
257
|
+
borderRadius={8}
|
|
258
|
+
shadowDisabled
|
|
259
|
+
hoverBackground="#F0F0F0"
|
|
260
|
+
height="40px"
|
|
261
|
+
/>
|
|
262
|
+
</div>
|
|
263
|
+
<div className="flex flex-col gap-0">
|
|
264
|
+
<div className="flex flex-row">
|
|
265
|
+
<Calendar
|
|
266
|
+
className="kselect-range left-calendar"
|
|
267
|
+
allowPartialRange
|
|
268
|
+
tileClassName={tileClassName}
|
|
269
|
+
tileContent={tileContent}
|
|
270
|
+
locale={lang.locale}
|
|
271
|
+
value={range}
|
|
272
|
+
activeStartDate={new Date(leftCalendarYear, leftCalendarMonth, 1)}
|
|
273
|
+
onChange={(dates) => {}}
|
|
274
|
+
onClickDay={(clickedDate) => {
|
|
275
|
+
onClickDayEvent(clickedDate)
|
|
276
|
+
}}
|
|
277
|
+
defaultValue={null}
|
|
278
|
+
next2Label={null}
|
|
279
|
+
prev2Label={null}
|
|
280
|
+
prevLabel={
|
|
281
|
+
<img
|
|
282
|
+
src={LeftIcon}
|
|
283
|
+
onClick={() => {
|
|
284
|
+
setLeftCalendarMonth((current: number) => current - 1)
|
|
285
|
+
}}
|
|
286
|
+
/>
|
|
287
|
+
}
|
|
288
|
+
nextLabel={null}
|
|
289
|
+
formatShortWeekday={formatShortWeekday}
|
|
290
|
+
selectRange
|
|
291
|
+
maxDetail="month"
|
|
292
|
+
minDetail="month"
|
|
293
|
+
minDate={props.minimumDate || undefined}
|
|
294
|
+
maxDate={props.maximumDate || undefined}
|
|
295
|
+
/>
|
|
296
|
+
<Calendar
|
|
297
|
+
className="kselect-range right-calendar"
|
|
298
|
+
tileClassName={tileClassName}
|
|
299
|
+
tileContent={tileContent}
|
|
300
|
+
locale={lang.locale}
|
|
301
|
+
value={range}
|
|
302
|
+
activeStartDate={new Date(leftCalendarYear, leftCalendarMonth + 1, 1)}
|
|
303
|
+
allowPartialRange
|
|
304
|
+
onChange={(dates) => {}}
|
|
305
|
+
maxDetail="month"
|
|
306
|
+
minDetail="month"
|
|
307
|
+
onClickDay={(clickedDate) => {
|
|
308
|
+
onClickDayEvent(clickedDate)
|
|
309
|
+
}}
|
|
310
|
+
defaultValue={null}
|
|
311
|
+
next2Label={null}
|
|
312
|
+
prev2Label={null}
|
|
313
|
+
prevLabel={null}
|
|
314
|
+
nextLabel={
|
|
315
|
+
<img
|
|
316
|
+
src={RightIcon}
|
|
317
|
+
onClick={() => {
|
|
318
|
+
setLeftCalendarMonth((current: number) => current + 1)
|
|
319
|
+
}}
|
|
320
|
+
/>
|
|
321
|
+
}
|
|
322
|
+
formatShortWeekday={formatShortWeekday}
|
|
323
|
+
formatMonthYear={formatMonthYear}
|
|
324
|
+
selectRange
|
|
325
|
+
minDate={props.minimumDate || undefined}
|
|
326
|
+
maxDate={props.maximumDate || undefined}
|
|
327
|
+
/>
|
|
328
|
+
</div>
|
|
329
|
+
<div
|
|
330
|
+
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]"
|
|
331
|
+
style={{
|
|
332
|
+
borderBottomRightRadius: "16px",
|
|
333
|
+
borderBottomLeftRadius: "0px"
|
|
334
|
+
}}
|
|
335
|
+
>
|
|
336
|
+
<div className="flex items-center gap-1">
|
|
337
|
+
<KSpan text={`${lang.common.range}:`} color="#999" />
|
|
338
|
+
<KSpan
|
|
339
|
+
text={
|
|
340
|
+
Array.isArray(range) ? `${convertToDayMonthYear(range[0])} - ${convertToDayMonthYear(range[1])}` : ""
|
|
341
|
+
}
|
|
342
|
+
color="#000"
|
|
343
|
+
fontWeight={500}
|
|
344
|
+
/>
|
|
345
|
+
</div>
|
|
346
|
+
<div className="flex flex-row gap-3">
|
|
347
|
+
<KButton
|
|
348
|
+
text={lang.button_text.cancel}
|
|
349
|
+
height="48px"
|
|
350
|
+
width="108px"
|
|
351
|
+
background="#FFF"
|
|
352
|
+
textColor="#111"
|
|
353
|
+
onClick={() => {
|
|
354
|
+
setRange(value)
|
|
355
|
+
setOpenCalendar(false)
|
|
356
|
+
setOpenBackdrop(false)
|
|
357
|
+
const approvedIndex = shorthandIndex.approved
|
|
358
|
+
setShorthandIndex({ ...shorthandIndex, current: approvedIndex })
|
|
359
|
+
if (Array.isArray(value) && value[0] !== null) {
|
|
360
|
+
setLeftCalendarYear(value[0].getFullYear())
|
|
361
|
+
setLeftCalendarMonth(value[0].getMonth())
|
|
362
|
+
}
|
|
363
|
+
}}
|
|
364
|
+
/>
|
|
365
|
+
<KButton
|
|
366
|
+
text={lang.button_text.apply}
|
|
367
|
+
height="48px"
|
|
368
|
+
width="108px"
|
|
369
|
+
background="#000"
|
|
370
|
+
textColor="#FFF"
|
|
371
|
+
disabled={Array.isArray(range) && (range[0] === null || range[1] === null)}
|
|
372
|
+
onClick={() => {
|
|
373
|
+
setValue(range)
|
|
374
|
+
setOpenCalendar(false)
|
|
375
|
+
setOpenBackdrop(false)
|
|
376
|
+
const currentIndex = shorthandIndex.current
|
|
377
|
+
setShorthandIndex({ ...shorthandIndex, approved: currentIndex })
|
|
378
|
+
if (Array.isArray(range) && range[0] !== null) {
|
|
379
|
+
setLeftCalendarYear(range[0].getFullYear())
|
|
380
|
+
setLeftCalendarMonth(range[0].getMonth())
|
|
381
|
+
}
|
|
382
|
+
}}
|
|
383
|
+
/>
|
|
384
|
+
</div>
|
|
385
|
+
</div>
|
|
386
|
+
</div>
|
|
387
|
+
</div>
|
|
388
|
+
)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const absolutePositionClassName = (position: string, align: string) => {
|
|
392
|
+
const finalPosition = position
|
|
393
|
+
let finalAlign = align
|
|
394
|
+
if (finalPosition === "top" || finalPosition === "bottom") {
|
|
395
|
+
finalAlign = align === "top" || align === "bottom" ? "center" : align
|
|
396
|
+
} else if (finalPosition === "left" || finalPosition === "right") {
|
|
397
|
+
finalAlign = align === "left" || align === "right" ? "center" : align
|
|
398
|
+
}
|
|
399
|
+
return `range-${finalPosition}-${finalAlign}`
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return (
|
|
403
|
+
<React.Fragment>
|
|
404
|
+
{openBackdrop && !hideBackdrop && (
|
|
405
|
+
<div className="w-[100vw] h-[100vh] fixed left-0 top-0 z-[49] bg-[#0000004d]" />
|
|
406
|
+
)}
|
|
407
|
+
{openCalendar && !anchorToButton && (
|
|
408
|
+
<div
|
|
409
|
+
className="w-[100vw] h-[100vh] fixed left-0 top-0 flex items-center justify-center z-50"
|
|
410
|
+
style={props.popupCalendarBackground ? { background: props.popupCalendarBackground } : {}}
|
|
411
|
+
>
|
|
412
|
+
<div>{renderPopUpCalendar()}</div>
|
|
413
|
+
</div>
|
|
414
|
+
)}
|
|
415
|
+
<div className="flex relative">
|
|
416
|
+
{openCalendar && anchorToButton && (
|
|
417
|
+
<div className={`absolute ${absolutePositionClassName(position, align)} z-[51]`}>
|
|
418
|
+
<div>{renderPopUpCalendar()}</div>
|
|
419
|
+
</div>
|
|
420
|
+
)}
|
|
421
|
+
<div className="flex flex-row justify-between gap-2 items-center">
|
|
422
|
+
<div
|
|
423
|
+
style={{
|
|
424
|
+
borderRadius: borderRadius,
|
|
425
|
+
boxShadow: boxShadow,
|
|
426
|
+
border: border
|
|
427
|
+
}}
|
|
428
|
+
>
|
|
429
|
+
<KButton
|
|
430
|
+
icon={icon}
|
|
431
|
+
onClick={() => {
|
|
432
|
+
if (!openCalendar) {
|
|
433
|
+
setOpenCalendar(true)
|
|
434
|
+
setOpenBackdrop(true)
|
|
435
|
+
} else {
|
|
436
|
+
setRange(value)
|
|
437
|
+
setOpenCalendar(false)
|
|
438
|
+
setOpenBackdrop(false)
|
|
439
|
+
const approvedIndex = shorthandIndex.approved
|
|
440
|
+
setShorthandIndex({ ...shorthandIndex, current: approvedIndex })
|
|
441
|
+
if (Array.isArray(value) && value[0] !== null) {
|
|
442
|
+
setLeftCalendarYear(value[0].getFullYear())
|
|
443
|
+
setLeftCalendarMonth(value[0].getMonth())
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}}
|
|
447
|
+
padding={padding}
|
|
448
|
+
width={width}
|
|
449
|
+
height={height}
|
|
450
|
+
background={backgroundColor}
|
|
451
|
+
hoverBackground={hoverBackgroundColor}
|
|
452
|
+
borderRadius={borderRadius}
|
|
453
|
+
shadowDisabled
|
|
454
|
+
/>
|
|
455
|
+
</div>
|
|
456
|
+
</div>
|
|
457
|
+
</div>
|
|
458
|
+
</React.Fragment>
|
|
459
|
+
)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export default KSelectRangeDate
|