ar-design 0.4.27 → 0.4.29
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/assets/css/components/data-display/calendar/styles.week-view.css +7 -3
- package/dist/components/data-display/calendar/Body.d.ts +4 -3
- package/dist/components/data-display/calendar/Body.js +2 -2
- package/dist/components/data-display/calendar/IProps.d.ts +3 -2
- package/dist/components/data-display/calendar/index.d.ts +4 -1
- package/dist/components/data-display/calendar/index.js +2 -2
- package/dist/components/data-display/calendar/views/Week.d.ts +4 -3
- package/dist/components/data-display/calendar/views/Week.js +56 -65
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
display: flex;
|
|
12
12
|
flex-direction: row;
|
|
13
13
|
width: 100%;
|
|
14
|
+
padding-left: 50px;
|
|
14
15
|
|
|
15
16
|
> .item {
|
|
16
17
|
display: flex;
|
|
@@ -50,22 +51,24 @@
|
|
|
50
51
|
> .grid {
|
|
51
52
|
position: relative;
|
|
52
53
|
width: 100%;
|
|
54
|
+
height: calc(24 * 60px);
|
|
53
55
|
border: solid 1px transparent;
|
|
54
56
|
border-top-color: var(--gray-200);
|
|
57
|
+
overflow: hidden;
|
|
55
58
|
|
|
56
59
|
> .events-layer {
|
|
57
60
|
position: absolute;
|
|
58
61
|
top: 0;
|
|
59
62
|
left: 0;
|
|
60
|
-
|
|
63
|
+
width: 100%;
|
|
64
|
+
height: 100%;
|
|
65
|
+
pointer-events: none;
|
|
61
66
|
z-index: 1;
|
|
62
67
|
|
|
63
68
|
> .event-box {
|
|
64
69
|
position: absolute;
|
|
65
|
-
background-color: rgba(var(--primary-rgb), 0.75);
|
|
66
70
|
width: calc(100% / 7);
|
|
67
71
|
padding: 0.5rem;
|
|
68
|
-
border-radius: var(--border-radius-sm);
|
|
69
72
|
color: var(--white);
|
|
70
73
|
font-size: 12px;
|
|
71
74
|
}
|
|
@@ -73,6 +76,7 @@
|
|
|
73
76
|
|
|
74
77
|
> .row {
|
|
75
78
|
position: relative;
|
|
79
|
+
height: 60px;
|
|
76
80
|
margin: auto;
|
|
77
81
|
|
|
78
82
|
&:nth-child(2) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View } from "../../../libs/types";
|
|
3
3
|
import { CalendarEvent } from "./IProps";
|
|
4
|
-
interface IProps {
|
|
5
|
-
data: CalendarEvent[];
|
|
4
|
+
interface IProps<T> {
|
|
5
|
+
data: (T & CalendarEvent)[];
|
|
6
|
+
renderItem: (item: T, index: number) => React.JSX.Element;
|
|
6
7
|
states: {
|
|
7
8
|
currentDate: {
|
|
8
9
|
get: Date;
|
|
@@ -17,5 +18,5 @@ interface IProps {
|
|
|
17
18
|
locale?: Intl.LocalesArgument;
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
|
-
declare const Body: ({ data, states, config }: IProps) => React.JSX.Element;
|
|
21
|
+
declare const Body: <T>({ data, renderItem, states, config }: IProps<T>) => React.JSX.Element;
|
|
21
22
|
export default Body;
|
|
@@ -2,11 +2,11 @@ import React from "react";
|
|
|
2
2
|
import Day from "./views/Day";
|
|
3
3
|
import Week from "./views/Week";
|
|
4
4
|
import Month from "./views/Month";
|
|
5
|
-
const Body = ({ data, states, config })
|
|
5
|
+
const Body = function ({ data, renderItem, states, config }) {
|
|
6
6
|
if (states.view.get === "Day")
|
|
7
7
|
return React.createElement(Day, null);
|
|
8
8
|
else if (states.view.get === "Week")
|
|
9
|
-
return React.createElement(Week, { data: data, states: { currentDate: states.currentDate }, config: config });
|
|
9
|
+
return React.createElement(Week, { data: data, renderItem: renderItem, states: { currentDate: states.currentDate }, config: config });
|
|
10
10
|
else if (states.view.get === "Month")
|
|
11
11
|
return React.createElement(Month, null);
|
|
12
12
|
return React.createElement(React.Fragment, null, "...");
|
|
@@ -2,8 +2,9 @@ export type CalendarEvent = {
|
|
|
2
2
|
start: Date;
|
|
3
3
|
end: Date;
|
|
4
4
|
};
|
|
5
|
-
interface IProps {
|
|
6
|
-
data: CalendarEvent[];
|
|
5
|
+
interface IProps<T> {
|
|
6
|
+
data: (T & CalendarEvent)[];
|
|
7
|
+
renderItem: (item: T, index: number) => React.JSX.Element;
|
|
7
8
|
config?: {
|
|
8
9
|
locale?: Intl.LocalesArgument;
|
|
9
10
|
weekStartsOn?: number;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import IProps from "./IProps";
|
|
3
3
|
import "../../../assets/css/components/data-display/calendar/styles.css";
|
|
4
|
-
declare const Calendar:
|
|
4
|
+
declare const Calendar: {
|
|
5
|
+
<T>({ data, renderItem, config }: IProps<T>): React.JSX.Element;
|
|
6
|
+
displayName: string;
|
|
7
|
+
};
|
|
5
8
|
export default Calendar;
|
|
@@ -3,7 +3,7 @@ import React, { useState } from "react";
|
|
|
3
3
|
import Body from "./Body";
|
|
4
4
|
import Header from "./Header";
|
|
5
5
|
import "../../../assets/css/components/data-display/calendar/styles.css";
|
|
6
|
-
const Calendar = ({ data, config })
|
|
6
|
+
const Calendar = function ({ data, renderItem, config }) {
|
|
7
7
|
// states
|
|
8
8
|
const [currentDate, setCurrentDate] = useState(new Date());
|
|
9
9
|
const [view, setView] = useState("Week");
|
|
@@ -15,7 +15,7 @@ const Calendar = ({ data, config }) => {
|
|
|
15
15
|
set: setView,
|
|
16
16
|
},
|
|
17
17
|
}, config: config }),
|
|
18
|
-
React.createElement(Body, { data: data, states: {
|
|
18
|
+
React.createElement(Body, { data: data, renderItem: renderItem, states: {
|
|
19
19
|
currentDate: { get: currentDate, set: setCurrentDate },
|
|
20
20
|
view: {
|
|
21
21
|
get: view,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CalendarEvent } from "../IProps";
|
|
3
|
-
interface IProps {
|
|
4
|
-
data: CalendarEvent[];
|
|
3
|
+
interface IProps<T> {
|
|
4
|
+
data: (T & CalendarEvent)[];
|
|
5
|
+
renderItem: (item: T, index: number) => React.JSX.Element;
|
|
5
6
|
states: {
|
|
6
7
|
currentDate: {
|
|
7
8
|
get: Date;
|
|
@@ -13,5 +14,5 @@ interface IProps {
|
|
|
13
14
|
weekStartsOn?: number;
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
|
-
declare const Week: ({ data, states, config }: IProps) => React.JSX.Element;
|
|
17
|
+
declare const Week: <T>({ data, renderItem, states, config }: IProps<T>) => React.JSX.Element;
|
|
17
18
|
export default Week;
|
|
@@ -1,82 +1,61 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
const Week = ({ data, states, config })
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
const Week = function ({ data, renderItem, states, config }) {
|
|
3
3
|
const startHour = 0;
|
|
4
4
|
const endHour = 24;
|
|
5
5
|
const hours = endHour - startHour;
|
|
6
6
|
const cellHeight = 60;
|
|
7
|
-
// const slotDuration = 15;
|
|
8
|
-
// const slotHeight = cellHeight / (60 / slotDuration);
|
|
9
|
-
// states
|
|
10
|
-
const [events, setEvents] = useState([]);
|
|
11
|
-
// const [tempStart, setTempStart] = useState<{
|
|
12
|
-
// date: Date;
|
|
13
|
-
// minutes: number;
|
|
14
|
-
// } | null>(null);
|
|
15
|
-
// methods
|
|
16
|
-
// const handleClick = (weekDay: Date, hourIndex: number) => (event: React.MouseEvent<HTMLDivElement>) => {
|
|
17
|
-
// const rect = event.currentTarget.getBoundingClientRect();
|
|
18
|
-
// const y = event.clientY - rect.top;
|
|
19
|
-
// const slotIndex = Math.floor(y / slotHeight);
|
|
20
|
-
// const minutes = hourIndex * 60 + slotIndex * slotDuration;
|
|
21
|
-
// if (!tempStart) {
|
|
22
|
-
// setTempStart({ date: weekDay, minutes });
|
|
23
|
-
// return;
|
|
24
|
-
// }
|
|
25
|
-
// const startMinutes = Math.min(tempStart.minutes, minutes);
|
|
26
|
-
// const endMinutes = Math.max(tempStart.minutes, minutes) + slotDuration;
|
|
27
|
-
// const startDate = new Date(weekDay);
|
|
28
|
-
// startDate.setHours(Math.floor(startMinutes / 60), startMinutes % 60, 0, 0);
|
|
29
|
-
// const endDate = new Date(weekDay);
|
|
30
|
-
// endDate.setHours(Math.floor(endMinutes / 60), endMinutes % 60, 0, 0);
|
|
31
|
-
// setEvents((prev) => [...prev, { start: startDate, end: endDate }]);
|
|
32
|
-
// setTempStart(null);
|
|
33
|
-
// };
|
|
34
7
|
const weekDays = useMemo(() => getWeekDays(states.currentDate.get, config?.weekStartsOn ?? 1), [states.currentDate.get, config?.weekStartsOn]);
|
|
35
|
-
// useEffects
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
setEvents(data);
|
|
38
|
-
}, [data]);
|
|
39
8
|
return (React.createElement("div", { className: "ar-calendar-week-view" },
|
|
40
|
-
React.createElement("div", { className: "head" }, weekDays.map((day) => (React.createElement("div", { key: day.toISOString(), className: "item" },
|
|
41
|
-
React.createElement("span", { className: "day-name" }, day
|
|
42
|
-
.toLocaleString(config?.locale ?? "tr", {
|
|
43
|
-
weekday: "short",
|
|
44
|
-
})
|
|
45
|
-
.toUpperCase()),
|
|
9
|
+
React.createElement("div", { className: "head" }, weekDays.map((day) => (React.createElement("div", { key: day.toISOString(), className: "item", style: { flex: 1, textAlign: "center" } },
|
|
10
|
+
React.createElement("span", { className: "day-name" }, day.toLocaleString(config?.locale ?? "tr", { weekday: "short" }).toUpperCase()),
|
|
46
11
|
React.createElement("span", { className: "date" }, day.getDate()))))),
|
|
47
12
|
React.createElement("div", { className: "body" },
|
|
48
|
-
React.createElement("div", { className: "clocks" }, Array.from({ length: hours }, (_, index) => (React.createElement("div", { key: index },
|
|
13
|
+
React.createElement("div", { className: "clocks", style: { width: "50px" } }, Array.from({ length: hours }, (_, index) => (React.createElement("div", { key: index },
|
|
49
14
|
React.createElement("span", null,
|
|
50
15
|
String(startHour + index).padStart(2, "0"),
|
|
51
16
|
":00"))))),
|
|
52
17
|
React.createElement("div", { role: "grid", className: "grid" },
|
|
53
|
-
React.createElement("div", { className: "
|
|
54
|
-
|
|
55
|
-
|
|
18
|
+
Array.from({ length: hours }).map((_, rowIndex) => (React.createElement("div", { key: rowIndex, className: "row" }, weekDays.map((_, colIndex) => (React.createElement("div", { key: colIndex, className: "cell" })))))),
|
|
19
|
+
React.createElement("div", { className: "events-layer" }, data.flatMap((event, eventIdx) => {
|
|
20
|
+
const eventColor = getColor(eventIdx);
|
|
21
|
+
// Her etkinlik için haftanın günlerini gezip, o güne düşen parçayı hesaplıyoruz
|
|
22
|
+
return weekDays.map((day, dayIndex) => {
|
|
23
|
+
const dayStart = new Date(day);
|
|
24
|
+
dayStart.setHours(0, 0, 0, 0);
|
|
25
|
+
const dayEnd = new Date(day);
|
|
26
|
+
dayEnd.setHours(23, 59, 59, 999);
|
|
27
|
+
// Etkinlik bu günle kesişiyor mu?
|
|
28
|
+
const overlapStart = new Date(Math.max(event.start.getTime(), dayStart.getTime()));
|
|
29
|
+
const overlapEnd = new Date(Math.min(event.end.getTime(), dayEnd.getTime()));
|
|
30
|
+
if (overlapStart < overlapEnd) {
|
|
31
|
+
// Bu güne düşen kısmın yükseklik ve top değerleri
|
|
32
|
+
const startMinutes = overlapStart.getHours() * 60 + overlapStart.getMinutes();
|
|
33
|
+
const durationMinutes = (overlapEnd.getTime() - overlapStart.getTime()) / 60000;
|
|
34
|
+
const top = (startMinutes / 60) * cellHeight;
|
|
35
|
+
const height = (durationMinutes / 60) * cellHeight;
|
|
36
|
+
// Durum Kontrolleri
|
|
37
|
+
const isContinuedFromYesterday = event.start < dayStart;
|
|
38
|
+
const isContinuingTomorrow = event.end > dayEnd;
|
|
39
|
+
return (React.createElement("div", { key: `${eventIdx}-${dayIndex}`, className: "event-box", style: {
|
|
40
|
+
backgroundColor: eventColor.bg,
|
|
41
|
+
top: `${top}px`,
|
|
42
|
+
height: `${height}px`,
|
|
43
|
+
left: `${(100 / 7) * dayIndex}%`,
|
|
44
|
+
width: `${100 / 7}%`,
|
|
45
|
+
borderTop: isContinuedFromYesterday ? "none" : `1px solid ${eventColor.border}`,
|
|
46
|
+
borderBottom: isContinuingTomorrow ? "none" : `1px solid ${eventColor.border}`,
|
|
47
|
+
borderRadius: isContinuedFromYesterday
|
|
48
|
+
? "0 0 var(--border-radius-sm) var(--border-radius-sm)"
|
|
49
|
+
: isContinuingTomorrow
|
|
50
|
+
? "var(--border-radius-sm) var(--border-radius-sm) 0 0"
|
|
51
|
+
: "var(--border-radius-sm)",
|
|
52
|
+
} }, !isContinuedFromYesterday && renderItem(event, eventIdx)));
|
|
53
|
+
}
|
|
56
54
|
return null;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const top = (startMinutes / 60) * cellHeight;
|
|
60
|
-
const height = (durationMinutes / 60) * cellHeight;
|
|
61
|
-
return (React.createElement("div", { key: index, className: "event-box", style: {
|
|
62
|
-
top,
|
|
63
|
-
height,
|
|
64
|
-
left: `${(100 / 7) * dayIndex}%`,
|
|
65
|
-
} },
|
|
66
|
-
event.start.toLocaleTimeString(config?.locale ?? "tr-TR", {
|
|
67
|
-
hour: "2-digit",
|
|
68
|
-
minute: "2-digit",
|
|
69
|
-
}),
|
|
70
|
-
" - ",
|
|
71
|
-
event.end.toLocaleTimeString(config?.locale ?? "tr-TR", {
|
|
72
|
-
hour: "2-digit",
|
|
73
|
-
minute: "2-digit",
|
|
74
|
-
})));
|
|
75
|
-
})),
|
|
76
|
-
Array.from({ length: hours }).map((_, rowIndex) => (React.createElement("div", { key: rowIndex, className: "row" }, weekDays.map((_, colIndex) => (
|
|
77
|
-
// <div key={colIndex} className="cell" onClick={handleClick(weekDay, rowIndex)} />
|
|
78
|
-
React.createElement("div", { key: colIndex, className: "cell" }))))))))));
|
|
55
|
+
});
|
|
56
|
+
}))))));
|
|
79
57
|
};
|
|
58
|
+
// Yardımcı Fonksiyonlar aynı kalıyor
|
|
80
59
|
const getWeekRange = (date, weekStartsOn = 1) => {
|
|
81
60
|
const current = new Date(date);
|
|
82
61
|
const currentDay = current.getDay();
|
|
@@ -96,4 +75,16 @@ const getWeekDays = (date, weekStartsOn = 1) => {
|
|
|
96
75
|
return d;
|
|
97
76
|
});
|
|
98
77
|
};
|
|
78
|
+
const getColor = (id) => {
|
|
79
|
+
const colors = [
|
|
80
|
+
{ bg: "#3174ad", border: "#2a6293" }, // Mavi
|
|
81
|
+
{ bg: "#4caf50", border: "#388e3c" }, // Yeşil
|
|
82
|
+
{ bg: "#ff9800", border: "#f57c00" }, // Turuncu
|
|
83
|
+
{ bg: "#9c27b0", border: "#7b1fa2" }, // Mor
|
|
84
|
+
{ bg: "#e91e63", border: "#c2185b" }, // Pembe
|
|
85
|
+
{ bg: "#00bcd4", border: "#0097a7" }, // Turkuaz
|
|
86
|
+
];
|
|
87
|
+
const index = typeof id === "number" ? id : id.length;
|
|
88
|
+
return colors[index % colors.length];
|
|
89
|
+
};
|
|
99
90
|
export default Week;
|