Skip to content

Commit ca0c824

Browse files
authored
Feat/date picker panel header locale (#568)
* feat: year and month header will in locale order * fix: picker header overflow and preview button font * build: add missing build storybook styles * feat: mod style inject method and mod reset body bg * chore: remove title and fix build error * style: add range-picker header overflow fix * Create wicked-comics-return.md * chore: mv monthBeforeYear to service and refactor * feat: add header locale and mod style * chore: fix unit test case * feat: trigger show date use locale format default * feat: mod style var and storybook preview
1 parent a78dbef commit ca0c824

18 files changed

+303
-107
lines changed

.changeset/wicked-comics-return.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/ui": patch
3+
---
4+
5+
Feat/date picker panel header locale

.storybook/global.scss

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import './reset-browser';
2+
@import '../src/theme/style.scss';

.storybook/preview.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { addons } from '@storybook/addons';
33
import type { Preview } from '@storybook/angular';
44

55
import docJson from '../documentation.json';
6+
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved
7+
import '!style-loader!css-loader!sass-loader!./global.scss';
68

79
setCompodocJson(docJson);
810

.storybook/reset-browser.scss

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
@import '../src/theme/var';
2+
@import '../src/theme/mixin';
3+
4+
* {
5+
&,
6+
&:before,
7+
&:after {
8+
margin: 0;
9+
padding: 0;
10+
border: 0;
11+
font: inherit;
12+
box-sizing: border-box;
13+
vertical-align: baseline;
14+
}
15+
16+
&:focus {
17+
outline: none;
18+
}
19+
}
20+
21+
em {
22+
font-style: italic;
23+
}
24+
25+
ol {
26+
list-style: decimal;
27+
margin-left: 16px;
28+
}
29+
30+
ul {
31+
list-style: none;
32+
}
33+
34+
blockquote,
35+
q {
36+
quotes: none;
37+
38+
&:before,
39+
&:after {
40+
content: '';
41+
content: none;
42+
}
43+
}
44+
45+
table {
46+
border-collapse: collapse;
47+
border-spacing: 0;
48+
}
49+
50+
body {
51+
-webkit-font-smoothing: auto;
52+
-moz-osx-font-smoothing: auto;
53+
display: flex;
54+
align-items: center;
55+
justify-content: center;
56+
min-width: 100%;
57+
min-height: 100%;
58+
color: use-text-color(main);
59+
background-color: use-rgb(n-10);
60+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
61+
Arial, 'Microsoft YaHei', sans-serif;
62+
font-size: 14px;
63+
font-weight: 400;
64+
line-height: 1.43;
65+
}
66+
67+
pre,
68+
code {
69+
font-family: Menlo, Monaco, 'Courier New', monospace;
70+
white-space: pre-wrap;
71+
font-size: 14px;
72+
line-height: 20px;
73+
padding: 12px;
74+
background: use-rgb(n-9);
75+
border-radius: 2px;
76+
77+
&[ngCodeColorize] {
78+
padding: 0 12px;
79+
}
80+
}
81+
82+
input:-webkit-autofill,
83+
input:-webkit-autofill:hover,
84+
input:-webkit-autofill:focus,
85+
input:-webkit-autofill:active {
86+
-webkit-text-fill-color: #{use-text-color(main)} !important;
87+
box-shadow: 0 0 0 3000px #{use-rgb(main-bg)} inset !important;
88+
}
89+
90+
[hidden] {
91+
display: none !important;
92+
}

src/date-picker/calendar/header/component.ts

+48-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import {
66
Input,
77
Output,
88
ViewEncapsulation,
9+
computed,
10+
signal,
911
} from '@angular/core';
1012
import dayjs, { ConfigType, Dayjs } from 'dayjs';
1113

1214
import { ButtonComponent } from '../../../button/button.component';
13-
import { I18nPipe } from '../../../i18n/i18n.pipe';
15+
import { I18nPipe, I18nService } from '../../../i18n';
1416
import { IconComponent } from '../../../icon/icon.component';
1517
import { buildBem } from '../../../internal/utils';
16-
import {
17-
CalendarHeaderRange,
18-
DateNavRange,
19-
Side,
20-
} from '../../date-picker.type';
18+
import { DateNavRange, Side } from '../../date-picker.type';
2119
import { MONTH, YEAR } from '../constant';
2220
import { calcRangeValue } from '../util';
2321

@@ -34,10 +32,28 @@ const bem = buildBem('aui-calendar-header');
3432
})
3533
export class CalendarHeaderComponent {
3634
@Input()
37-
dateNavRange = DateNavRange.Month;
35+
get dateNavRange() {
36+
return this.$$dateNavRange();
37+
}
38+
39+
set dateNavRange(val) {
40+
if (!val || this.$$dateNavRange() === val) {
41+
return;
42+
}
43+
this.$$dateNavRange.set(val);
44+
}
3845

3946
@Input()
40-
anchor = dayjs();
47+
get anchor() {
48+
return this.$$anchor();
49+
}
50+
51+
set anchor(val) {
52+
if (!val || this.$$anchor() === val) {
53+
return;
54+
}
55+
this.$$anchor.set(val);
56+
}
4157

4258
@Input()
4359
maxAvail?: ConfigType;
@@ -59,14 +75,35 @@ export class CalendarHeaderComponent {
5975
@Output()
6076
anchorChange = new EventEmitter<Dayjs>();
6177

62-
get headerRange(): CalendarHeaderRange {
63-
return calcRangeValue(this.dateNavRange, this.anchor);
64-
}
78+
private readonly $$dateNavRange = signal(DateNavRange.Month);
79+
private readonly $$anchor = signal(dayjs());
6580

6681
bem = bem;
6782

6883
DateNavRange = DateNavRange;
6984

85+
$monthBeforeYear = this.i18nService.$monthBeforeYear;
86+
87+
$headerRange = computed(() => {
88+
const locale = this.i18nService.$locale();
89+
const [start, end] = Object.values(
90+
calcRangeValue(this.$$dateNavRange(), this.$$anchor()),
91+
).map(date => date.toDate());
92+
93+
return {
94+
start: {
95+
year: start.toLocaleDateString(locale, { year: 'numeric' }),
96+
month: start.toLocaleDateString(locale, { month: 'short' }),
97+
},
98+
end: {
99+
year: end?.toLocaleDateString(locale, { year: 'numeric' }),
100+
month: end?.toLocaleDateString(locale, { month: 'short' }),
101+
},
102+
};
103+
});
104+
105+
constructor(private readonly i18nService: I18nService) {}
106+
70107
// maxAvail > current date :right btn hide
71108
// minAvail > current date :left btn hide
72109
shouldShowNav(type: DateNavRange, side: Side) {

src/date-picker/calendar/header/style.scss

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
$block: aui-calendar-header;
44

5+
$aui-text-button-mini-width: use-var(inline-height-xs);
6+
$aui-text-button-mini-spacing: use-var(spacing-s);
7+
58
.#{$block} {
69
&__container {
710
height: 24px;
@@ -12,6 +15,9 @@ $block: aui-calendar-header;
1215

1316
&__nav-content {
1417
flex: 1;
18+
max-width: calc(
19+
100% - $aui-text-button-mini-width * 4 - $aui-text-button-mini-spacing * 2
20+
);
1521
display: flex;
1622
flex-wrap: wrap;
1723
justify-content: center;
@@ -43,6 +49,10 @@ $block: aui-calendar-header;
4349
margin-left: 0;
4450
}
4551
}
52+
53+
.aui-button--text.header-range {
54+
max-width: 100%;
55+
}
4656
}
4757
}
4858

src/date-picker/calendar/header/template.html

+36-19
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,13 @@
1717
*ngIf="dateNavRange === DateNavRange.Month"
1818
[class]="bem.element('nav-content')"
1919
>
20-
<button
21-
aui-button="text"
22-
(click)="clickNav(DateNavRange.Year)"
23-
>
24-
{{ headerRange?.start?.year() }}{{ 'year_suffix' | auiI18n }}
25-
</button>
26-
<div class="separator">
27-
<span *ngIf="!('year_suffix' | auiI18n) && !('month_suffix' | auiI18n)">
28-
/
29-
</span>
30-
</div>
31-
<button
32-
aui-button="text"
33-
(click)="clickNav(DateNavRange.Month)"
34-
>
35-
{{ headerRange?.start?.month() + 1 }}{{ 'month_suffix' | auiI18n }}
36-
</button>
20+
<ng-container
21+
[ngTemplateOutlet]="$monthBeforeYear() ? monthTemplate : yearTemplate"
22+
></ng-container>
23+
<div class="separator"></div>
24+
<ng-container
25+
[ngTemplateOutlet]="$monthBeforeYear() ? yearTemplate : monthTemplate"
26+
></ng-container>
3727
</span>
3828

3929
<span
@@ -44,15 +34,15 @@
4434
aui-button="text"
4535
(click)="clickNav(DateNavRange.Year)"
4636
>
47-
{{ headerRange?.start?.year() }}{{ 'year_suffix' | auiI18n }}
37+
{{ $headerRange().start.year }}
4838
</button>
4939
</span>
5040

5141
<span
5242
*ngIf="dateNavRange === DateNavRange.Decade"
5343
[class]="bem.element('nav-content')"
5444
>
55-
{{ headerRange?.start.year() }} - {{ headerRange?.end?.year() }}
45+
{{ $headerRange().start.year }} - {{ $headerRange().end.year }}
5646
</span>
5747

5848
<div [class]="bem.element('nav-action')">
@@ -77,6 +67,8 @@
7767
<span class="action-bar">
7868
<button
7969
aui-button="text"
70+
size="mini"
71+
[square]="true"
8072
*ngIf="side === 'right'"
8173
[class.hidden]="
8274
!shouldShowNav(DateNavRange.Month, side) ||
@@ -88,6 +80,8 @@
8880
</button>
8981
<button
9082
aui-button="text"
83+
size="mini"
84+
[square]="true"
9185
(click)="navHead(DateNavRange.Year, side === 'left' ? -1 : 1)"
9286
[class.hidden]="!shouldShowNav(DateNavRange.Year, side)"
9387
>
@@ -97,6 +91,8 @@
9791
</button>
9892
<button
9993
aui-button="text"
94+
size="mini"
95+
[square]="true"
10096
*ngIf="side === 'left'"
10197
[class.hidden]="
10298
!shouldShowNav(DateNavRange.Month, side) ||
@@ -115,6 +111,8 @@
115111
>
116112
<button
117113
aui-button="text"
114+
size="mini"
115+
[square]="true"
118116
(click)="navHead(DateNavRange.Decade, side === 'left' ? -10 : 10)"
119117
[class.hidden]="!shouldShowNav(DateNavRange.Decade, side)"
120118
>
@@ -123,3 +121,22 @@
123121
></aui-icon>
124122
</button>
125123
</ng-template>
124+
125+
<ng-template #yearTemplate>
126+
<button
127+
aui-button="text"
128+
class="header-range"
129+
(click)="clickNav(DateNavRange.Year)"
130+
>
131+
{{ $headerRange().start.year }}
132+
</button>
133+
</ng-template>
134+
<ng-template #monthTemplate>
135+
<button
136+
aui-button="text"
137+
class="header-range"
138+
(click)="clickNav(DateNavRange.Month)"
139+
>
140+
{{ $headerRange().start.month }}
141+
</button>
142+
</ng-template>

src/date-picker/calendar/range-picker-panel/style.scss

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ $block: aui-date-range-picker-panel;
4141

4242
aui-calendar-header {
4343
flex: 0 0 $range-picker-header-width;
44+
max-width: 50%;
4445
}
4546
}
4647

0 commit comments

Comments
 (0)