kelt-ui-kit-react 1.0.2 → 1.0.3
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.
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { Value } from 'react-calendar/dist/cjs/shared/types';
|
|
2
|
+
|
|
3
|
+
export type DatePickerProps = {
|
|
4
|
+
value?: Value;
|
|
5
|
+
onChange?: (date: Value) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const Datepicker: ({ value, onChange }: DatePickerProps) => import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kelt-ui-kit-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@types/node": "^22.5.5",
|
|
10
10
|
"@vitejs/plugin-react": "^4.3.1",
|
|
11
11
|
"bootstrap-icons": "^1.11.3",
|
|
12
|
-
"react-
|
|
12
|
+
"react-date-picker": "^11.0.0",
|
|
13
13
|
"styled-components": "^6.1.13",
|
|
14
14
|
"vite": "^5.4.6",
|
|
15
15
|
"vite-plugin-dts": "^4.2.2",
|
|
@@ -1,25 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import Calendar from "react-calendar";
|
|
3
|
+
import { Value } from "react-calendar/dist/cjs/shared/types";
|
|
4
|
+
import { Icon } from "../icon/Icon";
|
|
5
|
+
import { IconSizeEnum } from "../icon/iconSize.enum";
|
|
6
|
+
import "./datePicker.css"; // Assuming you have some styles for the DatePicker
|
|
7
|
+
export type DatePickerProps = {
|
|
8
|
+
value?: Value;
|
|
9
|
+
onChange?: (date: Value) => void;
|
|
10
|
+
};
|
|
11
|
+
export const Datepicker = ({ value, onChange }: DatePickerProps) => {
|
|
12
|
+
const [date, setDate] = useState<Value>(value ?? new Date());
|
|
13
|
+
const [showCalendar, setShowCalendar] = useState(false);
|
|
14
|
+
|
|
15
|
+
const calendarRef = useRef<HTMLDivElement>(null);
|
|
16
|
+
|
|
17
|
+
const handleChange = useCallback(
|
|
18
|
+
(val: Value) => {
|
|
19
|
+
setDate(val);
|
|
20
|
+
if (onChange) {
|
|
21
|
+
onChange(val);
|
|
22
|
+
}
|
|
23
|
+
setShowCalendar(false);
|
|
24
|
+
},
|
|
25
|
+
[onChange]
|
|
26
|
+
);
|
|
4
27
|
|
|
5
|
-
|
|
6
|
-
|
|
28
|
+
const toggleCalendar = () => setShowCalendar(!showCalendar);
|
|
29
|
+
|
|
30
|
+
const handleClickOutside = useCallback((event: MouseEvent) => {
|
|
31
|
+
if (
|
|
32
|
+
calendarRef.current &&
|
|
33
|
+
!calendarRef.current.contains(event.target as Node)
|
|
34
|
+
) {
|
|
35
|
+
setShowCalendar(false);
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (showCalendar) {
|
|
41
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
42
|
+
} else {
|
|
43
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Nettoyage
|
|
47
|
+
return () => {
|
|
48
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
49
|
+
};
|
|
50
|
+
}, [showCalendar, handleClickOutside]);
|
|
7
51
|
|
|
8
52
|
return (
|
|
9
53
|
<div>
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
54
|
+
<div className="calendar" ref={calendarRef}>
|
|
55
|
+
<button className="calendar-button" onClick={toggleCalendar}>
|
|
56
|
+
<Icon
|
|
57
|
+
classIcon=" bi-calendar4-event"
|
|
58
|
+
size={IconSizeEnum.EXTRA_LARGE}
|
|
59
|
+
/>
|
|
60
|
+
</button>
|
|
61
|
+
{showCalendar && (
|
|
62
|
+
<div className="calendar-popup">
|
|
63
|
+
<Calendar onChange={handleChange} value={date} />
|
|
64
|
+
</div>
|
|
65
|
+
)}
|
|
66
|
+
</div>
|
|
23
67
|
</div>
|
|
24
68
|
);
|
|
25
69
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
.calendar {
|
|
2
|
+
position: relative;
|
|
3
|
+
.calendar-button {
|
|
4
|
+
width: 40px;
|
|
5
|
+
max-width: 40px;
|
|
6
|
+
min-width: 40px;
|
|
7
|
+
background-color: #fff;
|
|
8
|
+
i {
|
|
9
|
+
color: #333;
|
|
10
|
+
font-size: 1.6rem;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
.calendar-popup {
|
|
14
|
+
position: absolute;
|
|
15
|
+
z-index: 5;
|
|
16
|
+
.react-calendar {
|
|
17
|
+
border-color: #dedede;
|
|
18
|
+
border-style: solid;
|
|
19
|
+
border-width: 1px;
|
|
20
|
+
max-width: 300px;
|
|
21
|
+
font-size: 0.8rem;
|
|
22
|
+
button {
|
|
23
|
+
background-color: #fff;
|
|
24
|
+
color: #333;
|
|
25
|
+
min-width: auto;
|
|
26
|
+
width: auto;
|
|
27
|
+
font-size: 0.8rem;
|
|
28
|
+
padding: 0.5rem;
|
|
29
|
+
}
|
|
30
|
+
.react-calendar__month-view__weekdays__weekday {
|
|
31
|
+
text-align: center;
|
|
32
|
+
}
|
|
33
|
+
.react-calendar__navigation {
|
|
34
|
+
display: flex;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.react-calendar__tile--active {
|
|
38
|
+
background-color: #007bff;
|
|
39
|
+
color: #fff;
|
|
40
|
+
}
|
|
41
|
+
.react-calendar__tile--now {
|
|
42
|
+
background-color: #f0f0f0;
|
|
43
|
+
color: #000;
|
|
44
|
+
}
|
|
45
|
+
.react-calendar__tile--active:hover {
|
|
46
|
+
background-color: #0056b3;
|
|
47
|
+
color: #fff;
|
|
48
|
+
}
|
|
49
|
+
.react-calendar__tile--now:hover {
|
|
50
|
+
background-color: #e0e0e0;
|
|
51
|
+
color: #000;
|
|
52
|
+
}
|
|
53
|
+
.react-calendar__tile--disabled {
|
|
54
|
+
background-color: #f8f9fa;
|
|
55
|
+
color: #6c757d;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|