-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bruce-Jay <[email protected]>
- Loading branch information
Showing
3 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from "react"; | ||
import dayjs from "dayjs"; | ||
|
||
import "dayjs/locale/zh-cn"; | ||
|
||
import { Calendar, Col, Radio, Row, Select, theme, Typography } from "antd"; | ||
import type { CalendarProps } from "antd"; | ||
import type { Dayjs } from "dayjs"; | ||
import dayLocaleData from "dayjs/plugin/localeData"; | ||
|
||
dayjs.extend(dayLocaleData); | ||
|
||
const CustomCalendar: React.FC = () => { | ||
const { token } = theme.useToken(); | ||
|
||
const onPanelChange = (value: Dayjs, mode: CalendarProps<Dayjs>["mode"]) => { | ||
console.log(value.format("YYYY-MM-DD"), mode); | ||
}; | ||
|
||
const wrapperStyle: React.CSSProperties = { | ||
width: 300, | ||
border: `1px solid ${token.colorBorderSecondary}`, | ||
borderRadius: token.borderRadiusLG, | ||
}; | ||
|
||
return ( | ||
<div style={wrapperStyle}> | ||
<Calendar | ||
fullscreen={false} | ||
headerRender={({ value, onChange }) => { | ||
const start = 0; | ||
const end = 12; | ||
const monthOptions = []; | ||
|
||
let current = value.clone(); | ||
const localeData = value.localeData(); | ||
const months = []; | ||
for (let i = 0; i < 12; i++) { | ||
current = current.month(i); | ||
months.push(localeData.monthsShort(current)); | ||
} | ||
|
||
for (let i = start; i < end; i++) { | ||
monthOptions.push( | ||
<Select.Option key={i} value={i} className="month-item"> | ||
{months[i]} | ||
</Select.Option> | ||
); | ||
} | ||
|
||
const year = value.year(); | ||
const month = value.month(); | ||
const options = []; | ||
for (let i = year - 10; i < year + 10; i += 1) { | ||
options.push( | ||
<Select.Option key={i} value={i} className="year-item"> | ||
{i} | ||
</Select.Option> | ||
); | ||
} | ||
return ( | ||
<div style={{ padding: 8 }}> | ||
<Typography.Title level={4}>Custom header</Typography.Title> | ||
<Row gutter={8}> | ||
<Col> | ||
<Select | ||
size="small" | ||
popupMatchSelectWidth={false} | ||
className="my-year-select" | ||
value={year} | ||
onChange={(newYear) => { | ||
const now = value.clone().year(newYear); | ||
onChange(now); | ||
}} | ||
> | ||
{options} | ||
</Select> | ||
</Col> | ||
</Row> | ||
</div> | ||
); | ||
}} | ||
onPanelChange={onPanelChange} | ||
mode="year" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CustomCalendar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters