Skip to content

Commit b946333

Browse files
committed
Simplify the shortcuts logic
1 parent 653b684 commit b946333

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

react-tailwindcss-datepicker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 21e1da23ca1591cc8fd3b7bcefae00c168b0a1b1

src/components/Shortcuts.tsx

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,37 +96,32 @@ const Shortcuts: React.FC = () => {
9696
Object.keys(configs.shortcuts).forEach(item => {
9797
if (Object.keys(DEFAULT_SHORTCUTS).includes(item)) {
9898
options.push([item, DEFAULT_SHORTCUTS[item]]);
99-
} else {
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);
100106
if (
101-
configs.shortcuts &&
102-
configs.shortcuts.custom &&
103-
configs.shortcuts.custom.length > 0
107+
text &&
108+
start.isValid() &&
109+
end.isValid() &&
110+
(start.isBefore(end) || start.isSame(end))
104111
) {
105-
configs.shortcuts.custom.forEach(customConfig => {
106-
const text = customConfig.text;
107-
const start = dayjs(customConfig.period.start);
108-
const end = dayjs(customConfig.period.end);
109-
if (
110-
text &&
111-
start.isValid() &&
112-
end.isValid() &&
113-
(start.isBefore(end) || start.isSame(end))
114-
) {
115-
options.push([
116-
text,
117-
{
118-
text,
119-
period: {
120-
start: start.format(DATE_FORMAT),
121-
end: end.format(DATE_FORMAT)
122-
}
123-
}
124-
]);
112+
options.push([
113+
text,
114+
{
115+
text,
116+
period: {
117+
start: start.format(DATE_FORMAT),
118+
end: end.format(DATE_FORMAT)
119+
}
125120
}
126-
});
121+
]);
127122
}
128-
}
129-
});
123+
});
124+
}
130125
} else {
131126
return Object.entries(DEFAULT_SHORTCUTS);
132127
}

0 commit comments

Comments
 (0)