Skip to content

Commit dbe19da

Browse files
committed
fix(Calendar): 增加默认值
1 parent d537b83 commit dbe19da

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/core/src/Calendar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default CalendarView
9696
| `bar` | 导航栏 | React.ReactNode | - |
9797
| `onChange` | 选择时间事件 | (value: string) => void | - |
9898
| `renderDay` | 自定义渲染日期额外内容 | (date:any) => React.ReactNode | JSX.Element | - |
99+
| `value` || Date | - |
99100

100101

101102
### bar 参数

packages/core/src/Calendar/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface CalendarProps extends ViewProps {
3232
showBar?: boolean;
3333
// 自定义渲染日期额外内容
3434
renderDay?: (date: any) => React.ReactNode | JSX.Element;
35+
// 值
36+
value?: Date;
3537
}
3638

3739
const Calendar = (props: CalendarProps) => {
@@ -50,6 +52,7 @@ const Calendar = (props: CalendarProps) => {
5052
onChange,
5153
showBar = true,
5254
renderDay,
55+
value,
5356
} = props;
5457
const { barRightText, title, barLeftText, onPressBarLeft, render } = bar;
5558
const [currentYear, setCurrentYear] = useState<number>(toYear);
@@ -60,6 +63,17 @@ const Calendar = (props: CalendarProps) => {
6063
const [nextData, setNextData] = useState<number[]>([]);
6164
const [lunarName, setLunarName] = useState('');
6265

66+
useEffect(() => {
67+
if (value) {
68+
let toYear = value.getFullYear();
69+
let toMonth = value.getMonth();
70+
let toDays = value.getDate();
71+
setCurrentYear(toYear);
72+
setCurrentMonth(toMonth);
73+
setCurrentDays(toDays);
74+
}
75+
}, [value]);
76+
6377
useEffect(() => {
6478
let toMonths = getMonths(currentYear, currentMonth, currentDays);
6579
setLastData(toMonths[0]);

0 commit comments

Comments
 (0)