Skip to content

Commit

Permalink
feat(module:date-picker): add nzShowWeekNumber property (#7621)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleDave authored Sep 24, 2022
1 parent aecb788 commit 2cb80fc
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 11 deletions.
18 changes: 16 additions & 2 deletions components/date-picker/date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,18 @@ describe('NzDatePickerComponent', () => {
expect(element.classList.contains('ant-picker-dropdown-placement-bottomRight')).toBe(false);
expect(element.classList.contains('ant-picker-dropdown-placement-topRight')).toBe(true);
}));

it('should support nzShowWeekNumber', fakeAsync(() => {
fixtureInstance.nzShowWeekNumber = true;
fixture.detectChanges();
openPickerByClickTrigger();
expect(queryFromOverlay('.ant-picker-week-panel-row .ant-picker-cell-week')).toBeDefined();
fixtureInstance.nzShowWeekNumber = false;
fixture.detectChanges();
tick(500);
openPickerByClickTrigger();
expect(queryFromOverlay('.ant-picker-week-panel-row .ant-picker-cell-week')).toBeNull();
}));
});

describe('panel switch and move forward/afterward', () => {
Expand Down Expand Up @@ -1138,7 +1150,7 @@ describe('NzDatePickerComponent', () => {
return queryFromOverlay(`.${PREFIX_CLASS}-header-super-next-btn`);
}

describe('ngModel value accesors', () => {
describe('ngModel value accessors', () => {
beforeEach(() => (fixtureInstance.useSuite = 3));

it('should specified date provide by "modelValue" be chosen', fakeAsync(() => {
Expand Down Expand Up @@ -1356,14 +1368,15 @@ describe('in form', () => {
[nzInline]="nzInline"
[nzBackdrop]="nzBackdrop"
[nzPlacement]="nzPlacement"
[nzShowWeekNumber]="nzShowWeekNumber"
></nz-date-picker>
<ng-template #tplDateRender let-current>
<div [class.test-first-day]="current.getDate() === 1">{{ current.getDate() }}</div>
</ng-template>
<ng-template #tplExtraFooter>TEST_EXTRA_FOOTER</ng-template>
<!-- Suite 2 -->
<!-- use another picker to avoid nzOpen's side-effects beacuse nzOpen act as "true" if used -->
<!-- use another picker to avoid nzOpen's side-effects because nzOpen acts as "true" if used -->
<nz-date-picker *ngSwitchCase="2" [nzOpen]="nzOpen" (nzOnOpenChange)="nzOnOpenChange($event)"></nz-date-picker>
<!-- Suite 3 -->
Expand Down Expand Up @@ -1416,6 +1429,7 @@ class NzTestDatePickerComponent {
nzInline = false;
nzBackdrop = false;
nzPlacement = 'bottomLeft';
nzShowWeekNumber = false;

// nzRanges;
nzOnPanelChange(_: string): void {}
Expand Down
3 changes: 2 additions & 1 deletion components/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export type NzPlacement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
[isRange]="isRange"
[inline]="nzInline"
[defaultPickerValue]="nzDefaultPickerValue"
[showWeek]="nzMode === 'week'"
[showWeek]="nzShowWeekNumber || nzMode === 'week'"
[panelMode]="panelMode"
(panelModeChange)="onPanelModeChange($event)"
(calendarChange)="onCalendarChange($event)"
Expand Down Expand Up @@ -306,6 +306,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
@Input() @WithConfig() nzBackdrop = false;
@Input() nzId: string | null = null;
@Input() nzPlacement: NzPlacement = 'bottomLeft';
@Input() @InputBoolean() nzShowWeekNumber: boolean = false;

// TODO(@wenqi73) The PanelMode need named for each pickers and export
@Output() readonly nzOnPanelChange = new EventEmitter<NzDateMode | NzDateMode[] | string | string[]>();
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/date-range-popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { getTimeConfig, isAllowedDate, PREFIX_CLASS } from './util';
<ng-container *ngIf="isRange; else singlePanel">
<div class="{{ prefixCls }}-range-wrapper {{ prefixCls }}-date-range-wrapper">
<div class="{{ prefixCls }}-range-arrow" [style.left.px]="datePickerService?.arrowLeft"></div>
<div class="{{ prefixCls }}-panel-container">
<div class="{{ prefixCls }}-panel-container {{ showWeek ? prefixCls + '-week-number' : '' }}">
<div class="{{ prefixCls }}-panels">
<ng-container *ngIf="hasTimePicker; else noTimePicker">
<ng-container
Expand Down
14 changes: 14 additions & 0 deletions components/date-picker/demo/week-number.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 16
title:
zh-CN: 显示周数
en-US: Week Number
---

## zh-CN

使用 `nzShowWeekNumber` 显示周数

## en-US

Display week numbers with `nzShowWeekNumber`.
27 changes: 27 additions & 0 deletions components/date-picker/demo/week-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-date-picker-week-number',
template: `
<nz-radio-group [(ngModel)]="showWeekNumber">
<label nz-radio-button [nzValue]="true">true</label>
<label nz-radio-button [nzValue]="false">false</label>
</nz-radio-group>
<br />
<br />
<nz-date-picker [nzShowWeekNumber]="showWeekNumber"></nz-date-picker>
<br />
<nz-range-picker [nzShowWeekNumber]="showWeekNumber"></nz-range-picker>
`,
styles: [
`
nz-date-picker,
nz-range-picker {
margin: 0 8px 12px 0;
}
`
]
})
export class NzDemoDatePickerWeekNumberComponent {
showWeekNumber: boolean = false;
}
2 changes: 2 additions & 0 deletions components/date-picker/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The following APIs are shared by nz-date-picker, nz-range-picker.
| `[nzShowTime]` | to provide an additional time selection | `object \| boolean` | [TimePicker Options](/components/time-picker/en#api) |
| `[nzShowToday]` | whether to show 'Today' button | `boolean` | `true` |
| `[nzShowNow]` | whether to show 'Now' button on panel when `nzShowTime` is set | `boolean` | `true` |
| `[nzShowWeekNumber]` | whether to show the week number on each row (Only supported by date picker. Week picker always shows week numbers) | `boolean` | `false` |
| `(nzOnOk)` | callback when click ok button | `EventEmitter<Date>` | - |

### nz-range-picker
Expand All @@ -95,6 +96,7 @@ The following APIs are shared by nz-date-picker, nz-range-picker.
| -------- | ----------- | ---- | ------- |
| `[nzShowTime]` | to provide an additional time selection | `object \| boolean` | [TimePicker Options](/components/time-picker/en#api) |
| `[nzDisabledTime]` | to specify the time that cannot be selected | `(current: Date, partial: 'start' \| 'end') => { nzDisabledHours, nzDisabledMinutes, nzDisabledSeconds }` | - |
| `[nzShowWeekNumber]` | whether to show the week number on each row (Only supported by date picker. Week picker always shows week numbers) | `boolean` | `false` |
| `(nzOnOk)` | click ok callback | `EventEmitter<Date[]>` | - |

> Currently, supported `nz-time-picker` parameters in `nzShowTime` are: `nzFormat`, `nzHourStep`, `nzMinuteStep`, `nzSecondStep`, `nzDisabledHours`, `nzDisabledMinutes`, `nzDisabledSeconds`, `nzHideDisabledOptions`, `nzDefaultOpenValue`, `nzAddOn`
Expand Down
2 changes: 2 additions & 0 deletions components/date-picker/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ registerLocaleData(zh);
| `[nzShowTime]` | 增加时间选择功能 | `object \| boolean` | [TimePicker Options](/components/time-picker/zh#api) |
| `[nzShowToday]` | 是否展示“今天”按钮 | `boolean` | `true` |
| `[nzShowNow]` | 当设定了`nzShowTime`的时候,面板是否显示“此刻”按钮 | `boolean` | `true` |
| `[nzShowWeekNumber]` | 是否在每一行显示周数(仅日期选择器支持。周选择器始终显示周数) | `boolean` | `false` |
| `(nzOnOk)` | 点击确定按钮的回调 | `EventEmitter<Date>` | - |


Expand All @@ -96,6 +97,7 @@ registerLocaleData(zh);
| --- | --- | --- | --- |
| `[nzShowTime]` | 增加时间选择功能 | `object \| boolean` | [TimePicker Options](/components/time-picker/zh#api) |
| `[nzDisabledTime]` | 不可选择的时间 | `(current: Date, partial: 'start' \| 'end') => { nzDisabledHours, nzDisabledMinutes, nzDisabledSeconds }` | - |
| `[nzShowWeekNumber]` | 是否在每一行显示周数(仅日期选择器支持。周选择器始终显示周数) | `boolean` | `false` |
| `(nzOnOk)` | 点击确定按钮的回调 | `EventEmitter<Date[]>` | - |

> `nzShowTime` 中当前支持的 `nz-time-picker` 参数有:`nzFormat`, `nzHourStep`, `nzMinuteStep`, `nzSecondStep`, `nzDisabledHours`, `nzDisabledMinutes`, `nzDisabledSeconds`, `nzHideDisabledOptions`, `nzDefaultOpenValue`, `nzAddOn`
Expand Down
11 changes: 7 additions & 4 deletions components/date-picker/inner-popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ import { PREFIX_CLASS } from './util';
<date-header
[(value)]="activeDate"
[locale]="locale"
[showSuperPreBtn]="showWeek ? enablePrevNext('prev', 'week') : enablePrevNext('prev', 'date')"
[showSuperNextBtn]="showWeek ? enablePrevNext('next', 'week') : enablePrevNext('next', 'date')"
[showPreBtn]="showWeek ? enablePrevNext('prev', 'week') : enablePrevNext('prev', 'date')"
[showNextBtn]="showWeek ? enablePrevNext('next', 'week') : enablePrevNext('next', 'date')"
[showSuperPreBtn]="panelMode === 'week' ? enablePrevNext('prev', 'week') : enablePrevNext('prev', 'date')"
[showSuperNextBtn]="
panelMode === 'week' ? enablePrevNext('next', 'week') : enablePrevNext('next', 'date')
"
[showPreBtn]="panelMode === 'week' ? enablePrevNext('prev', 'week') : enablePrevNext('prev', 'date')"
[showNextBtn]="panelMode === 'week' ? enablePrevNext('next', 'week') : enablePrevNext('next', 'date')"
(panelModeChange)="panelModeChange.emit($event)"
(valueChange)="headerChange.emit($event)"
></date-header>
Expand All @@ -123,6 +125,7 @@ import { PREFIX_CLASS } from './util';
[cellRender]="dateRender"
[selectedValue]="selectedValue"
[hoverValue]="hoverValue"
[canSelectWeek]="panelMode === 'week'"
(valueChange)="onSelectDate($event)"
(cellHover)="cellHover.emit($event)"
></date-table>
Expand Down
2 changes: 2 additions & 0 deletions components/date-picker/lib/abstract-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export abstract class AbstractTable implements OnInit, OnChanges {
@Input() disabledDate?: (d: Date) => boolean;
@Input() cellRender?: string | TemplateRef<Date> | FunctionProp<TemplateRef<Date> | string>;
@Input() fullCellRender?: string | TemplateRef<Date> | FunctionProp<TemplateRef<Date> | string>;
@Input() canSelectWeek: boolean = false;

@Output() readonly valueChange = new EventEmitter<CandyDate>();
@Output() readonly cellHover = new EventEmitter<CandyDate>(); // Emitted when hover on a day by mouse enter
Expand Down Expand Up @@ -90,6 +91,7 @@ export abstract class AbstractTable implements OnInit, OnChanges {
changes.disabledDate ||
changes.locale ||
changes.showWeek ||
changes.selectWeek ||
this.isDateRealChange(changes.activeDate) ||
this.isDateRealChange(changes.value) ||
this.isDateRealChange(changes.selectedValue) ||
Expand Down
6 changes: 3 additions & 3 deletions components/date-picker/lib/date-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ export class DateTableComponent extends AbstractTable implements OnChanges, OnIn
row.dateCells.push(cell);
}
row.classMap = {
[`ant-picker-week-panel-row`]: this.showWeek,
[`ant-picker-week-panel-row-selected`]: this.showWeek && row.isActive
[`ant-picker-week-panel-row`]: this.canSelectWeek,
[`ant-picker-week-panel-row-selected`]: this.canSelectWeek && row.isActive
};
weekRows.push(row);
}
return weekRows;
}

addCellProperty(cell: DateCell, date: CandyDate): void {
if (this.hasRangeValue() && !this.showWeek) {
if (this.hasRangeValue() && !this.canSelectWeek) {
const [startHover, endHover] = this.hoverValue;
const [startSelected, endSelected] = this.selectedValue;
// Selected
Expand Down
9 changes: 9 additions & 0 deletions components/date-picker/style/patch.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@
top: unset;
left: unset;
}

// ensure table is correct width to display week numbers in date mode
.@{picker-prefix-cls}-panel-container.@{picker-prefix-cls}-week-number .@{picker-prefix-cls}-date-panel .@{picker-prefix-cls}-content {
width: 100%;

th {
width: inherit;
}
}

0 comments on commit 2cb80fc

Please sign in to comment.