Skip to content

Commit 1316205

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents d99cdb7 + 9d744e2 commit 1316205

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

src/components/Calendar/Days.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,18 @@ const Days: React.FC<Props> = ({
204204
);
205205

206206
const buttonClass = useCallback(
207-
(day: number, type: "current" | "previous" | "next") => {
207+
(day: number, type: "current" | "next" | "previous") => {
208208
const baseClass = "flex items-center justify-center w-12 h-12 lg:w-10 lg:h-10";
209-
return cn(
210-
baseClass,
211-
!activeDateData(day).active ? hoverClassByDay(day) : activeDateData(day).className,
212-
isDateDisabled(day, type) && "line-through"
213-
);
209+
if (type === "current") {
210+
return cn(
211+
baseClass,
212+
!activeDateData(day).active
213+
? hoverClassByDay(day)
214+
: activeDateData(day).className,
215+
isDateDisabled(day, type) && "line-through"
216+
);
217+
}
218+
return cn(baseClass, isDateDisabled(day, type) && "line-through", "text-gray-400");
214219
},
215220
[activeDateData, hoverClassByDay, isDateDisabled]
216221
);
@@ -345,7 +350,7 @@ const Days: React.FC<Props> = ({
345350
type="button"
346351
key={index}
347352
disabled={isDateDisabled(item, "previous")}
348-
className="flex items-center justify-center text-gray-400 h-12 w-12 lg:w-10 lg:h-10"
353+
className={`${buttonClass(item, "previous")}`}
349354
onClick={() => handleClickDay(item, "previous")}
350355
onMouseOver={() => {
351356
hoverDay(item, "previous");
@@ -375,7 +380,7 @@ const Days: React.FC<Props> = ({
375380
type="button"
376381
key={index}
377382
disabled={isDateDisabled(item, "next")}
378-
className="flex items-center justify-center text-gray-400 h-12 w-12 lg:w-10 lg:h-10"
383+
className={`${buttonClass(item, "next")}`}
379384
onClick={() => handleClickDay(item, "next")}
380385
onMouseOver={() => {
381386
hoverDay(item, "next");

src/components/Shortcuts.tsx

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,41 +91,43 @@ const Shortcuts: React.FC = () => {
9191
}, []);
9292

9393
const shortcutOptions = useMemo<[string, ShortcutsItem | ShortcutsItem[]][]>(() => {
94-
const options: [string, ShortcutsItem | ShortcutsItem[]][] = [];
95-
if (configs && configs.shortcuts) {
96-
Object.keys(configs.shortcuts).forEach(item => {
97-
if (Object.keys(DEFAULT_SHORTCUTS).includes(item)) {
98-
options.push([item, DEFAULT_SHORTCUTS[item]]);
99-
}
100-
});
101-
if (configs.shortcuts.custom && configs.shortcuts.custom.length > 0) {
102-
configs.shortcuts.custom.forEach(customConfig => {
103-
const text = customConfig.text;
104-
const start = dayjs(customConfig.period.start);
105-
const end = dayjs(customConfig.period.end);
106-
if (
107-
text &&
108-
start.isValid() &&
109-
end.isValid() &&
110-
(start.isBefore(end) || start.isSame(end))
111-
) {
112-
options.push([
94+
if (!configs?.shortcuts) {
95+
return Object.entries(DEFAULT_SHORTCUTS);
96+
}
97+
98+
return Object.entries(configs.shortcuts).flatMap(([key, customConfig]) => {
99+
if (Object.prototype.hasOwnProperty.call(DEFAULT_SHORTCUTS, key)) {
100+
return [[key, DEFAULT_SHORTCUTS[key]]];
101+
}
102+
103+
const { text, period } = customConfig as {
104+
text: string;
105+
period: { start: string; end: string };
106+
};
107+
if (!text || !period) {
108+
return [];
109+
}
110+
111+
const start = dayjs(period.start);
112+
const end = dayjs(period.end);
113+
114+
if (start.isValid() && end.isValid() && (start.isBefore(end) || start.isSame(end))) {
115+
return [
116+
[
117+
text,
118+
{
113119
text,
114-
{
115-
text,
116-
period: {
117-
start: start.format(DATE_FORMAT),
118-
end: end.format(DATE_FORMAT)
119-
}
120+
period: {
121+
start: start.format(DATE_FORMAT),
122+
end: end.format(DATE_FORMAT)
120123
}
121-
]);
122-
}
123-
});
124+
}
125+
]
126+
];
124127
}
125-
} else {
126-
return Object.entries(DEFAULT_SHORTCUTS);
127-
}
128-
return options;
128+
129+
return [];
130+
});
129131
}, [configs]);
130132

131133
const printItemText = useCallback((item: ShortcutsItem) => {

src/types/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ export interface Period {
77
end: string | null;
88
}
99

10+
interface CustomShortcuts {
11+
[key: string]: ShortcutsItem;
12+
}
13+
1014
interface DefaultShortcuts {
1115
today?: string;
1216
yesterday?: string;
1317
past?: (period: number) => string;
1418
currentMonth?: string;
1519
pastMonth?: string;
16-
custom?: ShortcutsItem[];
1720
}
1821
export interface Configs {
19-
shortcuts?: DefaultShortcuts;
22+
shortcuts?: DefaultShortcuts | CustomShortcuts;
2023
footer?: {
2124
cancel?: string;
2225
apply?: string;

0 commit comments

Comments
 (0)