Skip to content

Commit

Permalink
feat(Calendar): support panel-change event (#3385)
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao authored Dec 23, 2024
1 parent def5cf4 commit 58b67fc
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/calendar/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ name | params | description
change | `(value: timestamp)` | `0.28.0`
close | `(trigger: CalendarTrigger)` | `0.34.0`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/calendar/type.ts)。<br/>`type CalendarTrigger = 'close-btn' \| 'confirm-btn' \| 'overlay'`<br/>
confirm | `(value: timestamp)` | \-
panel-change | `(year: number; month: number)` | `1.8.4`
scroll | `({scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY})` | `1.4.6`。triggered when scrolling
select | `(value: timestamp)` | `0.28.0`

Expand All @@ -50,4 +51,4 @@ Name | Default Value | Description
--td-calendar-switch-mode-icon-color | @brand-color | -
--td-calendar-switch-mode-icon-disabled-color | @brand-color-disabled | -
--td-calendar-title-color | @text-color-primary | -
--td-calendar-title-font-size | 18px | -
--td-calendar-title-font-size | 18px | -
7 changes: 4 additions & 3 deletions src/calendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ title | String / Slot | - | 标题,不传默认为“请选择日期”。[通
type | String | 'single' | 日历的选择类型,single = 单选;multiple = 多选; range = 区间选择。可选项:single/multiple/range | N
use-popup | Boolean | true | `0.32.0`。是否使用弹出层包裹日历 | N
using-custom-navbar | Boolean | false | 是否使用了自定义导航栏 | N
value | Number / Array | - | 当前选择的日期,不传则默认今天,当 type = multiple 或 range 时传入数组。TS 类型:`number \| number[]` | N
default-value | Number / Array | undefined | 当前选择的日期,不传则默认今天,当 type = multiple 或 range 时传入数组。非受控属性。TS 类型:`number \| number[]` | N
value | Number / Array | - | 当前选择的日期,不传则选用 minDate 属性值或今天,优先级:minDate > today。当 type = multiple 或 range 时传入数组。TS 类型:`number \| number[]` | N
default-value | Number / Array | undefined | 当前选择的日期,不传则选用 minDate 属性值或今天,优先级:minDate > today。当 type = multiple 或 range 时传入数组。非受控属性。TS 类型:`number \| number[]` | N
visible | Boolean | false | 是否显示日历;`usePopup` 为 true 时有效 | N

### Calendar Events
Expand All @@ -97,6 +97,7 @@ visible | Boolean | false | 是否显示日历;`usePopup` 为 true 时有效 |
change | `(value: timestamp)` | `0.28.0`。不显示 confirm-btn 时,完成选择时触发(暂不支持 type = multiple)
close | `(trigger: CalendarTrigger)` | `0.34.0`。关闭按钮时触发。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/calendar/type.ts)。<br/>`type CalendarTrigger = 'close-btn' \| 'confirm-btn' \| 'overlay'`<br/>
confirm | `(value: timestamp)` | 点击确认按钮时触发
panel-change | `(year: number; month: number)` | `1.8.4`。切换月或年时触发(switch-mode 不为 none 时有效)
scroll | `({scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY})` | `1.4.6`。滚动时触发
select | `(value: timestamp)` | `0.28.0`。点击日期时触发

Expand All @@ -116,4 +117,4 @@ select | `(value: timestamp)` | `0.28.0`。点击日期时触发
--td-calendar-switch-mode-icon-color | @brand-color | -
--td-calendar-switch-mode-icon-disabled-color | @brand-color-disabled | -
--td-calendar-title-color | @text-color-primary | -
--td-calendar-title-font-size | 18px | -
--td-calendar-title-font-size | 18px | -
1 change: 1 addition & 0 deletions src/calendar/__test__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ exports[`Calendar Calendar switch-mode demo works fine 1`] = `
value="{{1645891200000}}"
visible="{{false}}"
bind:confirm="handleConfirm"
bind:panel-change="handlePanelChange"
/>
<t-cell
arrow="{{true}}"
Expand Down
5 changes: 5 additions & 0 deletions src/calendar/_example/switch-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ Component({
this.setData({ value: e.detail.value });
console.log(e.detail.value);
},

handlePanelChange(e) {
const { year, month } = e.detail;
console.log('year: ', year, 'month: ', month);
},
},
});
1 change: 1 addition & 0 deletions src/calendar/_example/switch-mode/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
minDate="{{minDate}}"
maxDate="{{maxDate}}"
bind:confirm="handleConfirm"
bind:panel-change="handlePanelChange"
/>
<t-cell arrow title="带翻页功能的日历" note="{{this.formatTimestamp(value)}}" bind:tap="handleCalendar" />
3 changes: 3 additions & 0 deletions src/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ export default class Calendar extends SuperComponent {
const newValue = funcMap[type]();
if (!newValue) return;

const { year, month } = this.getCurrentYearAndMonth(newValue);
this.triggerEvent('panel-change', { year, month: month + 1 });

this.calcCurrentMonth(newValue);
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ const props: TdCalendarProps = {
type: Boolean,
value: false,
},
/** 当前选择的日期,不传则默认今天,当 type = multiple 或 range 时传入数组 */
/** 当前选择的日期,不传则选用 minDate 属性值或今天,优先级:minDate > today。当 type = multiple 或 range 时传入数组 */
value: {
type: null,
value: null,
},
/** 当前选择的日期,不传则默认今天,当 type = multiple 或 range 时传入数组,非受控属性 */
/** 当前选择的日期,不传则选用 minDate 属性值或今天,优先级:minDate > today。当 type = multiple 或 range 时传入数组,非受控属性 */
defaultValue: {
type: null,
},
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ export interface TdCalendarProps {
value?: boolean;
};
/**
* 当前选择的日期,不传则默认今天,当 type = multiple 或 range 时传入数组
* 当前选择的日期,不传则选用 minDate 属性值或今天,优先级:minDate > today。当 type = multiple 或 range 时传入数组
*/
value?: {
type: null;
value?: number | number[];
};
/**
* 当前选择的日期,不传则默认今天,当 type = multiple 或 range 时传入数组,非受控属性
* 当前选择的日期,不传则选用 minDate 属性值或今天,优先级:minDate > today。当 type = multiple 或 range 时传入数组,非受控属性
*/
defaultValue?: {
type: null;
Expand Down

0 comments on commit 58b67fc

Please sign in to comment.