Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export default function Playground() {
period: {
start: new Date(new Date().setDate(new Date().getDate() - 3)),
end: new Date()
},
onClick: (text, e) => {
console.log("on click", text, e);
}
},
thisDay: {
Expand Down
15 changes: 12 additions & 3 deletions src/components/Shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ const ItemTemplate = React.memo((props: ItemTemplateProps) => {
return (
<li
className={getClassName()}
onClick={() => {
onClick={e => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
chosePeriod(props?.item.period);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
props?.item?.onClick && props?.item.onClick(props?.item.text, e);
}}
>
{children}
Expand All @@ -97,9 +101,13 @@ const Shortcuts: React.FC = () => {
return [[key, DEFAULT_SHORTCUTS[key]]];
}

const { text, period } = customConfig as {
const { text, period, onClick } = customConfig as {
text: string;
period: { start: string; end: string };
onClick?: (
text: string,
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
) => void;
};
if (!text || !period) {
return [];
Expand All @@ -117,7 +125,8 @@ const Shortcuts: React.FC = () => {
period: {
start: start.format(DATE_FORMAT),
end: end.format(DATE_FORMAT)
}
},
onClick: onClick
}
]
];
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ShortcutsItem {
start: Date | string;
end: Date | string;
};
onClick?: (text: string, e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
}

export type DateType = string | null | Date;
Expand Down